36template <
class SELF_T,
class SUPER_T = DtSpObject>
41 using Sptr = std::shared_ptr<SELF_T>;
88 LOG_WARN(
"UTIL") <<
"Cannot add null child ptr." << std::endl;
111 child->setParent(this->
self());
130 if (*findIt == child)
143 if (findIt->lock() == child)
152 if (found && child->parent() != this->self())
154 LOG_WARN(
"UTIL") <<
"Parent of child did not match this." << std::endl;
157 if (child->parent() == this->self())
159 child->setParent(
Sptr());
186 child.lock()->setParent(
Sptr());
206 for (
auto child : ownedCopy)
218 for (
auto child : unownedCopy)
220 if (!fn(child.lock()))
253 if (fn(child.lock()))
275 if (*findIt == child)
286 if (findIt->lock() == child)
312 if (!findIt->second.expired())
314 Sptr found = findIt->second.lock();
316 if (found->name() ==
name)
318 return findIt->second.lock();
333 if (it->second.expired())
348 return child->name() ==
name;
404 using Wptr = std::weak_ptr<SELF_T>;
Provides base classes for shared pointer managed objects with factory creation support.
virtual std::string name() const
Gets the name of this object.
Definition baseClass.h:153
Sptr self()
Definition baseClass.h:198
DtSpSubClass()
Definition baseClass.h:190
virtual Sptr findChild(FindChildFn fn)
Finds a child that matches a given predicate.
Definition treeClass.h:237
virtual void setOwnsChildren(bool owns)
Sets whether this node owns its children.
Definition treeClass.h:65
virtual Sptr parent()
Gets the parent of this node.
Definition treeClass.h:371
std::shared_ptr< SELF_T > Sptr
Shared pointer type for this class.
Definition treeClass.h:41
std::map< std::string, Wptr > ChildNameMap
Type for the map of child names to child pointers.
Definition treeClass.h:410
std::function< bool(Sptr child)> ForChildFn
Function type for child traversal callbacks.
Definition treeClass.h:43
virtual void removeAllChildren()
Removes all children from this node.
Definition treeClass.h:172
virtual bool removeChild(Sptr child)
Removes a child from this node.
Definition treeClass.h:123
bool myOwnsChildren
Flag indicating whether this node owns its children.
Definition treeClass.h:421
Wptr myParent
Weak reference to the parent node.
Definition treeClass.h:424
virtual ~DtTreeClass() override
Virtual destructor.
Definition treeClass.h:58
std::function< bool(Sptr child)> FindChildFn
Function type for child search predicates.
Definition treeClass.h:45
virtual bool ownsChildren()
Checks if this node owns its children.
Definition treeClass.h:69
virtual bool isChild(Sptr child)
Checks if a given node is a child of this node.
Definition treeClass.h:268
virtual Sptr findChild(const std::string &name)
Finds a child by name.
Definition treeClass.h:304
virtual bool addChild(Sptr child)
Adds a child to this node.
Definition treeClass.h:82
std::list< Wptr > UnownedChildList
Type for the list of unowned children.
Definition treeClass.h:408
virtual unsigned int numChildren()
Gets the total number of children.
Definition treeClass.h:363
UnownedChildList myUnownedChildren
List of children not owned by this node (weak references)
Definition treeClass.h:415
std::weak_ptr< SELF_T > Wptr
Weak pointer type for this class.
Definition treeClass.h:404
ChildNameMap myChildrenByName
Map of child names to child pointers for fast lookup.
Definition treeClass.h:418
virtual void setParent(Sptr parent)
Sets the parent of this node.
Definition treeClass.h:379
DtTreeClass()
Default constructor.
Definition treeClass.h:50
std::list< Sptr > OwnedChildList
Type for the list of owned children.
Definition treeClass.h:406
virtual bool forEachChild(ForChildFn fn)
Iterates over all children and applies a function to each.
Definition treeClass.h:203
OwnedChildList myOwnedChildren
List of children owned by this node (strong references)
Definition treeClass.h:413
virtual bool hasChildren()
Checks if this node has any children.
Definition treeClass.h:367
virtual void pruneChildren()
Removes expired weak references from the unowned children list.
Definition treeClass.h:386
Provides logging functionality with various severity levels and channels.
#define LOG_WARN(channel)
Macro to log a warning message to log files.
Definition logger.h:69
Include export definitions for this library.
Definition glsVreMessageUtil.h:49