20 #ifndef TULIP_ITERATOR_H 21 #define TULIP_ITERATOR_H 29 #include <tulip/tulipconf.h> 34 extern TLP_SCOPE
void incrNumIterators();
35 extern TLP_SCOPE
void decrNumIterators();
36 extern TLP_SCOPE
int getNumIterators();
103 enum IteratorStatus { Begin = 0, Finished = 1, End = 3 };
105 IteratorStatus _iteratorStatus;
108 iterator_t(Iterator<T> *it, IteratorStatus iteratorStatus = End)
109 : _iteratorStatus(iteratorStatus), _it(it) {
110 if ((_iteratorStatus == Begin) && (_it->hasNext() ==
false)) {
111 _iteratorStatus = Finished;
116 if (_iteratorStatus != End) {
121 inline bool operator!=(
const iterator_t &it)
const {
122 return ((_iteratorStatus & it._iteratorStatus) == 0) || (_it != it._it);
125 inline const iterator_t &operator++() {
127 _iteratorStatus = Finished;
131 inline T operator*()
const {
132 assert(_iteratorStatus != Finished);
138 inline iterator_t begin() {
139 return iterator_t(
this, iterator_t::Begin);
142 inline iterator_t end() {
143 return iterator_t(
this);
147 #ifndef DOXYGEN_NOTFOR_DEVEL 150 template <
typename T>
151 inline auto begin(Iterator<T> *it) -> decltype(it->begin()) {
155 template <
typename T>
156 inline auto end(Iterator<T> *it) -> decltype(it->end()) {
174 template <
typename T>
176 unsigned int count = 0;
177 while (it->hasNext()) {
198 template <
typename T>
200 unsigned int count = 0;
201 while (it->hasNext()) {
203 if (count == minNbElements) {
226 template <
typename T>
246 template <
typename T,
class MapFunction>
248 if (
sizeof(T) >
sizeof(
double)) {
249 for (
const auto &v : it) {
277 template <
typename T,
typename reduceType,
class ReduceFunction>
279 ReduceFunction reduceFunction) {
280 reduceType val = initVal;
281 if (
sizeof(T) >
sizeof(
double)) {
282 for (
const auto &v : it) {
283 val = reduceFunction(val, v);
287 val = reduceFunction(val, v);
306 template <
typename T>
309 while (it->hasNext()) {
310 ret.emplace_back(std::move(it->next()));
329 template <
typename T>
332 while (it->hasNext()) {
333 ret.emplace_back(std::move(it->next()));
352 template <
typename T>
355 while (it->hasNext()) {
356 ret.emplace(std::move(it->next()));
362 #ifndef DOXYGEN_NOTFOR_DEVEL 363 template <
typename TYPE>
364 class UINTIterator :
public Iterator<TYPE> {
367 ~UINTIterator()
override {
373 TYPE
next()
override {
374 return TYPE(it->
next());
381 #endif // DOXYGEN_NOTFOR_DEVEL 386 #include <tulip/Edge.h> 387 #include <tulip/Node.h> bool iteratorEmpty(Iterator< T > *it)
Checks if an iterator is empty.
unsigned int iteratorCount(Iterator< T > *it)
Counts the number of iterated elements.
virtual T next()=0
Moves the Iterator on the next element.
Interface for Tulip iterators. Allows basic iteration operations only.
void iteratorMap(Iterator< T > *it, MapFunction &&mapFunction)
Applies a function to each iterated element.
std::list< T > iteratorList(Iterator< T > *it)
Converts an iterator to a std::list.
std::set< T > iteratorSet(Iterator< T > *it)
Converts an iterator to a std::set.
bool iteratorCountCheck(Iterator< T > *it, unsigned int minNbElements)
Checks a minimum amount of iterated elements.
std::vector< T > iteratorVector(Iterator< T > *it)
Converts an iterator to a std::vector.
reduceType iteratorReduce(Iterator< T > *it, const reduceType &initVal, ReduceFunction reduceFunction)
Reduces iterated elements to a single value.
virtual bool hasNext()=0
Tells if the sequence is at its end.