BengArray2D< T > Class Template Reference

#include <Array2d.h>

List of all members.

Public Member Functions

 BengArray2D (unsigned int xsize, unsigned int ysize)
 ~BengArray2D (void)
void getSize (unsigned int &xOut, unsigned int &yOut)
 Returns the dimensions of the array in xOut and yOut.
void setElement (unsigned int xIn, unsigned int yIn, T data)
getElement (unsigned int xIn, unsigned int yIn)
T ** getRawData (void)

Protected Attributes

unsigned int sizeX
 The number of columns the array takes up.
unsigned int sizeY
 The number of rows the array takes up.
T * tileMap
 Contains the actual data used by the array, in contiguous space.
T ** tileRows
 Pointers to each row. This is returned on a call to getRawData().


Detailed Description

template<typename T>
class BengArray2D< T >

The BengArray2D class allows you to create a two-dimensional array with any size dimensions without having to specify them at compile-time. It makes use of templates so that you can use any type you desire, whether it is an int, short int, or perhaps an array of complex objects. One of the advantages of using this over other dynamic array methods is that you can use a BengCArray in the same way that you would with the traditional built-in C array. To access data, the class provides both a safe method (getElement() and setElement()) as well as an unsafe method:

BengArray<int> *myArray = new BengArray2D<int>(32, 32);

myArrayData = myArray->getRawData();
myArrayData[2][3] = FOO_BAR;

delete myArray;


Constructor & Destructor Documentation

template<typename T>
BengArray2D< T >::BengArray2D ( unsigned int  xsize,
unsigned int  ysize 
) [inline]

Creates a two-dimensional array and allocates the space for it so that it can be used like a C array. Like a traditional array, all the contents will be initialized to zero.

template<typename T>
BengArray2D< T >::~BengArray2D ( void   )  [inline]

Destroys the 2D array, freeing the allocated space. It does not, however, free up any objects referenced by pointers in the array if the array is typed as a pointer. You will need to do this manually.


Member Function Documentation

template<typename T>
T BengArray2D< T >::getElement ( unsigned int  xIn,
unsigned int  yIn 
) [inline]

Retrieves the value of one cell in the array, given coordinates xIn and yIn. This function will perform bounds checking. If the given coordinates are not in the array, the function does nothing.

template<typename T>
T** BengArray2D< T >::getRawData ( void   )  [inline]

Returns a T** pointer to the raw data of the array so that you can use it unchecked just like a C array:

myArrayData = myArray->getRawData();
myArrayData[2][3] = FOO_BAR;

template<typename T>
void BengArray2D< T >::getSize ( unsigned int &  xOut,
unsigned int &  yOut 
) [inline]

Returns the dimensions of the array in xOut and yOut.

template<typename T>
void BengArray2D< T >::setElement ( unsigned int  xIn,
unsigned int  yIn,
data 
) [inline]

Changes the value of one cell in the array, given coordinates xIn and yIn, and the data to replace the cell with. This function will perform bounds checking. If the given coordinates are not in the array, the function does nothing.


Member Data Documentation

template<typename T>
unsigned int BengArray2D< T >::sizeX [protected]

The number of columns the array takes up.

template<typename T>
unsigned int BengArray2D< T >::sizeY [protected]

The number of rows the array takes up.

template<typename T>
T* BengArray2D< T >::tileMap [protected]

Contains the actual data used by the array, in contiguous space.

template<typename T>
T** BengArray2D< T >::tileRows [protected]

Pointers to each row. This is returned on a call to getRawData().


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

Generated on Sun May 3 21:56:25 2009 for BlitzzEngine by  doxygen 1.5.8