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

Data Accessors

Basic templates to encapsulate access to the data of an iterator.

Data accessors are used to allow for flexible access to the data an iterator points to. When we access the data directly, we are bound to what `operator*()` returns, if this method exists at all. Encapsulating access in an accessor enables a better decoupling of data structures and algorithms. This paper contains a detailed description of the concept. Here is a brief list of the basic accessor requirements:

Operation | Result | Semantics
--- | --- | ---
`accessor(iter)` | convertible to `Accessor::value_type const &` | read data at the current position of the iterator
`accessor(iter, index)` | convertible to `Accessor::value_type const &` | read data at offset `index` relative to iterator's current position (random-access iterator only)
`accessor.set(value, iter)` | `void` | write data `value` at the current position of the iterator (mutable iterator only)
`accessor.set(value, iter, index)` | `void` | write data `value` at offset `index` relative to iterator's current position (mutable random-access iterator only)
`Accessor::value_type` | type of the data field the accessor refers to
`iter` is an iterator `index` has the iterator's index type (`Iterator::difference_type`) `value` is convertible to `Accessor::value_type const &`

The template `AccessorTraits<T>` can be used to find the default accessor associated with the type `T`, e.g.

typedef typename AccessorTraits<typename Image::value_type>::default_accessor Accessor;
typedef typename AccessorTraits<typename Image::value_type>::default_const_accessor ConstAccessor;

© 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.12.1