KS.Reactor.ksHierarchyObject< T > Class Template Reference

Templated base class for hierarchy objects that have a parent and list of children of type T. More...

Public Member Functions

delegate bool ForEachCallback (T obj)
 Callback for depth-first searches. More...
 
 ksHierarchyObject ()
 Constructor. More...
 
virtual bool AddChild (T child)
 Adds a child to the object if that does not create a circular reference. More...
 
virtual bool InsertChild (int index, T child)
 Inserts a child at an index if that does not create a circular reference. More...
 
virtual bool RemoveChild (T child)
 Removes a child from this object. More...
 
virtual void Detach ()
 Removes the object from its parent. Does nothing if the object has no parent. More...
 
bool IsDescendantOf (T obj)
 Checks if an object is a descendant of this object. More...
 
void ForEachDescendant (ForEachCallback callback)
 Iterates the descendants using depth-first search. More...
 
void ForSelfAndDescendants (ForEachCallback callback)
 Iterates this object and its descendants using depth-first search. More...
 

Protected Member Functions

virtual bool PerformAddChild (T child)
 Protected implementation of AddChild. More...
 
virtual bool PerformInsertChild (int index, T child)
 Protected implementation of InsertChild. More...
 
virtual bool PerformRemoveChild (T child)
 Protected implementation of RemoveChild. More...
 
virtual void PerformDetach ()
 Protected implementation of Detach. More...
 

Protected Attributes

m_parent
 
ksLinkedList< T > m_children = new ksLinkedList<T>()
 

Properties

Parent [get]
 Parent. More...
 
ksConstList< T > Children [get]
 Children More...
 
Root [get]
 The root ancestor of this object, or this if this object is a root. More...
 
IEnumerable< T > Descendants [get]
 Iterator for descendants. More...
 
IEnumerable< T > SelfAndDescendants [get]
 Iterator for this object and its descendants. More...
 
IEnumerable< T > Ancestors [get]
 Iterator for ancestors. More...
 
IEnumerable< T > SelfAndAncestors [get]
 Iterator for this object and its ancestors. More...
 

Detailed Description

Templated base class for hierarchy objects that have a parent and list of children of type T.

Non-templated base class for hierarchy objects with a parent and children.

There is also a non-templated variant of ksHierarchyObject.

Template Parameters
T

There is also a templated variant that enforces all objects in the hierarchy derive the templated type.

Type Constraints
T :ksHierarchyObject<T> 

Constructor & Destructor Documentation

◆ ksHierarchyObject()

Member Function Documentation

◆ AddChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.AddChild ( child)
virtual

Adds a child to the object if that does not create a circular reference.

If the child has another parent, removes it from its parent first. Throws ArgumentNullException if the child is null.

Parameters
childChild to add.
Returns
True if the child was added. False if it could not be added, either because it was already added or adding it would create a circular reference.

◆ Detach()

virtual void KS.Reactor.ksHierarchyObject< T >.Detach ( )
virtual

Removes the object from its parent. Does nothing if the object has no parent.

◆ ForEachCallback()

delegate bool KS.Reactor.ksHierarchyObject< T >.ForEachCallback ( obj)

Callback for depth-first searches.

Parameters
objObject being iterated.
Returns
True to iterate the children of the object.

◆ ForEachDescendant()

void KS.Reactor.ksHierarchyObject< T >.ForEachDescendant ( ForEachCallback  callback)

Iterates the descendants using depth-first search.

Parameters
callbackCallback to call on descendants. If it returns false, will not iterate children.

◆ ForSelfAndDescendants()

void KS.Reactor.ksHierarchyObject< T >.ForSelfAndDescendants ( ForEachCallback  callback)

Iterates this object and its descendants using depth-first search.

Parameters
callbackCallback to call on descendants. If it returns false, will not iterate children.

◆ InsertChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.InsertChild ( int  index,
child 
)
virtual

Inserts a child at an index if that does not create a circular reference.

If the child has another parent, removes it from its parent first. Throws ArgumentNullException if the child is null.

Parameters
indexIndex to insert at.
childChild to insert.
Returns
True if the child was inserted. False if it could not be inserted, either because it was already added, adding it would create a circular reference, or the index was out of bounds.

◆ IsDescendantOf()

bool KS.Reactor.ksHierarchyObject< T >.IsDescendantOf ( obj)

Checks if an object is a descendant of this object.

Parameters
objObject to check.
Returns
True if obj is a descendant of this object.

◆ PerformAddChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.PerformAddChild ( child)
protectedvirtual

Protected implementation of AddChild.

The public AddChild calls this one. Derived classes can override either to change public or internal behaviour.

Adds a child to the object if that does not create a circular reference. If the child has another parent, removes it from its parent first. Throws ArgumentNullException if the child is null.

Parameters
childChild to add.
Returns
True if the child was added. False if it could not be added, either because it was already added or adding it would create a circular reference.

◆ PerformDetach()

virtual void KS.Reactor.ksHierarchyObject< T >.PerformDetach ( )
protectedvirtual

Protected implementation of Detach.

Removes the object from its parent. Does nothing if the object has no parent.

◆ PerformInsertChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.PerformInsertChild ( int  index,
child 
)
protectedvirtual

Protected implementation of InsertChild.

The public InsertChild calls this one. Derived classes can override either to change public or internal behaviour.

Inserts a child at an index if that does not create a circular reference. If the child has another parent, removes it from its parent first. Throws ArgumentNullException if the child is null.

Parameters
indexIndex to insert at.
childChild to insert.
Returns
True if the child was inserted. False if it could not be inserted, either because it was already added, adding it would create a circular reference, or the index was out of bounds.

◆ PerformRemoveChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.PerformRemoveChild ( child)
protectedvirtual

Protected implementation of RemoveChild.

The public RemoveChild calls this one. Derived classes can override either to change public or internal behaviour.

Removes a child from this object. Throws ArgumentNullException if child is null.

Parameters
childChild to remove.
Returns
True if the child was found and removed.

◆ RemoveChild()

virtual bool KS.Reactor.ksHierarchyObject< T >.RemoveChild ( child)
virtual

Removes a child from this object.

Throws ArgumentNullException if child is null.

Parameters
childChild to remove.
Returns
True if the child was found and removed.

Property Documentation

◆ Ancestors

IEnumerable<T> KS.Reactor.ksHierarchyObject< T >.Ancestors
get

Iterator for ancestors.

◆ Children

Children

◆ Descendants

IEnumerable<T> KS.Reactor.ksHierarchyObject< T >.Descendants
get

Iterator for descendants.

◆ Parent

T KS.Reactor.ksHierarchyObject< T >.Parent
get

Parent.

◆ Root

The root ancestor of this object, or this if this object is a root.

◆ SelfAndAncestors

IEnumerable<T> KS.Reactor.ksHierarchyObject< T >.SelfAndAncestors
get

Iterator for this object and its ancestors.

◆ SelfAndDescendants

IEnumerable<T> KS.Reactor.ksHierarchyObject< T >.SelfAndDescendants
get

Iterator for this object and its descendants.