Initial Grease Pencil 3.0 stage #106848
|
@ -50,7 +50,7 @@ class TreeNode : public ::GreasePencilLayerTreeNode {
|
|||
}
|
||||
|
||||
TreeNode &operator=(const TreeNode &other) = delete;
|
||||
TreeNode &operator=(TreeNode &&other) = delete;
|
||||
~TreeNode()
|
||||
virtual ~TreeNode()
|
||||
{
|
||||
if (this->name) {
|
||||
MEM_freeN(this->name);
|
||||
|
@ -219,6 +219,9 @@ class Layer : public TreeNode, ::GreasePencilLayer {
|
|||
}
|
||||
return *this;
|
||||
}
|
||||
~Layer()
|
||||
Hans Goudey
commented
Returning an element added to a vector by reference is quite dangerous since they're invalidated by further additions, we usually don't do that. Either returning an index or not having these wrapper functions seems like the best choices IMO Returning an element added to a vector by reference is quite dangerous since they're invalidated by further additions, we usually don't do that. Either returning an index or not having these wrapper functions seems like the best choices IMO
Sergey Sharybin
commented
From quick look it seems that it should actually be From quick look it seems that it should actually be `emplace_layer()` or something like this.
And for that it is typically very handy to return reference. And not only that, since C++17 it is expected behavior for vector type containers as well.
Falk David
commented
I think I think `emplace_layer` would be a better name indeed.
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const Layer &other) const
|
||||
{
|
||||
|
@ -228,11 +231,6 @@ class Layer : public TreeNode, ::GreasePencilLayer {
|
|||
{
|
||||
return this != &other;
|
||||
}
|
||||
|
||||
Layer &as_layer()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class LayerGroup : public TreeNode {
|
||||
|
|
|
@ -14,11 +14,11 @@ TEST(gpencil, build_layer_tree)
|
|||
LayerGroup root{};
|
||||
|
||||
LayerGroup group("Group1");
|
||||
group.add_layer(Layer("Child1"));
|
||||
group.add_layer(Layer("Child2"));
|
||||
group.add_layer(Layer("Layer1"));
|
||||
group.add_layer(Layer("Layer2"));
|
||||
|
||||
Sergey Sharybin
commented
Use text fixtures: http://google.github.io/googletest/primer.html#same-data-multiple-tests Use text fixtures: http://google.github.io/googletest/primer.html#same-data-multiple-tests
Falk David
commented
I used fixtures before, but decided to use this approach instead, because all the tests are then under the same I used fixtures before, but decided to use this approach instead, because all the tests are then under the same `greasepencil` namespace. I didn't find a way to do this with fixtures, unless I name the class literally `greasepencil`.
Sergey Sharybin
commented
You can't do that either. It is at a very least discouraged to use the same name for fixture and "regular" test. Typically the "namespace" defines context you're testing, and it is perfectly fine to have multiple of such contexts per file ( I would love to improve the monolithic state of tests at some point (as it is really in a way every time I work on test), but that is outside of the scope of this patch. Would be nice to add a comment on top of the You can't do that either. It is at a very least discouraged to use the same name for fixture and "regular" test.
Typically the "namespace" defines context you're testing, and it is perfectly fine to have multiple of such contexts per file (`euclidean_resection_test.cc`). But with the monolithic nature of BKE/BLI tests there is no good way to achieve the same behavior.
I would love to improve the monolithic state of tests at some point (as it is really in a way every time I work on test), but that is outside of the scope of this patch.
Would be nice to add a comment on top of the `GreasePencilIDTestContext` which briefly summarizes your choice of this approach. Basically, so if someone else stumbles on this code and winders "why not fixtures" they have an answer.
|
||||
root.add_group(std::move(group));
|
||||
root.add_layer(Layer("Group2"));
|
||||
root.add_layer(Layer("Layer3"));
|
||||
|
||||
root.foreach_children_pre_order([](TreeNode &child) { std::cout << child.name << std::endl; });
|
||||
}
|
||||
|
|
Is defining these as
constexpr
helpful? I sort of doubt any real computation is done on these nodes at compile time. But maybe?The
const
in theconst bool
return type means nothing here