Detailed Description

template<class T> class TNT::Fortran_Array1D

Templated one-dimensional, numerical array which looks like a conventional Fortran array. This is useful when integrating with C/C++ codes translated from Fortran. Indexing is via the A(i) notation and A(1) is the first element.

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.

This class employs its own garbage collection via the use of reference counts. That is, whenever an internal array storage no longer has any references to it, it is destoryed.

Member Typedef Documentation

template<class T>

typedef T TNT::Fortran_Array1D<T>::value_type

Constructor & Destructor Documentation

template<class T>

TNT::Fortran_Array1D< T >::Fortran_Array1D<T> (

)

Create a null (0-length) array.

template<class T>

TNT::Fortran_Array1D< T >::Fortran_Array1D<T> (

int n )

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

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

Parameters:

m

the dimension of the new matrix.

template<class T>

TNT::Fortran_Array1D< T >::Fortran_Array1D<T> (

int n,

T * a )

Create a new n-length array, as a view of an existing one-dimensional C array. (Note that the storage for this pre-existing array will never be garbage collected by the Fortran_Array1D class.)

Parameters:

m

the first dimension of the new matrix.

n

the second dimension of the new matrix.

a

the one dimensional C array to use as data storage for the array.

template<class T>

TNT::Fortran_Array1D< T >::Fortran_Array1D<T> (

int n,

const T & val )

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

Parameters:

m

the dimension of the new matrix.

val

the constant value to set all elements of the new array to.

template<class T>

TNT::Fortran_Array1D< T >::Fortran_Array1D<T> (

const Fortran_Array1D<T> & A ) [inline]

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

template<class T>

TNT::Fortran_Array1D<T>::~Fortran_Array1D<T> (

)

Member Function Documentation

template<class T>

Fortran_Array1D< T > TNT::Fortran_Array1D< T >::copy (

) const

Create a new of existing matrix. Used in B = A.copy() or in the construction of B, e.g. Fortran_Array1D B(A.copy()), to create a new array that does not share data.

template<class T>

int TNT::Fortran_Array1D< T >::dim (

) const [inline]

Returns:

the size (dimension of) the array.

template<class T>

int TNT::Fortran_Array1D< T >::dim1 (

) const [inline]

Returns:

the size (dimension of) the array.

template<class T>

Fortran_Array1D< T > & TNT::Fortran_Array1D< T >::inject (

const Fortran_Array1D<T> & A )

Copy the elements to from one array to another, in place. That is B.inject(A), both A and B must conform (i.e. have identical dimensions).

This differs from B = A.copy() in that references to B before this assignment are also affected. That is, if we have