matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
StructArray.h
Go to the documentation of this file.
1 #ifndef MATIOCPP_STRUCTARRAY_H
2 #define MATIOCPP_STRUCTARRAY_H
3 
4 /*
5  * Copyright (C) 2020 Fondazione Istituto Italiano di Tecnologia
6  *
7  * This software may be modified and distributed under the terms of the
8  * BSD-2-Clause license (https://opensource.org/licenses/BSD-2-Clause).
9  */
10 
12 #include <matioCpp/Variable.h>
13 #include <matioCpp/Struct.h>
15 
21 {
22 
30  virtual bool checkCompatibility(const matvar_t* inputPtr, matioCpp::VariableType variableType, matioCpp::ValueType valueType) const final;
31 
32  template<bool>
33  friend class StructArrayElement;
34 
35 public:
36 
37  using index_type = size_t;
47  StructArray();
48 
54 
61 
73  const std::vector<matioCpp::Struct>& elements);
74 
84 
88  StructArray(const StructArray& other);
89 
93  StructArray(StructArray&& other);
94 
99  StructArray(const MatvarHandler& handler);
100 
104  ~StructArray();
105 
112  StructArray& operator=(const StructArray& other);
113 
121 
131 
144 
152  bool indicesFromRawIndex(size_t rawIndex, std::vector<index_type>& el) const;
153 
159  bool setName(const std::string& newName);
160 
167  void resize(const std::vector<index_type>& newDimensions);
168 
174 
179  index_type numberOfFields() const;
180 
186 
190  void clear();
191 
197  bool isFieldExisting(const std::string& field) const;
198 
204  size_t getFieldIndex(const std::string& field) const;
205 
211  bool addField(const std::string& newField);
212 
218  bool addFields(const std::vector<std::string>& newFields);
219 
228  bool setElement(const std::vector<index_type>& el, const matioCpp::Struct& newValue);
229 
238  bool setElement(index_type el, const matioCpp::Struct& newValue);
239 
248 
256 
264 
271 
280 
288 
296 
303 };
304 
305 #endif // MATIOCPP_STRUCTARRAY_H
StructArray is a particular type of Variable specialized for array of structs.
Definition: StructArray.h:21
bool fromVectorOfStructs(const std::vector< index_type > &dimensions, const std::vector< matioCpp::Struct > &elements)
Set from a vector of Variables.
bool addField(const std::string &newField)
Add a new field to all the structs.
void clear()
Clear the struct array.
index_type numberOfFields() const
Get the total number of fields in the struct.
Element 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 setName(const std::string &newName)
Change the name of the Variable.
void resize(const std::vector< index_type > &newDimensions)
Resize the array.
size_t getFieldIndex(const std::string &field) const
Get the index of the specified field in the struct by performing a linear search.
StructArray()
Const version of Element.
Definition: StructArray.cpp:29
bool isFieldExisting(const std::string &field) const
Check if a field is existing It performs a linear search over the output of fields().
Element operator[](const std::vector< index_type > &el)
Access specified element.
std::vector< std::string > fields() const
Get the list of fields.
bool indicesFromRawIndex(size_t rawIndex, std::vector< index_type > &el) const
Get the indices given the raw index.
~StructArray()
Destructor.
bool addFields(const std::vector< std::string > &newFields)
Add the fields to all the structs.
StructArray & operator=(const StructArray &other)
Assignement operator (copy) from another StructArray.
index_type numberOfElements() const
Get the total number of elements in the array.
bool setElement(const std::vector< index_type > &el, const matioCpp::Struct &newValue)
Set the element at the specified position.
Struct is a particular type of Variable specialized for structs.
Definition: Struct.h:18
The matioCpp::Variable class is the equivalent of matvar_t in matio.
Definition: Variable.h:23
std::string name() const
Get the name of the Variable.
Definition: Variable.cpp:494
matioCpp::Span< const size_t > dimensions() const
Get the dimensions of this object.
Definition: Variable.cpp:528
matioCpp::VariableType variableType() const
Get the VariableType.
Definition: Variable.cpp:506
matioCpp::ValueType valueType() const
Get the ValueType.
Definition: Variable.cpp:511
VariableType
Define the type of variable.
ValueType
The list of types for an element of a certain variable type.