Ceylan::Tree< Content > Class Template Reference

#include <CeylanTree.h>

Inheritance diagram for Ceylan::Tree< Content >:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::Tree< Content >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list< Tree
< Content > * > 
SubTreeList
 Shortcut for the list of sons of a Tree.

Public Member Functions

 Tree ()
 Constructs a tree made only from a node root, with an empty local content.
 Tree (Content &content)
 Constructs a tree made only from a node root, whose local content is provided.
virtual ~Tree () throw ()
 Virtual destructor, deletes all tree, including the subtrees and their content.
virtual void accept (Visitor &visitor)
 Allows given visitor to visit this object, thanks to a callback: 'visitor.visit( *this ) ;'.
virtual bool hasContent () const
 Tells whether this tree node (i.e.
virtual Content & getContent ()
 Returns the content that this root node of the tree owns.
virtual const Content & getContentAsConst () const
 Returns the content that this root node of the tree owns, as a const reference.
virtual void setContent (Content &newContent)
 Sets a new content for this root node of the tree.
virtual const SubTreeListgetSons () const
 Returns the list of sons (subtrees) of this tree.
virtual TreegetFather (Tree &child)
 Returns the father of the specified node, which is searched in specified tree.
virtual void addSon (Tree &subtree)
 Adds specified son to the list of sons of this tree.
virtual void traverseDepthFirst (TreeVisitor< Content > &treeVisitor, bool visitContent=true)
 Traverses this tree depth-first, and applies specified processing to each node being selected on this path, in the path order.
virtual void traverseBreadthFirst (TreeVisitor< Content > &treeVisitor, bool visitContent=true)
 Traverses this tree breadth-first, and applies specified processing to each node being selected on this path, in the path order.
virtual void appendSonsContents (std::list< Content * > &toBeAugmented)
 Adds in specified list the content of all direct child nodes.
virtual TreegetNodeOf (const Content &content)
 Returns the tree node that references specified content, if any.
virtual Content * getFatherContent (const Content &content)
 Returns the content associated with the father node of the node associated with specified content.
virtual void appendSonsContentsOf (const Content &content, std::list< Content * > &toBeAugmented)
 Adds in specified list the content of all direct child nodes.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns a user-friendly description of the state of this object.

Protected Attributes

Content * _content
 The content carried by this tree node.
SubTreeList _sons
 The sons, direct subtrees of this tree.

Private Member Functions

 Tree (const Tree &source)
 Copy constructor made private to ensure that it will never be called.
Treeoperator= (const Tree &source)
 Assignment operator made private to ensure that it will never be called.


Detailed Description

template<typename Content>
class Ceylan::Tree< Content >

Definition at line 280 of file CeylanTree.h.


Member Typedef Documentation

template<typename Content>
typedef std::list< Tree<Content>* > Ceylan::Tree< Content >::SubTreeList

Shortcut for the list of sons of a Tree.

Definition at line 288 of file CeylanTree.h.


Constructor & Destructor Documentation

template<typename Content >
Ceylan::Tree< Content >::Tree (  )  [inline, explicit]

Constructs a tree made only from a node root, with an empty local content.

Definition at line 645 of file CeylanTree.h.

template<typename Content >
Ceylan::Tree< Content >::Tree ( Content &  content  )  [inline, explicit]

Constructs a tree made only from a node root, whose local content is provided.

Parameters:
content the local content of this node.
Note:
The tree takes ownership of the content, hence will deallocate it when itself deallocated.

Definition at line 655 of file CeylanTree.h.

template<typename Content >
Ceylan::Tree< Content >::~Tree (  )  throw () [inline, virtual]

Virtual destructor, deletes all tree, including the subtrees and their content.

Definition at line 665 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, and Ceylan::Tree< Content >::_sons.

template<typename Content>
Ceylan::Tree< Content >::Tree ( const Tree< Content > &  source  )  [private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.

Note:
Made to avoid unwanted hidden clone of the Singleton.


Member Function Documentation

template<typename Content >
void Ceylan::Tree< Content >::accept ( Visitor visitor  )  [inline, virtual]

Allows given visitor to visit this object, thanks to a callback: 'visitor.visit( *this ) ;'.

Implements the Visitable interface.

Exceptions:
VisitException if the operation failed, including if the specified visitor is no a tree height-aware visitor.

Implements Ceylan::Visitable.

Definition at line 729 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, Ceylan::Tree< Content >::_sons, Ceylan::TreeHeightAwareVisitor< Content >::decrementHeight(), Ceylan::TreeHeightAwareVisitor< Content >::incrementHeight(), and Ceylan::Visitor::toString().

Referenced by Ceylan::XML::XMLParser::saveToFile().

template<typename Content >
void Ceylan::Tree< Content >::addSon ( Tree< Content > &  subtree  )  [inline, virtual]

Adds specified son to the list of sons of this tree.

Note:
A subtree cannot be registered more than once.
Exceptions:
TreeException if the operation failed, included if the subtree was already registered.
Note:
This tree takes ownership of the specified subtree.

Definition at line 843 of file CeylanTree.h.

References Ceylan::Tree< Content >::_sons, and Ceylan::Tree< Content >::toString().

Referenced by Ceylan::XML::XMLParser::handleNextElement().

template<typename Content >
void Ceylan::Tree< Content >::appendSonsContents ( std::list< Content * > &  toBeAugmented  )  [inline, virtual]

Adds in specified list the content of all direct child nodes.

Parameters:
toBeAugmented the list to which contents will be added.

Definition at line 900 of file CeylanTree.h.

References Ceylan::Tree< Content >::_sons.

Referenced by Ceylan::Tree< Content >::appendSonsContentsOf().

template<typename Content >
void Ceylan::Tree< Content >::appendSonsContentsOf ( const Content &  content,
std::list< Content * > &  toBeAugmented 
) [inline, virtual]

Adds in specified list the content of all direct child nodes.

Parameters:
content the content whose sons will be searched for content to append.
toBeAugmented the list to which contents will be added.

Definition at line 976 of file CeylanTree.h.

References Ceylan::Tree< Content >::appendSonsContents(), and Ceylan::Tree< Content >::getNodeOf().

template<typename Content >
Content & Ceylan::Tree< Content >::getContent (  )  [inline, virtual]

Returns the content that this root node of the tree owns.

Exceptions:
TreeException if no content is registered in this node.
See also:
hasContent

Definition at line 802 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content.

template<typename Content >
const Content & Ceylan::Tree< Content >::getContentAsConst (  )  const [inline, virtual]

Returns the content that this root node of the tree owns, as a const reference.

Exceptions:
TreeException if no content is registered in this node.
See also:
hasContent

Definition at line 816 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content.

template<typename Content >
Tree< Content > * Ceylan::Tree< Content >::getFather ( Tree< Content > &  child  )  [inline, virtual]

Returns the father of the specified node, which is searched in specified tree.

Parameters:
child the node whose father is searched in this tree.
Returns:
the father tree, if found, otherwise a null pointer.

Definition at line 695 of file CeylanTree.h.

References Ceylan::Tree< Content >::_sons, and Ceylan::Tree< Content >::getFather().

Referenced by Ceylan::Tree< Content >::getFather(), and Ceylan::XML::XMLParser::handleNextElement().

template<typename Content >
Content * Ceylan::Tree< Content >::getFatherContent ( const Content &  content  )  [inline, virtual]

Returns the content associated with the father node of the node associated with specified content.

The ownership of any returned content is kept by the tree.

Returns:
A pointer to the father content, if any, otherwise a null pointer if this node has no father (root node) or if it has a father but it is not associated with any content.
Note:
This is an expensive method, as it may traverse the full tree: this kind of tree has nodes that are not required to keep track of their father. Hence needing to use this method might be the sign of a poor design.
This search could be provided by a dedicated visitor, but it would result in a rather complex visitor with no real added value.

Definition at line 942 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, and Ceylan::Tree< Content >::_sons.

template<typename Content >
Tree< Content > * Ceylan::Tree< Content >::getNodeOf ( const Content &  content  )  [inline, virtual]

Returns the tree node that references specified content, if any.

Parameters:
content the content associated with the searched node.
Returns:
the (supposed) only one node that is associated with specified content, or a null pointer if no corresponding node was found.

Definition at line 919 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, Ceylan::Tree< Content >::_sons, and Ceylan::Tree< Content >::getNodeOf().

Referenced by Ceylan::Tree< Content >::appendSonsContentsOf(), and Ceylan::Tree< Content >::getNodeOf().

template<typename Content >
const std::list< Tree< Content > * > & Ceylan::Tree< Content >::getSons (  )  const [inline, virtual]

Returns the list of sons (subtrees) of this tree.

Definition at line 685 of file CeylanTree.h.

References Ceylan::Tree< Content >::_sons.

template<typename Content >
bool Ceylan::Tree< Content >::hasContent (  )  const [inline, virtual]

Tells whether this tree node (i.e.

the root of this tree) has a content.

Returns:
true iff this node owns a content instance.

Definition at line 792 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content.

template<typename Content>
Tree& Ceylan::Tree< Content >::operator= ( const Tree< Content > &  source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

template<typename Content >
void Ceylan::Tree< Content >::setContent ( Content &  newContent  )  [inline, virtual]

Sets a new content for this root node of the tree.

Note:
The node takes ownership of the content, and any previously owned content is deallocated first.
Exceptions:
TreeException if the operation failed.
See also:
hasContent

Definition at line 830 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content.

template<typename Content >
const std::string Ceylan::Tree< Content >::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [inline, virtual]

Returns a user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

Definition at line 994 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, Ceylan::Tree< Content >::_sons, and Ceylan::formatStringList().

Referenced by Ceylan::Tree< Content >::addSon(), Ceylan::XML::XMLParser::handleNextElement(), and Ceylan::XML::XMLParser::toString().

template<typename Content >
void Ceylan::Tree< Content >::traverseBreadthFirst ( TreeVisitor< Content > &  treeVisitor,
bool  visitContent = true 
) [inline, virtual]

Traverses this tree breadth-first, and applies specified processing to each node being selected on this path, in the path order.

Parameters:
treeVisitor the actual tree visitor that will visit the tree.
visitContent tells whether the visitor the tree nodes and their content, if true, or only the tree nodes, if false.
Note:
Content, if visited, will be visited just after its associated node is visited. If a given node has no content, then the visitor will only be called for the node, even if visitContent is true.
Exceptions:
TreeException if the visit failed.

Definition at line 880 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, Ceylan::Tree< Content >::_sons, and Ceylan::TreeVisitor< Content >::visit().

template<typename Content >
void Ceylan::Tree< Content >::traverseDepthFirst ( TreeVisitor< Content > &  treeVisitor,
bool  visitContent = true 
) [inline, virtual]

Traverses this tree depth-first, and applies specified processing to each node being selected on this path, in the path order.

Parameters:
treeVisitor the actual tree visitor that will visit the tree.
visitContent tells whether the visitor the tree nodes and their content, if true, or only the tree nodes, if false.
Note:
Content, if visited, will be visited just after its associated node is visited. If a given node has no content, then the visitor will only be called for the node, even if visitContent is true.
Exceptions:
TreeException if the visit failed.

Definition at line 860 of file CeylanTree.h.

References Ceylan::Tree< Content >::_content, Ceylan::Tree< Content >::_sons, and Ceylan::TreeVisitor< Content >::visit().


Member Data Documentation

template<typename Content>
Content* Ceylan::Tree< Content >::_content [protected]

template<typename Content>
SubTreeList Ceylan::Tree< Content >::_sons [protected]


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

Generated on Thu Jun 4 20:40:10 2009 for Ceylan by  doxygen 1.5.8