From 158caafa2a2861c88de11611584f0f7fb94340b3 Mon Sep 17 00:00:00 2001 From: heck Date: Sat, 10 Jul 2021 13:35:51 +0200 Subject: [PATCH] Test: PityTest - PityTree addCopy() for lvalue refs, too, please, add getChildrenCount(), debatable, copy-assign i think i like to avoid it. --- src/PityTree.hh | 9 +++++++-- src/PityTree.hxx | 31 ++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/PityTree.hh b/src/PityTree.hh index 2b0056d..c1a5bf8 100644 --- a/src/PityTree.hh +++ b/src/PityTree.hh @@ -29,7 +29,7 @@ namespace pEp { explicit PityTree(const PityTree& rhs, T& owner); // copy-assign - PityTree& operator=(const PityTree& rhs); +// PityTree& operator=(const PityTree& rhs); // clone virtual PityTree* clone() = 0; @@ -39,16 +39,21 @@ namespace pEp { template CT& addNew(Args&&... args); - // Creates a copy, add the copy as child and returns a ref to it + // Creates a copy, adds the copy as child and returns a ref to it template CT& addCopy(const CT&& child, const std::string& new_name = ""); + template + CT& addCopy(const CT& child, const std::string& new_name = ""); + // Just adds child as a non-owned reference. T& addRef(T& child); // Query + virtual T& getSelf() = 0; T* getParent() const; ChildRefs getChildRefs() const; + int getChildCount() const; T& getChild(const std::string& name); T& getRoot(); diff --git a/src/PityTree.hxx b/src/PityTree.hxx index e3f21d7..8cc6c6f 100644 --- a/src/PityTree.hxx +++ b/src/PityTree.hxx @@ -37,15 +37,15 @@ namespace pEp { _copyChildRefs(rhs); } - template - PityTree& PityTree::operator=(const PityTree& rhs) - { - _nodename = rhs._nodename; - _parent = nullptr; - _copyChildRefs(rhs); - return *this; - } - +// template +// PityTree& PityTree::operator=(const PityTree& rhs) +// { +// _nodename = rhs._nodename; +// _parent = nullptr; +// _copyChildRefs(rhs); +// return *this; +// } +// template template CT& PityTree::addNew(Args&&... args) @@ -71,6 +71,13 @@ namespace pEp { return *tmpraw; } + template + template + CT& PityTree::addCopy(const CT& child, const std::string& new_name) + { + return addCopy(std::move(child)); + } + template T& PityTree::addRef(T& child) { @@ -201,6 +208,12 @@ namespace pEp { addRef(ret); } } + + template + int PityTree::getChildCount() const + { + return _childrefs.size(); + } } // namespace PityTest11 } // namespace pEp