ocra-recipes
Doxygen documentation for the ocra-recipes repository
Public Member Functions | Protected Member Functions | Friends | List of all members
ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo > Class Template Reference

Base class for the Composite class of the Composite pattern. More...

#include <Composite.h>

Public Member Functions

bool isParentOf (const ComponentDerived &node)
 
size_t getNumChildhoods () const
 Basic access to the children. More...
 
const parenthood_t_getChildhood (size_t i) const
 
const_iterator_ children_begin () const
 Iterator range on the children. More...
 
iterator_ children_begin ()
 
const_iterator_ children_end () const
 
iterator_ children_end ()
 
virtual CompositeDerived & add (ComponentDerived &child)
 Append and detach a child. More...
 
virtual CompositeDerived & remove (ComponentDerived &child)
 

Protected Member Functions

 Composite ()
 
 ~Composite ()
 
void attach (ComponentDerived &child)
 Attaches a Component to a Composite by simply creating a Parenthood bond between them. More...
 
void detach (ComponentDerived &child)
 Erases a Parenthood bond between a Composite and a Component. More...
 
int isAncestorOf_impl (const ComponentDerived &node) const
 
void printTree_impl (int depth, std::ostream &os) const
 
virtual void onAttachedChild (const parenthood_t_ &child)
 Default implementation of the callbacks, to overload in the private part of class CompositeDerived. More...
 
virtual void onDetachedChild (const parenthood_t_ &child)
 

Friends

class Parenthood< ComponentDerived, CompositeDerived, ParenthoodInfo >
 

Detailed Description

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
class ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >

Base class for the Composite class of the Composite pattern.

See the wikipedia article about the Composite design pattern for more information.

See also
class ocra::Component
class ocra::Leaf
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 by the Parenthood class. 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.

Definition at line 38 of file Composite.h.

Constructor & Destructor Documentation

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::Composite ( )
inlineprotected

Definition at line 694 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::~Composite ( )
inlineprotected

Definition at line 697 of file Composite.h.

Member Function Documentation

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
virtual CompositeDerived& ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::add ( ComponentDerived &  child)
inlinevirtual

Append and detach a child.

Default implementation forwards the call to the protected methods attach and detach; you can overload these methods to wrap attach and detach with precondition tests and additional operations.

Reimplemented in ocra::CompositeVariable.

Definition at line 677 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
void ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::attach ( ComponentDerived &  child)
inlineprotected

Attaches a Component to a Composite by simply creating a Parenthood bond between them.

Definition at line 706 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
const_iterator_ ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::children_begin ( ) const
inline

Iterator range on the children.

Definition at line 663 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
iterator_ ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::children_begin ( )
inline

Definition at line 664 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
const_iterator_ ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::children_end ( ) const
inline

Definition at line 666 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
iterator_ ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::children_end ( )
inline

Definition at line 667 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
void ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::detach ( ComponentDerived &  child)
inlineprotected

Erases a Parenthood bond between a Composite and a Component.

Definition at line 712 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
const parenthood_t_& ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::getChildhood ( size_t  i) const
inline

Definition at line 658 of file Composite.h.

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

Basic access to the children.

Definition at line 657 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
int ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::isAncestorOf_impl ( const ComponentDerived &  node) const
inlineprotected

Definition at line 723 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
bool ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::isParentOf ( const ComponentDerived &  node)
inline

Definition at line 647 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
virtual void ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::onAttachedChild ( const parenthood_t_ child)
inlineprotectedvirtual

Default implementation of the callbacks, to overload in the private part of class CompositeDerived.

These callbacks are called once a parent and a child have been attached/detached. When the callback is called, the parenthood has already been registered/unregistered by the child and parent (this is guaranteed by the ocra::attach/ detach function).

Definition at line 689 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
virtual void ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::onDetachedChild ( const parenthood_t_ child)
inlineprotectedvirtual

Definition at line 690 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
void ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::printTree_impl ( int  depth,
std::ostream &  os 
) const
inlineprotected

Definition at line 725 of file Composite.h.

template<class ComponentDerived, class CompositeDerived, class ParenthoodInfo = NoInfo>
virtual CompositeDerived& ocra::Composite< ComponentDerived, CompositeDerived, ParenthoodInfo >::remove ( ComponentDerived &  child)
inlinevirtual

Reimplemented in ocra::CompositeVariable.

Definition at line 678 of file Composite.h.

Friends And Related Function Documentation

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

Definition at line 753 of file Composite.h.


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