|
VR-Engage
2.2
|
| SELF_T | The derived class type (CRTP pattern) |
| SUPER_T | The base class type, defaults to DtSpObject |
This class provides a comprehensive implementation of a tree data structure with smart pointer ownership management, child lookup by name, and various traversal capabilities. It's designed to be used as a base class for objects that need to exist in hierarchical relationships.
#include <treeClass.h>
Public Types | |
| using | Sptr = std::shared_ptr<SELF_T> |
| using | ForChildFn = std::function<bool(Sptr child)> |
| using | FindChildFn = std::function<bool(Sptr child)> |
Public Types inherited from makVre::DtSpSubClass< SELF_T, DtSpObject > | |
| using | Super |
| using | Ptr |
| using | Sptr |
| using | Wptr |
Public Types inherited from makVre::DtSpObject | |
| using | Ptr = DtSpObject* |
| using | Sptr = std::shared_ptr<DtSpObject> |
| using | Wptr = std::weak_ptr<DtSpObject> |
Public Member Functions | |
| DtTreeClass () | |
| virtual | ~DtTreeClass () override |
| virtual void | setOwnsChildren (bool owns) |
| virtual bool | ownsChildren () |
| virtual bool | addChild (Sptr child) |
| virtual bool | removeChild (Sptr child) |
| virtual void | removeAllChildren () |
| virtual bool | forEachChild (ForChildFn fn) |
| virtual Sptr | findChild (FindChildFn fn) |
| virtual bool | isChild (Sptr child) |
| virtual Sptr | findChild (const std::string &name) |
| virtual unsigned int | numChildren () |
| virtual bool | hasChildren () |
| virtual Sptr | parent () |
Public Member Functions inherited from makVre::DtSpSubClass< SELF_T, DtSpObject > | |
| DtSpSubClass () | |
| virtual | ~DtSpSubClass () |
| Sptr | self () |
| std::string | type () const override |
Public Member Functions inherited from makVre::DtSpObject | |
| DtSpObject () | |
| virtual | ~DtSpObject () |
| Sptr | self () |
| virtual void | setName (const std::string &name) |
| virtual std::string | name () const |
Protected Types | |
| using | Wptr = std::weak_ptr<SELF_T> |
| using | OwnedChildList = std::list<Sptr> |
| using | UnownedChildList = std::list<Wptr> |
| using | ChildNameMap = std::map<std::string, Wptr> |
Protected Member Functions | |
| virtual void | setParent (Sptr parent) |
| virtual void | pruneChildren () |
Protected Attributes | |
| OwnedChildList | myOwnedChildren |
| UnownedChildList | myUnownedChildren |
| ChildNameMap | myChildrenByName |
| bool | myOwnsChildren |
| Wptr | myParent |
Protected Attributes inherited from makVre::DtSpObject | |
| std::string | myName |
Additional Inherited Members | |
Static Public Member Functions inherited from makVre::DtSpSubClass< SELF_T, DtSpObject > | |
| static std::string | Type () |
| static std::shared_ptr< SELF_T > | create () |
| static void | registerCreator () |
| static std::shared_ptr< SELF_T > | createVersion (unsigned int version) |
| static void | registerCreatorVersion (unsigned int version) |
Static Public Member Functions inherited from makVre::DtSpObject | |
| template<class AS_T> | |
| static std::shared_ptr< AS_T > | cast (Sptr p) |
| template<class AS_T> | |
| static std::shared_ptr< AS_T > | unsafe_cast (Sptr p) |
Static Protected Member Functions inherited from makVre::DtSpSubClass< SELF_T, DtSpObject > | |
| static std::shared_ptr< DtBaseCreator< SELF_T > > & | creator () |
| static std::shared_ptr< DtBaseCreator< SELF_T > > & | creatorVersion (unsigned int version) |
| using makVre::DtTreeClass< SELF_T, SUPER_T >::Sptr = std::shared_ptr<SELF_T> |
Shared pointer type for this class.
| using makVre::DtTreeClass< SELF_T, SUPER_T >::ForChildFn = std::function<bool(Sptr child)> |
Function type for child traversal callbacks.
| using makVre::DtTreeClass< SELF_T, SUPER_T >::FindChildFn = std::function<bool(Sptr child)> |
Function type for child search predicates.
|
protected |
Weak pointer type for this class.
|
protected |
Type for the list of owned children.
|
protected |
Type for the list of unowned children.
|
protected |
Type for the map of child names to child pointers.
|
inline |
Default constructor.
Creates a new tree node with ownership of children enabled by default
References myOwnsChildren.
|
inlineoverridevirtual |
|
inlinevirtual |
Sets whether this node owns its children.
| owns | True if this node should own its children, false otherwise |
When a node owns its children, it maintains strong references to them, preventing their destruction as long as the parent exists
References myOwnsChildren.
|
inlinevirtual |
Checks if this node owns its children.
References myOwnsChildren.
Referenced by addChild().
|
inlinevirtual |
Adds a child to this node.
| child | Shared pointer to the child node to add |
This method adds a child to this node if:
The child is added to either the owned or unowned list based on the current ownership setting of this node.
Reimplemented in makVre::DtCigiPublisherBase.
References isChild(), LOG_WARN, myOwnedChildren, myUnownedChildren, ownsChildren(), pruneChildren(), and makVre::DtSpSubClass< SELF_T, DtSpObject >::self().
|
inlinevirtual |
Removes a child from this node.
| child | Shared pointer to the child node to remove |
This method searches for the child in both the owned and unowned children lists and removes it if found. It also clears the parent reference from the child.
References LOG_WARN, myOwnedChildren, myUnownedChildren, and pruneChildren().
|
inlinevirtual |
Removes all children from this node.
This method removes all children from this node, converting owned children to unowned first to prevent their destruction during the process. It then clears the parent reference from all children and clears internal lists.
References myChildrenByName, myOwnedChildren, myUnownedChildren, and pruneChildren().
Referenced by ~DtTreeClass().
|
inlinevirtual |
Iterates over all children and applies a function to each.
| fn | Function to apply to each child |
This method iterates over all children (both owned and unowned) and applies the provided function to each. If the function returns false for any child, iteration stops and the method returns false. Otherwise, it returns true.
Note that it creates copies of the child lists before iteration to allow safe modification of the lists during iteration.
References myOwnedChildren, myUnownedChildren, and pruneChildren().
|
inlinevirtual |
Finds a child that matches a given predicate.
| fn | Predicate function to test each child |
This method searches through all children (both owned and unowned) and returns the first child for which the predicate function returns true. If no child matches, it returns a null pointer.
References myOwnedChildren, myUnownedChildren, and pruneChildren().
Referenced by findChild().
|
inlinevirtual |
Checks if a given node is a child of this node.
| child | Shared pointer to the node to check |
This method checks both the owned and unowned children lists to determine if the specified node is a direct child of this node.
References myOwnedChildren, and myUnownedChildren.
Referenced by addChild().
|
inlinevirtual |
Finds a child by name.
| name | The name of the child to find |
This method first checks a name-to-child map for fast lookup. If the child is not found in the map, it searches all children for one with the given name. If found, it adds the child to the name map for faster subsequent lookups.
The method also performs cleanup of expired references in the name map.
References findChild(), myChildrenByName, and makVre::DtSpObject::name().
|
inlinevirtual |
Gets the total number of children.
References myOwnedChildren, and myUnownedChildren.
Referenced by hasChildren().
|
inlinevirtual |
Checks if this node has any children.
References numChildren().
|
inlinevirtual |
Gets the parent of this node.
References myParent.
Referenced by setParent().
|
inlineprotectedvirtual |
|
inlineprotectedvirtual |
Removes expired weak references from the unowned children list.
This protected method is called internally to clean up any weak references to children that have been destroyed. It iterates through the unowned children list and removes any expired references.
References myUnownedChildren.
Referenced by addChild(), findChild(), forEachChild(), removeAllChildren(), and removeChild().
|
protected |
List of children owned by this node (strong references)
Referenced by addChild(), findChild(), forEachChild(), isChild(), numChildren(), removeAllChildren(), and removeChild().
|
protected |
List of children not owned by this node (weak references)
Referenced by addChild(), findChild(), forEachChild(), isChild(), numChildren(), pruneChildren(), removeAllChildren(), and removeChild().
|
protected |
Map of child names to child pointers for fast lookup.
Referenced by findChild(), and removeAllChildren().
|
protected |
Flag indicating whether this node owns its children.
Referenced by DtTreeClass(), ownsChildren(), and setOwnsChildren().
|
protected |
Weak reference to the parent node.
Referenced by parent(), and setParent().