// This file is under GNU General Public License 3.0 // see LICENSE.txt #ifndef PITYTEST_PITYTREE_HH #define PITYTEST_PITYTREE_HH //#include "../../../src/pEpLog.hh" #include #include #include #include #include namespace pEp { namespace PityTest11 { template class PityTree { // TODO: NEEEEED THIS // static_assert(std::is_base_of, T>::value, "PityTree must be a base of T"); public: using ChildObj = std::shared_ptr; using ChildObjs = std::vector; using ChildRef = std::pair; using ChildRefs = std::map; // Constructors explicit PityTree(T& self, const std::string& name); explicit PityTree(T& self, const std::string& name, T& parent); explicit PityTree(const PityTree& rhs, T& owner); // copy-assign PityTree& operator=(const PityTree& rhs); // clone virtual PityTree* clone() = 0; // Append // creates a new instance of CT, add the new instance as child and returns a ref to it template CT& addNew(Args&&... args); // Creates a copy, add the copy as child and returns a ref to it template CT& addCopy(const CT&& child, const std::string& new_name = ""); // Just adds child as a non-owned reference. T& addRef(T& child); // Query T* getParent() const; ChildRefs getChildRefs() 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 std::string to_string(bool recursive = true, int indent = 0); //TODO HACK in PityTransport, this should be private static std::string _normalizeName(std::string name); virtual ~PityTree() = default; protected: void setParent(T* const parent); private: void _copyChildRefs(const PityTree& rhs); // Fields std::string _nodename; T& _self; T* _parent; //nullptr if RootUnit ChildRefs _childrefs; // map to guarantee uniqueness of sibling-names ChildObjs _childobjs; }; }; // namespace PityTest11 }; // namespace pEp #include "PityTree.hxx" #endif