Scene Fusion 2 API Reference
KS::ksHierarchyObject< T > Class Template Reference

#include <ksHierarchyObject.h>

Inheritance diagram for KS::ksHierarchyObject< T >:

Classes

class  AncestorIter
 
class  DescendantIter
 

Public Types

typedef std::function< bool(std::shared_ptr< T >)> ForEachCallback
 

Public Member Functions

 ksHierarchyObject ()
 
virtual ~ksHierarchyObject ()
 
std::shared_ptr< T > Parent ()
 
const std::list< std::shared_ptr< T > > & Children ()
 
std::shared_ptr< T > Child (size_t index)
 
int IndexOfChild (std::shared_ptr< T > childPtr)
 
void Detach ()
 
bool IsDescendantOf (std::shared_ptr< T > objPtr)
 
virtual bool AddChild (std::shared_ptr< T > childPtr)
 
virtual bool InsertChild (int index, std::shared_ptr< T > childPtr)
 
virtual bool RemoveChild (std::shared_ptr< T > childPtr)
 
void ForEachDescendant (ForEachCallback callback)
 
void ForSelfAndDescendants (ForEachCallback callback)
 
AncestorIter< std::shared_ptr< T > > SelfAndAncestors ()
 
AncestorIter< std::shared_ptr< T > > Ancestors ()
 
DescendantIter< std::shared_ptr< T > > SelfAndDescendants ()
 
DescendantIter< std::shared_ptr< T > > Descendants ()
 

Protected Member Functions

virtual bool MoveChild (std::shared_ptr< T > childPtr, int newIndex)
 
virtual bool PerformAddChild (std::shared_ptr< T > childPtr)
 
virtual bool PerformInsertChild (int index, std::shared_ptr< T > childPtr)
 
virtual bool PerformRemoveChild (std::shared_ptr< T > childPtr)
 
void PerformDetach ()
 

Protected Attributes

std::weak_ptr< T > m_parentPtr
 
std::list< std::shared_ptr< T > > m_children
 

Detailed Description

template<typename T>
class KS::ksHierarchyObject< T >

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

Member Typedef Documentation

◆ ForEachCallback

template<typename T >
typedef std::function<bool(std::shared_ptr<T>)> KS::ksHierarchyObject< T >::ForEachCallback

Callback for depth-first searches.

Parameters
std::shared_ptr<T>- pointer to the object being iterated.
Returns
bool - true to iterate the children of object.

Constructor & Destructor Documentation

◆ ksHierarchyObject()

template<typename T >
KS::ksHierarchyObject< T >::ksHierarchyObject ( )
inline

Constructor

◆ ~ksHierarchyObject()

template<typename T >
virtual KS::ksHierarchyObject< T >::~ksHierarchyObject ( )
inlinevirtual

Destructor

Member Function Documentation

◆ AddChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::AddChild ( std::shared_ptr< T >  childPtr)
inlinevirtual

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 std::invalid_argument exception if the child is null.

Parameters
std::shared_ptr<T>- pointer to the child to add.
Returns
bool - 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.

◆ Ancestors()

template<typename T >
AncestorIter<std::shared_ptr<T> > KS::ksHierarchyObject< T >::Ancestors ( )
inline

Get an ancestor iterator that does not include the current object.

Returns
AncestorIter<std::shared_ptr<T>>

◆ Child()

template<typename T >
std::shared_ptr<T> KS::ksHierarchyObject< T >::Child ( size_t  index)
inline

Return a pointer to a child object at a specific index. If the index is out of bounds then a null pointer is returned.

Parameters
size_t- child index
Returns
std::shared_ptr<T>

◆ Children()

template<typename T >
const std::list<std::shared_ptr<T> >& KS::ksHierarchyObject< T >::Children ( )
inline

Return a reference to this object's children list

Returns
const std::list<std::shared_ptr<T>>&

◆ Descendants()

template<typename T >
DescendantIter<std::shared_ptr<T> > KS::ksHierarchyObject< T >::Descendants ( )
inline

Get an descendant iterator that does not include the current object.

Returns
DescendantIter<std::shared_ptr<T>>

◆ Detach()

template<typename T >
void KS::ksHierarchyObject< T >::Detach ( )
inline

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

◆ ForEachDescendant()

template<typename T >
void KS::ksHierarchyObject< T >::ForEachDescendant ( ForEachCallback  callback)
inline

Iterates the descendants using depth-first search.

Parameters
ForEachCallback- callback to call on descendants. If it returns false, will not iterate children.

◆ ForSelfAndDescendants()

template<typename T >
void KS::ksHierarchyObject< T >::ForSelfAndDescendants ( ForEachCallback  callback)
inline

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

Parameters
ForEachCallback- callback to call on descendants. If it returns false, will not iterate children.

◆ IndexOfChild()

template<typename T >
int KS::ksHierarchyObject< T >::IndexOfChild ( std::shared_ptr< T >  childPtr)
inline

Get the index of a child in this object. Return -1 if the child is not in the list of children

Parameters
std::shared_ptr<T>- pointer to the child object
Returns
int - index of the child, -1 if the child was not found

◆ InsertChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::InsertChild ( int  index,
std::shared_ptr< T >  childPtr 
)
inlinevirtual

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 std::invalid_argument exception if the child is null.

Parameters
int- index to insert at.
std::shared_ptr<T>- child to insert.
Returns
bool - 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()

template<typename T >
bool KS::ksHierarchyObject< T >::IsDescendantOf ( std::shared_ptr< T >  objPtr)
inline

Checks if an object is a descendant of this object.

Parameters
std::shared_ptr<T>- pointer to the object to check.
Returns
bool - true if obj is a descendant of this object.

◆ MoveChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::MoveChild ( std::shared_ptr< T >  childPtr,
int  newIndex 
)
inlineprotectedvirtual

Moves a child to a new index. Throws std::invalid_argument exception if child is null.

Parameters
std::shared_ptr<T>- child to move.
int- new index
Returns
bool - true if the child was found and removed.

◆ Parent()

template<typename T >
std::shared_ptr<T> KS::ksHierarchyObject< T >::Parent ( )
inline

Get a pointer to this object's parent object

Returns
std::shared_ptr<T>

◆ PerformAddChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::PerformAddChild ( std::shared_ptr< T >  childPtr)
inlineprotectedvirtual

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 std::invalid_argument exception if the child is null.

Parameters
std::shared_ptr<T>- pointer to the child to add.
Returns
bool - 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()

template<typename T >
void KS::ksHierarchyObject< T >::PerformDetach ( )
inlineprotected

Protected implementation of Detach.

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

◆ PerformInsertChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::PerformInsertChild ( int  index,
std::shared_ptr< T >  childPtr 
)
inlineprotectedvirtual

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 std::invalid_argument exception if the child is null.

Parameters
int- index to insert at.
std::shared_ptr<T>- child to insert.
Returns
bool - 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()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::PerformRemoveChild ( std::shared_ptr< T >  childPtr)
inlineprotectedvirtual

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 std::invalid_argument exception if child is null.

Parameters
std::shared_ptr<T>- child to remove.
Returns
bool - true if the child was found and removed.

◆ RemoveChild()

template<typename T >
virtual bool KS::ksHierarchyObject< T >::RemoveChild ( std::shared_ptr< T >  childPtr)
inlinevirtual

Removes a child from this object. Throws std::invalid_argument exception if child is null.

Parameters
std::shared_ptr<T>- child to remove.
Returns
bool - true if the child was found and removed.

◆ SelfAndAncestors()

template<typename T >
AncestorIter<std::shared_ptr<T> > KS::ksHierarchyObject< T >::SelfAndAncestors ( )
inline

Get an ancestor iterator that includes the current object.

Returns
AncestorIter<std::shared_ptr<T>>

◆ SelfAndDescendants()

template<typename T >
DescendantIter<std::shared_ptr<T> > KS::ksHierarchyObject< T >::SelfAndDescendants ( )
inline

Get an descendant iterator that includes the current object.

Returns
DescendantIter<std::shared_ptr<T>>

The documentation for this class was generated from the following file: