Matrix Class Reference

Intermediary between GUI and the rest of the application. More...

#include <Matrix.h>

List of all members.

Public Types

typedef size_t SizeType
 Size type of the array (width / height / indexes).

Public Member Functions

 Matrix (const ConfigMatrix &config)
 Constructor - loads matrix data from config.
 ~Matrix ()
 Destructor.
iterator begin ()
 Returns an iterator to the first element of the matrix.
iterator end ()
 Returns an iterator just past the end of the matrix.
bool PutObject (Object *object, SizeType xIndex, SizeType yIndex)
 Puts selected object into the selected place.
bool MoveObject (SizeType xFrom, SizeType yFrom, SizeType xTo, SizeType yTo)
 Moves object on the selected place to another place.
bool DestroyObject (SizeType xIndex, SizeType yIndex)
 Destroy object at the selected place.
bool IsThereObject (SizeType xIndex, SizeType yIndex) const
 Returns true if there is an object on the selected index.
bool IsEditableByUser (SizeType xIndex, SizeType yIndex) const
 Returns true if the object on the selected place can be edited by user.
void MakeStep ()
 Makes one simulation step (moves objects, solves collisions etc.).
ConfigMatrixGetConfigMatrix () const
 Returns ConfigMatrix (containing whole matrix configuration, including objects).
SecondIndexoperator[] (SizeType firstIndex)
 Direct access to the specified place on the matrix.
SizeType GetWidth () const
 Returns width of the matrix.
SizeType GetHeight () const
 Returns height of the matrix.

Static Public Member Functions

static SizeType GetMinWidth ()
 Returns minimal width of the Matrix.
static SizeType GetMinHeight ()
 Returns minimal height of the Matrix.
static SizeType GetDefaultWidth ()
 Returns starting (default) width of the Matrix.
static SizeType GetDefaultHeight ()
 Returns starting (default) height of the Matrix.
static SizeType GetMaxWidth ()
 Returns maximal width of the Matrix.
static SizeType GetMaxHeight ()
 Returns maximal height of the Matrix.

Private Member Functions

void SendCollisions (Object *firstObject, Object *secondObject)
 Send collisions to selected objects.
void PerformActions ()
 Performs object's actions and solves collisions.
void PerformSpecificOperations ()
 Performs specific operations on saved objects in the matrix.
void IncreaseMatrixSizeForBorders ()
 Increases matrix width and height for borders (walls).
void CreateEmptyMatrix ()
 Creates empty matrix.
void CreateWallsAroundMatrix ()
 Creates walls around matrix.
void LoadObjectsFromConfig (const ConfigMatrix &config)
 Loads objects from the config.
void GenerateNextTicketNumber ()
 Generates next ticket number.
bool IsOutOfRange (SizeType xIndex, SizeType yIndex) const
 Returns true if the selected place is out of the matrix range.
string CreateOutOfRangeMessage (SizeType xIndex, SizeType yIndex) const
 Creates out of range message that should be put into exception message.
bool IndexExists (SizeType xIndex, SizeType yIndex) const
 Returns true if selected index exists.
void GetIndexOfNextPlace (SizeType xFrom, SizeType yFrom, const Direction &direction, SizeType &xTo, SizeType &yTo)
 Saves x and y index of the position where object is heading, according to it's diretion.
bool GetIndexOfNextFreePlace (SizeType xFrom, SizeType yFrom, SizeType &xTo, SizeType &yTo, Direction &direction)
 Saves x and y index of the position where there is "no object" and the direction of the place according to the original place.
bool IsFreePlace (SizeType xIndex, SizeType yIndex) const
 Returns true if selected place is "free".
bool OnBorder (SizeType xIndex, SizeType yIndex) const
 Returns true if selected position is on the border.
bool CanBeAdded (const Object *object, SizeType xIndex, SizeType yIndex) const
 Returns true if the selected object can be added into the selected place.
void InternalMoveObject (SizeType xFrom, SizeType yFrom, const Direction &direction)
 Moves selected object according to the selected direction (controls boundaries).
void InternalMoveObject (SizeType xFrom, SizeType yFrom, SizeType xTo, SizeType yTo)
 Moves selected object from one place to another (does NOT control boundaries).
bool PerformActionTakeObject (Object *object, SizeType xIndex, SizeType yIndex)
 Performs object's action: TakeObject.
bool PerformActionDropObject (Object *object, SizeType xIndex, SizeType yIndex)
 Performs object's action: DropObject.
bool PerformActionPutTrail (Object *object, SizeType xIndex, SizeType yIndex)
 Performs object's action: PutTrail.

Private Attributes

SizeType width
 Width of the matrix.
SizeType height
 Height of the matrix.
Item ** matrix
 Two-dimensional array (matrix itself).
SecondIndex secIndex
 Help object for the operator[] implementation.
Object::TicketSize ticketNumber
 Current ticket number (used in MakeStep()).

Static Private Attributes

static const SizeType MIN_WIDTH = 1
 Minimal width of the matrix.
static const SizeType MIN_HEIGHT = 1
 Minimal height of the matrix.
static const SizeType DEFAULT_WIDTH = 10
 Default width of the matrix.
static const SizeType DEFAULT_HEIGHT = 10
 Default height of the matrix.
static const SizeType MAX_WIDTH = std::numeric_limits<SizeType>::max() / 10
 Maximal width of the matrix.
static const SizeType MAX_HEIGHT = std::numeric_limits<SizeType>::max() / 10
 Maximal height of the matrix.
static const SizeType WIDTH_INCREMENT = 2
 Width increment (for borders).
static const SizeType HEIGHT_INCREMENT = 2
 Height increment (for borders).
static const Object::TicketSize STARTING_TICKET_NUMBER = 0
 Starting (default) ticket number.

Friends

class iterator

Classes

class  CallSpecificMethods
 Functor - calls specific methods for the selected object. More...
class  Item
 Item in the matrix array. More...
class  iterator
 Iterator is used to access the two-dimensional array in the Matrix class. More...
class  RemoveSpecificObjects
 Unary predicate - returns true if the selected object should be removed. More...
class  SaveObjectIntoConfig
 Functor - saves object into the matrix config. More...
class  SecondIndex
 Help class for operator [] implementation. More...


Detailed Description

Intermediary between GUI and the rest of the application.

Object of this class will be an intermediary between GUI and the rest of the application. It manipulates with the matrix (two-dimensional array) in the simulation on the program logic level. For manipulation on the GUI (graphics) level see Canvas class.


Member Typedef Documentation

typedef size_t Matrix::SizeType

Size type of the array (width / height / indexes).


Constructor & Destructor Documentation

Matrix::Matrix ( const ConfigMatrix config  )  [explicit]

Constructor - loads matrix data from config.

Parameters:
config Configuration that will be used to initialize whole matrix

Matrix::~Matrix (  ) 

Destructor.


Member Function Documentation

Matrix::iterator Matrix::begin (  ) 

Returns an iterator to the first element of the matrix.

bool Matrix::CanBeAdded ( const Object object,
SizeType  xIndex,
SizeType  yIndex 
) const [inline, private]

Returns true if the selected object can be added into the selected place.

Parameters:
object Selected object that has to be tested
xIndex First index (x)
yIndex Second index (y)
Tests whether user isn't trying to put wall over an agent etc.

void Matrix::CreateEmptyMatrix (  )  [private]

Creates empty matrix.

Only allocates matrix array with it's width/height.

string Matrix::CreateOutOfRangeMessage ( SizeType  xIndex,
SizeType  yIndex 
) const [private]

Creates out of range message that should be put into exception message.

Parameters:
xIndex First index (x)
yIndex Second index (y)

void Matrix::CreateWallsAroundMatrix (  )  [private]

Creates walls around matrix.

bool Matrix::DestroyObject ( SizeType  xIndex,
SizeType  yIndex 
)

Destroy object at the selected place.

Parameters:
xIndex First index (x) of the place
yIndex Second index (y) of the place
Returns:
Returns true if the selected object was destroyed
It also returns false if the selected index is out of range.

iterator Matrix::end (  )  [inline]

Returns an iterator just past the end of the matrix.

void Matrix::GenerateNextTicketNumber (  )  [inline, private]

Generates next ticket number.

ConfigMatrix * Matrix::GetConfigMatrix (  )  const

Returns ConfigMatrix (containing whole matrix configuration, including objects).

Warning: Returned object is allocated on the heap and you have to delete it explicitly after you don't need it.

static SizeType Matrix::GetDefaultHeight (  )  [inline, static]

Returns starting (default) height of the Matrix.

static SizeType Matrix::GetDefaultWidth (  )  [inline, static]

Returns starting (default) width of the Matrix.

SizeType Matrix::GetHeight (  )  const [inline]

Returns height of the matrix.

bool Matrix::GetIndexOfNextFreePlace ( SizeType  xFrom,
SizeType  yFrom,
SizeType xTo,
SizeType yTo,
Direction direction 
) [private]

Saves x and y index of the position where there is "no object" and the direction of the place according to the original place.

Parameters:
xFrom From index (x)
yFrom From index (y)
xTo x index of next free place
yTo y index of next free place
direction There will be saved direction of the free place
Returns:
Returns true if a free place was found, otherwise it returns false and the value of xTo, yTo and direction is undefined
"No object" means that there is no object with IsImaginary() == false.

void Matrix::GetIndexOfNextPlace ( SizeType  xFrom,
SizeType  yFrom,
const Direction direction,
SizeType xTo,
SizeType yTo 
) [private]

Saves x and y index of the position where object is heading, according to it's diretion.

Parameters:
xFrom From index (x)
yFrom From index (y)
direction Direction of the object
xTo Place where the object is heading (returned x index)
yTo Place where the object is heading (returned y index)

static SizeType Matrix::GetMaxHeight (  )  [inline, static]

Returns maximal height of the Matrix.

static SizeType Matrix::GetMaxWidth (  )  [inline, static]

Returns maximal width of the Matrix.

static SizeType Matrix::GetMinHeight (  )  [inline, static]

Returns minimal height of the Matrix.

static SizeType Matrix::GetMinWidth (  )  [inline, static]

Returns minimal width of the Matrix.

SizeType Matrix::GetWidth (  )  const [inline]

Returns width of the matrix.

void Matrix::IncreaseMatrixSizeForBorders (  )  [private]

Increases matrix width and height for borders (walls).

Call this member function before the matrix creation - if you don't, user will get smaller matrix then he requested (because walls will be placed on borders).

bool Matrix::IndexExists ( SizeType  xIndex,
SizeType  yIndex 
) const [inline, private]

Returns true if selected index exists.

Parameters:
xIndex First index (x)
yIndex Second index (y)

void Matrix::InternalMoveObject ( SizeType  xFrom,
SizeType  yFrom,
SizeType  xTo,
SizeType  yTo 
) [private]

Moves selected object from one place to another (does NOT control boundaries).

Parameters:
xFrom From index (x)
yFrom From index (y)
xTo Another place index (x)
yTo Another place index (y)

void Matrix::InternalMoveObject ( SizeType  xFrom,
SizeType  yFrom,
const Direction direction 
) [private]

Moves selected object according to the selected direction (controls boundaries).

Parameters:
xFrom From index (x)
yFrom From index (y)
direction Direction of the object

bool Matrix::IsEditableByUser ( SizeType  xIndex,
SizeType  yIndex 
) const

Returns true if the object on the selected place can be edited by user.

Parameters:
xIndex Index x
yIndex Index y
It returns false in following situations:

bool Matrix::IsFreePlace ( SizeType  xIndex,
SizeType  yIndex 
) const [inline, private]

Returns true if selected place is "free".

Parameters:
xIndex First index (x)
yIndex Second index (y)
"Free" means that there is no object or there is object but it's imaginary.

bool Matrix::IsOutOfRange ( SizeType  xIndex,
SizeType  yIndex 
) const [inline, private]

Returns true if the selected place is out of the matrix range.

Parameters:
xIndex First index (x)
yIndex Second index (y)

bool Matrix::IsThereObject ( SizeType  xIndex,
SizeType  yIndex 
) const

Returns true if there is an object on the selected index.

Parameters:
xIndex Index x
yIndex Index y
Doesn't control boundaries, so if the selected index is out of range it only returns false.

void Matrix::LoadObjectsFromConfig ( const ConfigMatrix config  )  [private]

Loads objects from the config.

Parameters:
config Config containing inforamtion about objects that has to be loaded

void Matrix::MakeStep (  ) 

Makes one simulation step (moves objects, solves collisions etc.).

bool Matrix::MoveObject ( SizeType  xFrom,
SizeType  yFrom,
SizeType  xTo,
SizeType  yTo 
)

Moves object on the selected place to another place.

Returns:
Returns true if the object on the selected place was moved, false otherwise
Parameters:
xFrom From place index (x)
yFrom From place index (y)
xTo To place index (x)
yTo To place index (y)

bool Matrix::OnBorder ( SizeType  xIndex,
SizeType  yIndex 
) const [inline, private]

Returns true if selected position is on the border.

Parameters:
xIndex First index (x)
yIndex Second index (y)
There are walls on the border, so it's necessary to have this member function.

Matrix::SecondIndex & Matrix::operator[] ( SizeType  firstIndex  ) 

Direct access to the specified place on the matrix.

Parameters:
firstIndex First index (x)
This operator uses SecondIndex object for accessing the second index.

bool Matrix::PerformActionDropObject ( Object object,
SizeType  xIndex,
SizeType  yIndex 
) [private]

Performs object's action: DropObject.

Parameters:
object Object that has to perform a DropObject action
xIndex First index (x)
yIndex Second index (y)
Returns:
Returns true if the action was performed successfully

bool Matrix::PerformActionPutTrail ( Object object,
SizeType  xIndex,
SizeType  yIndex 
) [private]

Performs object's action: PutTrail.

Parameters:
object Object that has to perform a PutTrail action
xIndex First index (x)
yIndex Second index (y)
Returns:
Returns true if the action was performed successfully

void Matrix::PerformActions (  )  [private]

Performs object's actions and solves collisions.

Handles action of each object in the matrix (object that's "on the top").

bool Matrix::PerformActionTakeObject ( Object object,
SizeType  xIndex,
SizeType  yIndex 
) [private]

Performs object's action: TakeObject.

Parameters:
object Object that has to perform a TakeObject action
xIndex First index (x)
yIndex Second index (y)
Returns:
Returns true if the action was performed successfully

void Matrix::PerformSpecificOperations (  )  [private]

Performs specific operations on saved objects in the matrix.

bool Matrix::PutObject ( Object object,
SizeType  xIndex,
SizeType  yIndex 
)

Puts selected object into the selected place.

Returns:
Returns true if the selected object was put, false otherwise
Parameters:
object Object that has to be put
xIndex First index (x)
yIndex Second index (y)
It will put this object only if it's priority is higher then the priority of the object that's currently on the "top".

void Matrix::SendCollisions ( Object firstObject,
Object secondObject 
) [private]

Send collisions to selected objects.

First object will send collision to the second one and vice versa.


Friends And Related Function Documentation

friend class iterator [friend]


Member Data Documentation

const Matrix::SizeType Matrix::DEFAULT_HEIGHT = 10 [static, private]

Default height of the matrix.

const Matrix::SizeType Matrix::DEFAULT_WIDTH = 10 [static, private]

Default width of the matrix.

SizeType Matrix::height [private]

Height of the matrix.

const Matrix::SizeType Matrix::HEIGHT_INCREMENT = 2 [static, private]

Height increment (for borders).

Item** Matrix::matrix [private]

Two-dimensional array (matrix itself).

const Matrix::SizeType Matrix::MAX_HEIGHT = std::numeric_limits<SizeType>::max() / 10 [static, private]

Maximal height of the matrix.

const Matrix::SizeType Matrix::MAX_WIDTH = std::numeric_limits<SizeType>::max() / 10 [static, private]

Maximal width of the matrix.

const Matrix::SizeType Matrix::MIN_HEIGHT = 1 [static, private]

Minimal height of the matrix.

const Matrix::SizeType Matrix::MIN_WIDTH = 1 [static, private]

Minimal width of the matrix.

SecondIndex Matrix::secIndex [private]

Help object for the operator[] implementation.

const Object::TicketSize Matrix::STARTING_TICKET_NUMBER = 0 [static, private]

Starting (default) ticket number.

Object::TicketSize Matrix::ticketNumber [private]

Current ticket number (used in MakeStep()).

SizeType Matrix::width [private]

Width of the matrix.

const Matrix::SizeType Matrix::WIDTH_INCREMENT = 2 [static, private]

Width increment (for borders).


The documentation for this class was generated from the following files:
Generated on Sun Apr 29 11:46:11 2007 for IPP/ICP2007 by  doxygen 1.4.7