Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
ConcatIterator.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 1 and Inria Bordeaux - Sud Ouest
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_CONCATITERATOR_H
22 #define TULIP_CONCATITERATOR_H
23 #include <tulip/Iterator.h>
24 
25 namespace tlp {
26 
27 /**
28 * @brief This Iterator iterates over the sequence formed by the concatenation of the sequences it is given.
29 * @warning This class takes ownership of the Iterators it is given.
30 **/
31 template<class itType> struct ConcatIterator : public Iterator<itType> {
32 
33  /**
34  * @brief Creates an Iterator that iterates over the concatenation of the two sequences it is given.
35  *
36  * @param itOne The first sequence to iterate upon.
37  * @param itTwo The second sequence, which will be iterated upon after the first sequence has been completely iterated upon.
38  **/
39  ConcatIterator(Iterator<itType> *itOne,Iterator<itType> *itTwo) :
40  itOne(itOne),
41  itTwo(itTwo) {
42  }
43 
44  /**
45  * @brief Deletes the two iterators it was given at construction.
46  **/
47  ~ConcatIterator() {
48  delete itOne;
49  delete itTwo;
50  }
51 
52  itType next() {
53  if (itOne->hasNext())
54  return itOne->next();
55  else {
56  return itTwo->next();
57  }
58  }
59 
60  bool hasNext() {
61  return (itOne->hasNext() || itTwo->hasNext());
62  }
63 
64 private :
65  Iterator<itType> *itOne;
66  Iterator<itType> *itTwo;
67 };
68 
69 }
70 #endif
71 ///@endcond