CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
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 105 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 122 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 110 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 124 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 113 of file image.hpp.

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

Definition at line 121 of file image.hpp.

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

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

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

Definition at line 119 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:
ownerThe image we will iterate through.
xX-coordinate of the pointed pixel.
yY-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]

Tell if the iterator is past the end of its owner.

Definition at line 409 of file image.ipp.

Referenced by claw::graphic::image::base_iterator< Image, Pixel >::base_iterator().

{
  if ( !m_owner )
    return true;
  else if ( m_pos.y >= m_owner->height() )
    return true;
  else if ( m_pos.y == m_owner->height() - 1 )
    return m_pos.x >= m_owner->width();
  else
    return false;
} // image::base_iterator::is_final()
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:
thatThe 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]

Get a reference on the pointed pixel.

Definition at line 371 of file image.ipp.

References CLAW_PRECOND.

{
  CLAW_PRECOND( !is_final() );

  return (*m_owner)[m_pos.y][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  n) const [inline]

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

Parameters:
nThe 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]

Preincrement.

Definition at line 302 of file image.ipp.

References CLAW_PRECOND.

{
  CLAW_PRECOND( !is_final() );

  ++m_pos.x;

  if ( m_pos.x == m_owner->width() )
    {
      m_pos.x = 0;
      ++m_pos.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  ) [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:
nNumber of steps of the move.

Definition at line 178 of file image.ipp.

References CLAW_PRECOND.

{
  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:
nThe 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:
thatThe 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]

Predecrement.

Definition at line 336 of file image.ipp.

References CLAW_PRECOND.

{
  CLAW_PRECOND( !is_final() );
  CLAW_PRECOND( (m_pos.y > 0) || (m_pos.x > 0) );

  if ( m_pos.x == 0 )
    {
      m_pos.x = m_owner->width() - 1;
      --m_pos.y;
    }
  else
    --m_pos.x;

  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) [inline]

Move the iterator.

Parameters:
nNumber of steps of the move.

Definition at line 203 of file image.ipp.

References CLAW_PRECOND.

{
  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_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:
thatThe other operand.

Definition at line 122 of file image.ipp.

References claw::math::coordinate_2d< T >::x.

{
  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:
thatThe 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:
thatThe other operand.

Definition at line 91 of file image.ipp.

References claw::graphic::image::base_iterator< Image, Pixel >::m_pos.

{
  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:
thatThe 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:
thatThe 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:
nIndex 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]

The image we are iterating through.

Definition at line 164 of file image.hpp.

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

Coordinates of the pointed pixel in m_owner.

Definition at line 167 of file image.hpp.

Referenced by claw::graphic::image::base_iterator< Image, Pixel >::operator==().


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