Test: PityTest - PityTree add copy assign operator

LIB-11
heck 2 years ago
parent c05d04683a
commit 0ac3de4264

@ -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;

@ -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