matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
matioCpp::MultiDimensionalArray< T > Class Template Reference

MultiDimensionalArray is a particular type of Variable specialized for multidimensional arrays of a generic type T. More...

#include <matioCpp/MultiDimensionalArray.h>

+ Inheritance diagram for matioCpp::MultiDimensionalArray< T >:

Public Types

using type = T
 
using element_type = typename get_type< T >::type
 Defines the type specified in the template. More...
 
using value_type = std::remove_cv_t< element_type >
 Defines the type of an element of the MultiDimensionalArray. More...
 
using allocator_type = std::allocator< element_type >
 Defines the type of an element of the MultiDimensionalArray without "const". More...
 
using index_type = size_t
 Defines how to allocate T. More...
 
using reference = element_type &
 The type used for indices. More...
 
using pointer = typename std::allocator_traits< std::allocator< element_type > >::pointer
 The reference type. More...
 
using const_pointer = typename std::allocator_traits< std::allocator< element_type > >::const_pointer
 The pointer type. More...
 

Public Member Functions

 MultiDimensionalArray ()
 The const pointer type. More...
 
 MultiDimensionalArray (const std::string &name)
 Constructor. More...
 
 MultiDimensionalArray (const std::string &name, const std::vector< index_type > &dimensions)
 Constructor. More...
 
 MultiDimensionalArray (const std::string &name, const std::vector< index_type > &dimensions, const_pointer inputVector)
 Constructor. More...
 
 MultiDimensionalArray (const MultiDimensionalArray< T > &other)
 Copy constructor. More...
 
 MultiDimensionalArray (MultiDimensionalArray< T > &&other)
 Move constructor. More...
 
 MultiDimensionalArray (const MatvarHandler &handler)
 Constructor to share the data ownership of another variable. More...
 
 ~MultiDimensionalArray ()
 Destructor. More...
 
MultiDimensionalArray< T > & operator= (const MultiDimensionalArray< T > &other)
 Assignement operator (copy) from another MultiDimensionalArray. More...
 
MultiDimensionalArray< T > & operator= (MultiDimensionalArray< T > &&other)
 Assignement operator (move) from another MultiDimensionalArray. More...
 
bool fromVectorizedArray (const std::vector< index_type > &dimensions, const_pointer inputVector)
 Set from a vectorized array. More...
 
index_type rawIndexFromIndices (const std::vector< index_type > &el) const
 Get the index in the vectorized array corresponding to the provided indices. More...
 
bool indicesFromRawIndex (size_t rawIndex, std::vector< index_type > &el) const
 Get the indices given the raw index. More...
 
matioCpp::Span< element_typetoSpan ()
 Get this MultiDimensionalArray as a Span. More...
 
const matioCpp::Span< const element_typetoSpan () const
 Get this MultiDimensionalArray as a Span (const version) More...
 
bool setName (const std::string &newName)
 Change the name of the Variable. More...
 
void resize (const std::vector< index_type > &newDimensions)
 Resize the vector. More...
 
void clear ()
 Clear the multidimensional array. More...
 
pointer data ()
 Direct access to the underlying array. More...
 
const_pointer data () const
 Direct access to the underlying array. More...
 
index_type numberOfElements () const
 Get the total number of elements in the array. More...
 
reference operator() (const std::vector< index_type > &el)
 Access specified element. More...
 
value_type operator() (const std::vector< index_type > &el) const
 Access specified element. More...
 
reference operator() (index_type el)
 Access specified element. More...
 
value_type operator() (index_type el) const
 Access specified element. More...
 
reference operator[] (const std::vector< index_type > &el)
 Access specified element. More...
 
value_type operator[] (const std::vector< index_type > &el) const
 Access specified element. More...
 
reference operator[] (index_type el)
 Access specified element. More...
 
value_type operator[] (index_type el) const
 Access specified element. More...
 
- Public Member Functions inherited from matioCpp::Variable
 Variable ()
 Default constructor. More...
 
 Variable (const matvar_t *inputVar)
 Constructor from an existing matvar_t pointer. More...
 
 Variable (const Variable &other)
 Copy constructor. More...
 
 Variable (Variable &&other)
 Move constructor. More...
 
 Variable (const MatvarHandler &handler)
 Constructor to share the data ownership of another variable. More...
 
 ~Variable ()
 Destructor. More...
 
Variableoperator= (const Variable &other)
 Copy assignement. More...
 
Variableoperator= (Variable &&other)
 Move assignement. More...
 
bool fromMatio (const matvar_t *inputVar)
 Set this variable from an existing matio variable. More...
 
bool fromOther (const Variable &other)
 Set this variable from another variable. More...
 
bool fromOther (Variable &&other)
 Set this variable from another variable. More...
 
const matvar_t * toMatio () const
 Convert this Variable to a matio variable. More...
 
matvar_t * toMatio ()
 Convert this Variable to a matio variable. More...
 
std::string name () const
 Get the name of the Variable. More...
 
matioCpp::VariableType variableType () const
 Get the VariableType. More...
 
matioCpp::ValueType valueType () const
 Get the ValueType. More...
 
bool isComplex () const
 Get if the variable is complex. More...
 
matioCpp::Span< const size_t > dimensions () const
 Get the dimensions of this object. More...
 
bool isValid () const
 Check if the variable is valid. More...
 
template<typename T >
matioCpp::Element< T > asElement ()
 Cast the variable as a Element. More...
 
template<typename T >
const matioCpp::Element< T > asElement () const
 Cast the variable as a const Element. More...
 
template<typename T >
matioCpp::Vector< T > asVector ()
 Cast the variable as a Vector. More...
 
template<typename T >
const matioCpp::Vector< T > asVector () const
 Cast the variable as a const Vector. More...
 
matioCpp::String asString ()
 Cast the variable as a String. More...
 
const matioCpp::String asString () const
 Cast the variable as a const String. More...
 
matioCpp::String16 asString16 ()
 Cast the variable as a String16. More...
 
const matioCpp::String16 asString16 () const
 Cast the variable as a const String16. More...
 
matioCpp::String32 asString32 ()
 Cast the variable as a String32. More...
 
const matioCpp::String32 asString32 () const
 Cast the variable as a const String32. More...
 
template<typename T >
matioCpp::MultiDimensionalArray< T > asMultiDimensionalArray ()
 Cast the variable as a MultiDimensionalArray. More...
 
template<typename T >
const matioCpp::MultiDimensionalArray< T > asMultiDimensionalArray () const
 Cast the variable as a const MultiDimensionalArray. More...
 
matioCpp::CellArray asCellArray ()
 Cast the variable as a CellArray. More...
 
const matioCpp::CellArray asCellArray () const
 Cast the variable as a const CellArray. More...
 
matioCpp::Struct asStruct ()
 Cast the variable as a Struct. More...
 
const matioCpp::Struct asStruct () const
 Cast the variable as a const Struct. More...
 
matioCpp::StructArray asStructArray ()
 Cast the variable as a StructArray. More...
 
const matioCpp::StructArray asStructArray () const
 Cast the variable as a const StructArray. More...
 

Additional Inherited Members

- Protected Member Functions inherited from matioCpp::Variable
bool initializeVariable (const std::string &name, const VariableType &variableType, const ValueType &valueType, matioCpp::Span< const size_t > dimensions, void *data)
 Initialize the variable. More...
 
bool initializeComplexVariable (const std::string &name, const VariableType &variableType, const ValueType &valueType, matioCpp::Span< const size_t > dimensions, void *realData, void *imaginaryData)
 Initialize a complex variable. More...
 
template<typename T >
bool initializeComplexVector (const std::string &name, const Span< T > realInputVector, const Span< T > imaginaryInputVector)
 Initialize a complex vector. More...
 
bool changeName (const std::string &newName)
 Change the name of the variable. More...
 
size_t getArrayNumberOfElements () const
 Get the total number of elements in the array. More...
 
bool setCellElement (size_t linearIndex, const Variable &newValue)
 Set a cell element at a specified linear position. More...
 
Variable getCellElement (size_t linearIndex)
 Get a cell element at a specified linear position. More...
 
const Variable getCellElement (size_t linearIndex) const
 Get a cell element at a specified linear position. More...
 
size_t getStructNumberOfFields () const
 Get the total number of fields in the variable, considered as a struct. More...
 
char *const * getStructFields () const
 Get the list of fields in the variable, considered as a struct. More...
 
size_t getStructFieldIndex (const std::string &field) const
 Get the index of the specified field in the variable, considered as a struct. More...
 
bool setStructField (size_t index, const Variable &newValue, size_t structPositionInArray=0)
 Set the field of the struct at the specified position. More...
 
bool addStructField (const std::string &newField)
 Add a new field to the variable, considered as a struct. More...
 
bool setStructField (const std::string &field, const Variable &newValue, size_t structPositionInArray=0)
 Set the field of the struct given the newValue name. More...
 
Variable getStructField (size_t index, size_t structPositionInArray=0)
 Get the specified field in the variable, considered as a struct. More...
 
const Variable getStructField (size_t index, size_t structPositionInArray=0) const
 Get the specified field in the variable, considered as a struct. More...
 
Struct getStructArrayElement (size_t linearIndex)
 Get an element of the variable, considered as a StructArray. More...
 
const Struct getStructArrayElement (size_t linearIndex) const
 Get an element of the variable, considered as a StructArray. More...
 

Detailed Description

template<typename T>
class matioCpp::MultiDimensionalArray< T >

MultiDimensionalArray is a particular type of Variable specialized for multidimensional arrays of a generic type T.

Note
The underlying array is in column-major format.

Definition at line 21 of file MultiDimensionalArray.h.

Member Typedef Documentation

◆ allocator_type

Defines the type of an element of the MultiDimensionalArray without "const".

Useful to use make_span.

Definition at line 41 of file MultiDimensionalArray.h.

◆ const_pointer

The pointer type.

Definition at line 49 of file MultiDimensionalArray.h.

◆ element_type

template<typename T >
using matioCpp::MultiDimensionalArray< T >::element_type = typename get_type<T>::type

Defines the type specified in the template.

Definition at line 37 of file MultiDimensionalArray.h.

◆ index_type

template<typename T >
using matioCpp::MultiDimensionalArray< T >::index_type = size_t

Defines how to allocate T.

Definition at line 43 of file MultiDimensionalArray.h.

◆ pointer

The reference type.

Definition at line 47 of file MultiDimensionalArray.h.

◆ reference

template<typename T >
using matioCpp::MultiDimensionalArray< T >::reference = element_type&

The type used for indices.

Definition at line 45 of file MultiDimensionalArray.h.

◆ type

template<typename T >
using matioCpp::MultiDimensionalArray< T >::type = T

Definition at line 35 of file MultiDimensionalArray.h.

◆ value_type

template<typename T >
using matioCpp::MultiDimensionalArray< T >::value_type = std::remove_cv_t<element_type>

Defines the type of an element of the MultiDimensionalArray.

Definition at line 39 of file MultiDimensionalArray.h.

Constructor & Destructor Documentation

◆ MultiDimensionalArray() [1/7]

The const pointer type.

Default Constructor

Note
The name is set to "unnamed_multidimensional_array".

Definition at line 46 of file MultiDimensionalArray.tpp.

References std::vector< T >::data().

◆ MultiDimensionalArray() [2/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( const std::string name)

Constructor.

Parameters
nameThe name of the MultiDimensionalArray

Definition at line 57 of file MultiDimensionalArray.tpp.

References std::vector< T >::data().

◆ MultiDimensionalArray() [3/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( const std::string name,
const std::vector< index_type > &  dimensions 
)

Constructor.

Parameters
nameThe name of the MultiDimensionalArray
dimensionsThe dimensions of the MultiDimensionalArray

◆ MultiDimensionalArray() [4/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( const std::string name,
const std::vector< index_type > &  dimensions,
const_pointer  inputVector 
)

Constructor.

Parameters
nameThe name of the MultiDimensionalArray
dimensionsThe dimensions of the MultiDimensionalArray
inputVectorThe raw pointer to the data stored in column-major order

◆ MultiDimensionalArray() [5/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( const MultiDimensionalArray< T > &  other)

Copy constructor.

Definition at line 109 of file MultiDimensionalArray.tpp.

◆ MultiDimensionalArray() [6/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( MultiDimensionalArray< T > &&  other)

Move constructor.

Definition at line 115 of file MultiDimensionalArray.tpp.

References std::forward().

◆ MultiDimensionalArray() [7/7]

template<typename T >
matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray ( const MatvarHandler handler)

Constructor to share the data ownership of another variable.

Parameters
handlerThe MatvarHandler handler to the matvar_t which has to be shared.

Definition at line 121 of file MultiDimensionalArray.tpp.

References std::vector< T >::data(), matioCpp::MatvarHandler::get(), matioCpp::Variable::initializeVariable(), matioCpp::MultiDimensionalArray, matioCpp::MatvarHandler::valueType(), and matioCpp::MatvarHandler::variableType().

◆ ~MultiDimensionalArray()

Destructor.

Definition at line 137 of file MultiDimensionalArray.tpp.

Member Function Documentation

◆ clear()

template<typename T >
void matioCpp::MultiDimensionalArray< T >::clear

Clear the multidimensional array.

Definition at line 269 of file MultiDimensionalArray.tpp.

References std::move().

◆ data() [1/2]

Direct access to the underlying array.

Note
The underlying array is in column-major format.
Returns
A pointer to the internal data.

Definition at line 275 of file MultiDimensionalArray.tpp.

◆ data() [2/2]

Direct access to the underlying array.

Note
The underlying array is in column-major format.
Returns
A pointer to the internal data.

Definition at line 281 of file MultiDimensionalArray.tpp.

◆ fromVectorizedArray()

template<typename T >
bool matioCpp::MultiDimensionalArray< T >::fromVectorizedArray ( const std::vector< index_type > &  dimensions,
const_pointer  inputVector 
)

Set from a vectorized array.

Note
The pointer is supposed to be in column-major format.
Parameters
dimensionsThe input dimensions
inputVectorThe input pointer.
Returns
True if successful.

Definition at line 157 of file MultiDimensionalArray.tpp.

References std::endl(), and matioCpp::MultiDimensionalArray.

◆ indicesFromRawIndex()

template<typename T >
bool matioCpp::MultiDimensionalArray< T >::indicesFromRawIndex ( size_t  rawIndex,
std::vector< index_type > &  el 
) const

Get the indices given the raw index.

Parameters
rawIndexThe input raw index from which to compute the indices
elThe output indices
Returns
True if successful, false otherwise (for example if rawIndex is out of bounds)

Definition at line 195 of file MultiDimensionalArray.tpp.

References std::endl().

◆ numberOfElements()

template<typename T >
matioCpp::MultiDimensionalArray< T >::index_type matioCpp::MultiDimensionalArray< T >::numberOfElements

Get the total number of elements in the array.

Returns
The total number of elements

Definition at line 287 of file MultiDimensionalArray.tpp.

◆ operator()() [1/4]

template<typename T >
reference matioCpp::MultiDimensionalArray< T >::operator() ( const std::vector< index_type > &  el)

Access specified element.

Parameters
elThe element to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A reference to the element.

◆ operator()() [2/4]

template<typename T >
value_type matioCpp::MultiDimensionalArray< T >::operator() ( const std::vector< index_type > &  el) const

Access specified element.

Parameters
elThe element to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A copy to the element.

◆ operator()() [3/4]

template<typename T >
reference matioCpp::MultiDimensionalArray< T >::operator() ( index_type  el)

Access specified element.

Parameters
elThe element to be accessed (raw index).
Returns
A reference to the element.

◆ operator()() [4/4]

template<typename T >
value_type matioCpp::MultiDimensionalArray< T >::operator() ( index_type  el) const

Access specified element.

Parameters
elThe element to be accessed (raw index).
Returns
A copy to the element.

◆ operator=() [1/2]

template<typename T >
matioCpp::MultiDimensionalArray< T > & matioCpp::MultiDimensionalArray< T >::operator= ( const MultiDimensionalArray< T > &  other)

Assignement operator (copy) from another MultiDimensionalArray.

Parameters
otherThe other MultiDimensionalArray.
Note
Also the name is copied
Returns
A reference to this MultiDimensionalArray.

Definition at line 143 of file MultiDimensionalArray.tpp.

◆ operator=() [2/2]

template<typename T >
matioCpp::MultiDimensionalArray< T > & matioCpp::MultiDimensionalArray< T >::operator= ( matioCpp::MultiDimensionalArray< T > &&  other)

Assignement operator (move) from another MultiDimensionalArray.

Parameters
otherThe other MultiDimensionalArray.
Note
Also the name is copied
Returns
A reference to this MultiDimensionalArray.

Definition at line 150 of file MultiDimensionalArray.tpp.

References std::forward().

◆ operator[]() [1/4]

template<typename T >
reference matioCpp::MultiDimensionalArray< T >::operator[] ( const std::vector< index_type > &  el)

Access specified element.

Parameters
elThe element to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A reference to the element.

◆ operator[]() [2/4]

template<typename T >
value_type matioCpp::MultiDimensionalArray< T >::operator[] ( const std::vector< index_type > &  el) const

Access specified element.

Parameters
elThe element to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A copy to the element.

◆ operator[]() [3/4]

template<typename T >
reference matioCpp::MultiDimensionalArray< T >::operator[] ( index_type  el)

Access specified element.

Parameters
elThe element to be accessed (raw index).
Returns
A reference to the element.

◆ operator[]() [4/4]

template<typename T >
value_type matioCpp::MultiDimensionalArray< T >::operator[] ( index_type  el) const

Access specified element.

Parameters
elThe element to be accessed (raw index).
Returns
A copy to the element.

◆ rawIndexFromIndices()

template<typename T >
matioCpp::MultiDimensionalArray< T >::index_type matioCpp::MultiDimensionalArray< T >::rawIndexFromIndices ( const std::vector< index_type > &  el) const

Get the index in the vectorized array corresponding to the provided indices.

Parameters
elThe desired element
Warning
It checks if the element is in the bounds only in debug mode.

Since the array is stored in column-major, an element (i,j,k,l,..) of an array of dimensions (n,m,p,k,...) corresponds to a row index equal to i + j*n + k*n*m + l*n*m*p +...

Returns
the index in the vectorized array corresponding to the provided indices

Definition at line 175 of file MultiDimensionalArray.tpp.

◆ resize()

template<typename T >
void matioCpp::MultiDimensionalArray< T >::resize ( const std::vector< index_type > &  newDimensions)

Resize the vector.

Parameters
newDimensionsThe new dimensions.
Warning
Previous data is lost.

Definition at line 246 of file MultiDimensionalArray.tpp.

References std::vector< T >::data(), std::endl(), and matioCpp::MultiDimensionalArray.

◆ setName()

template<typename T >
bool matioCpp::MultiDimensionalArray< T >::setName ( const std::string newName)

Change the name of the Variable.

Parameters
newNameThe new name
Returns
True if successful.

Definition at line 240 of file MultiDimensionalArray.tpp.

◆ toSpan() [1/2]

Get this MultiDimensionalArray as a Span.

Definition at line 228 of file MultiDimensionalArray.tpp.

References matioCpp::make_span().

◆ toSpan() [2/2]

template<typename T >
const matioCpp::Span< const typename matioCpp::MultiDimensionalArray< T >::element_type > matioCpp::MultiDimensionalArray< T >::toSpan

Get this MultiDimensionalArray as a Span (const version)

Definition at line 234 of file MultiDimensionalArray.tpp.

References matioCpp::make_span().


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