GCpp general purpose C++ library  version 1.0
GTreeNodeT< T > Class Template Referenceabstract

#include <GTreeNodeT.hh>

Inheritance diagram for GTreeNodeT< T >:
GNamed GTreeBranchT< T > GTreeLeafT< T >

Public Member Functions

template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
virtual GTreeNodeT< T > * Clone () const =0
 
virtual const char * ClassName () const
 
Constructors, affectation, destructor
 GTreeNodeT ()
 
 GTreeNodeT (const GTreeNodeT< T > &original)
 
virtual ~GTreeNodeT ()
 
Tree structure functions
virtual void SetParent (GTreeBranchT< T > *parent_ptr)
 
virtual void SetListIter (GListIterT< GTreeNodeT< T > > *iter_ptr)
 
virtual const GTreeBranchT< T > * GetParent () const
 
virtual GTreeBranchT< T > * GetParent ()
 
virtual const GTreeNodeT< T > * GetRoot () const
 
virtual GTreeNodeT< T > * GetRoot ()
 
virtual bool IsBranch () const
 
virtual bool IsLeaf () const
 
void SetUserData (void *data)
 
void * GetUserData () const
 
virtual GListIterT< GTreeNodeT
< T > > 
GetListIter () const
 
Tree structure exploration
virtual GTreeNodeT< T > * NextNode ()
 
virtual GTreeLeafT< T > * FirstLeaf ()
 
virtual GTreeLeafT< T > * NextLeaf ()
 
virtual GTreeNodeT< T > * FindNode (const string &name)
 
virtual GTreeBranchT< T > * FindBranch (const string &name)
 
Tree construction functions
virtual GTreeBranchT< T > * AddBranch (const string &bname)
 
virtual GTreeBranchT< T > * AddBranch (const string &parent, const string &bname)
 
virtual GTreeLeafT< T > * AddLeaf (T &object_ref)
 
virtual GTreeLeafT< T > * AddLeaf (const string &parent, T &object_ref)
 
virtual GTreeLeafT< T > * AddLeaf (T *object_ptr)
 
virtual GTreeLeafT< T > * AddLeaf (const string &parent, T *object_ptr)
 
Element information
u_int GetLevel () const
 
virtual string GetFullName () const
 
virtual u_int GetLeafCount () const =0
 
virtual u_int GetLeafTotalCount () const =0
 
Creation of objects structures from the tree
virtual GNamedListT< T > * CreateList ()
 
virtual GTreeNodeT< GItem > * CreateItemTree () const =0
 
virtual GItemListCreateItemList ()
 
Print out
virtual void Print (FILE *fp=stdout, const string &prefix="", bool info=false) const =0
 
- Public Member Functions inherited from GNamed
template<class Q >
bool IsInstanceOf () const
 
template<class Q >
bool IsInstanceOf ()
 
 GNamed (const string &object_name="")
 
 GNamed (const GNamed &object)
 
virtual ~GNamed ()
 
GNamedoperator= (const GNamed &object)
 
virtual const string & Name () const
 
virtual string & Name ()
 
virtual string GetName () const
 
virtual string GetInfo () const
 
virtual void SetName (const string &object_name)
 
int Compare (const GNamed &object) const
 
int CompareDict (const GNamed &object) const
 
bool operator== (const GNamed &object) const
 
bool operator!= (const GNamed &object) const
 
bool operator< (const GNamed &object) const
 
bool operator> (const GNamed &object) const
 
bool operator<= (const GNamed &object) const
 
bool operator>= (const GNamed &object) const
 

Static Public Member Functions

static const char * StaticClassName ()
 
- Static Public Member Functions inherited from GNamed
static const char * StaticClassName ()
 

Protected Attributes

GTreeBranchT< T > * parent
 Parent element of the tree.
 
GListIterT< GTreeNodeT< T > > * list_iter
 Pointer to the iterator in parent list.
 
void * user_data
 Pointer to a additional user data.
 
- Protected Attributes inherited from GNamed
string name
 Object name.
 

Detailed Description

template<class T>
class GTreeNodeT< T >

Template abstract base class to define a tree structure of objects. The tree elements inherit from the GNamed class for objects identification.

The main elements of a tree structure are:

  • the branches (GTreeBranchT), that can contain other (sub-)branches and/or leaves;
  • the leaves (GTreeLeafT), that is a terminal node, with a pointer to an object of class T.

The template class provide functions to dupplicate the tree structure, with GItem object pointing to the original tree class T objects.

Warning:

  • Do not use "/" (slash) character in names of objects from tree structure, unless explicitely specifying sub-tree branches.

See GCpp template classes for more information about the template classes.

GTreeT.png

Constructor & Destructor Documentation

template<class T >
GTreeNodeT< T >::GTreeNodeT ( )
inline
template<class T >
GTreeNodeT< T >::GTreeNodeT ( const GTreeNodeT< T > &  original)
inline

Copy constructor. The pointer to the parent is not copied: if an element is copied, it is outside the tree structure.

Parameters
originalobject to copy

References GDebugConst, GTreeNodeT< T >::list_iter, GTreeNodeT< T >::parent, and GTreeNodeT< T >::user_data.

template<class T >
GTreeNodeT< T >::~GTreeNodeT ( )
inlinevirtual

Destructor.

References GDebugDest.

Member Function Documentation

template<class T >
GTreeBranchT< T > * GTreeNodeT< T >::AddBranch ( const string &  bname)
inlinevirtual

Add a sub-branch in current node (redefined in branch).

Parameters
bnamename of the sub-branch

Reimplemented in GTreeBranchT< T >.

template<class T >
GTreeBranchT< T > * GTreeNodeT< T >::AddBranch ( const string &  parent,
const string &  bname 
)
virtual

Add a sub-branch in current tree.

Parameters
parentparent branch name
bnamename of the sub-branch

References GTreeBranchT< T >::AddBranch().

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::AddLeaf ( T &  object_ref)
inlinevirtual

Add a leaf in current node (redefined in branch). The object is not adopted by the created leaf.

Parameters
object_refobject given by reference

Reimplemented in GTreeBranchT< T >.

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::AddLeaf ( const string &  parent,
T &  object_ref 
)
virtual

Add a leaf in current tree. The object is not adopted by the created leaf.

Parameters
parentparent branch name
object_refobject given by reference

References GTreeBranchT< T >::AddLeaf().

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::AddLeaf ( T *  object_ptr)
inlinevirtual

Add a leaf in current node (redefined in branch). The object is adopted by the created leaf.

Parameters
object_ptrobject given by pointer

Reimplemented in GTreeBranchT< T >.

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::AddLeaf ( const string &  parent,
T *  object_ptr 
)
virtual

Add a leaf in current tree. The object is adopted by the created leaf.

Parameters
parentparent branch name
object_ptrobject given by pointer

References GTreeBranchT< T >::AddLeaf().

template<class T >
GItemList * GTreeNodeT< T >::CreateItemList ( )
virtual

Create a list of GItem, for each leaf of the tree structure. The GItem elements refer to the data associated to the leaves. The resulting list must be deleted by the calling function.

References GItemList::AddItem(), GTreeLeafT< T >::GetDataPtr(), GTreeLeafT< T >::GetName(), GTreeNodeT< T >::NextLeaf(), and GItem::SetInfo().

template<class T >
GNamedListT< T > * GTreeNodeT< T >::CreateList ( )
virtual

Create a list of objects, for each leaf of the tree structure. The list does not adopt the object pointers.

References GListT< T >::Append(), GTreeLeafT< T >::GetDataPtr(), and GTreeNodeT< T >::NextLeaf().

template<class T >
GTreeBranchT< T > * GTreeNodeT< T >::FindBranch ( const string &  name)
virtual

Function searching for a branch in the tree structure. The function calls FindNode and checks that the node found is a branch.

Parameters
namename of the searched branch.

References GTreeNodeT< T >::IsBranch().

template<class T >
GTreeNodeT< T > * GTreeNodeT< T >::FindNode ( const string &  name)
virtual

Function searching for a node in the tree structure. If name starts with '/', search from the tree root. Names "." and ".." respectively correspond to current and parent nodes. Note that the root name should not appear when searching from tree root: it is refered to by the '/' at name beginning.

Parameters
namename of the searched node.

References GListT< GTreeNodeT< T > >::Begin(), GTreeNodeT< T >::FindNode(), GNamed::GetName(), GTreeNodeT< T >::IsBranch(), and GListT< GTreeNodeT< T > >::Null().

Referenced by GTreeNodeT< T >::FindNode().

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::FirstLeaf ( )
virtual

Return the first node that is a leaf in the tree structure.

References GTreeNodeT< T >::IsInstanceOf(), and GTreeNodeT< T >::NextLeaf().

template<class T >
string GTreeNodeT< T >::GetFullName ( ) const
virtual

Return the full name of the node, including parent nodes. The name of root is not included.

template<class T>
virtual u_int GTreeNodeT< T >::GetLeafCount ( ) const
pure virtual

Function returning the number of leaves.

Implemented in GTreeBranchT< T >, and GTreeLeafT< T >.

template<class T>
virtual u_int GTreeNodeT< T >::GetLeafTotalCount ( ) const
pure virtual

Function returning the total number of leaves, recursively in the tree structure.

Implemented in GTreeBranchT< T >, and GTreeLeafT< T >.

template<class T >
u_int GTreeNodeT< T >::GetLevel ( ) const

Return the hierarchy level of the object (0 means top element).

References GTreeNodeT< T >::GetParent().

template<class T >
GListIterT< GTreeNodeT< T > > GTreeNodeT< T >::GetListIter ( ) const
inlinevirtual

Return the list iterator (to this element) from the parent branch, if defined, else return a null iterator.

Referenced by GTreeNodeT< T >::NextNode().

template<class T >
const GTreeBranchT< T > * GTreeNodeT< T >::GetParent ( ) const
inlinevirtual
template<class T >
GTreeBranchT< T > * GTreeNodeT< T >::GetParent ( )
inlinevirtual

Return the tree element parent pointer.

template<class T >
const GTreeNodeT< T > * GTreeNodeT< T >::GetRoot ( ) const
inlinevirtual

Return the root (top tree) element pointer.

References GTreeNodeT< T >::GetRoot().

Referenced by GTreeNodeT< T >::GetRoot().

template<class T >
GTreeNodeT< T > * GTreeNodeT< T >::GetRoot ( )
inlinevirtual

Return the root (top tree) element pointer.

template<class T >
void * GTreeNodeT< T >::GetUserData ( ) const
inline

Get the pointer to the additionnal user data.

template<class T >
bool GTreeNodeT< T >::IsBranch ( ) const
inlinevirtual

Return true if the node is a branch.

Reimplemented in GTreeBranchT< T >.

Referenced by GTreeBranchT< T >::CreateFolderTree(), GTreeNodeT< T >::FindBranch(), and GTreeNodeT< T >::FindNode().

template<class T>
template<class Q >
bool GTreeNodeT< T >::IsInstanceOf ( ) const
inline

Macro from GCpp library that defines the following functions:

  • ClassName(): return the real class name of the object
  • StaticClassName(): return the used class name of the object (that may be a base class of the real object).
  • IsInstanceOf<T>(): return true if the current object is an instance of the template class name argument
  • Clone(): return an allocated copy of the object.

Referenced by GTreeNodeT< T >::FirstLeaf(), and GTreeNodeT< T >::NextLeaf().

template<class T >
bool GTreeNodeT< T >::IsLeaf ( ) const
inlinevirtual

Return true if the node is a leaf.

Reimplemented in GTreeLeafT< T >.

template<class T >
GTreeLeafT< T > * GTreeNodeT< T >::NextLeaf ( )
virtual
template<class T >
GTreeNodeT< T > * GTreeNodeT< T >::NextNode ( )
virtual

Return the next node in the tree structure. This function allows to loop on all nodes (branches and leaves).

Reimplemented in GTreeBranchT< T >.

References GTreeNodeT< T >::GetListIter(), GTreeNodeT< T >::GetParent(), and GListIterT< T >::Next().

Referenced by GTreeNodeT< T >::NextLeaf(), and GTreeBranchT< T >::NextNode().

template<class T>
virtual void GTreeNodeT< T >::Print ( FILE *  fp = stdout,
const string &  prefix = "",
bool  info = false 
) const
pure virtual

Print the list: elements are given by their name or associated information.

Parameters
fpfile pointer
prefixtext written before each line
infoif true, the information is printed instead of the name

Implemented in GTreeBranchT< T >, and GTreeLeafT< T >.

template<class T >
void GTreeNodeT< T >::SetListIter ( GListIterT< GTreeNodeT< T > > *  iter_ptr)
inlinevirtual

Set the tree element parent pointer. This function is called when adding an element in a branch.

Parameters
iter_ptrpointer to the iterator in the branch list of elements

Referenced by GTreeBranchT< T >::__Add(), GTreeBranchT< T >::__Insert(), and GTreeBranchT< T >::__Take().

template<class T >
void GTreeNodeT< T >::SetParent ( GTreeBranchT< T > *  parent_ptr)
inlinevirtual

Set the tree element parent pointer. This function is called when adding an element in a branch.

Parameters
parent_ptrpointer to the tree parent object

Referenced by GTreeBranchT< T >::__Add(), GTreeBranchT< T >::__Insert(), and GTreeBranchT< T >::__Take().

template<class T >
void GTreeNodeT< T >::SetUserData ( void *  data)
inline

Set the pointer to an additionnal user data.

Parameters
datauser data pointer

Referenced by GTreeBranchT< T >::CreateFolderTree().


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