Tulip  4.10.0
Better Visualization Through Research
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 namespace tlp {
33 
34 class Graph;
35 class GraphImpl;
36 struct node;
37 struct edge;
38 class NodeIterator :public Iterator<node> {
39 };
40 
41 class EdgeIterator :public Iterator<edge> {
42 };
43 
44 #if !defined(NDEBUG) && !defined(_OPENMP)
45 class NodeIteratorObserver :public NodeIterator, public Observable {
46 private:
47  // Observable interface
48  void treatEvent(const Event&);
49 };
50 
51 class EdgeIteratorObserver :public EdgeIterator, public Observable {
52 private:
53  // Observable interface
54  void treatEvent(const Event&);
55 };
56 #endif
57 //===========================================================
58 ///Factorization of code for iterators
59 class FactorNodeIterator
60 #if defined(NDEBUG) || defined(_OPENMP)
61  :public NodeIterator
62 #else
63  :public NodeIteratorObserver
64 #endif
65 {
66 protected:
67  Graph *_parentGraph;
68  const MutableContainer<bool>& _filter;
69 public:
70  FactorNodeIterator(const Graph *sG,const MutableContainer<bool>& filter):
71  _parentGraph(sG->getSuperGraph()),
72  _filter(filter) {
73  }
74 };
75 
76 class FactorEdgeIterator
77 #if defined(NDEBUG) || defined(_OPENMP)
78  :public EdgeIterator
79 #else
80  :public EdgeIteratorObserver
81 #endif
82 {
83 protected:
84  Graph *_parentGraph;
85  const MutableContainer<bool>& _filter;
86 public:
87  FactorEdgeIterator(const Graph *sG,const MutableContainer<bool>& filter):
88  _parentGraph(sG->getSuperGraph()),
89  _filter(filter) {
90  }
91 };
92 //============================================================
93 ///Node iterator for GraphView
94 class SGraphNodeIterator:public FactorNodeIterator, public MemoryPool<SGraphNodeIterator> {
95 private:
96  const Graph* sg;
97  Iterator<node> *it;
98  node curNode;
99  bool value;
100 
101 public:
102  SGraphNodeIterator(const Graph *sG, const MutableContainer<bool>& filter,
103  bool value=true);
104  ~SGraphNodeIterator();
105  node next();
106  bool hasNext();
107 protected:
108  void prepareNext();
109 };
110 //============================================================
111 ///Out node iterator for GraphView
112 class OutNodesIterator:public FactorNodeIterator, public MemoryPool<OutNodesIterator> {
113 private:
114  Iterator<edge> *it;
115 #if !defined(NDEBUG) && !defined(_OPENMP)
116  const Graph *sg;
117 #endif
118 public:
119  OutNodesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
120  ~OutNodesIterator();
121  node next();
122  bool hasNext();
123 };
124 //============================================================
125 ///In node iterator for GraphView
126 class InNodesIterator:public FactorNodeIterator, public MemoryPool<InNodesIterator> {
127 private:
128  Iterator<edge> *it;
129 #if !defined(NDEBUG) && !defined(_OPENMP)
130  const Graph *sg;
131 #endif
132 public:
133  InNodesIterator(const Graph *sG, const MutableContainer<bool>& filter ,node n);
134  ~InNodesIterator();
135  node next();
136  bool hasNext();
137 };
138 //============================================================
139 ///In Out node iterator for GraphView
140 class InOutNodesIterator:public FactorNodeIterator, public MemoryPool<InOutNodesIterator> {
141 private:
142  Iterator<edge> *it;
143  node n;
144 #if !defined(NDEBUG) && !defined(_OPENMP)
145  const Graph *sg;
146 #endif
147 public:
148  InOutNodesIterator(const Graph *sG,const MutableContainer<bool>& filter,node n);
149  ~InOutNodesIterator();
150  node next();
151  bool hasNext();
152 };
153 //=============================================================
154 ///Edge iterator for GraphView
155 class SGraphEdgeIterator:public FactorEdgeIterator, public MemoryPool<SGraphEdgeIterator> {
156 private:
157  const Graph* sg;
158  Iterator<edge> *it;
159  edge curEdge;
160  bool value;
161 
162 public:
163  SGraphEdgeIterator(const Graph *sG, const MutableContainer<bool>& filter,
164  bool value = true);
165  ~SGraphEdgeIterator();
166  edge next();
167  bool hasNext();
168 protected:
169  void prepareNext();
170 };
171 //============================================================
172 ///Out edge iterator for GraphView
173 class OutEdgesIterator:public FactorEdgeIterator, public MemoryPool<OutEdgesIterator> {
174 private:
175  Iterator<edge> *it;
176  edge curEdge;
177 
178 public:
179  OutEdgesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
180  ~OutEdgesIterator();
181  edge next();
182  bool hasNext();
183 protected:
184  void prepareNext();
185 };
186 //============================================================
187 ///In edge iterator for GraphView
188 class InEdgesIterator:public FactorEdgeIterator, public MemoryPool<InEdgesIterator> {
189 private:
190  Iterator<edge> *it;
191  edge curEdge;
192 
193 public:
194  InEdgesIterator(const Graph *sG,const MutableContainer<bool>& filter,node n);
195  ~InEdgesIterator();
196  edge next();
197  bool hasNext();
198 protected:
199  void prepareNext();
200 };
201 //============================================================
202 ///In Out edge iterator for GraphView
203 class InOutEdgesIterator:public FactorEdgeIterator, public MemoryPool<InOutEdgesIterator> {
204 private:
205  Iterator<edge> *it;
206  edge curEdge;
207 
208 public:
209  InOutEdgesIterator(const Graph *sG, const MutableContainer<bool>& filter, node n);
210  ~InOutEdgesIterator();
211  edge next();
212  bool hasNext();
213 protected:
214  void prepareNext();
215 };
216 
217 //============================================================
218 //Iterator for the GraphImpl
219 //============================================================
220 class GraphImplNodeIterator
221 #if defined(NDEBUG) || defined(_OPENMP)
222  :public NodeIterator, public MemoryPool<GraphImplNodeIterator>
223 #else
224  :public NodeIteratorObserver
225 #endif
226 {
227 private:
228 #if !defined(NDEBUG) && !defined(_OPENMP)
229  GraphImpl *graph;
230 #endif
231  Iterator<node> *itId;
232 public:
233  GraphImplNodeIterator(const Graph *g, Iterator<node>* it);
234  ~GraphImplNodeIterator();
235  node next();
236  bool hasNext();
237 };
238 //=============================================================
239 ///Edge iterator for data sg
240 class GraphImplEdgeIterator
241 #if defined(NDEBUG) || defined(_OPENMP)
242  :public EdgeIterator, public MemoryPool<GraphImplEdgeIterator>
243 #else
244  :public EdgeIteratorObserver
245 #endif
246 {
247 private:
248 #if !defined(NDEBUG) && !defined(_OPENMP)
249  GraphImpl *graph;
250 #endif
251  Iterator<edge> *itId;
252 public:
253  GraphImplEdgeIterator(const Graph *g, Iterator<edge>* it);
254  ~GraphImplEdgeIterator();
255  edge next();
256  bool hasNext();
257 };
258 //============================================================
259 
260 }
261 #endif
262 
263 ///@endcond
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39