LTI-Lib latest version v1.9 - last update 24 Nov 2005
Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

lti::array< T > Class Template Reference
[Aggregate Data Types]

Array class. More...

#include <ltiArray.h>

Inheritance diagram for lti::array< T >:

Inheritance graph
[legend]
Collaboration diagram for lti::array< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 array ()
 array (int from, int to, const T &iniValue=T())
 array (const array< T > &other)
 array (const vector< T > &other, int theOffset=0)
 array (bool init, int from, int to)
virtual ~array ()
virtual const char * getTypeName () const
void resize (int from, int to, const T &iniValue=T(), bool copyData=true, bool initNew=true)
void shift (int sh)
void fill (const T &data, int from=MinInt32, int to=MaxInt32)
int firstIdx () const
void setFirstIdx (int newIdx)
int lastIdx () const
T & at (int x)
const T & at (int x) const
T & operator[] (int x)
const T & operator[] (int x) const
array< T > & copy (const vector< T > &other)
array< T > & copy (const array< T > &other)
array< T > & operator= (const vector< T > &other)
array< T > & operator= (const array< T > &other)
template<class U>
array< T > & castFrom (const array< U > &other)
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)
Apply Methods
array< T > & apply (T(*function)(T))
array< T > & apply (const array< T > &other, T(*function)(T))
array< T > & apply (T(*function)(const T &))
array< T > & apply (const array< T > &other, T(*function)(const T &))
array< T > & apply (const array< T > &other, T(*function)(const T &, const T &))
array< T > & apply (const array< T > &other, T(*function)(T, T))
array< T > & apply (const array< T > &a, const array< T > &b, T(*function)(const T &, const T &))
array< T > & apply (const array< T > &a, const array< T > &b, T(*function)(T, T))

Protected Attributes

int offset
int firstArrayElement
int lastArrayElement
T * theElement0

Detailed Description

template<class T>
class lti::array< T >

Array class.

A n-dimensional array indexed between from and to, where to-from+1 = n. The indices from and to can be negative, but from must be lower or equal to.

All inherited arithmetical operations still need to be reviewed, since the vector methods will only check if the size n of the array is correct. Use these operations at your own risk. It is safer if you use the on-place version of the arithmetical methods, since they won't change the index range of the array. Otherwise, the range will be change to [0,n-1].


Constructor & Destructor Documentation

template<class T>
lti::array< T >::array  ) 
 

default constructor creates an empty array;

template<class T>
lti::array< T >::array int  from,
int  to,
const T &  iniValue = T()
 

constructor.

creates an array indexed between from and to and initializes it with iniValue

template<class T>
lti::array< T >::array const array< T > &  other  ) 
 

copy constructor.

copy contents of other array in this array.

template<class T>
lti::array< T >::array const vector< T > &  other,
int  theOffset = 0
 

copy constructor.

copy contents of other vector in this array.

template<class T>
lti::array< T >::array bool  init,
int  from,
int  to
 

If init is true this constructor is equivalent to calling array(int theSize), and thus initializing all elements with T().

However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large arrays, the unnecessary constructor initialization is very time consuming.

If init is false, memory is allocated but no initialization takes place.

Parameters:
init initialize matrix or not
from first index
to last index

template<class T>
virtual lti::array< T >::~array  )  [virtual]
 

destructor


Member Function Documentation

template<class T>
array<T>& lti::array< T >::apply const array< T > &  a,
const array< T > &  b,
T(*)(T, T)  function
 

a two-parameter C-function receives the i-th elements of the given arrays and leaves the result here.

Note that both arrays MUST have the same size! If both arrays have different size, the function will throw an assertion without changing anything!

Parameters:
a the first array
b the second array
function a pointer to a two parameters C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply const array< T > &  a,
const array< T > &  b,
T(*)(const T &, const T &)  function
 

a two-parameter C-function receives the i-th elements of the given arrays and leaves the result here.

Note that both arrays MUST have the same size! If both arrays have different size, the function will throw an assertion without changing anything!

The following example uses lti::min as function. The arrays a and b contain the values [1,2,3,4] and [4,3,2,1], respectively. After applying the function, array c contains the values [1,2,2,1].

 iarray a,b,c;
 int i=0;
 for (i=0; i<4; ++i) {
   a.at(i)=i+1;
   b.at(i)=4-i;
 }
 c.apply(a,b,lti::min);
Parameters:
a the first array
b the second array
function a pointer to a two parameters C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply const array< T > &  other,
T(*)(T, T)  function
 

a two-parameter C-function receives the i-th elements of this and the given array and the result will be left in this array.

Note that both arrays MUST have the same size! If both arrays have different size, the function will throw an assertion without changing anything!

Parameters:
other the second array to be considered (the first array will be this object!)
function a pointer to a two parameters C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply const array< T > &  other,
T(*)(const T &, const T &)  function
 

a two-parameter C-function receives the i-th elements of this and the given array and the result will be left in this array.

Note that both arrays MUST have the same size! If both arrays have different size, the function will throw an assertion without changing anything!

Parameters:
other the second array to be considered (the first array will be this object!)
function a pointer to a two parameters C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply const array< T > &  other,
T(*)(const T &)  function
 

applies a C-function to each element the other array and leaves the result here.

Parameters:
other the array with the source data
function a pointer to a C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply T(*)(const T &)  function  ) 
 

applies a C-function to each element of the array.

Parameters:
function a pointer to a C-function
Returns:
a reference to the actual array

Reimplemented from lti::genericVector< T >.

template<class T>
array<T>& lti::array< T >::apply const array< T > &  other,
T(*)(T)  function
 

applies a C-function to each element of the other array and leaves the result here.

Parameters:
other the source array
function a pointer to a C-function
Returns:
a reference to the actual array

template<class T>
array<T>& lti::array< T >::apply T(*)(T)  function  ) 
 

applies a C-function to each element of the array.

In the following example, array vct is initialized with 4.0. After applying sqrt(), all elements of vct are 2.0.

 array<float> vct(4,4.0);
 vct.apply(sqrt);
Parameters:
function a pointer to a C-function
Returns:
a reference to the actual array

Reimplemented from lti::genericVector< T >.

template<class T>
const T& lti::array< T >::at int  x  )  const [inline]
 

const access operator.

access element x with firstIdx() <= x <= lastIdx().

Reimplemented from lti::genericVector< T >.

template<class T>
T& lti::array< T >::at int  x  )  [inline]
 

access operator.

access element x with firstIdx() <= x <= lastIdx().

Reimplemented from lti::genericVector< T >.

template<class T>
template<class U>
array<T>& lti::array< T >::castFrom const array< U > &  other  )  [inline]
 

cast and copy the elements of the "other" array

template<class T>
array<T>& lti::array< T >::copy const array< T > &  other  ) 
 

assigment operator.

copy content of array other

template<class T>
array<T>& lti::array< T >::copy const vector< T > &  other  ) 
 

assigment operator.

copy content of vector other

template<class T>
void lti::array< T >::fill const T &  data,
int  from = MinInt32,
int  to = MaxInt32
 

fills the array with value data between from and to.

Reimplemented from lti::genericVector< T >.

template<class T>
int lti::array< T >::firstIdx  )  const [inline]
 

returns first index.

the returned value is equal to from by construction or resizing.

Reimplemented from lti::genericVector< T >.

template<class T>
virtual const char* lti::array< T >::getTypeName  )  const [virtual]
 

returns the name of this type

Reimplemented from lti::vector< T >.

Reimplemented in lti::kernel1D< T >, lti::kernel1D< double >, and lti::kernel1D< float >.

template<class T>
int lti::array< T >::lastIdx  )  const [inline]
 

returns last index.

the returned value is equal to to by contruction or resizing

Reimplemented from lti::genericVector< T >.

template<class T>
array<T>& lti::array< T >::operator= const array< T > &  other  )  [inline]
 

assigment operator.

(alias for copy(other).

template<class T>
array<T>& lti::array< T >::operator= const vector< T > &  other  )  [inline]
 

assigment operator.

(alias for copy(other).

template<class T>
const T& lti::array< T >::operator[] int  x  )  const [inline]
 

const access operator (alias for at(x))

Reimplemented from lti::genericVector< T >.

template<class T>
T& lti::array< T >::operator[] int  x  )  [inline]
 

access operator (alias for at(x)).

Reimplemented from lti::genericVector< T >.

template<class T>
virtual bool lti::array< T >::read ioHandler handler,
const bool  complete = true
[virtual]
 

read the object from the given ioHandler

Reimplemented from lti::genericVector< T >.

Reimplemented in lti::kernel1D< T >, lti::kernel1D< double >, and lti::kernel1D< float >.

template<class T>
void lti::array< T >::resize int  from,
int  to,
const T &  iniValue = T(),
bool  copyData = true,
bool  initNew = true
 

change the dimension and/or range of the array.

If the new dimension of the array (to-from+1) is different from the old one or if this array doesn't own the data, new memory is allocated.

If copyData is true the data is copied according to the indices, e.g. if the old array is (-2, 2) and contains the values 0 to 4 and a resize(0,4,10) is performed the new array will be [2, 3, 4, 10, 10]. If the indices don't overlap no copying takes place.

To adjust the range of an array, i.e. the data contained and the size stays the same, but the start and end indices change, use shift(int).

If the new size is not equal to the old size (i.e. to-from+1), the array always owns the data afterwards (i.e. new memory is allocated) even if it didn't own the data before. Otherwise the ownership remains unchanged. You can use restoreOwnership() if you just want to own the data.

template<class T>
void lti::array< T >::setFirstIdx int  newIdx  ) 
 

change the first index of the array, without changing the content

template<class T>
void lti::array< T >::shift int  sh  ) 
 

Shift all indices of the array by the given value sh.

Negative values result in a left shift, positive values in a right shift.

An array with range (-2,2) will have range (0,4) after shift(2) is performed.

template<class T>
virtual bool lti::array< T >::write ioHandler handler,
const bool  complete = true
const [virtual]
 

write the object in the given ioHandler

Reimplemented from lti::genericVector< T >.

Reimplemented in lti::kernel1D< T >, lti::kernel1D< double >, and lti::kernel1D< float >.


Member Data Documentation

template<class T>
int lti::array< T >::firstArrayElement [protected]
 

index of the first element of the array

template<class T>
int lti::array< T >::lastArrayElement [protected]
 

index of the last element of the array.

if the array is casted to a vector, the "lastIdx()" should return size()-1 instead of the array lastIdx!. That's the reason why we use a new member for the last index in the array!

template<class T>
int lti::array< T >::offset [protected]
 

offset for the 0-th element

template<class T>
T* lti::array< T >::theElement0 [protected]
 

A pointer to the element at index 0 (This allows a faster access than adding the offset each time).


The documentation for this class was generated from the following file:
Generated on Thu Nov 24 16:54:38 2005 for LTI-Lib by Doxygen 1.4.4