Protected Attributes | List of all members
cwchess::PieceIterator Class Reference

Non-mutable iterator over selective chess pieces in a chess position. More...

#include <PieceIterator.h>

Inheritance diagram for cwchess::PieceIterator:
Inheritance graph
[legend]

Public Member Functions

Constructors
 PieceIterator (void)
 Construct the corresponding one-passed-the-end iterator. More...
 
 PieceIterator (int)
 Construct the corresponding one-before-the-beginning iterator.
 
 PieceIterator (PieceIterator const& iter)
 Copy-constructor.
 
 PieceIterator (ChessPosition const* chess_position, BitBoard pieces)
 Construct a fully initialized PieceIterator. More...
 
 PieceIterator (ChessPosition const* chess_position, BitBoard pieces, int)
 Construct a fully initialized PieceIterator. More...
 
Assignment operator
PieceIterator&  operator= (PieceIterator const& iter)
 Assign from another PieceIterator.
 
Comparison operators
bool operator== (PieceIterator const& iter) const
 Return TRUE if the current index of this PieceIterator and iter are equal.
 
bool operator!= (PieceIterator const& iter) const
 Return TRUE if the current index of this PieceIterator and iter differ.
 
Accessors
Piece operator* () const
 Return the Piece that stands on the current index.
 
Piece const*  operator-> (void) const
 Return a pointer to the Piece standing on the current index.
 
Index const&  index (void) const
 Return the current index.
 
Increment and decrement operators
PieceIterator&  operator++ ()
 
PieceIterator operator++ (int)
 
PieceIterator&  operator-- ()
 
PieceIterator operator-- (int)
 

Protected Attributes

ChessPosition const*  M_chess_position
 The underlaying chess position.
 
BitBoard M_pieces
 The pieces that the iterator will iterate over.
 
Index M_current_index
 The index to the current piece, or 64 if this iterator points one passed the end.
 

Detailed Description

Non-mutable iterator over selective chess pieces in a chess position.

This iterator iterates over bits in a given BitBoard, passed during creation, and returns the Piece at the given position when dereferenced.

Definition at line 42 of file PieceIterator.h.

Constructor & Destructor Documentation

cwchess::PieceIterator::PieceIterator ( void  )
inline

Construct the corresponding one-passed-the-end iterator.

See also
ChessPosition::piece_end(void)

Definition at line 57 of file PieceIterator.h.

cwchess::PieceIterator::PieceIterator ( ChessPosition const*   chess_position,
BitBoard  pieces 
)
inline

Construct a fully initialized PieceIterator.

Parameters
chess_position: The ChessPosition that we will retrieve the Pieces from. It is only used when the iterator is dereferenced.
pieces: A BitBoard with bits set for each square that the iterator should visit.

This iterator is initialized to point at the beginning (the least significant bit). A typical loop would look as follows:

PieceIterator const piece_end;
for (PieceIterator piece_iter(chess_position, bitboard); piece_iter != piece_end; ++piece_iter)
{
// Use piece_iter.index(), the square that the piece is standing on, or
// access the Piece directly through piece_iter->.
}

which will run over all bits set in bitboard.

See also
ChessPosition::piece_begin, ChessPosition::all

Definition at line 89 of file PieceIterator.h.

cwchess::PieceIterator::PieceIterator ( ChessPosition const*   chess_position,
BitBoard  pieces,
int   
)
inline

Construct a fully initialized PieceIterator.

Parameters
chess_position: The ChessPosition that we will retrieve the Pieces from.
pieces: The pieces, a BitBoard with bits set for each square that the iterator should visit.

This iterator is initialized to point at the end rather than the beginning. A typical loop would look as follows:

PieceIterator const piece_end(0);
for (PieceIterator piece_iter(chess_position, bitboard, 0); piece_iter != piece_end; --piece_iter)
{
// Use piece_iter.index(), the square that the piece is standing on, or
// access the Piece directly through piece_iter->.
}

Definition at line 109 of file PieceIterator.h.


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

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.