/usr/include/vigra/iteratoradapter.hxx is in libvigraimpex-dev 1.9.0+dfsg-10+b2.
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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | /************************************************************************/
/* */
/* Copyright 1998-2002 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_ITERATORADAPTER_HXX
#define VIGRA_ITERATORADAPTER_HXX
namespace vigra {
/********************************************************/
/* */
/* IteratorAdaptor */
/* */
/********************************************************/
/*! \brief Quickly create 1-dimensional iterator adapters.
This class supports the easy creation of 1D iterator adapters out
of existing iterators. To use it, you must first implement a policy class
that defines the iterator's behavior. The policy is used to
instantiate the IteratorAdapter template, which thus automatically
obtains all required functions of an STL-compatible iterator.
General information on how this works can be found on the
<a href="http://www.boost.org/libs/utility/iterator_adaptors.htm">Boost Iterator Adaptor</a>
page, although there are some differences in the details of the
boost and VIGRA implementations.
Here is an example policy class that just exports the behaviour
of the underlying iterator:
\code
template <class Iterator>
class TrivialIteratorAdaptorPolicy
{
public:
// the underlying iterator
typedef Iterator BaseType;
// the adaptor's value type
typedef typename Iterator::value_type value_type;
// the adaptor's difference type (result of 'iter1 - iter2',
// argument of 'iter[n]')
typedef typename Iterator::difference_type difference_type;
// the adaptor's reference type (result of '*iter')
typedef typename Iterator::reference reference;
// the adaptor's index_reference type (result of 'iter[n]')
typedef typename Iterator::index_reference index_reference;
// the adaptor's pointer type (result of 'iter.operator->()')
typedef typename Iterator::pointer pointer;
// the adaptor's iterator category
typedef typename Iterator::iterator_category iterator_category;
// do some additional initialization in the adaptor's constructor
static void initialize(BaseType & d) {}
// called by '*iter', 'iter->'
static reference dereference(BaseType const & d)
{ return *d; }
// called by 'iter[n]'
static index_reference dereference(BaseType d, difference_type n)
{ return d[n]; }
// called by 'iter1 == iter2', 'iter1 != iter2'
static bool equal(BaseType const & d1, BaseType const & d2)
{ return d1 == d2; }
// called by 'iter1 < iter2', 'iter1 <= iter2', 'iter1 > iter2', 'iter1 >= iter2'
static bool less(BaseType const & d1, BaseType const & d2)
{ return d1 < d2; }
// called by 'iter1 - iter2'
static difference_type difference(BaseType const & d1, BaseType const & d2)
{ return d1 - d2; }
// called by '++iter', 'iter++'
static void increment(BaseType & d)
{ ++d; }
// called by '--iter', 'iter--'
static void decrement(BaseType & d)
{ --d; }
// called by 'iter += n', 'iter -= n'
static void advance(BaseType & d, difference_type n)
{ d += n; }
};
\endcode
This policy class is used like this:
\code
SomeIterator iter = ...;
vigra::IteratorAdaptor<vigra::TrivialIteratorAdaptorPolicy<SomeIterator> > iter_adaptor(iter);
\endcode
By changing the definition of the policy members, a wide range of
adaptor behaviors can be achieved. If the base iterator isn't a
random access iterator, just drop the functions that cannot be implemented.
This simply means that some adaptor functions may not be called,
as one would expect from an iterator that doesn't support random access.
Note also that the <TT>BaseType</TT> needs not be an iterator -
it can be any type that contains the information necessary for the
adaptor to do it's work.
<b>\#include</b> \<vigra/iteratoradapter.hxx\><br>
Namespace: vigra
*/
template <class Policy>
class IteratorAdaptor
{
public:
typedef typename Policy::BaseType BaseType;
typedef typename Policy::value_type value_type;
typedef typename Policy::difference_type difference_type;
typedef typename Policy::reference reference;
typedef typename Policy::index_reference index_reference;
typedef typename Policy::pointer pointer;
typedef typename Policy::iterator_category iterator_category;
IteratorAdaptor()
: adaptee_()
{}
/** Construct from an instance of the policy class' BaseType
Note that the functions of the adaptor implement the
interface of an random access iterator as defined in the
C++ standard, so there is no need for explicit documentation.
*/
explicit IteratorAdaptor(BaseType const & o)
: adaptee_(o)
{
Policy::initialize(adaptee_);
}
IteratorAdaptor(IteratorAdaptor const & o)
: adaptee_(o.adaptee_)
{}
IteratorAdaptor & operator=(BaseType const & o)
{
if(this != &o)
{
adaptee_ = o;
Policy::initialize(adaptee_);
}
return *this;
}
IteratorAdaptor & operator=(IteratorAdaptor const & o)
{
if(this != &o)
adaptee_ = o.adaptee_;
return *this;
}
IteratorAdaptor & operator+=(difference_type d)
{
Policy::advance(adaptee_, d);
return *this;
}
IteratorAdaptor operator+(difference_type d) const
{
return IteratorAdaptor(*this) += d;
}
IteratorAdaptor & operator-=(difference_type d)
{
Policy::advance(adaptee_, -d);
return *this;
}
IteratorAdaptor operator-(difference_type d) const
{
return IteratorAdaptor(*this) -= d;
}
IteratorAdaptor & operator++()
{
Policy::increment(adaptee_);
return *this;
}
IteratorAdaptor operator++(int)
{
IteratorAdaptor res(*this);
Policy::increment(adaptee_);
return res;
}
IteratorAdaptor & operator--()
{
Policy::decrement(adaptee_);
return *this;
}
IteratorAdaptor operator--(int)
{
IteratorAdaptor res(*this);
Policy::decrement(adaptee_);
return res;
}
bool operator==(IteratorAdaptor const & o) const
{
return Policy::equal(adaptee_, o.adaptee_);
}
bool operator!=(IteratorAdaptor const & o) const
{
return !Policy::equal(adaptee_, o.adaptee_);
}
bool operator<(IteratorAdaptor const & o) const
{
return Policy::less(adaptee_, o.adaptee_);
}
bool operator<=(IteratorAdaptor const & o) const
{
return !Policy::less(o.adaptee_, adaptee_);
}
bool operator>(IteratorAdaptor const & o) const
{
return Policy::less(o.adaptee_, adaptee_);
}
bool operator>=(IteratorAdaptor const & o) const
{
return !Policy::less(adaptee_, o.adaptee_);
}
difference_type operator-(IteratorAdaptor const & o) const
{
return Policy::difference(adaptee_, o.adaptee_);
}
reference operator*() const
{
return Policy::dereference(adaptee_);
}
index_reference operator[](difference_type d) const
{
return Policy::dereference(adaptee_, d);
}
pointer operator->() const
{
return &Policy::dereference(adaptee_);
}
protected:
BaseType adaptee_;
};
} // namespace vigra
#endif /* VIGRA_ITERATORADAPTER_HXX */
|