#include "grid.h"
Public Member Functions | |
| Grid () | |
| Grid (int numRows, int numCols) | |
| ~Grid () | |
| int | numRows () |
| int | numCols () |
| void | resize (int numRows, int numCols) |
| ElemType | getAt (int row, int col) |
| void | setAt (int row, int col, ElemType value) |
| ElemType & | operator() (int row, int col) |
| const Grid & | operator= (const Grid &rhs) |
| Grid (const Grid &rhs) | |
This no-argument constructor initializes a new empty grid with 0 rows and 0 cols.
This two-argument constructor initializes a new grid with num rows and cols. Each element in the grid has value equal to the default for that element type (e.g. for strings it would be empty string, for ints, the default value is uninitialized). Raises an error if numRowsx or numCols is negative.
The destructor deallocates storage associated with this grid.
| int Grid< ElemType >::numRows | ( | ) |
These member functions returns the number of rows or columns in this grid.
| int Grid< ElemType >::numCols | ( | ) |
| void Grid< ElemType >::resize | ( | int | numRows, | |
| int | numCols | |||
| ) |
This member function sets the number of rows and columns in this grid to the specified values. Any previous grid contents are discarded. Each element in the resized grid has value equal to the default for that element type. Raises an error if numRows or numCols is negative.
| ElemType Grid< ElemType >::getAt | ( | int | row, | |
| int | col | |||
| ) |
| void Grid< ElemType >::setAt | ( | int | row, | |
| int | col, | |||
| ElemType | value | |||
| ) |
| ElemType & Grid< ElemType >::operator() | ( | int | row, | |
| int | col | |||
| ) |
This member function overloads () to access elements from this grid. This allows the client to use function-like notation to get/set individual elements. Returns a reference to the element to allow in-place modification of values. Raises an error if row is outside the range [0, numRows()-1] or if col is outside the range [0, numCols()-1].
| const Grid< ElemType > & Grid< ElemType >::operator= | ( | const Grid< ElemType > & | rhs | ) |
This copy constructor and operator= are defined to make a deep copy, making it possible to pass/return grids by value and assign from one grid to another. The entire contents of the grid, including all elements, are copied. Each grid element is copied from the original grid to the copy using assignment (operator=). Making copies is generally avoided because of the expense and thus, grids are typically passed by reference, however, when a copy is needed, these operations are supported.
1.5.1