matio-cpp  v0.2.5
A C++ wrapper of the matio library, with memory ownership handling, to read and write .mat files.
Vector.h
Go to the documentation of this file.
1 #ifndef MATIOCPP_VECTOR_H
2 #define MATIOCPP_VECTOR_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 
11 
14 #include <matioCpp/Span.h>
15 #include <matioCpp/Variable.h>
17 
21 template<typename T>
23 {
24 public:
25 
26  using type = T;
28  using element_type = typename get_type<T>::type;
30  using value_type = std::remove_cv_t<element_type>;
34  using index_type = size_t;
61  Vector();
62 
68  Vector(const std::string& name);
69 
76 
82  template<typename in = element_type,
88 
94  Vector(const std::string& name, const string_input_type &inputString);
95 
101  Vector(const std::string& name, const std::vector<bool>& inputVector);
102 
106  Vector(const Vector<T>& other);
107 
111  Vector(Vector<T>&& other);
112 
117  Vector(const MatvarHandler& handler);
118 
122  ~Vector();
123 
130  Vector<T>& operator=(const Vector<T>& other);
131 
138  Vector<T>& operator=(Vector<T>&& other);
139 
146 
153  Vector<T>& operator=(const string_input_type &other);
154 
161  Vector<T>& operator=(const std::vector<bool>& other);
162 
167 
172 
178  bool setName(const std::string& newName);
179 
184  index_type size() const;
185 
192  void resize(index_type newSize);
193 
197  void clear();
198 
203  pointer data();
204 
209  const_pointer data() const;
210 
218 
226 
233 
241 
249 
254  iterator begin();
255 
261  iterator end();
262 
267  const_iterator begin() const;
268 
274  const_iterator end() const;
275 
280  const_iterator cbegin() const;
281 
287  const_iterator cend() const;
288 
295 
303 
310 
318 
325 
333 
334 private:
335 
342  bool initializeVector(const std::string& name, Span<const element_type> inputVector);
343 
351  virtual bool checkCompatibility(const matvar_t* inputPtr, matioCpp::VariableType variableType, matioCpp::ValueType valueType) const final;
352 
353 };
354 
355 #include "impl/Vector.tpp"
356 
357 #endif // MATIOCPP_VECTOR_H
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
Vector is a particular type of Variable specialized for 1-D arrays of a generic type T.
Definition: Vector.h:23
Vector(const std::string &name, index_type dimensions)
Constructor.
matioCpp::Span< element_type > toSpan()
Get this Vector as a Span.
Definition: Vector.tpp:242
value_type operator()(index_type el) const
Access specified element.
size_t index_type
Defines how to allocate T.
Definition: Vector.h:34
pointer data()
Direct access to the underlying array.
Definition: Vector.tpp:286
index_type size() const
Get the size of the vector.
Definition: Vector.tpp:260
Vector< T > & operator=(const Vector< T > &other)
Assignement operator (copy) from another Vector.
Definition: Vector.tpp:167
reverse_iterator rend()
rend Iterator to the element following the last element of the reversed vector.
Definition: Vector.tpp:374
const_reverse_iterator crend() const
crend Iterator to the element following the last element of the reversed vector.
Definition: Vector.tpp:398
Vector< element_type > & operator=(const Span< element_type > &other)
Assignement operator from another Vector.
std::remove_cv_t< element_type > value_type
Defines the type of an element of the Vector.
Definition: Vector.h:30
element_type & reference
The type used for indices.
Definition: Vector.h:36
typename get_type< T >::type element_type
Defines the type specified in the template.
Definition: Vector.h:28
typename std::allocator_traits< std::allocator< element_type > >::const_pointer const_pointer
The pointer type.
Definition: Vector.h:40
typename std::conditional< matioCpp::is_string16_compatible< T >::value, std::u16string, typename std::conditional< matioCpp::is_string32_compatible< T >::value, std::u32string, std::string >::type >::type string_input_type
The const reverse iterator type.
Definition: Vector.h:51
value_type operator[](index_type el) const
Access specified element.
reverse_iterator rbegin()
rbegin Iterator to the first element of the reversed vector
Definition: Vector.tpp:368
Vector()
The output type of the conversion to string.
Definition: Vector.tpp:52
iterator begin()
begin Iterator
Definition: Vector.tpp:332
void clear()
Clear the vector.
Definition: Vector.tpp:280
string_output_type operator()() const
Get the Vector as a string.
Definition: Vector.tpp:310
const_iterator cbegin() const
cbegin Iterator
Definition: Vector.tpp:356
reference operator[](index_type el)
Access specified element.
typename std::conditional< matioCpp::is_string_compatible< T >::value, std::string, typename std::conditional< matioCpp::is_string16_compatible< T >::value, std::u16string, typename std::conditional< matioCpp::is_string32_compatible< T >::value, std::u32string, void >::type >::type >::type string_output_type
The type of string that can be used as initialization.
Definition: Vector.h:55
typename std::allocator_traits< std::allocator< element_type > >::pointer pointer
The reference type.
Definition: Vector.h:38
void resize(index_type newSize)
Resize the vector.
Definition: Vector.tpp:269
const_reverse_iterator crbegin() const
crbegin Iterator to the first element of the reversed vector
Definition: Vector.tpp:392
const_iterator cend() const
cend Iterator
Definition: Vector.tpp:362
Vector(const std::string &name, Span< const element_type > inputVector)
Constructor.
iterator end()
end Iterator
Definition: Vector.tpp:338
reference operator()(index_type el)
Access specified element.
~Vector()
Destructor.
Definition: Vector.tpp:161
bool setName(const std::string &newName)
Change the name of the Variable.
Definition: Vector.tpp:254
VariableType
Define the type of variable.
ValueType
The list of types for an element of a certain variable type.
Utility metafunction to get the ValueType from a given primitive type.