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

iteratorfacade.hxx |

1 /************************************************************************/
2 /* */
3 /* Copyright 2014 by Thorsten Beier */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 #ifndef VIGRA_ITERATORFACADE_HXX
36 #define VIGRA_ITERATORFACADE_HXX
37
38 /*std*/
39 #include <iterator>
40
41 /*vigra*/
42 #include "metaprogramming.hxx"
43
44 namespace vigra {
45
46 // facade needs to make this class
47 // a friend class
48 class IteratorFacadeCoreAccess{
49 public:
50 template<class F>
51 static bool equal(const F & fa,const F & fb){
52 return fa.equal(fb);
53 }
54
55 template<class F,class REFERENCE>
56 static REFERENCE dereference(const F & f){
57 return f.dereference();
58 }
59
60 template<class F>
61 static void increment(F & f){
62 f.increment();
63 }
64 };
65
66
67 // see boost iterator facade
68 template<class FACADE,class VALUE_TYPE,bool IS_CONST = true>
69 class ForwardIteratorFacade{
70 private:
71
72 public:
73
74 typedef std::forward_iterator_tag iterator_category;
75 typedef typename UnqualifiedType<VALUE_TYPE>::type value_type;
76 typedef typename IfBool<IS_CONST, value_type const * , value_type *>::type pointer;
77 typedef typename IfBool<IS_CONST, const value_type & , value_type &>::type reference;
78 typedef std::ptrdiff_t difference_type;
79
80
81 FACADE & operator++()
82 {
83 IteratorFacadeCoreAccess::increment(getF());
84 return getF();
85 }
86
87 FACADE operator++(int)
88 {
89 FACADE res(getF());
90 IteratorFacadeCoreAccess::increment(getF());
91 return res;
92 }
93
94 bool operator ==(const FACADE & f)const{
95 return IteratorFacadeCoreAccess::equal(getF(),f);
96 }
97 bool operator !=(const FACADE & f)const{
98 return !IteratorFacadeCoreAccess::equal(getF(),f);
99 }
100
101 reference operator*()const{
102 return IteratorFacadeCoreAccess:: template dereference<FACADE,reference>(getF());
103 }
104
105 pointer operator->()const{
106 return &IteratorFacadeCoreAccess:: template dereference<FACADE,reference>(getF());
107 }
108
109 private:
110
111
112 const FACADE & getF()const{
113 return *static_cast<FACADE const *>(this);
114 }
115 FACADE & getF(){
116 return *static_cast<FACADE *>(this);
117 }
118 };
119
120 template<class MAP>
121 class MapKeyIterator
122 : public ForwardIteratorFacade<MapKeyIterator<MAP>,typename MAP::key_type,true>
123 {
124
125 public:
126 typedef ForwardIteratorFacade<MapKeyIterator<MAP>,typename MAP::key_type,true> BaseType;
127 typedef typename MAP::const_iterator InternalIterator;
128 typedef typename BaseType::value_type value_type;
129 typedef typename BaseType::reference reference;
130 typedef typename BaseType::pointer pointer;
131
132 MapKeyIterator(InternalIterator i)
133 : iter_(i)
134 {}
135
136 private:
137
138 friend class IteratorFacadeCoreAccess;
139
140 bool equal(const MapKeyIterator & other) const{
141 return iter_ == other.iter_;
142 }
143
144 void increment(){
145 ++iter_;
146 }
147
148 reference dereference()const{
149 return iter_->first;
150 }
151
152 InternalIterator iter_;
153 };
154
155 template <class MAP>
156 inline MapKeyIterator<MAP>
157 key_begin(MAP const & m)
158 {
159 return MapKeyIterator<MAP>(m.begin());
160
161 }
162
163 template <class MAP>
164 inline MapKeyIterator<MAP>
165 key_end(MAP const & m)
166 {
167 return MapKeyIterator<MAP>(m.end());
168
169 }
170
171 } // namespace vigra
172
173
174 #endif /* VIGRA_ITERATORFACADE_HXX */
vigra::operator!=
bool operator!=(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
not equal
Definition: fftw3.hxx:841
vigra::operator==
bool operator==(FFTWComplex< R > const &a, const FFTWComplex< R > &b)
equal
Definition: fftw3.hxx:825

© 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)