KrisLibrary  1.0.0
Classes | Public Member Functions | Public Attributes | Protected Attributes | List of all members
Array2D< T > Class Template Reference

A two-dimensional m x n array. More...

#include <array2d.h>

Classes

class  iterator
 

Public Member Functions

 Array2D (int m, int n)
 
 Array2D (int m, int n, const T &initVal)
 
 Array2D (const Array2D< T > &rhs)
 
 Array2D (Array2D< T > &&rhs)
 
T & operator() (int i, int j)
 
const T & operator() (int i, int j) const
 
T & operator() (const IntPair &t)
 
const T & operator() (const IntPair &t) const
 
Array2D< T > & operator= (const Array2D< T > &rhs)
 
Array2D< T > & operator= (Array2D< T > &&rhs)
 
bool Read (File &f)
 
bool Write (File &f) const
 
int numRows () const
 
int numCols () const
 
IntPair size () const
 
bool empty () const
 
void initialize (int m, int n)
 
void initialize (int m, int n, const T &initVal)
 
void resize (int m, int n)
 
void resize (int m, int n, const T &initVal)
 
void reserve (int numItems)
 
void clear ()
 
bool find (const T &item, int &i, int &j) const
 
bool find (const T &item, IntPair &t) const
 
bool contains (const T &item) const
 
void set (const T &item)
 
void set (const Array2D< T > &)
 
void swap (Array2D< T > &)
 
T * getData () const
 
T * getRowData (int i) const
 
iterator begin () const
 
iterator end () const
 
iterator begin (const Range2Indices &range) const
 
iterator end (const Range2Indices &range) const
 

Public Attributes

int m
 
int n
 

Protected Attributes

T * items
 
int capacity
 

Detailed Description

template<class T>
class Array2D< T >

A two-dimensional m x n array.

Indices are in the range [0,m) x [0,n). Elements can be accessed with the (i,j) operator, or with the (IntPair) operator. They are stored in memory in row-major order.

The array is sized with initialize(m,n) or resize(m,n). The difference is that initialize always deallocates previously allocated memory, and resize only deallocates it if the new size is greater than the established capacity (capacity >= m*n). Capacity can be set using the reserve() method, but only if the array is empty. The existing elements are not maintained in any particular order upon a resize.

If the optional initVal parameter is passed to initialize or resize, all elements are set to initVal after resizing.

The iterator class allows fast iteration of all or some elements. A range of the array can be accessed using the Range2Indices class.


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