fesa-core
5.0.1
|
#include <ImmutableArray2D.h>
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_ |
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.
T | Type of the elements |
runtimeCheck | whether to check index boundaries at runtime |
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.
data | shared pointer to elements to use. There must be at least nRows * nCols elements pointed. |
nRows | number of rows of this array |
nCols | number of columns of this array |
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.
data | pointer to elements to use. There must be at least nRows * nCols elements pointed. |
nRows | number of rows of this array |
nCols | number of columns of this array |
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".
other | the Array2D to copy |
|
protected |
Constructor. Initializes nRows * nCols elements.
nRows | |
nCols |
|
protected |
Ensures that row is less than nRows_.
FesaException |
|
protected |
Ensures that row is less than nRows_ and column less than nCols_.
FesaException |
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.
Array2D< T, runtimeCheck > fesa::ImmutableArray2D< T, runtimeCheck >::getMutable | ( | ) | const |
Returns an Array2D which contains a copy of the elements of this ImmutableArray2D.
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfColumns | ( | ) | const |
Returns the number of columns of this array.
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfElements | ( | ) | const |
Returns the total number of elements in this array.
std::size_t fesa::ImmutableArray2D< T, runtimeCheck >::getNumberOfRows | ( | ) | const |
Returns the number of rows of this array.
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.
fesa::ImmutableArray2D< T, runtimeCheck >::operator const T * | ( | ) | const |
Converts this object to a T* by returning a pointer to the data.
fesa::ImmutableArray2D< T, runtimeCheck >::operator const void * | ( | ) | const |
Converts this object to void* by returning a pointer to the data.
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".
other | the Array2D to copy |
const Array2DRow< T, runtimeCheck > fesa::ImmutableArray2D< T, runtimeCheck >::operator[] | ( | S | index | ) | const |
Returns a reference to the row at the given index (read-only).
index | the row index |
|
protected |
Pointer to the elements of this ImmutableArray2D. Subclasses which use ownData_ must set it to &ownData_[0].
|
protected |
The number of columns of this ImmutableArray2D.
|
protected |
The number of rows of this ImmutableArray2D.
|
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.
|
protected |
Shared pointer to the elements of this ImmutableArray2D. If used, data_ must point on sharedData_.get();