Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Tree.h
1 /*
2  * $Id$
3  * Tree class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2008, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_GENSTRUCT_TREE_H
23 #define ELM_GENSTRUCT_TREE_H
24 
25 #include <elm/PreIterator.h>
26 #include <elm/inhstruct/Tree.h>
27 
28 namespace elm { namespace genstruct {
29 
30 // Tree class
31 template <class T>
32 class Tree: private inhstruct::Tree {
33 public:
34  inline Tree(const T& value): _value(value) { }
35 
36  inline const T& data(void) const { return _value; }
37  inline T& data(void) { return _value; }
38 
39  // Accessors
40  inline const Tree *children(void) const
41  { return static_cast<Tree *>(inhstruct::Tree::children()); }
42  inline Tree *children(void)
43  { return static_cast<Tree *>(inhstruct::Tree::children()); }
44  inline const Tree *sibling(void) const
45  { return static_cast<Tree *>(inhstruct::Tree::sibling()); }
46  inline Tree *sibling(void)
47  { return static_cast<Tree *>(inhstruct::Tree::sibling()); }
48  bool hasChild(Tree *tree) const
49  { return inhstruct::Tree::hasChild(tree); }
50  inline bool contains(Tree *tree) const { return hasChild(tree); }
51  inline int count(void) const
52  { return inhstruct::Tree::count(); }
53  inline bool isEmpty(void) const
54  { return inhstruct::Tree::isEmpty(); }
55  inline operator bool(void) const
56  { return inhstruct::Tree::isEmpty(); }
57 
58  // Iterator class
59  class Iterator: public PreIterator<Iterator, const T&> {
60  public:
61  inline Iterator(const Iterator& iter): it(iter.it) { }
62  inline Iterator(const Tree *tree): it(tree) { }
63  inline bool ended (void) const { return it.ended(); }
64  inline const T& item(void) const
65  { return static_cast<Tree *>(it.item())->_value; }
66  inline void next(void) { it.next(); }
67  private:
69  };
70 
71  // Mutators
72  inline void prependChild(Tree *child)
74  inline void appendChild(Tree *child)
76  inline void addSibling(Tree *newSibling)
77  { inhstruct::Tree::addSibling(newSibling); }
78  inline void add(Tree *child)
79  { inhstruct::Tree::add(child); }
80  template <class TT> void addAll(const TT& coll)
81  { inhstruct::Tree::addAll(coll); }
82  inline void removeChild(Tree *child)
84  inline void remove(Tree *child)
85  { inhstruct::Tree::remove(child); }
86  inline void remove(const Iterator& iter)
87  { removeChild(iter); }
88  template <class TT> void removeAll(const TT& coll)
89  { inhstruct::Tree::removeAll(coll); }
90  inline void clear(void)
92 
93 private:
94  T _value;
95 };
96 
97 } } // elm:genstruct
98 
99 #endif // ELM_GENSTRUCT_TREE_H
Tree * item(void) const
Definition: Tree.h:51
Definition: Tree.h:59
void prependChild(Tree *child)
Definition: Tree.h:58
Definition: PreIterator.h:29
void prependChild(Tree *child)
Definition: Tree.h:72
void addSibling(Tree *newSibling)
Definition: Tree.h:76
Tree * sibling(void)
Definition: Tree.h:46
bool hasChild(Tree *tree) const
Definition: Tree.h:39
bool ended(void) const
Definition: Tree.h:50
void addSibling(Tree *newSibling)
Definition: Tree.h:65
void next(void)
Definition: Tree.h:52
void clear(void)
Definition: Tree.h:90
Tree(const T &value)
Definition: Tree.h:34
int count(void) const
Definition: Tree.h:51
bool isEmpty(void) const
Definition: Tree.h:42
T & data(void)
Definition: Tree.h:37
void next(void)
Definition: Tree.h:66
value_t value(CString name, int value)
Definition: rtti.h:40
bool isEmpty(void) const
Definition: Tree.h:53
Tree * sibling(void) const
Definition: Tree.h:38
void removeAll(const TT &coll)
Definition: Tree.h:88
Tree * children(void) const
Definition: Tree.h:37
Tree * children(void)
Definition: Tree.h:42
bool hasChild(Tree *tree) const
Definition: Tree.h:48
void clear(void)
Definition: Tree.h:79
void add(Tree *child)
Definition: Tree.h:78
void removeChild(Tree *child)
Definition: inhstruct_Tree.cpp:145
bool contains(Tree *tree) const
Definition: Tree.h:50
bool ended(void) const
Definition: Tree.h:63
void remove(Tree *child)
Definition: Tree.h:75
Definition: Tree.h:46
const T & data(void) const
Definition: Tree.h:36
const Tree * sibling(void) const
Definition: Tree.h:44
void appendChild(Tree *child)
Definition: Tree.h:74
void appendChild(Tree *child)
Definition: inhstruct_Tree.cpp:115
void addAll(const TT &coll)
Definition: Tree.h:80
void removeAll(const TT &coll)
Definition: Tree.h:77
const Tree * children(void) const
Definition: Tree.h:40
void add(Tree *child)
Definition: Tree.h:71
void removeChild(Tree *child)
Definition: Tree.h:82
Iterator(const Iterator &iter)
Definition: Tree.h:61
void addAll(const TT &coll)
Definition: Tree.h:72
Definition: Tree.h:31
Iterator(const Tree *tree)
Definition: Tree.h:62
int count(void) const
Definition: inhstruct_Tree.cpp:76
const T & item(void) const
Definition: Tree.h:64
Definition: Tree.h:32