matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
Struct.h
Go to the documentation of this file.
1 #ifndef MATIOCPP_STRUCT_H
2 #define MATIOCPP_STRUCT_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 
18 {
19 
27  virtual bool checkCompatibility(const matvar_t* inputPtr, matioCpp::VariableType variableType, matioCpp::ValueType valueType) const final;
28 
29  friend class StructArray;
30 
31 public:
32 
33  using index_type = size_t;
39  Struct();
40 
45  Struct(const std::string& name);
46 
52  Struct(const std::string& name, const std::vector<Variable> &elements);
53 
57  Struct(const Struct& other);
58 
62  Struct(Struct&& other);
63 
68  Struct(const MatvarHandler& handler);
69 
73  ~Struct();
74 
81  Struct& operator=(const Struct& other);
82 
89  Struct& operator=(Struct&& other);
90 
97  bool fromVectorOfVariables(const std::vector<Variable> &elements);
98 
104  bool setName(const std::string& newName);
105 
110  index_type numberOfFields() const;
111 
117 
121  void clear();
122 
128  bool isFieldExisting(const std::string& field) const;
129 
135  size_t getFieldIndex(const std::string& field) const;
136 
144  bool setField(index_type index, const Variable& newValue);
145 
154  bool setField(const std::string& field, const Variable& newValue);
155 
162  bool setField(const Variable& newValue);
163 
172 
180  const matioCpp::Variable operator()(index_type el) const;
181 
190 
198  const matioCpp::Variable operator()(const std::string& el) const;
199 
208 
216  const matioCpp::Variable operator[](index_type el) const;
217 
226 
234  const matioCpp::Variable operator[](const std::string& el) const;
235 };
236 
237 #endif // MATIOCPP_STRUCT_H
StructArray is a particular type of Variable specialized for array of structs.
Definition: StructArray.h:21
Struct is a particular type of Variable specialized for structs.
Definition: Struct.h:18
size_t getFieldIndex(const std::string &field) const
Get the index of the specified field in the struct by performing a linear search.
Definition: Struct.cpp:168
bool setName(const std::string &newName)
Change the name of the Struct.
Definition: Struct.cpp:131
~Struct()
Destructor.
Definition: Struct.cpp:94
std::vector< std::string > fields() const
Get the list of fields.
Definition: Struct.cpp:141
bool fromVectorOfVariables(const std::vector< Variable > &elements)
Set from a vector of Variables.
Definition: Struct.cpp:111
matioCpp::Variable operator[](index_type el)
Access field at a specific index.
Definition: Struct.cpp:215
size_t index_type
Definition: Struct.h:33
Struct & operator=(const Struct &other)
Assignement operator (copy) from another Struct.
Definition: Struct.cpp:99
bool setField(index_type index, const Variable &newValue)
Set the field at the specified position.
Definition: Struct.cpp:173
void clear()
Clear the struct.
Definition: Struct.cpp:158
Struct()
The type used for indices.
Definition: Struct.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().
Definition: Struct.cpp:163
index_type numberOfFields() const
Get the total number of fields in the struct.
Definition: Struct.cpp:136
matioCpp::Variable operator()(index_type el)
Access field at a specific index.
Definition: Struct.cpp:189
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::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.