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