Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
conversioniterator.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 CONVERSIONITERATOR_H
22 #define CONVERSIONITERATOR_H
23 #include <tulip/Iterator.h>
24 #include <tulip/memorypool.h>
25 //
26 namespace tlp {
27 /**
28  * @class ConversionIterator
29  * @ingroup Iterators
30  * @brief Iterator that enables to convert an Iterator of type TYPEIN to an Iterator if type TYPEOUT
31  * @param it, the iterator that should be converted
32  * @param convFunctor, the functor that enable to convert TYPEIN in TYPEOUT
33  *
34  * The functor function shoul have the following form
35  * @code
36  * class AConversionFunctor {
37  * TYPEOUT operator()(TYPEIN a) {
38  * return a converted in TYPEOUT;
39  * }
40  * };
41  * @endcode
42  */
43 template <typename TYPEIN, typename TYPEOUT, typename CONVERSIONFUNCTOR>
44 class ConversionIterator : public Iterator<TYPEOUT> {
45 public:
46  ConversionIterator(Iterator<TYPEIN> *it, CONVERSIONFUNCTOR convFunctor):_it(it), _convFunctor(convFunctor) {
47  }
48  ~ConversionIterator() {
49  delete _it;
50  }
51  inline bool hasNext() {
52  return _it->hasNext();
53  }
54  inline TYPEOUT next() {
55  return _convFunctor(_it->next());
56  }
57 private:
58  tlp::Iterator<TYPEIN> *_it;
59  CONVERSIONFUNCTOR _convFunctor;
60 };
61 /**
62  * @class MPConversionIterator
63  * @ingroup Iterators
64  * @brief MPConversionIterator implements memory pool for ConversionIterator
65  * @warning never inherit from that class
66  * @see ConversionIterator
67  */
68 template <typename TYPEIN, typename TYPEOUT, typename CONVERSIONFUNCTOR>
69 class MPConversionIterator : public ConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR>, public MemoryPool<MPConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR> > {
70 public:
71  MPConversionIterator(Iterator<TYPEIN> *it, CONVERSIONFUNCTOR convFunctor):
72  ConversionIterator<TYPEIN, TYPEOUT, CONVERSIONFUNCTOR>(it, convFunctor) {
73  }
74 };
75 
76 }
77 #endif // CONVERSIONITERATOR_H
78 ///@endcond