From bb831cc338a0feb3dac789c6fd8dc12497ba9765 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 7 Jul 2021 15:08:06 +0200 Subject: [PATCH] Tests: PityTree - add setName() / getChild() --- test/pitytest11/src/PityTree.hh | 5 +++-- test/pitytest11/src/PityTree.hxx | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/test/pitytest11/src/PityTree.hh b/test/pitytest11/src/PityTree.hh index 543d9fa..380bf59 100644 --- a/test/pitytest11/src/PityTree.hh +++ b/test/pitytest11/src/PityTree.hh @@ -28,9 +28,10 @@ namespace pEp { T* getParent() const; Children getChildren() const; - + T& getChild(const std::string& name); T& getRoot(); + void setName(const std::string& name); std::string getName() const; std::string getPath() const; bool isRoot() const; // true if has no parent @@ -47,7 +48,7 @@ namespace pEp { private: // Fields - const std::string _nodename; + std::string _nodename; T& _self; T* _parent = nullptr; //nullptr if RootUnit Children _children; // map to guarantee uniqueness of sibling-names diff --git a/test/pitytest11/src/PityTree.hxx b/test/pitytest11/src/PityTree.hxx index 2ec4773..464e60a 100644 --- a/test/pitytest11/src/PityTree.hxx +++ b/test/pitytest11/src/PityTree.hxx @@ -21,13 +21,13 @@ namespace pEp { namespace PityTest11 { template - PityTree::PityTree(T& self, const std::string &name) : + PityTree::PityTree(T& self, const std::string& name) : _self{ self }, _nodename{ _normalizeName(name) } { } template - PityTree::PityTree(T& self, const std::string &name, T& parent) : + PityTree::PityTree(T& self, const std::string& name, T& parent) : _self(self), _nodename{ _normalizeName(name) } { parent.add(_self); @@ -42,13 +42,13 @@ namespace pEp { } template - void PityTree::setParent(T *parent) + void PityTree::setParent(T* parent) { _parent = parent; } template - T *PityTree::getParent() const + T* PityTree::getParent() const { return _parent; } @@ -63,6 +63,12 @@ namespace pEp { } } + template + void PityTree::setName(const std::string& name) + { + _nodename = name; + } + template std::string PityTree::getName() const { @@ -120,6 +126,12 @@ namespace pEp { return _children; } + template + T& PityTree::getChild(const std::string& name) + { + return _children.at(name); + } + // name is alphanumeric only (everything else will be replaced by an underscore) // static template