Tulip  4.10.0
Better Visualization Through Research
Iterator.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_ITERATOR_H
22 #define TULIP_ITERATOR_H
23 
24 #include <tulip/tulipconf.h>
25 
26 namespace tlp {
27 
28 ///@cond DOXYGEN_HIDDEN
29 extern TLP_SCOPE void incrNumIterators();
30 extern TLP_SCOPE void decrNumIterators();
31 extern TLP_SCOPE int getNumIterators();
32 ///@endcond
33 
34 /**
35 * @brief Interface for Tulip iterators.
36 * Allows basic iteration operations only.
37 * @see forEach
38 **/
39 template<class itType> struct Iterator {
40  ///
41  Iterator() {
42 #ifndef NDEBUG
43  incrNumIterators();
44 #endif
45  }
46  ///
47  virtual ~Iterator() {
48 #ifndef NDEBUG
49  decrNumIterators();
50 #endif
51  }
52  /**
53  * @brief Moves the Iterator on the next element.
54  *
55  * @return The current element pointed by the Iterator.
56  **/
57  virtual itType next()=0;
58 
59  /**
60  * @brief Tells if the sequence is at its end.
61  *
62  * @return bool Whether there are more elements to iterate.
63  **/
64  virtual bool hasNext()=0;
65 };
66 
67 //template<class C>class Iterator;
68 #ifndef DOXYGEN_NOTFOR_DEVEL
69 template<typename TYPE> class UINTIterator : public Iterator<TYPE> {
70 public:
71  UINTIterator(Iterator<unsigned int> *it):it(it) {
72  }
73  ~UINTIterator() {
74  delete it;
75  }
76  bool hasNext() {
77  return it->hasNext();
78  }
79  TYPE next() {
80  return TYPE(it->next());
81  }
82 private:
84 };
85 #endif // DOXYGEN_NOTFOR_DEVEL
86 
87 }
88 
89 
90 #ifdef _MSC_VER
91 
92 #include <tulip/Edge.h>
93 #include <tulip/Node.h>
94 
95 template struct TLP_SCOPE tlp::Iterator<tlp::edge>;
96 template struct TLP_SCOPE tlp::Iterator<tlp::node>;
97 #endif
98 #endif
99 
100 ///@endcond
virtual itType next()=0
Moves the Iterator on the next element.
Interface for Tulip iterators. Allows basic iteration operations only.
Definition: Iterator.h:39
virtual bool hasNext()=0
Tells if the sequence is at its end.