ocra-recipes
Doxygen documentation for the ocra-recipes repository
Classes | Public Types | Friends | List of all members
ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo > Class Template Reference

Stores information about a Parent/Child relationship in the Composite design pattern. More...

#include <Composite.h>

Inheritance diagram for ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >:
[legend]
Collaboration diagram for ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >:
[legend]

Classes

struct  childIs
 
struct  parentIs
 Functors to locate a parent or a child. More...
 

Public Types

typedef Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo > parenthood_t
 
typedef ComponentDerived component_t
 
typedef CompositeDerived parent_t
 

Public Member Functions

CompositeDerived & getParent () const
 Access to parenthood info, parent, child and their ranks, see constructor postconditions and class description. More...
 
size_t getRankOfParent () const
 
ComponentDerived & getChild () const
 
size_t getRankOfChild () const
 
ParenthoodInfo & getInfo () const
 
ParenthoodgetPreviousParent () const
 These methods return the parent of this->getChild() at position this->getRankOfParent()-1 (+1 respectively). More...
 
ParenthoodgetNextParent () const
 
ParenthoodgetPreviousChild () const
 
ParenthoodgetNextChild () const
 

Friends

class Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >
 

Detailed Description

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:

In this implementation, a node can be part of several trees and can therefore have several parents. However, cycles are forbidden.

Template Parameters
ComponentDerivedis the abstract type used to manipulate both nodes and leaves without knowledge of whether they are composite or not.
CompositeDerivedis the type of the composite objects, i.e. objects that are composed of several subobjects.
ParenthoodInfois 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.

Member Typedef Documentation

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
typedef ComponentDerived ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::component_t

Definition at line 99 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
typedef CompositeDerived ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::parent_t

Definition at line 100 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
typedef Parenthood<ComponentDerived, CompositeDerived, ParenthoodInfo> ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::parenthood_t

Definition at line 98 of file Composite.h.

Member Function Documentation

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
ComponentDerived& ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getChild ( ) const
inline

Definition at line 224 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
ParenthoodInfo& ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getInfo ( ) const
inline

Definition at line 227 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
Parenthood* ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getNextChild ( ) const
inline

Definition at line 269 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
Parenthood* ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getNextParent ( ) const
inline

Definition at line 245 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
CompositeDerived& ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getParent ( ) const
inline

Access to parenthood info, parent, child and their ranks, see constructor postconditions and class description.

Definition at line 221 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
Parenthood* ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getPreviousChild ( ) const
inline
template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
Parenthood* ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getPreviousParent ( ) const
inline

These methods return the parent of this->getChild() at position this->getRankOfParent()-1 (+1 respectively).

These methods return a null pointer if called on the first (last) parenthood.

Definition at line 235 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
size_t ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getRankOfChild ( ) const
inline

Definition at line 225 of file Composite.h.

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
size_t ocra::Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >::getRankOfParent ( ) const
inline

Definition at line 222 of file Composite.h.

Friends And Related Function Documentation

template<class ComponentDerived , class CompositeDerived , class ParenthoodInfo = NoInfo>
friend class Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >
friend

Definition at line 105 of file Composite.h.


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