Browse Source

Test: PityTest - PityTree addCopy() for lvalue refs, too, please, add getChildrenCount(), debatable, copy-assign i think i like to avoid it.

master
heck 4 years ago
parent
commit
158caafa2a
  1. 9
      src/PityTree.hh
  2. 31
      src/PityTree.hxx

9
src/PityTree.hh

@ -29,7 +29,7 @@ namespace pEp {
explicit PityTree(const PityTree& rhs, T& owner); explicit PityTree(const PityTree& rhs, T& owner);
// copy-assign // copy-assign
PityTree& operator=(const PityTree<T>& rhs); // PityTree& operator=(const PityTree<T>& rhs);
// clone // clone
virtual PityTree* clone() = 0; virtual PityTree* clone() = 0;
@ -39,16 +39,21 @@ namespace pEp {
template<typename CT, typename... Args> template<typename CT, typename... Args>
CT& addNew(Args&&... args); 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<typename CT> template<typename CT>
CT& addCopy(const CT&& child, const std::string& new_name = ""); CT& addCopy(const CT&& child, const std::string& new_name = "");
template<typename CT>
CT& addCopy(const CT& child, const std::string& new_name = "");
// Just adds child as a non-owned reference. // Just adds child as a non-owned reference.
T& addRef(T& child); T& addRef(T& child);
// Query // Query
virtual T& getSelf() = 0;
T* getParent() const; T* getParent() const;
ChildRefs getChildRefs() const; ChildRefs getChildRefs() const;
int getChildCount() const;
T& getChild(const std::string& name); T& getChild(const std::string& name);
T& getRoot(); T& getRoot();

31
src/PityTree.hxx

@ -37,15 +37,15 @@ namespace pEp {
_copyChildRefs(rhs); _copyChildRefs(rhs);
} }
template<class T> // template<class T>
PityTree<T>& PityTree<T>::operator=(const PityTree<T>& rhs) // PityTree<T>& PityTree<T>::operator=(const PityTree<T>& rhs)
{ // {
_nodename = rhs._nodename; // _nodename = rhs._nodename;
_parent = nullptr; // _parent = nullptr;
_copyChildRefs(rhs); // _copyChildRefs(rhs);
return *this; // return *this;
} // }
//
template<typename T> template<typename T>
template<typename CT, typename... Args> template<typename CT, typename... Args>
CT& PityTree<T>::addNew(Args&&... args) CT& PityTree<T>::addNew(Args&&... args)
@ -71,6 +71,13 @@ namespace pEp {
return *tmpraw; return *tmpraw;
} }
template<typename T>
template<typename CT>
CT& PityTree<T>::addCopy(const CT& child, const std::string& new_name)
{
return addCopy(std::move(child));
}
template<class T> template<class T>
T& PityTree<T>::addRef(T& child) T& PityTree<T>::addRef(T& child)
{ {
@ -201,6 +208,12 @@ namespace pEp {
addRef(ret); addRef(ret);
} }
} }
template<class T>
int PityTree<T>::getChildCount() const
{
return _childrefs.size();
}
} // namespace PityTest11 } // namespace PityTest11
} // namespace pEp } // namespace pEp

Loading…
Cancel
Save