fesa-core  5.0.1
fesa::ImmutableArray2D< T, runtimeCheck > Class Template Reference

#include <ImmutableArray2D.h>

Inheritance diagram for fesa::ImmutableArray2D< T, runtimeCheck >:
fesa::Array2D< T, runtimeCheck >

Public Member Functions

 ImmutableArray2D (const boost::shared_array< T > &data, std::size_t nRows, std::size_t nCols)
 
 ImmutableArray2D (const T *data, std::size_t nRows, std::size_t nCols)
 
 ImmutableArray2D (const ImmutableArray2D< T, runtimeCheck > &other)
 
ImmutableArray2D< T > & operator= (const ImmutableArray2D< T > &other)
 
Array2D< T, runtimeCheck > getMutable () const
 
std::size_t getNumberOfRows () const
 
std::size_t getNumberOfColumns () const
 
std::size_t getNumberOfElements () const
 
bool hasOwnData () const
 
template<typename S >
const Array2DRow< T, runtimeCheck > operator[] (S index) const
 
const T & get (std::size_t row, std::size_t column) const
 
 operator const T * () const
 
 operator const void * () const
 

Protected Member Functions

 ImmutableArray2D (std::size_t nRows, std::size_t nCols)
 
void doRuntimeCheck (std::size_t row) const
 
void doRuntimeCheck (std::size_t row, std::size_t column) const
 

Protected Attributes

std::size_t nRows_
 
std::size_t nCols_
 
boost::container::vector< T > ownData_
 
const boost::shared_array< T > sharedData_
 
const T * data_
 

Detailed Description

template<typename T, bool runtimeCheck>
class fesa::ImmutableArray2D< T, runtimeCheck >

Wrapper class for 2 dimensions arrays. An ImmutableArray2D doesn't copy any data, and works on the raw data provided to its constructor. As the name suggests, an ImmutableArray2D doesn't allow modification of its data. If needed, the getMutable() method can be used: it returns an Array2D which works on a copy of the original data.

Template Parameters
TType of the elements
runtimeCheckwhether to check index boundaries at runtime

Constructor & Destructor Documentation

template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::ImmutableArray2D ( const boost::shared_array< T > &  data,
std::size_t  nRows,
std::size_t  nCols 
)

Constructor. No copy of the data is performed.

Parameters
datashared pointer to elements to use. There must be at least nRows * nCols elements pointed.
nRowsnumber of rows of this array
nColsnumber of columns of this array
template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::ImmutableArray2D ( const T *  data,
std::size_t  nRows,
std::size_t  nCols 
)

Constructor. No copy of the data is performed; elements pointed to by data must not be destroyed before this ImmutableArray2D is.

Parameters
datapointer to elements to use. There must be at least nRows * nCols elements pointed.
nRowsnumber of rows of this array
nColsnumber of columns of this array
template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::ImmutableArray2D ( const ImmutableArray2D< T, runtimeCheck > &  other)

Copy constructor. If "other" has its own data, the data is copied and this object will work on its own data as well. Otherwise, no copy is performed, and this object will use the same data as "other".

Parameters
otherthe Array2D to copy
template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::ImmutableArray2D ( std::size_t  nRows,
std::size_t  nCols 
)
protected

Constructor. Initializes nRows * nCols elements.

Parameters
nRows
nCols

Member Function Documentation

template<typename T , bool runtimeCheck>
void fesa::ImmutableArray2D< T, runtimeCheck >::doRuntimeCheck ( std::size_t  row) const
protected

Ensures that row is less than nRows_.

Exceptions
FesaException
template<typename T , bool runtimeCheck>
void fesa::ImmutableArray2D< T, runtimeCheck >::doRuntimeCheck ( std::size_t  row,
std::size_t  column 
) const
protected

Ensures that row is less than nRows_ and column less than nCols_.

Exceptions
FesaException
template<typename T , bool runtimeCheck>
const T & fesa::ImmutableArray2D< T, runtimeCheck >::get ( std::size_t  row,
std::size_t  column 
) const

Returns the element at the given row, column. This method has the best performance. It shoud be favored over operator[], especially when iterating over the whole array.

template<typename T , bool runtimeCheck>
Array2D< T, runtimeCheck > fesa::ImmutableArray2D< T, runtimeCheck >::getMutable ( ) const

Returns an Array2D which contains a copy of the elements of this ImmutableArray2D.

template<typename T , bool runtimeCheck>
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfColumns ( ) const

Returns the number of columns of this array.

template<typename T , bool runtimeCheck>
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfElements ( ) const

Returns the total number of elements in this array.

template<typename T , bool runtimeCheck>
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfRows ( ) const

Returns the number of rows of this array.

template<typename T , bool runtimeCheck>
bool fesa::ImmutableArray2D< T, runtimeCheck >::hasOwnData ( ) const

Returns whether this object owns its data. This is never the case for objects of type ImmutableArray2D (subclasses can override this behaviour). If this is true, modifying the content of the array modifies this object's copy of the data.

template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::operator const T * ( ) const

Converts this object to a T* by returning a pointer to the data.

template<typename T , bool runtimeCheck>
fesa::ImmutableArray2D< T, runtimeCheck >::operator const void * ( ) const

Converts this object to void* by returning a pointer to the data.

template<typename T , bool runtimeCheck>
ImmutableArray2D< T > & fesa::ImmutableArray2D< T, runtimeCheck >::operator= ( const ImmutableArray2D< T > &  other)

Assignment operator. If "other" has its own data, the data is copied and this object will work on its own data as well. Otherwise, no copy is performed, and this object will use the same data as "other".

Parameters
otherthe Array2D to copy
template<typename T , bool runtimeCheck>
template<typename S >
const Array2DRow< T, runtimeCheck > fesa::ImmutableArray2D< T, runtimeCheck >::operator[] ( index) const

Returns a reference to the row at the given index (read-only).

Parameters
indexthe row index

Member Data Documentation

template<typename T , bool runtimeCheck>
const T* fesa::ImmutableArray2D< T, runtimeCheck >::data_
protected

Pointer to the elements of this ImmutableArray2D. Subclasses which use ownData_ must set it to &ownData_[0].

template<typename T , bool runtimeCheck>
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::nCols_
protected

The number of columns of this ImmutableArray2D.

template<typename T , bool runtimeCheck>
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::nRows_
protected

The number of rows of this ImmutableArray2D.

template<typename T , bool runtimeCheck>
boost::container::vector<T> fesa::ImmutableArray2D< T, runtimeCheck >::ownData_
protected

Can be used by subclasses to store a copy of the data. Not used by ImmutableArray2D. A boost::container vector is used because it allows pointer access to bool values, unlike std::vector which groups them into bitsets.

template<typename T , bool runtimeCheck>
const boost::shared_array<T> fesa::ImmutableArray2D< T, runtimeCheck >::sharedData_
protected

Shared pointer to the elements of this ImmutableArray2D. If used, data_ must point on sharedData_.get();


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