TNT::Array2D< T > Class Template Reference

#include <tnt_array2d.h>

Collaboration diagram for TNT::Array2D< T >:
[legend]

List of all members.

Public Types

typedef T value_type

Public Member Functions

 Array2D ()
 Array2D (int m, int n)
 Array2D (int m, int n, T *a)
 Array2D (int m, int n, const T &val)
 Array2D (const Array2D &A)
 operator T ** ()
 operator const T ** () const
Array2Doperator= (const T &val)
Array2Doperator= (const Array2D &A)
Array2Dref (const Array2D &A)
Array2D copy () const
Array2Dinject (const Array2D &A)
T * operator[] (int i)
const T * operator[] (int i) const
int dim1 () const
int dim2 () const
 ~Array2D ()
int ref_count ()
int ref_count_data ()
int ref_count_dim1 ()
Array2D subarray (int i0, int i1, int j0, int j1)

Private Attributes

Array1D< T > data_
Array1D< T * > v_
int m_
int n_


Detailed Description

template<class T>
class TNT::Array2D< T >

Ttwo-dimensional numerical array which looks like a conventional C multiarray. Storage corresponds to C (row-major) ordering. Elements are accessed via A[i][j] notation for 0-based indexing, and A(i,j) for 1-based indexing..

Array assignment is by reference (i.e. shallow assignment). That is, B=A implies that the A and B point to the same array, so modifications to the elements of A will be reflected in B. If an independent copy is required, then B = A.copy() can be used. Note that this facilitates returning arrays from functions without relying on compiler optimizations to eliminate extensive data copying.

The indexing and layout of this array object makes it compatible with C and C++ algorithms that utilize the familiar C[i][j] notation. This includes numerous

textbooks, such as Numercial Recipes, and various public domain codes.

Definition at line 64 of file tnt_array2d.h.


Member Typedef Documentation

template<class T>
typedef T TNT::Array2D< T >::value_type

Used to determined the data type of array entries. This is most commonly used when requiring scalar temporaries in templated algorithms that have TNT arrays as input. For example,

  template &lt class ArrayTwoD &gt
  void foo(ArrayTwoD &A)
  {
    A::value_type first_entry = A[0][0];
    ...
  }
  

Definition at line 94 of file tnt_array2d.h.


Constructor & Destructor Documentation

template<class T >
TNT::Array2D< T >::Array2D (  )  [inline]

Create a null array. This is not the same as Array2D(0,0), which consumes some memory overhead.

Create a new (m x n) array, WIHOUT initializing array elements. To create an initialized array of constants, see Array2D(m,n,value).

This version avoids the O(m*n) initialization overhead and is used just before manual assignment.

Parameters:
m the first (row) dimension of the new matrix.
n the second (column) dimension of the new matrix.

Definition at line 218 of file tnt_array2d.h.

template<class T >
TNT::Array2D< T >::Array2D ( int  m,
int  n 
) [inline]

Create a new (m x n) array, without initalizing elements. (This encurs an O(1) operation cost, rather than a O(m*n) cost.)

Parameters:
m the first (row) dimension of the new matrix.
n the second (column) dimension of the new matrix.

Definition at line 229 of file tnt_array2d.h.

template<class T>
TNT::Array2D< T >::Array2D ( int  m,
int  n,
T *  a 
) [inline]

Create a new (m x n) array, as a view of an existing one-dimensional array stored in row-major order, i.e. right-most dimension varying fastest. Note that the storage for this pre-existing array will never be destroyed by TNT.

Parameters:
m the first (row) dimension of the new matrix.
n the second (column) dimension of the new matrix.
a the one dimensional C array to use as data storage for the array.

Definition at line 261 of file tnt_array2d.h.

template<class T>
TNT::Array2D< T >::Array2D ( int  m,
int  n,
const T &  val 
) [inline]

Create a new (m x n) array, initializing array elements to constant specified by argument. Most often used to create an array of zeros, as in A(m, n, 0.0).

Parameters:
m the first (row) dimension of the new matrix.
n the second (column) dimension of the new matrix.
val the constant value to set all elements of the new array to.

Definition at line 245 of file tnt_array2d.h.

template<class T>
TNT::Array2D< T >::Array2D ( const Array2D< T > &  A  )  [inline]

Copy constructor. Array data is NOT copied, but shared. Thus, in Array2D B(A), subsequent changes to A will be reflected in B. For an indepent copy of A, use Array2D B(A.copy()), or B = A.copy(), instead.

Definition at line 222 of file tnt_array2d.h.

template<class T >
TNT::Array2D< T >::~Array2D (  )  [inline]

Definition at line 374 of file tnt_array2d.h.


Member Function Documentation

template<class T >
Array2D< T > TNT::Array2D< T >::copy (  )  const [inline]

Definition at line 316 of file tnt_array2d.h.

template<class T >
int TNT::Array2D< T >::dim1 (  )  const [inline]

Definition at line 367 of file tnt_array2d.h.

template<class T >
int TNT::Array2D< T >::dim2 (  )  const [inline]

Definition at line 370 of file tnt_array2d.h.

template<class T >
Array2D< T > & TNT::Array2D< T >::inject ( const Array2D< T > &  A  )  [inline]

Definition at line 330 of file tnt_array2d.h.

template<class T >
TNT::Array2D< T >::operator const T ** (  )  const [inline]

Convert a const 2D array into a const multidimensional C pointer. Most often called automatically when calling C interfaces that expect things like "const double**" rather than "const Array2D<dobule>&".

Definition at line 385 of file tnt_array2d.h.

template<class T >
TNT::Array2D< T >::operator T ** (  )  [inline]

Convert 2D array into a regular multidimensional C pointer. Most often called automatically when calling C interfaces that expect things like double** rather than Array2D<dobule>.

Definition at line 380 of file tnt_array2d.h.

template<class T>
Array2D< T > & TNT::Array2D< T >::operator= ( const Array2D< T > &  A  )  [inline]

Assign one Array2D to another. (This is a shallow-assignement operation, and it is the identical semantics to ref(A).

Parameters:
A the array to assign this one to.

Definition at line 361 of file tnt_array2d.h.

template<class T>
Array2D< T > & TNT::Array2D< T >::operator= ( const T &  val  )  [inline]

Assign all elements of array the same value.

Parameters:
val the value to assign each element.

Definition at line 302 of file tnt_array2d.h.

template<class T >
const T * TNT::Array2D< T >::operator[] ( int  i  )  const [inline]

Definition at line 290 of file tnt_array2d.h.

template<class T >
T * TNT::Array2D< T >::operator[] ( int  i  )  [inline]

Definition at line 277 of file tnt_array2d.h.

template<class T >
Array2D< T > & TNT::Array2D< T >::ref ( const Array2D< T > &  A  )  [inline]

Definition at line 345 of file tnt_array2d.h.

template<class T >
int TNT::Array2D< T >::ref_count (  )  [inline]

Definition at line 425 of file tnt_array2d.h.

template<class T >
int TNT::Array2D< T >::ref_count_data (  )  [inline]

Definition at line 433 of file tnt_array2d.h.

template<class T >
int TNT::Array2D< T >::ref_count_dim1 (  )  [inline]

Definition at line 439 of file tnt_array2d.h.

template<class T >
Array2D< T > TNT::Array2D< T >::subarray ( int  i0,
int  i1,
int  j0,
int  j1 
) [inline]

Create a new view to a subarray defined by the boundaries [i0][i0] and [i1][j1]. The size of the subarray is (i1-i0) by (j1-j0). If either of these lengths are zero or negative, the subarray view is null.

Definition at line 399 of file tnt_array2d.h.


Member Data Documentation

template<class T>
Array1D<T> TNT::Array2D< T >::data_ [private]

Definition at line 72 of file tnt_array2d.h.

template<class T>
int TNT::Array2D< T >::m_ [private]

Definition at line 74 of file tnt_array2d.h.

template<class T>
int TNT::Array2D< T >::n_ [private]

Definition at line 75 of file tnt_array2d.h.

template<class T>
Array1D<T*> TNT::Array2D< T >::v_ [private]

Definition at line 73 of file tnt_array2d.h.


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

Generated on Fri Feb 6 13:30:19 2009 for CorAL by  doxygen 1.5.8