template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
class ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >
Stores information about a Parent/Child relationship in the Composite design pattern.
Composite objects are built upon a tree of objects, whose nodes implement the type Component. Component is specialized in:
See the wikipedia article about the Composite design pattern for more information.
This class represents the bond between a parent and a child node in the tree. It contains:
- the parent and the child,
- the position of the child among the parent's children
- the position of the parent among the child's parents,
- additional, custom information, whose type is given by the last template argument (ParenthoodInfo).
In this implementation, a node can be part of several trees and can therefore have several parents. However, cycles are forbidden.
- Template Parameters
-
ComponentDerived | is the abstract type used to manipulate both nodes and leaves without knowledge of whether they are composite or not. |
CompositeDerived | is the type of the composite objects, i.e. objects that are composed of several subobjects. |
ParenthoodInfo | is an additional type to associate additional information with a parenthood relationship. It must be default constructible with a default constructor (it can be the one defined by the compiler). |
- Precondition
- CompositeDerived is a publicly derived class of ComponentDerived.
-
ParenthoodInfo is default constructible with a no-throw default constructor.
-
ComponentDerived publicly derives Component<ComponentDerived, CompositeDerived, ParenthoodInfo>.
-
CompositeDerived publicly derives Composite<ComponentDerived, CompositeDerived, ParenthoodInfo>.
The preconditions on the template parameters will be enforced at compile-time. If a BOOST_STATIC_ASSERT is fired when compiling your composite classes, please have a look at the name of the parameter of the failing assertion: it will give you a hint about how to correct your code.
- Invariant
- &parent.getChildhood(getRankOfChild()) == &child.getParenthood(getRankOfParent()) && &parent.getChildhood(getRankOfChild()) == this
-
this->getParent().isAncestorOf(this->getChild()) == true
-
this->getChild().isAncestorOf(this->getParent()) == false
Invariants will be checked at runtime in DEBUG mode at construction and destruction.
Definition at line 94 of file Composite.h.