vigra - vigra/transform_iterator.hxx Source File

[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

transform_iterator.hxx |

1
2
3
4 namespace vigra{
5
6
7
8
9 template<class T>
10 class TransformIterValProxy{
11 public:
12 typedef const T & reference;
13 typedef const T * pointer;
14 typedef T value_type;
15
16 reference getRef(const T & functionReturn){
17 t_ = functionReturn;
18 return t_;
19 }
20 pointer getPr(const T & functionReturn){
21 t_ = functionReturn;
22 return &t_;
23 }
24 private:
25 T t_;
26 };
27
28
29 template<class T>
30 class TransformIterValProxy<const T &>{
31 typedef const T & reference;
32 typedef const T * pointer;
33 typedef T value_type;
34
35 reference getRef(const T & functionReturn){
36 t_ = functionReturn;
37 return t_;
38 }
39 pointer getPr(const T & functionReturn){
40 t_ = functionReturn;
41 return &t_;
42 }
43 private:
44 T t_;
45 };
46
47 template<class T>
48 class TransformIterValProxy<T &>{
49 typedef T & reference;
50 typedef T * pointer;
51 typedef T value_type;
52
53 reference getRef(const T & functionReturn){
54 t_ = functionReturn;
55 return t_;
56 }
57 pointer getPr(const T & functionReturn){
58 t_ = functionReturn;
59 return &t_;
60 }
61 private:
62 T t_;
63 };
64
65
66 template <
67 class UnaryFunction,
68 class Iterator
69 >
70 class TransformIterator{
71
72 public:
73
74 typedef typename UnaryFunction::result_type function_result_type;
75 typedef TransformIterValProxy<function_result_type> RetHelper;
76
77 typedef typename RetHelper::value_type value_type;
78 typedef typename RetHelper::reference reference;
79 typedef typename RetHelper::pointer pointer;
80
81 typedef typename std::iterator_traits<Iterator>::difference_type difference_type;
82 typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category;
83
84 TransformIterator(const Iterator & iter = Iterator(), const UnaryFunction & f = UnaryFunction())
85 : iter_(iter),
86 f_(f){
87 }
88
89 reference operator * () const{
90 return retHelper_.getRef(f_(*iter_));
91 }
92
93 reference operator[](const difference_type i) const{
94 return retHelper_.getRef(f_(iter_[i]));
95 }
96
97 pointer operator -> () const{
98 return retHelper_.getRef(f_(*iter_));
99 }
100
101
102 #define TRANSFORMITERATOR_CP_OP_GEN(OP)\
103 bool operator OP (const TransformIterator & rhs)const{\
104 return iter_ OP rhs.iter_;\
105 }
106
107 TRANSFORMITERATOR_CP_OP_GEN(==);
108 TRANSFORMITERATOR_CP_OP_GEN(!=);
109 TRANSFORMITERATOR_CP_OP_GEN(<);
110 TRANSFORMITERATOR_CP_OP_GEN(<=);
111 TRANSFORMITERATOR_CP_OP_GEN(>);
112 TRANSFORMITERATOR_CP_OP_GEN(>=);
113
114 #undef TRANSFORMITERATOR_CP_OP_GEN
115
116 TransformIterator & operator ++ (){
117 ++iter_;
118 return *this;
119 }
120 TransformIterator & operator -- (){
121 --iter_;
122 return *this;
123 }
124 TransformIterator operator ++ (int) const{
125 TransformIterator res(*this);
126 ++res.iter_;
127 return res;
128 }
129 TransformIterator operator -- (int)const{
130 TransformIterator res(*this);
131 --res.iter_;
132 return res;
133 }
134 TransformIterator & operator+=( const difference_type i ){
135 iter_ += i;
136 return *this;
137 }
138 TransformIterator & operator-=( const difference_type i ){
139 iter_ -= i;
140 return *this;
141 }
142 TransformIterator operator+( const difference_type i )const{
143 TransformIterator res(*this);
144 res += i;
145 return res;
146 }
147 TransformIterator operator-( const difference_type i )const{
148 TransformIterator res(*this);
149 res -= i;
150 return res;
151 }
152
153 difference_type operator - (const TransformIterator rhs) const{
154 return iter_ - rhs.iter_;
155 }
156
157 protected:
158 const Iterator & baseIterator()const{
159 return iter_;
160 }
161 const UnaryFunction & unaryFunction()const{
162 return f_;
163 }
164 private:
165 Iterator iter_;
166 UnaryFunction f_;
167 mutable RetHelper retHelper_;
168 };
169
170
171 template <
172 class UnaryFunction,
173 class Iterator
174 >
175 class EndAwareTransformIterator
176 : public TransformIterator<UnaryFunction, Iterator>
177 {
178 public:
179 EndAwareTransformIterator(const Iterator & iter = Iterator(), const UnaryFunction & f = UnaryFunction())
180 : TransformIterator<UnaryFunction, Iterator>(iter,f){
181 }
182
183 EndAwareTransformIterator getEndIterator()const{
184 return EndAwareTransformIterator(this->baseIterator().getEndIterator(),
185 this->unaryFunction());
186 }
187 private:
188
189 };
190
191
192 }
vigra::operator-
Diff2D operator-(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:711
vigra::operator+
Diff2D operator+(Diff2D const &a, Diff2D const &b)
Definition: diff2d.hxx:739
vigra::operator-=
FFTWComplex< R > & operator-=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
subtract-assignment
Definition: fftw3.hxx:867
vigra::operator+=
FFTWComplex< R > & operator+=(FFTWComplex< R > &a, const FFTWComplex< R > &b)
add-assignment
Definition: fftw3.hxx:859

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)