#include <Matrix.h>
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.). | |
| ConfigMatrix * | GetConfigMatrix () const |
| Returns ConfigMatrix (containing whole matrix configuration, including objects). | |
| SecondIndex & | operator[] (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... | |
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.
| typedef size_t Matrix::SizeType |
Size type of the array (width / height / indexes).
| Matrix::Matrix | ( | const ConfigMatrix & | config | ) | [explicit] |
Constructor - loads matrix data from config.
| config | Configuration that will be used to initialize whole matrix |
| Matrix::~Matrix | ( | ) |
Destructor.
| 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.
| object | Selected object that has to be tested | |
| xIndex | First index (x) | |
| yIndex | Second index (y) |
| void Matrix::CreateEmptyMatrix | ( | ) | [private] |
Creates empty matrix.
Only allocates matrix array with it's width/height.
Creates out of range message that should be put into exception message.
| xIndex | First index (x) | |
| yIndex | Second index (y) |
| void Matrix::CreateWallsAroundMatrix | ( | ) | [private] |
Creates walls around matrix.
Destroy object at the selected place.
| xIndex | First index (x) of the place | |
| yIndex | Second index (y) of the place |
| 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.
| 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 |
| 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.
| 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) |
| 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).
Returns true if selected index exists.
| 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).
| 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).
| xFrom | From index (x) | |
| yFrom | From index (y) | |
| direction | Direction of the object |
Returns true if the object on the selected place can be edited by user.
| xIndex | Index x | |
| yIndex | Index y |
Returns true if selected place is "free".
| xIndex | First index (x) | |
| yIndex | Second index (y) |
Returns true if the selected place is out of the matrix range.
| xIndex | First index (x) | |
| yIndex | Second index (y) |
Returns true if there is an object on the selected index.
| xIndex | Index x | |
| yIndex | Index y |
| void Matrix::LoadObjectsFromConfig | ( | const ConfigMatrix & | config | ) | [private] |
Loads objects from the config.
| config | Config containing inforamtion about objects that has to be loaded |
| void Matrix::MakeStep | ( | ) |
Makes one simulation step (moves objects, solves collisions etc.).
Moves object on the selected place to another place.
| xFrom | From place index (x) | |
| yFrom | From place index (y) | |
| xTo | To place index (x) | |
| yTo | To place index (y) |
Returns true if selected position is on the border.
| xIndex | First index (x) | |
| yIndex | Second index (y) |
| Matrix::SecondIndex & Matrix::operator[] | ( | SizeType | firstIndex | ) |
Direct access to the specified place on the matrix.
| firstIndex | First index (x) |
| bool Matrix::PerformActionDropObject | ( | Object * | object, | |
| SizeType | xIndex, | |||
| SizeType | yIndex | |||
| ) | [private] |
Performs object's action: DropObject.
| object | Object that has to perform a DropObject action | |
| xIndex | First index (x) | |
| yIndex | Second index (y) |
Performs object's action: PutTrail.
| object | Object that has to perform a PutTrail action | |
| xIndex | First index (x) | |
| yIndex | Second index (y) |
| 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.
| object | Object that has to perform a TakeObject action | |
| xIndex | First index (x) | |
| yIndex | Second index (y) |
| void Matrix::PerformSpecificOperations | ( | ) | [private] |
Performs specific operations on saved objects in the matrix.
Puts selected object into the selected place.
| object | Object that has to be put | |
| xIndex | First index (x) | |
| yIndex | Second index (y) |
Send collisions to selected objects.
First object will send collision to the second one and vice versa.
friend class iterator [friend] |
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).
1.4.7