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

#include <matioCpp/StructArrayElement.h>

Public Types

using index_type = size_t
 
using input_vector_type = std::conditional_t< isConst, const matioCpp::StructArray, matioCpp::StructArray >
 The type used for indices. More...
 
using output_variable_type = std::conditional_t< isConst, const matioCpp::Variable, matioCpp::Variable >
 
using output_struct_type = std::conditional_t< isConst, const matioCpp::Struct, matioCpp::Struct >
 

Public Member Functions

 StructArrayElement (index_type index, input_vector_type *array)
 Element. More...
 
 StructArrayElement ()=delete
 Deleted default constructor. More...
 
 StructArrayElement (const StructArrayElement< isConst > &other)
 Copy operator. More...
 
template<bool B, typename = typename std::enable_if_t<!B && isConst>>
 StructArrayElement (const StructArrayElement< B > &other)
 Copy operator. More...
 
 StructArrayElement (matioCpp::StructArrayElement< isConst > &&other)
 Move operator. More...
 
template<bool B, typename = typename std::enable_if_t<!B && isConst>>
 StructArrayElement (matioCpp::StructArrayElement< B > &&other)
 Move operator. More...
 
StructArrayElementoperator= (const StructArrayElement &other)=delete
 Deleted copy assignement since it is not clear whether the index or the content have to be copied. More...
 
StructArrayElement< isConst > & operator= (StructArrayElement< isConst > &&other)
 Move assignement. More...
 
template<bool B, typename = typename std::enable_if_t<!B && isConst>>
StructArrayElement< isConst > & operator= (StructArrayElement< B > &&other)
 Move assignement (from non-const to const) More...
 
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
StructArrayElementoperator= (const matioCpp::Struct &other) const
 Assignement operator from a struct. More...
 
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
bool fromVectorOfVariables (const std::vector< Variable > &elements) const
 Set from a vector of Variables. More...
 
index_type numberOfFields () const
 Get the total number of fields in the struct. More...
 
std::vector< std::stringfields () const
 Get the list of fields. More...
 
bool isFieldExisting (const std::string &field) const
 Check if a field is existing It performs a linear search over the output of fields(). More...
 
size_t getFieldIndex (const std::string &field) const
 Get the index of the specified field in the struct by performing a linear search. More...
 
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
bool setField (index_type index, const Variable &newValue) const
 Set the field at the specified position. More...
 
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
bool setField (const std::string &field, const Variable &newValue) const
 Set the field given the field name. More...
 
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
bool setField (const Variable &newValue) const
 Set the field given the newValue name. More...
 
output_struct_type asStruct () const
 Get the element as a Struct. More...
 
output_variable_type operator() (index_type el) const
 Access field at a specific index. More...
 
output_variable_type operator() (const std::string &el) const
 Access field at a specific index. More...
 
output_variable_type operator[] (index_type el) const
 Access field at a specific index. More...
 
output_variable_type operator[] (const std::string &el) const
 Access field at a specific index. More...
 
template<bool B, typename >
matioCpp::StructArrayElement< isConst > & operator= (matioCpp::StructArrayElement< B > &&other)
 
template<bool B, typename >
matioCpp::StructArrayElement< isConst > & operator= (const matioCpp::Struct &other) const
 

Friends

class StructArrayElement< true >
 The pointer to the array. More...
 

Detailed Description

template<bool isConst>
class matioCpp::StructArrayElement< isConst >

Definition at line 16 of file StructArrayElement.h.

Member Typedef Documentation

◆ index_type

template<bool isConst>
using matioCpp::StructArrayElement< isConst >::index_type = size_t

Definition at line 21 of file StructArrayElement.h.

◆ input_vector_type

template<bool isConst>
using matioCpp::StructArrayElement< isConst >::input_vector_type = std::conditional_t<isConst, const matioCpp::StructArray, matioCpp::StructArray>

The type used for indices.

Definition at line 23 of file StructArrayElement.h.

◆ output_struct_type

template<bool isConst>
using matioCpp::StructArrayElement< isConst >::output_struct_type = std::conditional_t<isConst, const matioCpp::Struct, matioCpp::Struct>

Definition at line 27 of file StructArrayElement.h.

◆ output_variable_type

template<bool isConst>
using matioCpp::StructArrayElement< isConst >::output_variable_type = std::conditional_t<isConst, const matioCpp::Variable, matioCpp::Variable>

Definition at line 25 of file StructArrayElement.h.

Constructor & Destructor Documentation

◆ StructArrayElement() [1/6]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::StructArrayElement ( index_type  index,
input_vector_type array 
)

Element.

Parameters
index
array

Definition at line 12 of file StructArrayElement.tpp.

◆ StructArrayElement() [2/6]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::StructArrayElement ( )
delete

Deleted default constructor.

◆ StructArrayElement() [3/6]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::StructArrayElement ( const StructArrayElement< isConst > &  other)

Copy operator.

Parameters
otherThe Element to be copied
Note
The content of the element is not copied

Definition at line 20 of file StructArrayElement.tpp.

◆ StructArrayElement() [4/6]

template<bool isConst>
template<bool B, typename >
matioCpp::StructArrayElement< isConst >::StructArrayElement ( const StructArrayElement< B > &  other)

Copy operator.

Parameters
otherThe Element to be copied
Note
The content of the element is not copied

Definition at line 29 of file StructArrayElement.tpp.

◆ StructArrayElement() [5/6]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::StructArrayElement ( matioCpp::StructArrayElement< isConst > &&  other)

Move operator.

Parameters
otherThe Element to be moved
Note
The content of the element is not copied

Definition at line 38 of file StructArrayElement.tpp.

◆ StructArrayElement() [6/6]

template<bool isConst>
template<bool B, typename >
matioCpp::StructArrayElement< isConst >::StructArrayElement ( matioCpp::StructArrayElement< B > &&  other)

Move operator.

Parameters
otherThe Element to be moved
Note
The content of the element is not copied

Definition at line 47 of file StructArrayElement.tpp.

Member Function Documentation

◆ asStruct()

template<bool isConst>
matioCpp::StructArrayElement< isConst >::output_struct_type matioCpp::StructArrayElement< isConst >::asStruct

Get the element as a Struct.

Note
This requires memory allocation. In particular, it needs to allocate a number of pointers equal to the number of fields
Returns
A Struct with a weak ownership to the underlying mat variable. This means that the data can be changed, but the variable cannot be resized and the name cannot change.

Definition at line 190 of file StructArrayElement.tpp.

◆ fields()

template<bool isConst>
std::vector< std::string > matioCpp::StructArrayElement< isConst >::fields

Get the list of fields.

Returns
The list of fields.

Definition at line 131 of file StructArrayElement.tpp.

◆ fromVectorOfVariables()

template<bool isConst>
template<bool B, typename >
bool matioCpp::StructArrayElement< isConst >::fromVectorOfVariables ( const std::vector< Variable > &  elements) const

Set from a vector of Variables.

Parameters
elementsThe elements to be set.
Note
Previous fields are lost
Returns
True if successful. False otherwise, for example if one of the input variables is not valid or if the fields do not match the already existing fields.

Definition at line 91 of file StructArrayElement.tpp.

References std::endl(), std::vector< T >::size(), and std::to_string().

◆ getFieldIndex()

template<bool isConst>
size_t matioCpp::StructArrayElement< isConst >::getFieldIndex ( const std::string field) const

Get the index of the specified field in the struct by performing a linear search.

Parameters
fieldThe field to search
Returns
The index of the field, the output of numberOfFields() if not found.

Definition at line 143 of file StructArrayElement.tpp.

◆ isFieldExisting()

template<bool isConst>
bool matioCpp::StructArrayElement< isConst >::isFieldExisting ( const std::string field) const

Check if a field is existing It performs a linear search over the output of fields().

Returns
True if the field is existing, false otherwise.

Definition at line 137 of file StructArrayElement.tpp.

◆ numberOfFields()

template<bool isConst>
matioCpp::StructArrayElement< isConst >::index_type matioCpp::StructArrayElement< isConst >::numberOfFields

Get the total number of fields in the struct.

Returns
The total number of fields

Definition at line 125 of file StructArrayElement.tpp.

◆ operator()() [1/2]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::output_variable_type matioCpp::StructArrayElement< isConst >::operator() ( const std::string el) const

Access field at a specific index.

Parameters
elThe name of the field to be accessed.
Returns
A Variable with a weak ownership to the underlying mat variable. This means that the data can be changed, but the variable cannot be resized and the name cannot change.
Note
If the field is not found, the output variable is not valid.

Definition at line 203 of file StructArrayElement.tpp.

◆ operator()() [2/2]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::output_variable_type matioCpp::StructArrayElement< isConst >::operator() ( index_type  el) const

Access field at a specific index.

Parameters
elThe index of the field to be accessed.
Returns
A Variable with a weak ownership to the underlying mat variable. This means that the data can be changed, but the variable cannot be resized and the name cannot change.
Note
An assertion is thrown if index is out of bounds, but only in debug mode

Definition at line 196 of file StructArrayElement.tpp.

◆ operator=() [1/6]

template<bool isConst>
template<bool B, typename >
matioCpp::StructArrayElement<isConst>& matioCpp::StructArrayElement< isConst >::operator= ( const matioCpp::Struct other) const

Definition at line 78 of file StructArrayElement.tpp.

References matioCpp::unused().

◆ operator=() [2/6]

template<bool isConst>
template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
StructArrayElement& matioCpp::StructArrayElement< isConst >::operator= ( const matioCpp::Struct other) const

Assignement operator from a struct.

Parameters
otherThe struct to be copied
Note
The whole struct is copied
Returns
A reference to this Element.

◆ operator=() [3/6]

template<bool isConst>
StructArrayElement& matioCpp::StructArrayElement< isConst >::operator= ( const StructArrayElement< isConst > &  other)
delete

Deleted copy assignement since it is not clear whether the index or the content have to be copied.

◆ operator=() [4/6]

template<bool isConst>
template<bool B, typename >
matioCpp::StructArrayElement<isConst>& matioCpp::StructArrayElement< isConst >::operator= ( matioCpp::StructArrayElement< B > &&  other)

Definition at line 66 of file StructArrayElement.tpp.

◆ operator=() [5/6]

template<bool isConst>
template<bool B, typename = typename std::enable_if_t<!B && isConst>>
StructArrayElement<isConst>& matioCpp::StructArrayElement< isConst >::operator= ( StructArrayElement< B > &&  other)

Move assignement (from non-const to const)

Parameters
otherThe other Element.
Note
No data is copied
Returns
A reference to this Element.

◆ operator=() [6/6]

template<bool isConst>
matioCpp::StructArrayElement< isConst > & matioCpp::StructArrayElement< isConst >::operator= ( matioCpp::StructArrayElement< isConst > &&  other)

Move assignement.

Parameters
otherThe other Element.
Note
No data is copied
Returns
A reference to this Element.

Definition at line 56 of file StructArrayElement.tpp.

◆ operator[]() [1/2]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::output_variable_type matioCpp::StructArrayElement< isConst >::operator[] ( const std::string el) const

Access field at a specific index.

Parameters
elThe name of the field to be accessed.
Returns
A Variable with a weak ownership to the underlying mat variable. This means that the data can be changed, but the variable cannot be resized and the name cannot change.
Note
If the field is not found, the output variable is not valid.

Definition at line 218 of file StructArrayElement.tpp.

◆ operator[]() [2/2]

template<bool isConst>
matioCpp::StructArrayElement< isConst >::output_variable_type matioCpp::StructArrayElement< isConst >::operator[] ( index_type  el) const

Access field at a specific index.

Parameters
elThe index of the field to be accessed.
Returns
A Variable with a weak ownership to the underlying mat variable. This means that the data can be changed, but the variable cannot be resized and the name cannot change.
Note
An assertion is thrown if index is out of bounds, but only in debug mode

Definition at line 211 of file StructArrayElement.tpp.

◆ setField() [1/3]

template<bool isConst>
template<bool B, typename >
bool matioCpp::StructArrayElement< isConst >::setField ( const std::string field,
const Variable newValue 
) const

Set the field given the field name.

Parameters
fieldThe field to change
newValueThe Variable that will be copied in the specified field (the name is not considered)
Returns
True if successful, false otherwise (for example if the newValue is not valid or the field is not found)

Definition at line 166 of file StructArrayElement.tpp.

References std::endl().

◆ setField() [2/3]

template<bool isConst>
template<bool B, typename >
bool matioCpp::StructArrayElement< isConst >::setField ( const Variable newValue) const

Set the field given the newValue name.

Parameters
newValueThe Variable that will be copied in the specified field
Returns
True if successful, false otherwise (for example if the newValue is not valid or the field is not found)

Definition at line 182 of file StructArrayElement.tpp.

References matioCpp::Variable::name().

◆ setField() [3/3]

template<bool isConst>
template<bool B, typename >
bool matioCpp::StructArrayElement< isConst >::setField ( index_type  index,
const Variable newValue 
) const

Set the field at the specified position.

Parameters
indexThe linear index of the specified field
newValueThe Variable that will be copied in the specified location
Returns
True if successful, false otherwise (for example if the newValue is not valid)
Note
An assertion is thrown if index is out of bounds, but only in debug mode
The name is of newValue is not considered.

Definition at line 150 of file StructArrayElement.tpp.

References std::endl(), and matioCpp::Variable::isValid().

Friends And Related Function Documentation

◆ StructArrayElement< true >

template<bool isConst>
friend class StructArrayElement< true >
friend

The pointer to the array.

Definition at line 213 of file StructArrayElement.h.


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