8 #ifndef MATIOCPP_VECTOR_TPP
9 #define MATIOCPP_VECTOR_TPP
14 size_t dimensions[] = {1,
static_cast<size_t>(inputVector.size())};
25 std::cerr <<
"[matioCpp::Vector::checkCompatibility] The variable type is not compatible with a vector." <<
std::endl;
29 if (inputPtr->isComplex)
31 std::cerr <<
"[matioCpp::Vector::checkCompatibility] Cannot use a complex variable into a non-complex one." <<
std::endl;
35 if (!matioCpp::is_convertible_to_primitive_type<T>(valueType))
42 std::cerr <<
"[matioCpp::Vector::checkCompatibility] The value type is not convertible to " <<
43 get_type<T>::toString() <<
"." <<
std::endl <<
44 " Input class type: " << classType <<
std::endl <<
45 " Input data type: " << dataType <<
std::endl;
60 size_t dimensions[] = {1, 0};
76 for (
size_t i = 0; i < name.
size(); ++i)
82 size_t dimensions[] = {1,
static_cast<size_t>(name.
size())};
100 size_t dimensionsVec[] = {1, dimensions};
110 template<
typename,
typename>
113 initializeVector(name, inputVector);
116 template <
typename T>
122 "The assignement operator from a string is available only if the type of the vector is char, char16_t, char32_t, uint8_t, uint16_t or uint32_t.");
123 size_t dimensions[] = {1,
static_cast<size_t>(inputString.size())};
127 template <
typename T>
133 this->operator=(inputVector);
183 if (size() == other.size())
189 bool ok = initializeVector(name(), other);
190 assert(ok &&
"Failed to resize.");
202 "The assignement operator from a string is available only if the type of the vector is char, char16_t, char32_t, uint8_t, uint16_t or uint32_t.");
203 if (size() == other.size())
205 memcpy(toMatio()->data, other.data(), size() *
sizeof(T));
209 size_t dimensions[] = {1,
static_cast<size_t>(other.size())};
221 if (size() != other.
size())
227 assert(
false &&
"Failed to resize.");
232 for (
size_t i = 0; i < size(); ++i)
234 this->operator()(i) = other[i];
256 return changeName(newName);
263 assert(this->dimensions().size() == 2);
265 return std::min(this->dimensions()[0], this->dimensions()[1]) > 0 ?
std::max(this->dimensions()[0], this->dimensions()[1]) : 0;
271 if (newSize != size())
275 this->operator=(newVector);
315 "The operator () to convert to a string is available only if the type of the vector is a char type or uint type.");
322 return this->operator()(el);
328 return this->operator()(el);
ValueType valueType() const
Get the value type of the pointer.
virtual matvar_t * get() const =0
Get the shared matvar_t pointer.
VariableType variableType() const
Get the variable type of the pointer.
The matioCpp::Variable class is the equivalent of matvar_t in matio.
matioCpp::Vector< T > asVector()
Cast the variable as a Vector.
Vector is a particular type of Variable specialized for 1-D arrays of a generic type T.
matioCpp::Span< element_type > toSpan()
Get this Vector as a Span.
size_t index_type
Defines how to allocate T.
pointer data()
Direct access to the underlying array.
index_type size() const
Get the size of the vector.
Vector< T > & operator=(const Vector< T > &other)
Assignement operator (copy) from another Vector.
reverse_iterator rend()
rend Iterator to the element following the last element of the reversed vector.
const_reverse_iterator crend() const
crend Iterator to the element following the last element of the reversed vector.
std::remove_cv_t< element_type > value_type
Defines the type of an element of the Vector.
element_type & reference
The type used for indices.
typename get_type< T >::type element_type
Defines the type specified in the template.
typename std::allocator_traits< std::allocator< element_type > >::const_pointer const_pointer
The pointer type.
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.
reverse_iterator rbegin()
rbegin Iterator to the first element of the reversed vector
Vector()
The output type of the conversion to string.
iterator begin()
begin Iterator
void clear()
Clear the vector.
string_output_type operator()() const
Get the Vector as a string.
const_iterator cbegin() const
cbegin Iterator
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.
typename std::allocator_traits< std::allocator< element_type > >::pointer pointer
The reference type.
void resize(index_type newSize)
Resize the vector.
const_reverse_iterator crbegin() const
crbegin Iterator to the first element of the reversed vector
const_iterator cend() const
cend Iterator
iterator end()
end Iterator
bool setName(const std::string &newName)
Change the name of the Variable.
MATIOCPP_CONSTEXPR Span< ElementType > make_span(ElementType *ptr, typename Span< ElementType >::index_type count)
VariableType
Define the type of variable.
ValueType
The list of types for an element of a certain variable type.
bool get_types_names_from_matvart(const matvar_t *input, std::string &classType, std::string &dataType)
Get the type names from the input pointer.
Utility metafunction to get the ValueType from a given primitive type.
Utility meta-function to check if a type is compatible with a std::u16string.
Utility meta-function to check if a type is compatible with a std::u32string.
Utility meta-function to check if a type is compatible with a std::string.