Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions
Saf::Collection::Array< N, T > Class Template Reference

Multi-dimensional array of values. More...

#include <Array.h>

List of all members.

Public Types

typedef const T * ConstIterator
 Random-access non-mutable Array iterator.
typedef T * Iterator
 Random-access mutable Array iterator.

Public Member Functions

 Array ()
 Default constructor.
 Array (const Math::Algebra::Vector< N, Size > &dim)
 Constructor.
 Array (const Math::Algebra::Vector< N, Size > &dim, const T &val)
 Constructor.
 Array (Size sz)
 Constructor applicable to one-dimensional arrays.
 Array (Size sz, const T &val)
 Constructor applicable to one-dimensional arrays.
 Array (const MyType &v)
 Copy constructor.
 ~Array ()
 Destructor.
Iterator Back ()
 Iterator to the last element.
ConstIterator Back () const
 Iterator to the last element.
Iterator Begin ()
 Iterator to the first element.
ConstIterator Begin () const
 Iterator to the first element.
void Coord (Size idx, Math::Algebra::Vector< N, Size > &coord) const
 Calculate the coordinates of an element with a given index.
void Coords (const Collection::Array< 1, Size > &iv, Collection::Array< 1, Math::Algebra::Vector< N, Size > > &cv) const
 Calculate the coordinates of elements with given indexes.
const Math::Algebra::Vector< N,
Size > & 
Dimensions () const
 Get array dimensions.
Size Elements () const
 Get total number of elements in the array.
Iterator End ()
 Iterator one after the last element.
ConstIterator End () const
 Iterator one after the last element.
MyTypeFree ()
 Free memory occupied by the array.
Iterator Front ()
 Iterator to the first element.
ConstIterator Front () const
 Iterator to the first element.
template<class U >
Index (const Math::Algebra::Vector< N, U > &ofs) const
 Calculate index into the array corresponding to given vector offset.
template<class U >
void Indexes (const Collection::Array< 1, Math::Algebra::Vector< N, U > > &ofs, Collection::Array< 1, U > &idx) const
 Calculate indexes into the array corresponding to given vector offsets.
bool IsEmpty () const
 Check if the array is empty.
bool operator!= (const MyType &a) const
 Comparison operator.
MyTypeoperator= (const MyType &a)
 Assignment operator.
bool operator== (const MyType &a) const
 Comparison operator.
T & operator[] (Size i)
 Subscript operator.
const T & operator[] (Size i) const
 Subscript operator.
MyTypeResize (const Math::Algebra::Vector< N, Size > &dim)
 Resize the array.
MyTypeResize (const Math::Algebra::Vector< N, Size > &dim, const T &val)
 Resize the array.
MyTypeResize (Size sz, const T &val)
 Resize applicable to one-dimensional arrays.
MyTypeResize (Size sz)
 Resize applicable to one-dimensional arrays.
const Math::Algebra::Vector< N,
Size > & 
Stride () const
 Get array element stride.
MyTypeSwap (MyType &a)
 Swap the content of two arrays.

Static Public Member Functions

template<class U >
static U Index (const Math::Algebra::Vector< N, Size > &dim, const Math::Algebra::Vector< N, U > &ofs)
 Calculate index into the array corresponding to given vector offset.
template<class U >
static void Indexes (const Math::Algebra::Vector< N, Size > &dim, const Collection::Array< 1, Math::Algebra::Vector< N, U > > &ofs, Collection::Array< 1, U > &idx)
 Calculate indexes into the array corresponding to given vector offsets.

Protected Types

typedef Array< N, T > MyType

Protected Member Functions

void CheckOverflow (const Math::Algebra::Vector< N, Size > &dim)
 Check if it is possible to store data with given dimensions in the memory.
void UpdateCache ()
 Recompute cached values.

Detailed Description

template<Size N, class T>
class Saf::Collection::Array< N, T >

Multi-dimensional array of values.

This class represents a multi-dimensional array of data. All elements are stored in one continuous memory region without any memory overhead. The array can be dynamically resized, however, its intended use is for data whose size is set once and then many operations are performed on them, e.g., images. It is not optimized for frequent size changes. During resize the old content is lost.

Alternatives:

Iterator category: Random-access.

Template Parameters:
NNumber of dimensions.
TData type.
See also:
Collection::DynArray, Collection::Deque.

Member Typedef Documentation

template<Size N, class T>
typedef const T* Saf::Collection::Array< N, T >::ConstIterator

Random-access non-mutable Array iterator.

template<Size N, class T>
typedef T* Saf::Collection::Array< N, T >::Iterator

Random-access mutable Array iterator.

template<Size N, class T>
typedef Array<N,T> Saf::Collection::Array< N, T >::MyType [protected]

Constructor & Destructor Documentation

template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( ) [inline]

Default constructor.

template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( const Math::Algebra::Vector< N, Size > &  dim) [inline, explicit]

Constructor.

Constructs and resizes the array. Values are initialized with their default constructor.

Parameters:
[in]dimRequested dimensions of the array.
template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( const Math::Algebra::Vector< N, Size > &  dim,
const T &  val 
) [inline]

Constructor.

Constructs and resizes the array. Element values are set to val.

Parameters:
[in]dimRequested dimensions of the array.
[in]valValue used to initialize the elements.
template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( Size  sz) [inline, explicit]

Constructor applicable to one-dimensional arrays.

Constructs and resizes the array. Values are initialized with their default constructor.

Parameters:
[in]szRequested size of the array.
template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( Size  sz,
const T &  val 
) [inline]

Constructor applicable to one-dimensional arrays.

Constructs and resizes the array. Element values are set to val.

Parameters:
[in]szRequested size of the array.
[in]valValue used to initialize the elements.
template<Size N, class T>
Saf::Collection::Array< N, T >::Array ( const MyType v) [inline]

Copy constructor.

template<Size N, class T>
Saf::Collection::Array< N, T >::~Array ( ) [inline]

Destructor.


Member Function Documentation

template<Size N, class T>
Iterator Saf::Collection::Array< N, T >::Back ( ) [inline]

Iterator to the last element.

template<Size N, class T>
ConstIterator Saf::Collection::Array< N, T >::Back ( ) const [inline]

Iterator to the last element.

template<Size N, class T>
Iterator Saf::Collection::Array< N, T >::Begin ( ) [inline]

Iterator to the first element.

template<Size N, class T>
ConstIterator Saf::Collection::Array< N, T >::Begin ( ) const [inline]

Iterator to the first element.

template<Size N, class T>
void Saf::Collection::Array< N, T >::CheckOverflow ( const Math::Algebra::Vector< N, Size > &  dim) [inline, protected]

Check if it is possible to store data with given dimensions in the memory.

template<Size N, class T>
void Saf::Collection::Array< N, T >::Coord ( Size  idx,
Math::Algebra::Vector< N, Size > &  coord 
) const [inline]

Calculate the coordinates of an element with a given index.

See also:
Index.
template<Size N, class T>
void Saf::Collection::Array< N, T >::Coords ( const Collection::Array< 1, Size > &  iv,
Collection::Array< 1, Math::Algebra::Vector< N, Size > > &  cv 
) const [inline]

Calculate the coordinates of elements with given indexes.

Parameters:
[in]ivList of indexes.
[out]cvCoordinates of elements at indexes in nv.
See also:
Indexes.
template<Size N, class T>
const Math::Algebra::Vector<N,Size>& Saf::Collection::Array< N, T >::Dimensions ( ) const [inline]

Get array dimensions.

template<Size N, class T>
Size Saf::Collection::Array< N, T >::Elements ( ) const [inline]

Get total number of elements in the array.

Properties:

  • Worst-case time complexity: $ \mathcal{O}(1) $.
template<Size N, class T>
Iterator Saf::Collection::Array< N, T >::End ( ) [inline]

Iterator one after the last element.

template<Size N, class T>
ConstIterator Saf::Collection::Array< N, T >::End ( ) const [inline]

Iterator one after the last element.

template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Free ( ) [inline]

Free memory occupied by the array.

template<Size N, class T>
Iterator Saf::Collection::Array< N, T >::Front ( ) [inline]

Iterator to the first element.

template<Size N, class T>
ConstIterator Saf::Collection::Array< N, T >::Front ( ) const [inline]

Iterator to the first element.

template<Size N, class T>
template<class U >
U Saf::Collection::Array< N, T >::Index ( const Math::Algebra::Vector< N, U > &  ofs) const [inline]

Calculate index into the array corresponding to given vector offset.

See also:
Coord.
template<Size N, class T>
template<class U >
static U Saf::Collection::Array< N, T >::Index ( const Math::Algebra::Vector< N, Size > &  dim,
const Math::Algebra::Vector< N, U > &  ofs 
) [inline, static]

Calculate index into the array corresponding to given vector offset.

Static version of the method.

Parameters:
[in]dimDimensions of the array.
[in]ofsOffset for which the index should be computed.
template<Size N, class T>
template<class U >
void Saf::Collection::Array< N, T >::Indexes ( const Collection::Array< 1, Math::Algebra::Vector< N, U > > &  ofs,
Collection::Array< 1, U > &  idx 
) const [inline]

Calculate indexes into the array corresponding to given vector offsets.

Parameters:
[in]ofsList of vector offsets.
[out]idxElement index for each vector in ofs.
See also:
Coords.
template<Size N, class T>
template<class U >
static void Saf::Collection::Array< N, T >::Indexes ( const Math::Algebra::Vector< N, Size > &  dim,
const Collection::Array< 1, Math::Algebra::Vector< N, U > > &  ofs,
Collection::Array< 1, U > &  idx 
) [inline, static]

Calculate indexes into the array corresponding to given vector offsets.

Static version of the method.

Parameters:
[in]dimDimensions of the array.
[in]ofsList of vector offsets.
[out]idxElement index for each vector in ofs.
See also:
Coords.
template<Size N, class T>
bool Saf::Collection::Array< N, T >::IsEmpty ( ) const [inline]

Check if the array is empty.

template<Size N, class T>
bool Saf::Collection::Array< N, T >::operator!= ( const MyType a) const [inline]

Comparison operator.

template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::operator= ( const MyType a) [inline]

Assignment operator.

template<Size N, class T>
bool Saf::Collection::Array< N, T >::operator== ( const MyType a) const [inline]

Comparison operator.

template<Size N, class T>
T& Saf::Collection::Array< N, T >::operator[] ( Size  i) [inline]

Subscript operator.

template<Size N, class T>
const T& Saf::Collection::Array< N, T >::operator[] ( Size  i) const [inline]

Subscript operator.

template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Resize ( const Math::Algebra::Vector< N, Size > &  dim) [inline]

Resize the array.

If the new number of elements is different then the old content is lost during this operation and the values are initialized using their default constructor. Otherwise, only the dimensions and stride are updated.

Parameters:
[in]dimNew array dimensions.
template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Resize ( const Math::Algebra::Vector< N, Size > &  dim,
const T &  val 
) [inline]

Resize the array.

The old content of the array is lost and values of new elements are set to val.

Parameters:
[in]dimNew array dimensions.
[in]valValue of the new elements.
template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Resize ( Size  sz,
const T &  val 
) [inline]

Resize applicable to one-dimensional arrays.

template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Resize ( Size  sz) [inline]

Resize applicable to one-dimensional arrays.

template<Size N, class T>
const Math::Algebra::Vector<N,Size>& Saf::Collection::Array< N, T >::Stride ( ) const [inline]

Get array element stride.

template<Size N, class T>
MyType& Saf::Collection::Array< N, T >::Swap ( MyType a) [inline]

Swap the content of two arrays.

Properties:

  • Worst-case time complexity: $ \mathcal{O}(1) $.
template<Size N, class T>
void Saf::Collection::Array< N, T >::UpdateCache ( ) [inline, protected]

Recompute cached values.


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