Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
GraphIterator.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip 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.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef TULIP_GGRAPHITERATOR_H
22 #define TULIP_GGRAPHITERATOR_H
23 #include <tulip/Iterator.h>
24 #include <tulip/memorypool.h>
25 #include <set>
26 
27 #include <tulip/MutableContainer.h>
28 #include <tulip/Observable.h>
29 #include <tulip/tulipconf.h>
30 #include <iostream>
31 
32 #ifndef DOXYGEN_NOTFOR_DEVEL
33 namespace tlp {
34 
35 class Graph;
36 class GraphImpl;
37 struct node;
38 struct edge;
39 class NodeIterator :public Iterator<node> {
40 };
41 
42 class EdgeIterator :public Iterator<edge> {
43 };
44 
45 #if !defined(NDEBUG) && !defined(_OPENMP)
46 class NodeIteratorObserver :public NodeIterator, public Observable {
47 private:
48  // Observable interface
49  void treatEvent(const Event&);
50 };
51 
52 class EdgeIteratorObserver :public EdgeIterator, public Observable {
53 private:
54  // Observable interface
55  void treatEvent(const Event&);
56 };
57 #endif
58 //===========================================================
59 ///Factorization of code for iterators
60 class FactorNodeIterator
61 #if defined(NDEBUG) || defined(_OPENMP)
62  :public NodeIterator
63 #else
64  :public NodeIteratorObserver
65 #endif
66 {
67 protected:
68  Graph *_parentGraph;
69  const MutableContainer<bool>& _filter;
70 public:
71  FactorNodeIterator(const Graph *sG,const MutableContainer<bool>& filter):
72  _parentGraph(sG->getSuperGraph()),
73  _filter(filter) {
74  }
75 };
76 
77 class FactorEdgeIterator
78 #if defined(NDEBUG) || defined(_OPENMP)
79  :public EdgeIterator
80 #else
81  :public EdgeIteratorObserver
82 #endif
83 {
84 protected:
85  Graph *_parentGraph;
86  const MutableContainer<bool>& _filter;
87 public:
88  FactorEdgeIterator(const Graph *sG,const MutableContainer<bool>& filter):
89  _parentGraph(sG->getSuperGraph()),
90  _filter(filter) {
91  }
92 };
93 //============================================================
94 ///Node iterator for GraphView
95 class SGraphNodeIterator:public FactorNodeIterator, public MemoryPool<SGraphNodeIterator> {
96 private:
97  const Graph* sg;
98  Iterator<node> *it;
99  node curNode;
100  bool value;
101 
102 public:
103  SGraphNodeIterator(const Graph *sG, const MutableContainer<bool>& filter,
104  bool value=true);
105  ~SGraphNodeIterator();
106  node next();
107  bool hasNext();
108 protected:
109  void prepareNext();
110 };
111 //============================================================
112 ///Out node iterator for GraphView
113 class OutNodesIterator:public FactorNodeIterator, public MemoryPool<OutNodesIterator> {
114 private:
115  Iterator<edge> *it;
116 #if !defined(NDEBUG) && !defined(_OPENMP)
117  const Graph *sg;
118 #endif
119 public:
120  OutNodesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
121  ~OutNodesIterator();
122  node next();
123  bool hasNext();
124 };
125 //============================================================
126 ///In node iterator for GraphView
127 class InNodesIterator:public FactorNodeIterator, public MemoryPool<InNodesIterator> {
128 private:
129  Iterator<edge> *it;
130 #if !defined(NDEBUG) && !defined(_OPENMP)
131  const Graph *sg;
132 #endif
133 public:
134  InNodesIterator(const Graph *sG, const MutableContainer<bool>& filter ,node n);
135  ~InNodesIterator();
136  node next();
137  bool hasNext();
138 };
139 //============================================================
140 ///In Out node iterator for GraphView
141 class InOutNodesIterator:public FactorNodeIterator, public MemoryPool<InOutNodesIterator> {
142 private:
143  Iterator<edge> *it;
144  node n;
145 #if !defined(NDEBUG) && !defined(_OPENMP)
146  const Graph *sg;
147 #endif
148 public:
149  InOutNodesIterator(const Graph *sG,const MutableContainer<bool>& filter,node n);
150  ~InOutNodesIterator();
151  node next();
152  bool hasNext();
153 };
154 //=============================================================
155 ///Edge iterator for GraphView
156 class SGraphEdgeIterator:public FactorEdgeIterator, public MemoryPool<SGraphEdgeIterator> {
157 private:
158  const Graph* sg;
159  Iterator<edge> *it;
160  edge curEdge;
161  bool value;
162 
163 public:
164  SGraphEdgeIterator(const Graph *sG, const MutableContainer<bool>& filter,
165  bool value = true);
166  ~SGraphEdgeIterator();
167  edge next();
168  bool hasNext();
169 protected:
170  void prepareNext();
171 };
172 //============================================================
173 ///Out edge iterator for GraphView
174 class OutEdgesIterator:public FactorEdgeIterator, public MemoryPool<OutEdgesIterator> {
175 private:
176  Iterator<edge> *it;
177  edge curEdge;
178 
179 public:
180  OutEdgesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
181  ~OutEdgesIterator();
182  edge next();
183  bool hasNext();
184 protected:
185  void prepareNext();
186 };
187 //============================================================
188 ///In edge iterator for GraphView
189 class InEdgesIterator:public FactorEdgeIterator, public MemoryPool<InEdgesIterator> {
190 private:
191  Iterator<edge> *it;
192  edge curEdge;
193 
194 public:
195  InEdgesIterator(const Graph *sG,const MutableContainer<bool>& filter,node n);
196  ~InEdgesIterator();
197  edge next();
198  bool hasNext();
199 protected:
200  void prepareNext();
201 };
202 //============================================================
203 ///In Out edge iterator for GraphView
204 class InOutEdgesIterator:public FactorEdgeIterator, public MemoryPool<InOutEdgesIterator> {
205 private:
206  Iterator<edge> *it;
207  edge curEdge;
208 
209 public:
210  InOutEdgesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
211  ~InOutEdgesIterator();
212  edge next();
213  bool hasNext();
214 protected:
215  void prepareNext();
216 };
217 
218 //============================================================
219 //Iterator for the GraphImpl
220 //============================================================
221 class GraphImplNodeIterator
222 #if defined(NDEBUG) || defined(_OPENMP)
223  :public NodeIterator, public MemoryPool<GraphImplNodeIterator>
224 #else
225  :public NodeIteratorObserver
226 #endif
227 {
228 private:
229 #if !defined(NDEBUG) && !defined(_OPENMP)
230  GraphImpl *graph;
231 #endif
232  Iterator<node> *itId;
233 public:
234  GraphImplNodeIterator(const Graph *g, Iterator<node>* it);
235  ~GraphImplNodeIterator();
236  node next();
237  bool hasNext();
238 };
239 //=============================================================
240 ///Edge iterator for data sg
241 class GraphImplEdgeIterator
242 #if defined(NDEBUG) || defined(_OPENMP)
243  :public EdgeIterator, public MemoryPool<GraphImplEdgeIterator>
244 #else
245  :public EdgeIteratorObserver
246 #endif
247 {
248 private:
249 #if !defined(NDEBUG) && !defined(_OPENMP)
250  GraphImpl *graph;
251 #endif
252  Iterator<edge> *itId;
253 public:
254  GraphImplEdgeIterator(const Graph *g, Iterator<edge>* it);
255  ~GraphImplEdgeIterator();
256  edge next();
257  bool hasNext();
258 };
259 //============================================================
260 
261 }
262 #endif // DOXYGEN_NOTFOR_DEVEL
263 #endif
264 ///@endcond