Browse Source

Test: PityTest - PityTree add copy assign operator

LIB-11
heck 11 months ago
parent
commit
0ac3de4264
2 changed files with 24 additions and 5 deletions
  1. +5
    -0
      test/pitytest11/src/PityTree.hh
  2. +19
    -5
      test/pitytest11/src/PityTree.hxx

+ 5
- 0
test/pitytest11/src/PityTree.hh View File

@ -29,6 +29,10 @@ namespace pEp {
explicit PityTree(T& self, const std::string& name, T& parent);
explicit PityTree(const PityTree& rhs, T& owner);
// copy-assign
PityTree& operator=(const PityTree<T>& rhs);
// clone
virtual PityTree* clone() = 0;
// Append
@ -62,6 +66,7 @@ namespace pEp {
void setParent(T* const parent);
private:
void _cloneChildRefs(const PityTree<T>& rhs);
// Fields
std::string _nodename;
T& _self;


+ 19
- 5
test/pitytest11/src/PityTree.hxx View File

@ -44,12 +44,15 @@ namespace pEp {
{
_nodename = rhs._nodename;
_parent = nullptr;
_cloneChildRefs(rhs);
}
for (const ChildRef& cr : rhs.getChildRefs()) {
_childobjs.push_back(ChildObj(cr.second.clone()));
T& ret = *_childobjs.back().get();
addRef(ret);
}
template<class T>
PityTree<T>& PityTree<T>::operator=(const PityTree<T>& rhs) {
_nodename = rhs._nodename;
_parent = nullptr;
_cloneChildRefs(rhs);
return *this;
}
template<class T>
@ -196,6 +199,17 @@ namespace pEp {
return name;
}
// When you copy a treenode, you need to create a copy of all children
// and take ownership
template<class T>
void PityTree<T>::_cloneChildRefs(const PityTree<T>& rhs) {
for (const ChildRef& cr : rhs.getChildRefs()) {
_childobjs.push_back(ChildObj(cr.second.clone()));
T& ret = *_childobjs.back().get();
addRef(ret);
}
}
} // namespace PityTest11
} // namespace pEp

Loading…
Cancel
Save