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

Struct is a particular type of Variable specialized for structs. More...

#include <matioCpp/Struct.h>

+ Inheritance diagram for matioCpp::Struct:

Public Types

using index_type = size_t
 

Public Member Functions

 Struct ()
 The type used for indices. More...
 
 Struct (const std::string &name)
 Constructor. More...
 
 Struct (const std::string &name, const std::vector< Variable > &elements)
 Constructor. More...
 
 Struct (const Struct &other)
 Copy constructor. More...
 
 Struct (Struct &&other)
 Move constructor. More...
 
 Struct (const MatvarHandler &handler)
 Constructor to share the data ownership of another variable. More...
 
 ~Struct ()
 Destructor. More...
 
Structoperator= (const Struct &other)
 Assignement operator (copy) from another Struct. More...
 
Structoperator= (Struct &&other)
 Assignement operator (move) from another Struct. More...
 
bool fromVectorOfVariables (const std::vector< Variable > &elements)
 Set from a vector of Variables. More...
 
bool setName (const std::string &newName)
 Change the name of the Struct. 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...
 
void clear ()
 Clear the struct. 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...
 
bool setField (index_type index, const Variable &newValue)
 Set the field at the specified position. More...
 
bool setField (const std::string &field, const Variable &newValue)
 Set the given field to the newValue. More...
 
bool setField (const Variable &newValue)
 Set the field given the newValue name. More...
 
matioCpp::Variable operator() (index_type el)
 Access field at a specific index. More...
 
const matioCpp::Variable operator() (index_type el) const
 Access field at a specific index. More...
 
matioCpp::Variable operator() (const std::string &el)
 Access field at a specific index. More...
 
const matioCpp::Variable operator() (const std::string &el) const
 Access field at a specific index. More...
 
matioCpp::Variable operator[] (index_type el)
 Access field at a specific index. More...
 
const matioCpp::Variable operator[] (index_type el) const
 Access field at a specific index. More...
 
matioCpp::Variable operator[] (const std::string &el)
 Access field at a specific index. More...
 
const matioCpp::Variable operator[] (const std::string &el) const
 Access field at a specific index. 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...
 

Friends

class StructArray
 

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

Struct is a particular type of Variable specialized for structs.

Definition at line 17 of file Struct.h.

Member Typedef Documentation

◆ index_type

Definition at line 33 of file Struct.h.

Constructor & Destructor Documentation

◆ Struct() [1/6]

matioCpp::Struct::Struct ( )

The type used for indices.

Default Constructor

Note
The name is set to "unnamed_struct".

Definition at line 29 of file Struct.cpp.

References matioCpp::Struct, and matioCpp::VARIABLE.

◆ Struct() [2/6]

matioCpp::Struct::Struct ( const std::string name)

Constructor.

Parameters
nameThe name of the Struct

Definition at line 38 of file Struct.cpp.

References matioCpp::Struct, and matioCpp::VARIABLE.

◆ Struct() [3/6]

matioCpp::Struct::Struct ( const std::string name,
const std::vector< Variable > &  elements 
)

Constructor.

Parameters
nameThe name of the Struct
elementsThe elements to be added to the Struct (they are copied)

Definition at line 47 of file Struct.cpp.

References std::vector< T >::data(), std::endl(), matioCpp::MatvarHandler::GetMatvarDuplicate(), std::vector< T >::push_back(), std::vector< T >::size(), matioCpp::Struct, and matioCpp::VARIABLE.

◆ Struct() [4/6]

matioCpp::Struct::Struct ( const Struct other)

Copy constructor.

Definition at line 70 of file Struct.cpp.

◆ Struct() [5/6]

matioCpp::Struct::Struct ( matioCpp::Struct &&  other)

Move constructor.

Definition at line 75 of file Struct.cpp.

◆ Struct() [6/6]

matioCpp::Struct::Struct ( 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 80 of file Struct.cpp.

References matioCpp::MatvarHandler::get(), matioCpp::Variable::initializeVariable(), matioCpp::Struct, matioCpp::MatvarHandler::valueType(), matioCpp::VARIABLE, and matioCpp::MatvarHandler::variableType().

◆ ~Struct()

matioCpp::Struct::~Struct ( )

Destructor.

Definition at line 94 of file Struct.cpp.

Member Function Documentation

◆ clear()

void matioCpp::Struct::clear ( )

Clear the struct.

Definition at line 158 of file Struct.cpp.

References std::move().

◆ fields()

std::vector< std::string > matioCpp::Struct::fields ( ) const

Get the list of fields.

Returns
The list of fields.

Definition at line 141 of file Struct.cpp.

References std::vector< T >::emplace_back(), and std::vector< T >::reserve().

◆ fromVectorOfVariables()

bool matioCpp::Struct::fromVectorOfVariables ( const std::vector< Variable > &  elements)

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.

Definition at line 111 of file Struct.cpp.

References std::vector< T >::data(), std::endl(), matioCpp::MatvarHandler::GetMatvarDuplicate(), std::vector< T >::size(), matioCpp::Struct, and matioCpp::VARIABLE.

◆ getFieldIndex()

size_t matioCpp::Struct::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 168 of file Struct.cpp.

◆ isFieldExisting()

bool matioCpp::Struct::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 163 of file Struct.cpp.

◆ numberOfFields()

matioCpp::Struct::index_type matioCpp::Struct::numberOfFields ( ) const

Get the total number of fields in the struct.

Returns
The total number of fields

Definition at line 136 of file Struct.cpp.

Referenced by matioCpp::StructArray::setElement().

◆ operator()() [1/4]

matioCpp::Variable matioCpp::Struct::operator() ( const std::string el)

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 201 of file Struct.cpp.

◆ operator()() [2/4]

const matioCpp::Variable matioCpp::Struct::operator() ( const std::string el) const

Access field at a specific index.

Parameters
elThe name of the field to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A const Variable with a weak ownership to the underlying mat variable.
Note
If the field is not found, the output variable is not valid.

Definition at line 208 of file Struct.cpp.

◆ operator()() [3/4]

matioCpp::Variable matioCpp::Struct::operator() ( index_type  el)

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 189 of file Struct.cpp.

◆ operator()() [4/4]

const matioCpp::Variable matioCpp::Struct::operator() ( index_type  el) const

Access field at a specific index.

Parameters
elThe index of the field to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A const Variable with a weak ownership to the underlying mat variable.
Note
An assertion is thrown if index is out of bounds, but only in debug mode

Definition at line 195 of file Struct.cpp.

◆ operator=() [1/2]

matioCpp::Struct & matioCpp::Struct::operator= ( const Struct other)

Assignement operator (copy) from another Struct.

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

Definition at line 99 of file Struct.cpp.

◆ operator=() [2/2]

matioCpp::Struct & matioCpp::Struct::operator= ( matioCpp::Struct &&  other)

Assignement operator (move) from another Struct.

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

Definition at line 105 of file Struct.cpp.

◆ operator[]() [1/4]

matioCpp::Variable matioCpp::Struct::operator[] ( const std::string el)

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 227 of file Struct.cpp.

◆ operator[]() [2/4]

const matioCpp::Variable matioCpp::Struct::operator[] ( const std::string el) const

Access field at a specific index.

Parameters
elThe name of the field to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A const Variable with a weak ownership to the underlying mat variable.
Note
If the field is not found, the output variable is not valid.

Definition at line 234 of file Struct.cpp.

◆ operator[]() [3/4]

matioCpp::Variable matioCpp::Struct::operator[] ( index_type  el)

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 215 of file Struct.cpp.

◆ operator[]() [4/4]

const matioCpp::Variable matioCpp::Struct::operator[] ( index_type  el) const

Access field at a specific index.

Parameters
elThe index of the field to be accessed.
Warning
Each element of el has to be strictly smaller than the corresponding dimension.
Returns
A const Variable with a weak ownership to the underlying mat variable.
Note
An assertion is thrown if index is out of bounds, but only in debug mode

Definition at line 221 of file Struct.cpp.

◆ setField() [1/3]

bool matioCpp::Struct::setField ( const std::string field,
const Variable newValue 
)

Set the given field to the newValue.

Parameters
fieldThe name of the field to set
newValueThe Variable that will be copied in the specified field
Returns
True if successful, false otherwise (for example if the newValue is not valid)
Note
If the field is not found, a new field is created and appended to the struct.
The field is searched linearly. The name of newValue is not used

Definition at line 179 of file Struct.cpp.

◆ setField() [2/3]

bool matioCpp::Struct::setField ( const Variable newValue)

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)
Note
If the field is not found, a new field is created and appended to the struct.

Definition at line 184 of file Struct.cpp.

References matioCpp::Variable::name().

◆ setField() [3/3]

bool matioCpp::Struct::setField ( index_type  index,
const Variable newValue 
)

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

Definition at line 173 of file Struct.cpp.

Referenced by matioCpp::make_struct(), and matioCpp::make_variable().

◆ setName()

bool matioCpp::Struct::setName ( const std::string newName)

Change the name of the Struct.

Parameters
newNameThe new name
Returns
True if successful.

Definition at line 131 of file Struct.cpp.

Friends And Related Function Documentation

◆ StructArray

friend class StructArray
friend

Definition at line 29 of file Struct.h.


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