Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

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 104 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 121 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 109 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 123 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 112 of file image.hpp.

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

Definition at line 120 of file image.hpp.

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

Definition at line 119 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 115 of file image.hpp.

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

Definition at line 118 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().

  : m_owner(NULL), m_pos(0, 0)
{
  CLAW_POSTCOND(is_final());
} // 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.

  : m_owner(&owner), m_pos(x, y)
{

} // 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.

{
  return !(*this == that);
} // 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.

{
  self_type that(*this);

  return that += n;
} // 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++ (  )  [inline]
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.

{
  self_type that(*this);
  ++(*this);
  return that;
} // 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+= ( 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.

{
  if (n < 0)
    return *this -= -n;
  else
    {
      CLAW_PRECOND( !is_final() );

      unsigned int n_y = n / m_owner->width();
      unsigned int n_x = n % m_owner->width();

      m_pos.x += n_x;
      m_pos.y += n_y;

      return *this;
    }
} // 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.

{
  self_type that(*this);

  return that -= n;
} // 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.

{
  CLAW_PRECOND( is_final() || that.is_final() || (m_owner == that.m_owner) );

  if ( that.is_final() )
    {
      if ( is_final() )
        return 0;
      else
        return -(m_owner->height() - m_pos.y) * m_owner->width() - m_pos.x;
    }
  else if ( is_final() )
    return (that.m_owner->height() - that.m_pos.y) * that.m_owner->width()
      + that.m_pos.x;
  else
    return m_pos.y * m_owner->width() + m_pos.x
      - that.m_pos.y * that.m_owner->width() + that.m_pos.x;
} // 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.

{
  self_type that(*this);
  --(*this);
  return that;
} // 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]
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.

{
  if (n < 0)
    return *this += -n;
  else
    {
      CLAW_PRECOND( m_owner );

      unsigned int n_y = n / m_owner->width();
      unsigned int n_x = n % m_owner->width();

      CLAW_PRECOND( m_pos.x >= n_x );
      CLAW_PRECOND( m_pos.y >= n_y );

      m_pos.x -= n_x;
      m_pos.y -= n_y;

      return *this;
    }
} // 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.

{
  CLAW_PRECOND( !is_final() );

  return &(*m_owner)[m_pos.y][m_pos.x];
} // 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.

{
  if ( this->m_pos.y == that.m_pos.y)
    return this->m_pos.x < that.m_pos.x;
  else
    return this->m_pos.y < that.m_pos.y;
} // 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.

{
  return !(*this > that);
} // 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.

{
  if ( is_final() && that.is_final() )
    return true;
  else if ( m_owner == that.m_owner )
    return m_pos == that.m_pos;
  else
    return false;
} // 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.

{
  return that < *this;
} // 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.

{
  return !(*this < that);
} // 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.

{
  return *(*this + n);
} // 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: