claw::graphic::image::base_iterator< Image, Pixel > Class Template Reference

Base class for iterators on an image. More...

#include <image.hpp>

List of all members.

Public Types

typedef pixel_type value_type
typedef pixel_typereference
typedef pixel_typepointer
typedef ptrdiff_t difference_type
typedef
std::random_access_iterator_tag 
iterator_category

Public Member Functions

 base_iterator ()
 Constructor.
 base_iterator (image_type &owner, unsigned int x=0, unsigned int y=0)
 Constructor, from an image.
bool operator== (const self_type &that) const
 Tell if two iterator point to the same address.
bool operator!= (const self_type &that) const
 Tell if two iterator points to different addresses.
bool operator< (const self_type &that) const
 Tell if the current iterator is before an other.
bool operator> (const self_type &that) const
 Tell if the current iterator is after an other.
bool operator<= (const self_type &that) const
 Tell if the current iterator is before an other, or on the same address.
bool operator>= (const self_type &that) const
 Tell if the current iterator is after an other, or on the same address.
self_typeoperator+= (int n)
 Move the iterator.
self_typeoperator-= (int n)
 Move the iterator.
self_type operator+ (int n) const
 Get an iterator at a specific distance of the current iterator.
self_type operator- (int n) const
 Get an iterator at a specific distance of the current iterator.
difference_type operator- (const self_type &that) const
 Get the distance between two iterators.
self_typeoperator++ ()
 Preincrement.
self_type operator++ (int)
 Postincrement.
self_typeoperator-- ()
 Predecrement.
self_type operator-- (int)
 Postdecrement.
reference operator* () const
 Get a reference on the pointed pixel.
pointer operator-> () const
 Get a pointer on the pointed pixel.
reference operator[] (int n) const
 Get a pixel, using the iterator like an array.

Private Types

typedef Image image_type
 The type of the image we are iterating through.
typedef Pixel pixel_type
 The type of the pointed pixels.
typedef base_iterator
< image_type, pixel_type
self_type
 The type of the current class.

Private Member Functions

bool is_final () const
 Tell if the iterator is past the end of its owner.

Private Attributes

image_typem_owner
 The image we are iterating through.
math::coordinate_2d< unsigned int > m_pos
 Coordinates of the pointed pixel in m_owner.

Friends

template<typename ImageT , typename PixelT >
self_type operator+ (int n, const self_type &self)

Detailed Description

template<typename Image, typename Pixel>
class claw::graphic::image::base_iterator< Image, Pixel >

Base class for iterators on an image.

Author:
Julien Jorge.

Definition at line 103 of file image.hpp.


Member Typedef Documentation

template<typename Image, typename Pixel>
typedef ptrdiff_t claw::graphic::image::base_iterator< Image, Pixel >::difference_type

Definition at line 120 of file image.hpp.

template<typename Image, typename Pixel>
typedef Image claw::graphic::image::base_iterator< Image, Pixel >::image_type [private]

The type of the image we are iterating through.

Definition at line 108 of file image.hpp.

template<typename Image, typename Pixel>
typedef std::random_access_iterator_tag claw::graphic::image::base_iterator< Image, Pixel >::iterator_category

Definition at line 122 of file image.hpp.

template<typename Image, typename Pixel>
typedef Pixel claw::graphic::image::base_iterator< Image, Pixel >::pixel_type [private]

The type of the pointed pixels.

Definition at line 111 of file image.hpp.

template<typename Image, typename Pixel>
typedef pixel_type* claw::graphic::image::base_iterator< Image, Pixel >::pointer

Definition at line 119 of file image.hpp.

template<typename Image, typename Pixel>
typedef pixel_type& claw::graphic::image::base_iterator< Image, Pixel >::reference

Definition at line 118 of file image.hpp.

template<typename Image, typename Pixel>
typedef base_iterator<image_type, pixel_type> claw::graphic::image::base_iterator< Image, Pixel >::self_type [private]

The type of the current class.

Definition at line 114 of file image.hpp.

template<typename Image, typename Pixel>
typedef pixel_type claw::graphic::image::base_iterator< Image, Pixel >::value_type

Definition at line 117 of file image.hpp.


Constructor & Destructor Documentation

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::base_iterator (  )  [inline]

Constructor.

Definition at line 62 of file image.ipp.

References CLAW_POSTCOND, and claw::graphic::image::base_iterator< Image, Pixel >::is_final().

00063   : m_owner(NULL), m_pos(0, 0)
00064 {
00065   CLAW_POSTCOND(is_final());
00066 } // image::base_iterator::base_iterator()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::base_iterator ( image_type owner,
unsigned int  x = 0,
unsigned int  y = 0 
) [inline]

Constructor, from an image.

Parameters:
owner The image we will iterate through.
x X-coordinate of the pointed pixel.
y Y-coordinate of the pointed pixel.

Definition at line 77 of file image.ipp.

00078   : m_owner(&owner), m_pos(x, y)
00079 {
00080 
00081 } // image::base_iterator::base_iterator()


Member Function Documentation

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::is_final (  )  const [inline, private]
template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator!= ( const self_type that  )  const [inline]

Tell if two iterator points to different addresses.

Parameters:
that The other operand.

Definition at line 109 of file image.ipp.

00110 {
00111   return !(*this == that);
00112 } // image::base_iterator::operator!=()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::reference claw::graphic::image::base_iterator< Image, Pixel >::operator* (  )  const [inline]
template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type claw::graphic::image::base_iterator< Image, Pixel >::operator+ ( int  n  )  const [inline]

Get an iterator at a specific distance of the current iterator.

Parameters:
n The distance of the wanted iterator.

Definition at line 231 of file image.ipp.

00232 {
00233   self_type that(*this);
00234 
00235   return that += n;
00236 } // image::base_iterator::operator+()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type claw::graphic::image::base_iterator< Image, Pixel >::operator++ ( int   )  [inline]

Postincrement.

Definition at line 323 of file image.ipp.

00324 {
00325   self_type that(*this);
00326   ++(*this);
00327   return that;
00328 } // image::base_iterator::operator++() [postincrement]

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type & claw::graphic::image::base_iterator< Image, Pixel >::operator++ (  )  [inline]

Preincrement.

Definition at line 302 of file image.ipp.

References CLAW_PRECOND, claw::graphic::image::base_iterator< Image, Pixel >::is_final(), claw::graphic::image::base_iterator< Image, Pixel >::m_owner, claw::graphic::image::base_iterator< Image, Pixel >::m_pos, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

00303 {
00304   CLAW_PRECOND( !is_final() );
00305 
00306   ++m_pos.x;
00307 
00308   if ( m_pos.x == m_owner->width() )
00309     {
00310       m_pos.x = 0;
00311       ++m_pos.y;
00312     }
00313 
00314   return *this;
00315 } // image::base_iterator::operator++()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type & claw::graphic::image::base_iterator< Image, Pixel >::operator+= ( int  n  )  [inline]

Move the iterator.

Parameters:
n Number of steps of the move.

Definition at line 178 of file image.ipp.

References CLAW_PRECOND, claw::graphic::image::base_iterator< Image, Pixel >::is_final(), claw::graphic::image::base_iterator< Image, Pixel >::m_owner, claw::graphic::image::base_iterator< Image, Pixel >::m_pos, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

00179 {
00180   if (n < 0)
00181     return *this -= -n;
00182   else
00183     {
00184       CLAW_PRECOND( !is_final() );
00185 
00186       unsigned int n_y = n / m_owner->width();
00187       unsigned int n_x = n % m_owner->width();
00188 
00189       m_pos.x += n_x;
00190       m_pos.y += n_y;
00191 
00192       return *this;
00193     }
00194 } // image::base_iterator::operator+=()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::difference_type claw::graphic::image::base_iterator< Image, Pixel >::operator- ( const self_type that  )  const [inline]

Get the distance between two iterators.

Parameters:
that The other operand.

Definition at line 277 of file image.ipp.

References CLAW_PRECOND.

00278 {
00279   CLAW_PRECOND( is_final() || that.is_final() || (m_owner == that.m_owner) );
00280 
00281   if ( that.is_final() )
00282     {
00283       if ( is_final() )
00284         return 0;
00285       else
00286         return -(m_owner->height() - m_pos.y) * m_owner->width() - m_pos.x;
00287     }
00288   else if ( is_final() )
00289     return (that.m_owner->height() - that.m_pos.y) * that.m_owner->width()
00290       + that.m_pos.x;
00291   else
00292     return m_pos.y * m_owner->width() + m_pos.x
00293       - that.m_pos.y * that.m_owner->width() + that.m_pos.x;
00294 } // image::base_iterator::operator-()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type claw::graphic::image::base_iterator< Image, Pixel >::operator- ( int  n  )  const [inline]

Get an iterator at a specific distance of the current iterator.

Parameters:
n The distance of the wanted iterator.

Definition at line 245 of file image.ipp.

00246 {
00247   self_type that(*this);
00248 
00249   return that -= n;
00250 } // image::base_iterator::operator-()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type claw::graphic::image::base_iterator< Image, Pixel >::operator-- ( int   )  [inline]

Postdecrement.

Definition at line 358 of file image.ipp.

00359 {
00360   self_type that(*this);
00361   --(*this);
00362   return that;
00363 } // image::base_iterator::operator--() [postdecrement]

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type & claw::graphic::image::base_iterator< Image, Pixel >::operator-- (  )  [inline]

Predecrement.

Definition at line 336 of file image.ipp.

References CLAW_PRECOND, claw::graphic::image::base_iterator< Image, Pixel >::is_final(), claw::graphic::image::base_iterator< Image, Pixel >::m_owner, claw::graphic::image::base_iterator< Image, Pixel >::m_pos, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

00337 {
00338   CLAW_PRECOND( !is_final() );
00339   CLAW_PRECOND( (m_pos.y > 0) || (m_pos.x > 0) );
00340 
00341   if ( m_pos.x == 0 )
00342     {
00343       m_pos.x = m_owner->width() - 1;
00344       --m_pos.y;
00345     }
00346   else
00347     --m_pos.x;
00348 
00349   return *this;
00350 } // image::base_iterator::operator--()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::self_type & claw::graphic::image::base_iterator< Image, Pixel >::operator-= ( int  n  )  [inline]

Move the iterator.

Parameters:
n Number of steps of the move.

Definition at line 203 of file image.ipp.

References CLAW_PRECOND, claw::graphic::image::base_iterator< Image, Pixel >::m_owner, claw::graphic::image::base_iterator< Image, Pixel >::m_pos, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

00204 {
00205   if (n < 0)
00206     return *this += -n;
00207   else
00208     {
00209       CLAW_PRECOND( m_owner );
00210 
00211       unsigned int n_y = n / m_owner->width();
00212       unsigned int n_x = n % m_owner->width();
00213 
00214       CLAW_PRECOND( m_pos.x >= n_x );
00215       CLAW_PRECOND( m_pos.y >= n_y );
00216 
00217       m_pos.x -= n_x;
00218       m_pos.y -= n_y;
00219 
00220       return *this;
00221     }
00222 } // image::base_iterator::operator-=()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::pointer claw::graphic::image::base_iterator< Image, Pixel >::operator-> (  )  const [inline]

Get a pointer on the pointed pixel.

Definition at line 384 of file image.ipp.

References CLAW_PRECOND, claw::graphic::image::base_iterator< Image, Pixel >::is_final(), claw::graphic::image::base_iterator< Image, Pixel >::m_pos, claw::math::coordinate_2d< T >::x, and claw::math::coordinate_2d< T >::y.

00385 {
00386   CLAW_PRECOND( !is_final() );
00387 
00388   return &(*m_owner)[m_pos.y][m_pos.x];
00389 } // image::base_iterator::operator->()

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator< ( const self_type that  )  const [inline]

Tell if the current iterator is before an other.

Parameters:
that The other operand.

Definition at line 122 of file image.ipp.

00123 {
00124   if ( this->m_pos.y == that.m_pos.y)
00125     return this->m_pos.x < that.m_pos.x;
00126   else
00127     return this->m_pos.y < that.m_pos.y;
00128 } // image::base_iterator::operator<()

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator<= ( const self_type that  )  const [inline]

Tell if the current iterator is before an other, or on the same address.

Parameters:
that The other operand.

Definition at line 152 of file image.ipp.

00153 {
00154   return !(*this > that);
00155 } // image::base_iterator::operator<=()

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator== ( const self_type that  )  const [inline]

Tell if two iterator point to the same address.

Parameters:
that The other operand.

Definition at line 91 of file image.ipp.

00092 {
00093   if ( is_final() && that.is_final() )
00094     return true;
00095   else if ( m_owner == that.m_owner )
00096     return m_pos == that.m_pos;
00097   else
00098     return false;
00099 } // image::base_iterator::operator==()

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator> ( const self_type that  )  const [inline]

Tell if the current iterator is after an other.

Parameters:
that The other operand.

Definition at line 138 of file image.ipp.

00139 {
00140   return that < *this;
00141 } // image::base_iterator::operator>()

template<typename Image , typename Pixel >
bool claw::graphic::image::base_iterator< Image, Pixel >::operator>= ( const self_type that  )  const [inline]

Tell if the current iterator is after an other, or on the same address.

Parameters:
that The other operand.

Definition at line 166 of file image.ipp.

00167 {
00168   return !(*this < that);
00169 } // image::base_iterator::operator>=()

template<typename Image , typename Pixel >
claw::graphic::image::base_iterator< Image, Pixel >::reference claw::graphic::image::base_iterator< Image, Pixel >::operator[] ( int  n  )  const [inline]

Get a pixel, using the iterator like an array.

Parameters:
n Index of the cell from which we want the pixel.

Definition at line 398 of file image.ipp.

00399 {
00400   return *(*this + n);
00401 } // image::base_iterator::operator[]()


Friends And Related Function Documentation

template<typename Image, typename Pixel>
template<typename ImageT , typename PixelT >
self_type operator+ ( int  n,
const self_type self 
) [friend]

Member Data Documentation

template<typename Image, typename Pixel>
image_type* claw::graphic::image::base_iterator< Image, Pixel >::m_owner [private]
template<typename Image, typename Pixel>
math::coordinate_2d<unsigned int> claw::graphic::image::base_iterator< Image, Pixel >::m_pos [private]

The documentation for this class was generated from the following files:

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1