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
DAGNode.h
1 /*
2  * $Id$
3  * DAGNode class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2005-08, 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_DAGNODE_H
23 #define ELM_GENSTRUCT_DAGNODE_H
24 
25 #include <elm/assert.h>
26 #include <elm/PreIterator.h>
27 #include <elm/genstruct/SLList.h>
28 #include <elm/genstruct/HashTable.h>
29 
30 namespace elm { namespace genstruct {
31 
32 // DAGNode class
33 template <class T> class DAGNode {
34 
35  T value;
36  SLList<DAGNode*> children;
37  bool deleted;
38 
39 
40 public:
41 
42  // Constructors / Destructors
43  inline DAGNode(const T& _value);
44  inline ~DAGNode();
45 
46  // Mutators
47  inline void addChild(DAGNode *child);
48  inline void removeChild(DAGNode *child);
49 
50  // Accessors
51  inline T& useValue(void);
52 
53  // Iterator class
54  class Iterator: public PreIterator<Iterator, DAGNode*> {
55  friend class DAGNode;
56 
57  typename SLList<DAGNode*>::Iterator iter;
58  inline void skipDeleted();
59  public:
60  inline Iterator(const DAGNode& _node);
61  inline Iterator(const Iterator& source);
62 
63  inline void operator=(const Iterator& source);
64  inline bool ended(void) const;
65  inline DAGNode* item(void) const;
66  inline void next(void);
67  };
68 
69 
70 };
71 
72 template <class T>
73 inline T& DAGNode<T>::useValue(void) {
74  return value;
75 }
76 
77 template <class T>
78 inline DAGNode<T>::DAGNode(const T& _value) : value(_value), deleted(false) {
79 
80 }
81 
82 template <class T>
84 }
85 
86 template <class T>
87 inline void DAGNode<T>::addChild(DAGNode *child) {
88  this->children.addFirst(child);
89 }
90 
91 template <class T>
92 inline void DAGNode<T>::removeChild(DAGNode *child) {
93  this->children.remove(child);
94 }
95 
96 // DAGNode::Iterator class
97 template <class T> inline DAGNode<T>::Iterator::Iterator(const DAGNode& _node)
98 : iter(typename SLList<DAGNode*>::Iterator(_node.children)) {
99 }
100 
101 template <class T> inline DAGNode<T>::Iterator::Iterator(const Iterator& source)
102 : iter(source.iter) {
103 }
104 
105 template <class T> inline void DAGNode<T>::Iterator::operator=(const Iterator& source)
106 {
107  iter = source.iter;
108 }
109 template <class T> inline bool DAGNode<T>::Iterator::ended(void) const {
110  return iter.ended();
111 }
112 template <class T> inline DAGNode<T>* DAGNode<T>::Iterator::item(void) const {
113  return iter.item();
114 }
115 template <class T> inline void DAGNode<T>::Iterator::next(void) {
116  iter.next();
117 
118 }
119 
120 template <class T> inline void DAGNode<T>::Iterator::skipDeleted(void) {
121  while ((!iter.ended()) && (iter.item()->deleted) ) {
122  iter.next();
123  }
124 }
125 
126 } } // elm::genstruct
127 
128 #endif // ELM_GENSTRUCT_DAGNODE_H
bool ended(void) const
Definition: DAGNode.h:109
Definition: PreIterator.h:29
DAGNode(const T &_value)
Definition: DAGNode.h:78
void next(void)
Definition: DAGNode.h:115
Definition: SLList.h:34
DAGNode * item(void) const
Definition: DAGNode.h:112
Definition: DAGNode.h:33
void removeChild(DAGNode *child)
Definition: DAGNode.h:92
value_t value(CString name, int value)
Definition: rtti.h:40
void operator=(const Iterator &source)
Definition: DAGNode.h:105
Definition: DAGNode.h:54
void addChild(DAGNode *child)
Definition: DAGNode.h:87
T & useValue(void)
Definition: DAGNode.h:73
~DAGNode()
Definition: DAGNode.h:83
Iterator(const DAGNode &_node)
Definition: DAGNode.h:97
Definition: SLList.h:67