Browse Source

Tests: PityTree - add setName() / getChild()

master
heck 4 years ago
parent
commit
4b48fcd203
  1. 5
      src/PityTree.hh
  2. 20
      src/PityTree.hxx

5
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

20
src/PityTree.hxx

@ -21,13 +21,13 @@ namespace pEp {
namespace PityTest11 {
template<class T>
PityTree<T>::PityTree(T& self, const std::string &name) :
PityTree<T>::PityTree(T& self, const std::string& name) :
_self{ self }, _nodename{ _normalizeName(name) }
{
}
template<class T>
PityTree<T>::PityTree(T& self, const std::string &name, T& parent) :
PityTree<T>::PityTree(T& self, const std::string& name, T& parent) :
_self(self), _nodename{ _normalizeName(name) }
{
parent.add(_self);
@ -42,13 +42,13 @@ namespace pEp {
}
template<class T>
void PityTree<T>::setParent(T *parent)
void PityTree<T>::setParent(T* parent)
{
_parent = parent;
}
template<class T>
T *PityTree<T>::getParent() const
T* PityTree<T>::getParent() const
{
return _parent;
}
@ -63,6 +63,12 @@ namespace pEp {
}
}
template<class T>
void PityTree<T>::setName(const std::string& name)
{
_nodename = name;
}
template<class T>
std::string PityTree<T>::getName() const
{
@ -120,6 +126,12 @@ namespace pEp {
return _children;
}
template<class T>
T& PityTree<T>::getChild(const std::string& name)
{
return _children.at(name);
}
// name is alphanumeric only (everything else will be replaced by an underscore)
// static
template<class T>

Loading…
Cancel
Save