Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/Iterator.h
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_ITERATOR_H
00022 #define TULIP_ITERATOR_H
00023 
00024 #include <tulip/tulipconf.h>
00025 
00026 namespace tlp {
00027 
00028 #ifndef DOXYGEN_NOTFOR_DEVEL
00029 extern TLP_SCOPE void incrNumIterators();
00030 extern TLP_SCOPE void decrNumIterators();
00031 extern TLP_SCOPE int getNumIterators();
00032 #endif // DOXYGEN_NOTFOR_DEVEL
00033 
00034 /**
00035 * @brief Interface for Tulip iterators.
00036 * Allows basic iteration operations only.
00037 * @see forEach
00038 **/
00039 template<class itType> struct Iterator {
00040   ///
00041   Iterator() {
00042 #ifndef NDEBUG
00043     incrNumIterators();
00044 #endif
00045   }
00046   ///
00047   virtual ~Iterator() {
00048 #ifndef NDEBUG
00049     decrNumIterators();
00050 #endif
00051   }
00052   /**
00053   * @brief Moves the Iterator on the next element.
00054   *
00055   * @return The current element pointed by the Iterator.
00056   **/
00057   virtual itType next()=0;
00058 
00059   /**
00060   * @brief Tells if the sequence is at its end.
00061   *
00062   * @return bool Whether there are more elements to iterate.
00063   **/
00064   virtual bool hasNext()=0;
00065 };
00066 
00067 //template<class C>class Iterator;
00068 #ifndef DOXYGEN_NOTFOR_DEVEL
00069 template<typename TYPE> class UINTIterator : public Iterator<TYPE> {
00070 public:
00071   UINTIterator(Iterator<unsigned int> *it):it(it) {
00072   }
00073   ~UINTIterator() {
00074     delete it;
00075   }
00076   bool hasNext() {
00077     return it->hasNext();
00078   }
00079   TYPE next() {
00080     return TYPE(it->next());
00081   }
00082 private:
00083   Iterator<unsigned int> *it;
00084 };
00085 #endif // DOXYGEN_NOTFOR_DEVEL
00086 
00087 }
00088 
00089 
00090 #ifdef _MSC_VER
00091 
00092 #include <tulip/Edge.h>
00093 #include <tulip/Node.h>
00094 
00095 template struct TLP_SCOPE tlp::Iterator<tlp::edge>;
00096 template struct TLP_SCOPE tlp::Iterator<tlp::node>;
00097 #endif
00098 #endif
00099 
00100 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties