![]() |
Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 ///@cond DOXYGEN_HIDDEN 00020 00021 #ifndef TULIP_CONCATITERATOR_H 00022 #define TULIP_CONCATITERATOR_H 00023 #include <tulip/Iterator.h> 00024 00025 namespace tlp { 00026 00027 /** 00028 * @brief This Iterator iterates over the sequence formed by the concatenation of the sequences it is given. 00029 * @warning This class takes ownership of the Iterators it is given. 00030 **/ 00031 template<class itType> struct ConcatIterator : public Iterator<itType> { 00032 00033 /** 00034 * @brief Creates an Iterator that iterates over the concatenation of the two sequences it is given. 00035 * 00036 * @param itOne The first sequence to iterate upon. 00037 * @param itTwo The second sequence, which will be iterated upon after the first sequence has been completely iterated upon. 00038 **/ 00039 ConcatIterator(Iterator<itType> *itOne,Iterator<itType> *itTwo) : 00040 itOne(itOne), 00041 itTwo(itTwo) { 00042 } 00043 00044 /** 00045 * @brief Deletes the two iterators it was given at construction. 00046 **/ 00047 ~ConcatIterator() { 00048 delete itOne; 00049 delete itTwo; 00050 } 00051 00052 itType next() { 00053 if (itOne->hasNext()) 00054 return itOne->next(); 00055 else { 00056 return itTwo->next(); 00057 } 00058 } 00059 00060 bool hasNext() { 00061 return (itOne->hasNext() || itTwo->hasNext()); 00062 } 00063 00064 private : 00065 Iterator<itType> *itOne; 00066 Iterator<itType> *itTwo; 00067 }; 00068 00069 } 00070 #endif 00071 ///@endcond