GCpp general purpose C++ library  version 1.0
GTreeNodeT.hh
Go to the documentation of this file.
1 //======================================================================
2 /*! \file GTreeNodeT.hh
3  *
4  * Include file for GTreeNodeT template class.
5  */
6 //======================================================================
7 
8 #ifndef G_TREE_NODE_T_HH
9 #define G_TREE_NODE_T_HH
10 
11 #include "GNamedListT.hh"
12 
13 template <class T> class GTreeBranchT;
14 template <class T> class GTreeLeafT;
15 
16 #include "GItem.hh"
17 #include "GItemList.hh"
18 
19 //======================================================================
20 /*! \class GTreeNodeT
21  *
22  * Template abstract base class to define a tree structure of objects.
23  * The tree elements inherit from the GNamed class for objects
24  * identification.
25  *
26  * The main elements of a tree structure are:
27  * - the branches (GTreeBranchT), that can contain other (sub-)branches
28  * and/or leaves;
29  * - the leaves (GTreeLeafT), that is a terminal node, with a pointer
30  * to an object of class \b T.
31  *
32  * The template class provide functions to dupplicate the tree structure,
33  * with GItem object pointing to the original tree class \b T objects.
34  *
35  * \b Warning: \n
36  * - Do not use "/" (slash) character in names of objects from
37  * tree structure, unless explicitely specifying sub-tree
38  * branches.
39  *
40  * See \ref gcpp_templates for more information about the template classes.
41  *
42  * \image html GTreeT.png
43  */
44 template <class T> class GTreeNodeT : public GNamed
45 {
46  //------------------------------------------------------------
47  /*! \object_doc */
49  //------------------------------------------------------------
50 
51  protected:
52  GTreeBranchT<T> * parent; ///< Parent element of the tree
53  GListIterT < GTreeNodeT <T> > * list_iter; ///< Pointer to the iterator in parent list
54 
55  void * user_data; ///< Pointer to a additional user data
56 
57  public:
58 
59  //------------------------------------------------------------
60  /** @name Constructors, affectation, destructor */
61  //@{
62  GTreeNodeT ( );
63  GTreeNodeT ( const GTreeNodeT<T> & original );
64  virtual ~GTreeNodeT ( );
65  //@}
66 
67  //------------------------------------------------------------
68  /** @name Tree structure functions */
69  //@{
70  virtual void SetParent ( GTreeBranchT<T> * parent_ptr ); // inline
71  virtual void SetListIter ( GListIterT<GTreeNodeT <T> > * iter_ptr ); // inline
72 
73  virtual const GTreeBranchT<T> * GetParent ( ) const; // inline
74  virtual GTreeBranchT<T> * GetParent ( ); // inline
75  virtual const GTreeNodeT<T> * GetRoot ( ) const; // inline
76  virtual GTreeNodeT<T> * GetRoot ( ); // inline
77 
78  virtual bool IsBranch ( ) const; //inline
79  virtual bool IsLeaf ( ) const; //inline
80 
81  void SetUserData ( void * data ); // inline
82  void * GetUserData ( ) const; // inline
83 
84  virtual GListIterT < GTreeNodeT <T> > GetListIter ( ) const; // inline
85 
86  //@}
87 
88  //------------------------------------------------------------
89  /** @name Tree structure exploration */
90  //@{
91  virtual GTreeNodeT<T> * NextNode ( );
92 
93  virtual GTreeLeafT<T> * FirstLeaf ( );
94  virtual GTreeLeafT<T> * NextLeaf ( );
95 
96  virtual GTreeNodeT<T> * FindNode ( const string & name );
97  virtual GTreeBranchT<T> * FindBranch ( const string & name );
98  //@}
99 
100 
101  //------------------------------------------------------------
102  /** @name Tree construction functions */
103  //@{
104  virtual GTreeBranchT<T> * AddBranch ( const string & bname ); // inline
105  virtual GTreeBranchT<T> * AddBranch ( const string & parent, const string & bname );
106 
107  virtual GTreeLeafT<T> * AddLeaf ( T & object_ref ); // inline
108  virtual GTreeLeafT<T> * AddLeaf ( const string & parent, T & object_ref );
109 
110  virtual GTreeLeafT<T> * AddLeaf ( T * object_ptr ); // inline
111  virtual GTreeLeafT<T> * AddLeaf ( const string & parent, T * object_ptr );
112  //@}
113 
114  //------------------------------------------------------------
115  /** @name Element information */
116  //@{
117  u_int GetLevel ( ) const;
118  virtual string GetFullName ( ) const;
119 
120  /*! Function returning the number of leaves.*/
121  virtual u_int GetLeafCount ( ) const = 0;
122 
123  /*! Function returning the total number of leaves, recursively in the
124  * tree structure.*/
125  virtual u_int GetLeafTotalCount ( ) const = 0;
126 
127  //@}
128 
129  //------------------------------------------------------------
130  /** @name Creation of objects structures from the tree */
131  //@{
132  virtual GNamedListT<T> * CreateList ( );
133 
134  virtual GTreeNodeT<GItem> * CreateItemTree ( ) const = 0;
135  virtual GItemList * CreateItemList ( );
136  //@}
137 
138  //------------------------------------------------------------
139  /** @name Print out */
140  //@{
141  /*! Print the list: elements are given by their name or associated information.
142  * \param fp file pointer
143  * \param prefix text written before each line
144  * \param info if true, the information is printed instead of the name
145  */
146  virtual void Print ( FILE * fp = stdout, const string & prefix = "", bool info = false ) const = 0;
147  //@}
148 };
149 
150 //----------------------------------------------------------------------
151 // Inline functions
152 #include "icc/GTreeNodeT.icc"
153 
154 //======================================================================
155 #endif
156 
GTreeBranchT< T > * parent
Parent element of the tree.
Definition: GTreeNodeT.hh:52
virtual GTreeNodeT< T > * FindNode(const string &name)
Definition: GTreeNodeT.icc:207
virtual GTreeLeafT< T > * FirstLeaf()
Definition: GTreeNodeT.icc:155
Definition: GNamed.hh:21
Definition: GListIterT.hh:21
virtual bool IsLeaf() const
Definition: GTreeNodeT.icc:88
virtual void SetParent(GTreeBranchT< T > *parent_ptr)
Definition: GTreeNodeT.icc:53
Definition: GTreeLeafT.hh:23
Definition: GTreeBranchT.hh:20
virtual void SetListIter(GListIterT< GTreeNodeT< T > > *iter_ptr)
Definition: GTreeNodeT.icc:60
virtual GItemList * CreateItemList()
Definition: GTreeNodeT.icc:455
Definition: GNamedListT.hh:23
virtual void Print(FILE *fp=stdout, const string &prefix="", bool info=false) const =0
virtual GNamedListT< T > * CreateList()
Definition: GTreeNodeT.icc:436
GListIterT< GTreeNodeT< T > > * list_iter
Pointer to the iterator in parent list.
Definition: GTreeNodeT.hh:53
virtual GTreeLeafT< T > * AddLeaf(T &object_ref)
Definition: GTreeNodeT.icc:355
string name
Object name.
Definition: GNamed.hh:31
u_int GetLevel() const
Definition: GTreeNodeT.icc:419
#define GObjectV(T)
Definition: GClassDefine.hh:77
virtual const GTreeBranchT< T > * GetParent() const
Definition: GTreeNodeT.icc:66
void * GetUserData() const
Definition: GTreeNodeT.icc:100
virtual const GTreeNodeT< T > * GetRoot() const
Definition: GTreeNodeT.icc:74
virtual u_int GetLeafTotalCount() const =0
virtual string GetFullName() const
Definition: GTreeNodeT.icc:401
virtual bool IsBranch() const
Definition: GTreeNodeT.icc:84
virtual u_int GetLeafCount() const =0
Definition: GItemList.hh:26
void SetUserData(void *data)
Definition: GTreeNodeT.icc:96
virtual GTreeBranchT< T > * FindBranch(const string &name)
Definition: GTreeNodeT.icc:314
Definition: GItem.hh:24
virtual GTreeBranchT< T > * AddBranch(const string &bname)
Definition: GTreeNodeT.icc:335
Definition: GTreeNodeT.hh:44
unsigned int u_int
Definition: GTypes.hh:38
void * user_data
Pointer to a additional user data.
Definition: GTreeNodeT.hh:55
virtual GTreeLeafT< T > * NextLeaf()
Definition: GTreeNodeT.icc:173
virtual GTreeNodeT< T > * NextNode()
Definition: GTreeNodeT.icc:120
virtual GListIterT< GTreeNodeT< T > > GetListIter() const
Definition: GTreeNodeT.icc:108