Grid< ElemType > Class Template Reference

#include "grid.h"

List of all members.

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 Gridoperator= (const Grid &rhs)
 Grid (const Grid &rhs)


Detailed Description

template<typename ElemType>
class Grid< ElemType >

The class Grid stores an indexed, two-dimensional collection. It is supplied as a class template. The client specializes the grid to hold values of a specific type. Because the class is defined with private data members, clients have no access to the underlying data members and can only manipulate a grid object through its public member functions.


Constructor & Destructor Documentation

template<typename ElemType>
Grid< ElemType >::Grid (  ) 

This no-argument constructor initializes a new empty grid with 0 rows and 0 cols.

template<typename ElemType>
Grid< ElemType >::Grid ( int  numRows,
int  numCols 
)

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.

template<typename ElemType>
Grid< ElemType >::~Grid (  ) 

The destructor deallocates storage associated with this grid.

template<typename ElemType>
Grid< ElemType >::Grid ( const Grid< ElemType > &  rhs  ) 


Member Function Documentation

template<typename ElemType>
int Grid< ElemType >::numRows (  ) 

These member functions returns the number of rows or columns in this grid.

template<typename ElemType>
int Grid< ElemType >::numCols (  ) 

template<typename ElemType>
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.

template<typename ElemType>
ElemType Grid< ElemType >::getAt ( int  row,
int  col 
)

This member function returns the element at specified row/col location in this grid. Locations are indexed starting from 0. Raises an error if row is outside range [0, numRows()-1] or if col is outside range [0, numCols()-1].

template<typename ElemType>
void Grid< ElemType >::setAt ( int  row,
int  col,
ElemType  value 
)

This member function replaces the element at the specified row/col location in this grid with a new value. The previous value at that location is overwritten with the new value. Raises an error if row is outside the range [0, numRows()-1] or if col is outside the range [0, numCols()-1].

template<typename ElemType>
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].

template<typename ElemType>
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.


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1