matio-cpp
v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
|
The matioCpp::Variable class is the equivalent of matvar_t in matio. More...
#include <matioCpp/Variable.h>
Public Member Functions | |
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... | |
Variable & | operator= (const Variable &other) |
Copy assignement. More... | |
Variable & | operator= (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... | |
Protected Member Functions | |
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... | |
virtual bool | checkCompatibility (const matvar_t *inputPtr, matioCpp::VariableType variableType, matioCpp::ValueType valueType) const |
Check if an input matio pointer is compatible with the specified variable. More... | |
The matioCpp::Variable class is the equivalent of matvar_t in matio.
It is supposed to be a basic access to object that are or need to be saved in a mat file.
Definition at line 22 of file Variable.h.
matioCpp::Variable::Variable | ( | ) |
Default constructor.
Definition at line 375 of file Variable.cpp.
matioCpp::Variable::Variable | ( | const matvar_t * | inputVar | ) |
Constructor from an existing matvar_t pointer.
inputVar | The input pointer. It has to be not null. |
Definition at line 381 of file Variable.cpp.
References matioCpp::MatvarHandler::duplicateMatvar().
matioCpp::Variable::Variable | ( | const Variable & | other | ) |
Copy constructor.
Definition at line 387 of file Variable.cpp.
References matioCpp::MatvarHandler::duplicateMatvar(), isValid(), and toMatio().
matioCpp::Variable::Variable | ( | matioCpp::Variable && | other | ) |
Move constructor.
Definition at line 396 of file Variable.cpp.
matioCpp::Variable::Variable | ( | const MatvarHandler & | handler | ) |
Constructor to share the data ownership of another variable.
handler | The MatvarHandler handler to the matvar_t which has to be shared. |
Definition at line 402 of file Variable.cpp.
matioCpp::Variable::~Variable | ( | ) |
Destructor.
Definition at line 408 of file Variable.cpp.
|
protected |
Add a new field to the variable, considered as a struct.
newField | The new field |
Definition at line 282 of file Variable.cpp.
References std::string::c_str(), and std::endl().
matioCpp::CellArray matioCpp::Variable::asCellArray | ( | ) |
Cast the variable as a CellArray.
Definition at line 547 of file Variable.cpp.
const matioCpp::CellArray matioCpp::Variable::asCellArray | ( | ) | const |
Cast the variable as a const CellArray.
Definition at line 552 of file Variable.cpp.
matioCpp::Element< T > matioCpp::Variable::asElement |
Cast the variable as a Element.
The implementation is in Element.tpp
Definition at line 176 of file Element.tpp.
const matioCpp::Element< T > matioCpp::Variable::asElement |
Cast the variable as a const Element.
The implementation is in Element.tpp
Definition at line 182 of file Element.tpp.
matioCpp::MultiDimensionalArray< T > matioCpp::Variable::asMultiDimensionalArray |
Cast the variable as a MultiDimensionalArray.
The implementation is in MultiDimensionalArray.tpp
Definition at line 345 of file MultiDimensionalArray.tpp.
const matioCpp::MultiDimensionalArray< T > matioCpp::Variable::asMultiDimensionalArray |
Cast the variable as a const MultiDimensionalArray.
The implementation is in MultiDimensionalArray.tpp
Definition at line 351 of file MultiDimensionalArray.tpp.
matioCpp::String matioCpp::Variable::asString | ( | ) |
Cast the variable as a String.
Definition at line 577 of file Variable.cpp.
const matioCpp::String matioCpp::Variable::asString | ( | ) | const |
Cast the variable as a const String.
Definition at line 582 of file Variable.cpp.
matioCpp::String16 matioCpp::Variable::asString16 | ( | ) |
Cast the variable as a String16.
Definition at line 587 of file Variable.cpp.
const matioCpp::String16 matioCpp::Variable::asString16 | ( | ) | const |
Cast the variable as a const String16.
Definition at line 592 of file Variable.cpp.
matioCpp::String32 matioCpp::Variable::asString32 | ( | ) |
Cast the variable as a String32.
Definition at line 597 of file Variable.cpp.
const matioCpp::String32 matioCpp::Variable::asString32 | ( | ) | const |
Cast the variable as a const String32.
Definition at line 602 of file Variable.cpp.
matioCpp::Struct matioCpp::Variable::asStruct | ( | ) |
Cast the variable as a Struct.
Definition at line 557 of file Variable.cpp.
const matioCpp::Struct matioCpp::Variable::asStruct | ( | ) | const |
Cast the variable as a const Struct.
Definition at line 562 of file Variable.cpp.
matioCpp::StructArray matioCpp::Variable::asStructArray | ( | ) |
Cast the variable as a StructArray.
Definition at line 567 of file Variable.cpp.
const matioCpp::StructArray matioCpp::Variable::asStructArray | ( | ) | const |
Cast the variable as a const StructArray.
Definition at line 572 of file Variable.cpp.
matioCpp::Vector< T > matioCpp::Variable::asVector |
Cast the variable as a Vector.
The implementation is in Vector.tpp
Definition at line 404 of file Vector.tpp.
const matioCpp::Vector< T > matioCpp::Variable::asVector |
Cast the variable as a const Vector.
The implementation is in Vector.tpp
Definition at line 410 of file Vector.tpp.
|
protected |
Change the name of the variable.
newName | The new name to set |
Definition at line 150 of file Variable.cpp.
References std::string::c_str().
|
protectedvirtual |
Check if an input matio pointer is compatible with the specified variable.
inputPtr | The input matvar_t pointer. |
variableType | The type of variable. |
valueType | The value type. |
Definition at line 370 of file Variable.cpp.
matioCpp::Span< const size_t > matioCpp::Variable::dimensions | ( | ) | const |
Get the dimensions of this object.
Definition at line 528 of file Variable.cpp.
References matioCpp::make_span().
Referenced by initializeVariable(), and matioCpp::File::write().
bool matioCpp::Variable::fromMatio | ( | const matvar_t * | inputVar | ) |
Set this variable from an existing matio variable.
inputVar | The not null pointer to a matio variable. The variable is cloned. |
Definition at line 433 of file Variable.cpp.
References std::endl(), matioCpp::get_types_from_matvart(), matioCpp::Unsupported, and matioCpp::UNSUPPORTED.
bool matioCpp::Variable::fromOther | ( | const Variable & | other | ) |
Set this variable from another variable.
other | The Variable from which to copy the content (data, name, type, dimensions,..). |
Definition at line 453 of file Variable.cpp.
References toMatio().
bool matioCpp::Variable::fromOther | ( | matioCpp::Variable && | other | ) |
Set this variable from another variable.
other | The source Variable. Content is moved. |
Definition at line 458 of file Variable.cpp.
References std::endl().
|
protected |
Get the total number of elements in the array.
Definition at line 169 of file Variable.cpp.
|
protected |
Get a cell element at a specified linear position.
linearIndex | The linear index of the specified element |
Definition at line 211 of file Variable.cpp.
|
protected |
Get a cell element at a specified linear position.
linearIndex | The linear index of the specified element |
Definition at line 217 of file Variable.cpp.
|
protected |
Get an element of the variable, considered as a StructArray.
linearIndex | The linear index of the struct to retrieve |
Definition at line 338 of file Variable.cpp.
References std::string::c_str(), std::vector< T >::data(), matioCpp::Delete, and std::to_string().
|
protected |
Get an element of the variable, considered as a StructArray.
linearIndex | The linear index of the struct to retrieve |
Definition at line 354 of file Variable.cpp.
References std::string::c_str(), std::vector< T >::data(), matioCpp::Delete, and std::to_string().
|
protected |
Get the specified field in the variable, considered as a struct.
index | The index of the field |
structPositionInArray | The linear position of the struct to set in the struct array |
Definition at line 326 of file Variable.cpp.
|
protected |
Get the specified field in the variable, considered as a struct.
index | The index of the field |
structPositionInArray | The linear position of the struct to set in the struct array |
Definition at line 332 of file Variable.cpp.
|
protected |
Get the index of the specified field in the variable, considered as a struct.
field | The field to search |
Definition at line 235 of file Variable.cpp.
References std::string::c_str().
|
protected |
Get the list of fields in the variable, considered as a struct.
Definition at line 229 of file Variable.cpp.
Referenced by matioCpp::StructArray::setElement().
|
protected |
Get the total number of fields in the variable, considered as a struct.
Definition at line 223 of file Variable.cpp.
|
protected |
Initialize a complex variable.
name | The name of the variable. |
variableType | The type of variable |
valueType | The type of each element in the variable |
dimensions | Vector containing the variable dimensions. The size of this vector should be at least 2. |
realData | A void pointer to the (flattened) real data. Check the documentation of initializeVariable for understanding how to obtain/interpret this vector. |
imaginaryData | A void pointer to the (flattened) imaginary data. Check the documentation of initializeVariable for understanding how to obtain/interpret this vector. |
Definition at line 75 of file Variable.cpp.
References std::vector< T >::assign(), matioCpp::Span< ElementType, Extent >::begin(), std::string::c_str(), std::vector< T >::data(), matioCpp::MatvarHandler::DeleteMatvar(), std::string::empty(), matioCpp::Span< ElementType, Extent >::end(), std::endl(), matioCpp::get_matio_types(), matioCpp::LOGICAL, matioCpp::Span< ElementType, Extent >::size(), and std::vector< T >::size().
Referenced by initializeComplexVector().
|
inlineprotected |
Initialize a complex vector.
name | The name of the variable. |
realInputVector | The real input vector. |
imaginaryInputVector | The imaginary input vector. |
Definition at line 65 of file Variable.h.
References matioCpp::Span< ElementType, Extent >::data(), std::string::empty(), std::endl(), initializeComplexVariable(), name(), matioCpp::Span< ElementType, Extent >::size(), and matioCpp::Vector.
|
protected |
Initialize the variable.
name | The name of the variable. |
variableType | The type of variable |
valueType | The type of each element in the variable |
dimensions | Vector containing the variable dimensions. The size of this vector should be at least 2. |
data | A void pointer to the (flattened) data. |
Definition at line 16 of file Variable.cpp.
References std::vector< T >::assign(), std::string::c_str(), std::vector< T >::data(), matioCpp::MatvarHandler::DeleteMatvar(), dimensions(), std::string::empty(), std::endl(), matioCpp::MatvarHandler::get(), matioCpp::get_matio_types(), matioCpp::MatvarHandler::importMatvar(), matioCpp::LOGICAL, name(), std::vector< T >::size(), valueType(), and variableType().
Referenced by matioCpp::CellArray::CellArray(), matioCpp::Element< T >::Element(), matioCpp::MultiDimensionalArray< T >::MultiDimensionalArray(), matioCpp::Struct::Struct(), and matioCpp::StructArray::StructArray().
bool matioCpp::Variable::isComplex | ( | ) | const |
Get if the variable is complex.
Definition at line 516 of file Variable.cpp.
bool matioCpp::Variable::isValid | ( | ) | const |
Check if the variable is valid.
A Variable may not be valid if it does not point to any data, or the the dimensions().size() < 2.
Definition at line 542 of file Variable.cpp.
Referenced by matioCpp::File::Impl::isVariableValid(), matioCpp::File::read(), setCellElement(), matioCpp::CellArray::setElement(), matioCpp::StructArrayElement< isConst >::setField(), setStructField(), and Variable().
std::string matioCpp::Variable::name | ( | ) | const |
Get the name of the Variable.
Definition at line 494 of file Variable.cpp.
Referenced by initializeComplexVector(), initializeVariable(), matioCpp::File::Impl::isVariableValid(), matioCpp::Struct::setField(), and matioCpp::StructArrayElement< isConst >::setField().
matioCpp::Variable & matioCpp::Variable::operator= | ( | const Variable & | other | ) |
Copy assignement.
other | The variable to be copied |
Definition at line 417 of file Variable.cpp.
References matioCpp::unused().
matioCpp::Variable & matioCpp::Variable::operator= | ( | matioCpp::Variable && | other | ) |
Move assignement.
other | The variable to be moved |
Definition at line 425 of file Variable.cpp.
References matioCpp::unused().
|
protected |
Set a cell element at a specified linear position.
linearIndex | The linear index of the specified element |
newValue | The Variable that will be copied in the specified location |
Definition at line 180 of file Variable.cpp.
References matioCpp::MatvarHandler::DeleteMatvar(), std::endl(), matioCpp::MatvarHandler::GetMatvarDuplicate(), isValid(), and toMatio().
|
protected |
Set the field of the struct given the newValue name.
field | The field to set |
newValue | The Variable that will be copied in the specified field |
structPositionInArray | The linear position of the struct to set in the struct array |
Definition at line 307 of file Variable.cpp.
References std::endl().
|
protected |
Set the field of the struct at the specified position.
index | The linear index of the specified field |
newValue | The Variable that will be copied in the specified location |
structPositionInArray | The linear position of the struct to set in the struct array |
Definition at line 254 of file Variable.cpp.
References matioCpp::MatvarHandler::DeleteMatvar(), std::endl(), matioCpp::MatvarHandler::GetMatvarDuplicate(), isValid(), and toMatio().
matvar_t * matioCpp::Variable::toMatio | ( | ) |
Convert this Variable to a matio variable.
Definition at line 487 of file Variable.cpp.
const matvar_t * matioCpp::Variable::toMatio | ( | ) | const |
Convert this Variable to a matio variable.
Definition at line 480 of file Variable.cpp.
Referenced by fromOther(), setCellElement(), setStructField(), Variable(), and matioCpp::File::write().
matioCpp::ValueType matioCpp::Variable::valueType | ( | ) | const |
Get the ValueType.
Definition at line 511 of file Variable.cpp.
Referenced by initializeVariable(), and matioCpp::File::write().
matioCpp::VariableType matioCpp::Variable::variableType | ( | ) | const |
Get the VariableType.
Definition at line 506 of file Variable.cpp.
Referenced by initializeVariable(), and matioCpp::File::write().