14 std::cerr <<
"[matioCpp::CellArray::checkCompatibility] The variable type is not compatible with a cell array." <<
std::endl;
18 if (inputPtr->isComplex)
20 std::cerr <<
"[matioCpp::CellArray::checkCompatibility] Cannot use a complex variable into a non-complex one." <<
std::endl;
30 initializeVariable(
"unnamed_cell_array",
39 initializeVariable(name,
51 std::cerr <<
"[ERROR][matioCpp::CellArray::CellArray] Zero dimension detected." <<
std::endl;
56 initializeVariable(name,
72 std::cerr <<
"[ERROR][matioCpp::CellArray::CellArray] The size of elements vector does not match the provided dimensions. The total number is different." <<
std::endl;
78 if (!elements[
i].isValid())
80 std::cerr <<
"[ERROR][matioCpp::CellArray::CellArray] The element at index "<<
i <<
" (0-based) is not valid." <<
std::endl;
86 initializeVariable(name,
99 fromOther(std::forward<CellArray>(
other));
129 fromOther(std::forward<CellArray>(
other));
143 std::cerr <<
"[ERROR][matioCpp::CellArray::fromVectorOfVariables] The size of elements vector does not match the provided dimensions. The total number is different." <<
std::endl;
149 if (!elements[
i].isValid())
151 std::cerr <<
"[ERROR][matioCpp::CellArray::fromVectorOfVariables] The element at index "<<
i <<
" (0-based) is not valid." <<
std::endl;
157 return initializeVariable(name(),
165 assert(dimensions().size() > 0 && numberOfElements() > 0 &&
"[matioCpp::CellArray::rawIndexFromIndices] The array is empty.");
166 assert(
el.size() > 0 == dimensions().size() > 0 &&
"[matioCpp::CellArray::rawIndexFromIndices] The input vector el should have the same number of dimensions of the array.");
167 assert(
el[0] < dimensions()[0] &&
"[matioCpp::CellArray::rawIndexFromIndices] The required element is out of bounds.");
172 for (
size_t i = 0;
i <
el.size(); ++
i)
174 assert(
el[
i] < dimensions()[
i] &&
"[matioCpp::CellArray::rawIndexFromIndices] The required element is out of bounds.");
188 std::cerr <<
"[ERROR][matioCpp::CellArray::indicesFromRawIndex] rawIndex is greater than the number of elements." <<
std::endl;
196 for (
size_t i = 1;
i <
el.size(); ++
i)
204 for (
size_t i =
el.size() - 1;
i > 0; --
i)
206 el[
i] = remainder /
el[
i - 1];
207 remainder -=
el[
i] *
el[
i - 1];
232 return getArrayNumberOfElements();
239 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] The CellArray has not been properly initialized." <<
std::endl;
245 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] The input variable is not valid." <<
std::endl;
249 if (!setCellElement(rawIndexFromIndices(
el),
newValue))
251 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] Failed to set the cell element." <<
std::endl;
260 assert(
el < numberOfElements() &&
"[matioCpp::CellArray::setElement] The required element is out of bounds.");
264 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] The CellArray has not been properly initialized." <<
std::endl;
270 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] The input variable is not valid." <<
std::endl;
276 std::cerr <<
"[ERROR][matioCpp::CellArray::setElement] Failed to set the cell element." <<
std::endl;
285 return getCellElement(rawIndexFromIndices(
el));
290 return getCellElement(rawIndexFromIndices(
el));
295 assert(
el < numberOfElements() &&
"[matioCpp::CellArray::operator()] The required element is out of bounds.");
296 return getCellElement(
el);
301 assert(
el < numberOfElements() &&
"[matioCpp::CellArray::operator()] The required element is out of bounds.");
302 return getCellElement(
el);
307 return getCellElement(rawIndexFromIndices(
el));
312 return getCellElement(rawIndexFromIndices(
el));
317 assert(
el < numberOfElements() &&
"[matioCpp::CellArray::operator[]] The required element is out of bounds.");
318 return getCellElement(
el);
323 assert(
el < numberOfElements() &&
"[matioCpp::CellArray::operator[]] The required element is out of bounds.");
324 return getCellElement(
el);
CellArray is a particular type of Variable specialized for cell arrays.
matioCpp::Variable operator[](const std::vector< index_type > &el)
Access specified element.
index_type rawIndexFromIndices(const std::vector< index_type > &el) const
Get the linear index corresponding to the provided indices.
bool fromVectorOfVariables(const std::vector< index_type > &dimensions, std::vector< Variable > &elements)
Set from a vector of Variables.
bool setElement(const std::vector< index_type > &el, const Variable &newValue)
Set the element at the specified position.
index_type numberOfElements() const
Get the total number of elements in the array.
matioCpp::Variable operator()(const std::vector< index_type > &el)
Access specified element.
bool setName(const std::string &newName)
Change the name of the Variable.
CellArray & operator=(const CellArray &other)
Assignement operator (copy) from another CellArray.
CellArray()
The type used for indices.
void clear()
Clear the cell array.
bool indicesFromRawIndex(size_t rawIndex, std::vector< index_type > &el) const
Get the indices given the raw index.
void resize(const std::vector< index_type > &newDimensions)
Resize the cell array.
static matvar_t * GetMatvarDuplicate(const matvar_t *inputPtr)
Get a duplicate of the input matvar pointer/.
MultiDimensionalArray is a particular type of Variable specialized for multidimensional arrays of a g...
void resize(const std::vector< index_type > &newDimensions)
Resize the vector.
pointer data()
Direct access to the underlying array.
The matioCpp::Variable class is the equivalent of matvar_t in matio.
bool isValid() const
Check if the variable is valid.
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.
matioCpp::ValueType valueType() const
Get the ValueType.
VariableType
Define the type of variable.
ValueType
The list of types for an element of a certain variable type.