matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
StructArrayElement.h
Go to the documentation of this file.
1 #ifndef MATIOCPP_STRUCTARRAYELEMENT_H
2 #define MATIOCPP_STRUCTARRAYELEMENT_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>
14 
15 template <bool isConst>
17 {
18 
19 public:
20 
21  using index_type = size_t;
23  using input_vector_type = std::conditional_t<isConst, const matioCpp::StructArray, matioCpp::StructArray>;
24 
25  using output_variable_type = std::conditional_t<isConst, const matioCpp::Variable, matioCpp::Variable>;
26 
27  using output_struct_type = std::conditional_t<isConst, const matioCpp::Struct, matioCpp::Struct>;
28 
35 
39  StructArrayElement() = delete;
40 
47 
53  template<bool B, typename = typename std::enable_if_t<!B && isConst>>
55 
62 
68  template<bool B, typename = typename std::enable_if_t<!B && isConst>>
70 
75 
83 
90  template<bool B, typename = typename std::enable_if_t<!B && isConst>>
92 
99  template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
101 
108  template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
109  bool fromVectorOfVariables(const std::vector<Variable> &elements) const;
110 
115  index_type numberOfFields() const;
116 
122 
128  bool isFieldExisting(const std::string& field) const;
129 
135  size_t getFieldIndex(const std::string& field) const;
136 
145  template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
146  bool setField(index_type index, const Variable& newValue) const;
147 
154  template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
155  bool setField(const std::string& field, const Variable& newValue) const;
156 
162  template<bool B = isConst, typename = typename std::enable_if_t<(B == isConst) && !B>>
163  bool setField(const Variable& newValue) const;
164 
172 
181 
190 
199 
208 
209 private:
210 
211  index_type m_innerIndex;
213  input_vector_type* m_array;
215  friend class StructArrayElement<true>;
216 };
217 
219 
220 #endif // MATIOCPP_STRUCTARRAYELEMENT_H
StructArrayElement & operator=(const matioCpp::Struct &other) const
Assignement operator from a struct.
StructArrayElement< isConst > & operator=(StructArrayElement< B > &&other)
Move assignement (from non-const to const)
output_variable_type operator()(index_type el) const
Access field at a specific index.
index_type numberOfFields() const
Get the total number of fields in the struct.
bool isFieldExisting(const std::string &field) const
Check if a field is existing It performs a linear search over the output of fields().
bool fromVectorOfVariables(const std::vector< Variable > &elements) const
Set from a vector of Variables.
output_struct_type asStruct() const
Get the element as a Struct.
std::conditional_t< isConst, const matioCpp::Struct, matioCpp::Struct > output_struct_type
bool setField(index_type index, const Variable &newValue) const
Set the field at the specified position.
output_variable_type operator[](index_type el) const
Access field at a specific index.
StructArrayElement & operator=(const StructArrayElement &other)=delete
Deleted copy assignement since it is not clear whether the index or the content have to be copied.
StructArrayElement()=delete
Deleted default constructor.
std::conditional_t< isConst, const matioCpp::StructArray, matioCpp::StructArray > input_vector_type
The type used for indices.
std::vector< std::string > fields() const
Get the list of fields.
std::conditional_t< isConst, const matioCpp::Variable, matioCpp::Variable > output_variable_type
size_t getFieldIndex(const std::string &field) const
Get the index of the specified field in the struct by performing a linear search.
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