16 std::cerr <<
"[matioCpp::Struct::checkCompatibility] The variable type is not compatible with a struct." <<
std::endl;
20 if (inputPtr->isComplex)
22 std::cerr <<
"[matioCpp::Struct::checkCompatibility] Cannot use a complex variable into a non-complex one." <<
std::endl;
31 size_t emptyDimensions[] = {1, 1};
32 initializeVariable(
"unnamed_struct",
40 size_t emptyDimensions[] = {1, 1};
41 initializeVariable(name,
49 size_t emptyDimensions[] = {1, 1};
51 for (
size_t i = 0; i < elements.
size(); ++i)
53 if (elements[i].isValid())
59 std::cerr <<
"[ERROR][matioCpp::Struct::Struct] The element of " << name <<
" at index " << i <<
" (0-based) is not valid. It will be skipped." <<
std::endl;
64 initializeVariable(name,
67 vectorOfPointers.
data());
77 fromOther(std::forward<Struct>(other));
86 size_t emptyDimensions[] = {1, 1};
107 fromOther(std::forward<Struct>(other));
114 for (
size_t i = 0; i < elements.
size(); ++i)
116 if (!elements[i].isValid())
118 std::cerr <<
"[ERROR][matioCpp::Struct::fromVectorOfVariables] The element at index "<< i <<
" (0-based) is not valid." <<
std::endl;
124 initializeVariable(name(),
127 vectorOfPointers.
data());
133 return changeName(newName);
138 return getStructNumberOfFields();
144 char *
const * matvarOutput = getStructFields();
147 size_t numberOfFields = getStructNumberOfFields();
148 output.
reserve(numberOfFields);
149 for (
size_t i = 0; i < numberOfFields; ++i)
165 return getStructFieldIndex(field) < numberOfFields();
170 return getStructFieldIndex(field);
175 assert(index < numberOfFields() &&
"The specified index is out of bounds");
176 return setStructField(index, newValue);
181 return setStructField(field, newValue);
186 return setStructField(newValue.
name(), newValue);
191 assert(el < numberOfFields() &&
"The specified index is out of bounds");
192 return getStructField(el);
197 assert(el < numberOfFields() &&
"The specified index is out of bounds");
198 return getStructField(el);
203 size_t index = getFieldIndex(el);
204 assert(index < numberOfFields() &&
"The specified field does not exist.");
205 return getStructField(index);
210 size_t index = getFieldIndex(el);
211 assert(index < numberOfFields() &&
"The specified field does not exist.");
212 return getStructField(index);
217 assert(el < numberOfFields() &&
"The specified index is out of bounds");
218 return getStructField(el);
223 assert(el < numberOfFields() &&
"The specified index is out of bounds");
224 return getStructField(el);
229 size_t index = getFieldIndex(el);
230 assert(index < numberOfFields() &&
"The specified field does not exist.");
231 return getStructField(index);
236 size_t index = getFieldIndex(el);
237 assert(index < numberOfFields() &&
"The specified field does not exist.");
238 return getStructField(index);
static matvar_t * GetMatvarDuplicate(const matvar_t *inputPtr)
Get a duplicate of the input matvar pointer/.
ValueType valueType() const
Get the value type of the pointer.
virtual matvar_t * get() const =0
Get the shared matvar_t pointer.
VariableType variableType() const
Get the variable type of the pointer.
Struct is a particular type of Variable specialized for structs.
size_t getFieldIndex(const std::string &field) const
Get the index of the specified field in the struct by performing a linear search.
bool setName(const std::string &newName)
Change the name of the Struct.
std::vector< std::string > fields() const
Get the list of fields.
bool fromVectorOfVariables(const std::vector< Variable > &elements)
Set from a vector of Variables.
matioCpp::Variable operator[](index_type el)
Access field at a specific index.
Struct & operator=(const Struct &other)
Assignement operator (copy) from another Struct.
bool setField(index_type index, const Variable &newValue)
Set the field at the specified position.
void clear()
Clear the struct.
Struct()
The type used for indices.
bool isFieldExisting(const std::string &field) const
Check if a field is existing It performs a linear search over the output of fields().
index_type numberOfFields() const
Get the total number of fields in the struct.
matioCpp::Variable operator()(index_type el)
Access field at a specific index.
The matioCpp::Variable class is the equivalent of matvar_t in matio.
std::string name() const
Get the name of the Variable.
matioCpp::VariableType variableType() const
Get the VariableType.
bool initializeVariable(const std::string &name, const VariableType &variableType, const ValueType &valueType, matioCpp::Span< const size_t > dimensions, void *data)
Initialize the variable.
T emplace_back(T... args)
VariableType
Define the type of variable.
ValueType
The list of types for an element of a certain variable type.