SPUC  3.0
Public Types | Public Member Functions | List of all members
SPUC::array1d< T > Class Template Reference

#include <array1d.h>

Public Types

typedef T value_type
 

Public Member Functions

 array1d ()
 
 array1d (int n)
 
 array1d (int n, T *a)
 
 array1d (int n, const T &a)
 
 array1d (const array1d &A)
 
array1doperator= (const T &a)
 
array1doperator= (const array1d &A)
 
array1dref (const array1d &A)
 
array1d copy () const
 
array1dinject (const array1d &A)
 
T & operator[] (int i)
 
const T & operator[] (int i) const
 
int dim1 () const
 
int dim () const
 
int ref_count () const
 
 ~array1d ()
 
array1d< T > mid (int s, int nr) const
 
void replace_mid (int s, const array1d< T > &v) const
 
int length () const
 
array1d< T > & set_size (int m, bool f)
 
array1d< T > & newsize (int m, bool f)
 
array1d< T > & newsize (int m)
 
array1d< T > & set_size (int m)
 

Detailed Description

template<class T>
class SPUC::array1d< T >

Templated one-dimensional, numerical array which looks like a conventional C array. Elements are accessed via the familiar A[i] notation.

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] notation. This includes numerous textbooks, such as Numercial Recipes, and various public domain codes.

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 SPUC::array1d< T >::value_type

Constructor & Destructor Documentation

template<class T >
SPUC::array1d< T >::array1d ( )

Null constructor. Creates a 0-length (NULL) array. (Reference count is also zero.)

template<class T >
SPUC::array1d< T >::array1d ( int  n)
explicit

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

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

Parameters
nthe dimension (length) of the new matrix.
template<class T >
SPUC::array1d< T >::array1d ( 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 destroyed by the Aray1DRef class.)

Parameters
nthe dimension (length) of the new matrix.
athe one dimensional C array to use as data storage for the array.
template<class T >
SPUC::array1d< T >::array1d ( int  n,
const T &  val 
)

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

Parameters
nthe dimension (length) of the new matrix.
valthe constant value to set all elements of the new array to.
template<class T >
SPUC::array1d< T >::array1d ( const array1d< T > &  A)
inline

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

template<class T >
SPUC::array1d< T >::~array1d ( )

Member Function Documentation

template<class T >
array1d< T > SPUC::array1d< T >::copy ( ) const

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

template<class T >
int SPUC::array1d< T >::dim ( ) const
inline
Returns
the dimension (number of elements) of the array. This is equivalent to dim1() and dim1().

Referenced by SPUC::array1d< T >::replace_mid().

template<class T >
int SPUC::array1d< T >::dim1 ( ) const
inline
Returns
the dimension (number of elements) of the array. This is equivalent to dim() and dim1().

Referenced by SPUC::array1d< T >::set_size().

template<class T >
array1d< T > & SPUC::array1d< T >::inject ( const 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 row and column dimensions).

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

        array1d A(n);
        array1d C(n);
        array1d B(C);        // elements of B and C are shared.

then B.inject(A) affects both and C, while B=A.copy() creates a new array B which shares no data with C or A.

Parameters
Athe array from which elements will be copied
Returns
an instance of the modifed array. That is, in B.inject(A), it returns B. If A and B are not conformat, no modifications to B are made.
template<class T >
int SPUC::array1d< T >::length ( ) const
inline
template<class T >
array1d< T > SPUC::array1d< T >::mid ( int  s,
int  nr 
) const
template<class T>
array1d<T>& SPUC::array1d< T >::newsize ( int  m,
bool  f 
)
inline

References SPUC::array1d< T >::set_size().

Here is the call graph for this function:

template<class T>
array1d<T>& SPUC::array1d< T >::newsize ( int  m)
inline

References SPUC::array1d< T >::set_size().

Here is the call graph for this function:

template<class T >
array1d< T > & SPUC::array1d< T >::operator= ( const T &  a)
inline

Assign all elemnts of A to a constant scalar.

template<class T >
array1d< T > & SPUC::array1d< T >::operator= ( const array1d< T > &  A)
inline

B = A is shorthand notation for B.ref(A).

template<class T >
T & SPUC::array1d< T >::operator[] ( int  i)
inline

A[i] indexes the ith element of A. The first element is A[0]. If SPUC_BOUNDS_CHECK is defined, then the index is checked that it falls within the array bounds.

template<class T >
const T & SPUC::array1d< T >::operator[] ( int  i) const
inline

A[i] indexes the ith element of A. The first element is A[0]. If SPUC_BOUNDS_CHECK is defined, then the index is checked that it fall within the array bounds.

template<class T >
array1d< T > & SPUC::array1d< T >::ref ( const array1d< T > &  A)
inline

Create a reference (shallow assignment) to another existing array. In B.ref(A), B and A shared the same data and subsequent changes to the array elements of one will be reflected in the other.

This is what operator= calls, and B=A and B.ref(A) are equivalent operations.

Returns
The new referenced array: in B.ref(A), it returns B.
template<class T >
int SPUC::array1d< T >::ref_count ( ) const
inline
Returns
the number of arrays that share the same storage area as this one. (Must be at least one.)
template<class T >
void SPUC::array1d< T >::replace_mid ( int  s,
const array1d< T > &  v 
) const

References SPUC::array1d< T >::dim().

Here is the call graph for this function:

template<class T>
array1d<T>& SPUC::array1d< T >::set_size ( int  m,
bool  f 
)
inline

References SPUC::array1d< T >::set_size().

Referenced by SPUC::array1d< T >::newsize(), and SPUC::array1d< T >::set_size().

Here is the call graph for this function:

template<class T>
array1d<T>& SPUC::array1d< T >::set_size ( int  m)
inline

References SPUC::array1d< T >::dim1().

Here is the call graph for this function:


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