Cleanup: GPv3: Constructors and destructors
The `TreeNode`, `Layer` and `LayerGroup` constructors and destructors had some inconsistencies. Now the code is a bit more clean and shared.
This commit is contained in:
@@ -194,6 +194,7 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
|
||||
explicit TreeNode(GreasePencilLayerTreeNodeType type);
|
||||
explicit TreeNode(GreasePencilLayerTreeNodeType type, StringRefNull name);
|
||||
TreeNode(const TreeNode &other);
|
||||
~TreeNode();
|
||||
|
||||
public:
|
||||
/* Define the common functions for #TreeNode. */
|
||||
|
||||
@@ -441,15 +441,18 @@ TreeNode::TreeNode(GreasePencilLayerTreeNodeType type, StringRefNull name) : Tre
|
||||
}
|
||||
|
||||
TreeNode::TreeNode(const TreeNode &other)
|
||||
: TreeNode::TreeNode(GreasePencilLayerTreeNodeType(other.type))
|
||||
: TreeNode(GreasePencilLayerTreeNodeType(other.type))
|
||||
{
|
||||
if (!other.name().is_empty()) {
|
||||
this->GreasePencilLayerTreeNode::name = BLI_strdup(other.name().c_str());
|
||||
}
|
||||
this->GreasePencilLayerTreeNode::name = BLI_strdup_null(other.GreasePencilLayerTreeNode::name);
|
||||
this->flag = other.flag;
|
||||
copy_v3_v3_uchar(this->color, other.color);
|
||||
}
|
||||
|
||||
TreeNode::~TreeNode()
|
||||
{
|
||||
MEM_SAFE_FREE(this->GreasePencilLayerTreeNode::name);
|
||||
}
|
||||
|
||||
void TreeNode::set_name(StringRefNull name)
|
||||
{
|
||||
this->GreasePencilLayerTreeNode::name = BLI_strdup(name.c_str());
|
||||
@@ -513,7 +516,7 @@ LayerMask::~LayerMask()
|
||||
|
||||
Layer::Layer()
|
||||
{
|
||||
this->base = TreeNode(GP_LAYER_TREE_LEAF);
|
||||
new (&this->base) TreeNode(GP_LAYER_TREE_LEAF);
|
||||
|
||||
this->frames_storage.num = 0;
|
||||
this->frames_storage.keys = nullptr;
|
||||
@@ -529,12 +532,12 @@ Layer::Layer()
|
||||
|
||||
Layer::Layer(StringRefNull name) : Layer()
|
||||
{
|
||||
this->base.name = BLI_strdup(name.c_str());
|
||||
new (&this->base) TreeNode(GP_LAYER_TREE_LEAF, name);
|
||||
}
|
||||
|
||||
Layer::Layer(const Layer &other) : Layer()
|
||||
{
|
||||
this->base = TreeNode(other.base.wrap());
|
||||
new (&this->base) TreeNode(other.base.wrap());
|
||||
|
||||
/* TODO: duplicate masks. */
|
||||
|
||||
@@ -550,7 +553,8 @@ Layer::Layer(const Layer &other) : Layer()
|
||||
|
||||
Layer::~Layer()
|
||||
{
|
||||
MEM_SAFE_FREE(this->base.name);
|
||||
this->base.wrap().~TreeNode();
|
||||
|
||||
MEM_SAFE_FREE(this->frames_storage.keys);
|
||||
MEM_SAFE_FREE(this->frames_storage.values);
|
||||
|
||||
@@ -758,7 +762,7 @@ void Layer::tag_frames_map_keys_changed()
|
||||
|
||||
LayerGroup::LayerGroup()
|
||||
{
|
||||
this->base = TreeNode(GP_LAYER_TREE_GROUP);
|
||||
new (&this->base) TreeNode(GP_LAYER_TREE_GROUP);
|
||||
|
||||
BLI_listbase_clear(&this->children);
|
||||
|
||||
@@ -767,12 +771,12 @@ LayerGroup::LayerGroup()
|
||||
|
||||
LayerGroup::LayerGroup(StringRefNull name) : LayerGroup()
|
||||
{
|
||||
this->base.name = BLI_strdup(name.c_str());
|
||||
new (&this->base) TreeNode(GP_LAYER_TREE_GROUP, name);
|
||||
}
|
||||
|
||||
LayerGroup::LayerGroup(const LayerGroup &other) : LayerGroup()
|
||||
{
|
||||
this->base = TreeNode(other.base.wrap());
|
||||
new (&this->base) TreeNode(other.base.wrap());
|
||||
|
||||
LISTBASE_FOREACH (GreasePencilLayerTreeNode *, child, &other.children) {
|
||||
switch (child->type) {
|
||||
@@ -794,7 +798,7 @@ LayerGroup::LayerGroup(const LayerGroup &other) : LayerGroup()
|
||||
|
||||
LayerGroup::~LayerGroup()
|
||||
{
|
||||
MEM_SAFE_FREE(this->base.name);
|
||||
this->base.wrap().~TreeNode();
|
||||
|
||||
LISTBASE_FOREACH_MUTABLE (GreasePencilLayerTreeNode *, child, &this->children) {
|
||||
switch (child->type) {
|
||||
|
||||
Reference in New Issue
Block a user