Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/conversioniterator.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 CONVERSIONITERATOR_H
00022 #define CONVERSIONITERATOR_H
00023 #include <tulip/Iterator.h>
00024 #include <tulip/memorypool.h>
00025 //
00026 namespace tlp {
00027 /**
00028   * @class ConversionIterator
00029   * @ingroup Iterators
00030   * @brief Iterator that enables to convert an Iterator of type TYPEIN to an Iterator if type TYPEOUT
00031   * @param it, the iterator that should be converted
00032   * @param convFunctor, the functor that enable to convert TYPEIN in TYPEOUT
00033   *
00034   * The functor function shoul have the following form
00035   * @code
00036   * class AConversionFunctor {
00037   *  TYPEOUT operator()(TYPEIN a) {
00038   *    return a converted in TYPEOUT;
00039   *  }
00040   * };
00041   * @endcode
00042   */
00043 template <typename TYPEIN, typename TYPEOUT, typename CONVERSIONFUNCTOR>
00044 class ConversionIterator : public Iterator<TYPEOUT> {
00045 public:
00046   ConversionIterator(Iterator<TYPEIN> *it, CONVERSIONFUNCTOR convFunctor):_it(it), _convFunctor(convFunctor) {
00047   }
00048   ~ConversionIterator() {
00049     delete _it;
00050   }
00051   inline bool hasNext() {
00052     return _it->hasNext();
00053   }
00054   inline TYPEOUT next() {
00055     return _convFunctor(_it->next());
00056   }
00057 private:
00058   tlp::Iterator<TYPEIN> *_it;
00059   CONVERSIONFUNCTOR _convFunctor;
00060 };
00061 /**
00062   * @class MPConversionIterator
00063   * @ingroup Iterators
00064   * @brief MPConversionIterator implements memory pool for ConversionIterator
00065   * @warning never inherit from that class
00066   * @see ConversionIterator
00067   */
00068 template <typename TYPEIN, typename TYPEOUT, typename CONVERSIONFUNCTOR>
00069 class MPConversionIterator : public ConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR>, public MemoryPool<MPConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR> > {
00070 public:
00071   MPConversionIterator(Iterator<TYPEIN> *it, CONVERSIONFUNCTOR convFunctor):
00072     ConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR>(it, convFunctor) {
00073   }
00074 };
00075 
00076 }
00077 #endif // CONVERSIONITERATOR_H
00078 ///@endcond
 All Classes Files Functions Variables Enumerations Enumerator Properties