About
maxon::HierarchyObjectInterface is a base interface used to create elements that can be organized in a tree like structure. A parent element can have one or many child elements. A child element can have only one parent but none, one or many siblings.
A parent object can organize its child elements in multiple sub-branches.
Hierarchy Interface
The hierarchy interface provides functions to insert an element into a given tree structure:
const TreeElementRef root = TreeElementFactory().Create(
"root"_s)
iferr_return;
const TreeElementRef elementA = TreeElementFactory().Create(
"Element A"_s)
iferr_return;
const TreeElementRef elementB = TreeElementFactory().Create(
"Element B"_s)
iferr_return;
const TreeElementRef elementC = TreeElementFactory().Create(
"Element C"_s)
iferr_return;
for (const auto& child : children)
{
const TreeElementRef treeElement = maxon::Cast<TreeElementRef>(child);
}
Child elements can be replaced or removed:
const TreeElementRef root = TreeElementFactory().Create(
"root"_s)
iferr_return;
const TreeElementRef elementA = TreeElementFactory().Create(
"Element A"_s)
iferr_return;
const TreeElementRef elementB = TreeElementFactory().Create(
"Element B"_s)
iferr_return;
const TreeElementRef elementC = TreeElementFactory().Create(
"Element C"_s)
iferr_return;
elementA.Remove();
const TreeElementRef firstElement = maxon::Cast<TreeElementRef>(firstChild);
Within a given hierarchy level one can navigate with:
while (child)
{
if (child.IsInstanceOf<TreeElementRef>())
{
const TreeElementRef treeElement = maxon::Cast<TreeElementRef>(child);
}
child = child.GetNext();
}
The parent of an element is accessed with:
The child elements of a parent object are accessed with:
These observables are called on certain events:
ObservableHierarchyInsert:
Is called when an element was inserted in the hierarchy.
ObservableHierarchyRemove:
Is called when an element was removed from the hierarchy.
To navigate through a given hierarchy one can use these utility functions:
maxon::TraverseMeAndChildren<TreeElementRef>(root,
{
return true;
maxon::TraverseChildren<TreeElementRef>(root,
{
return true;
It is also possible to iterate over all elements of a hierarchy using maxon::HierarchyObjectIterator:
Custom Implementations
A custom interface can be based on maxon::HierarchyObjectInterface. The resulting reference object can be organized in a tree. The default implementation of maxon::HierarchyObjectInterface is maxon::HierarchyObjectClass
.
An interface based on maxon::HierarchyObjectInterface can implement maxon::HierarchyObjectInterface::ParentChanged() to be informed when the parent of the element has changed. This function must not be called by user code.
class TreeElementImplementation :
public maxon::Component<TreeElementImplementation, TreeElementInterface>
{
public:
{
_name = name;
}
{
return _name;
}
{
const auto parentObject = super.GetParent();
if (!parentObject)
if (!parentObject.IsInstanceOf<TreeElementRef>())
const TreeElementRef treeElement = maxon::Cast<TreeElementRef>(parentObject);
return treeElement.GetName();
}
{
if (removed)
return;
const auto parentObject = super.GetParent();
if (parentObject.IsInstanceOf<TreeElementRef>())
{
const TreeElementRef treeElement = maxon::Cast<TreeElementRef>(parentObject);
}
}
{
self.SetName(name);
}
private:
};
Further Reading