8#ifndef MATIOCPP_STRUCTARRAYELEMENT_TPP 
    9#define MATIOCPP_STRUCTARRAYELEMENT_TPP 
   11template <
bool isConst>
 
   19template <
bool isConst>
 
   21    : m_innerIndex(
other.m_innerIndex)
 
   22    , m_array(
other.m_array)
 
 
   27template <
bool isConst>
 
   28template<
bool B, 
typename >
 
   30    : m_innerIndex(
other.m_innerIndex)
 
   31    , m_array(
other.m_array)
 
   33    static_assert (!
B && 
isConst, 
"This constructor is meant to be used to obtain a const element from a non const one.");
 
 
   37template <
bool isConst>
 
   39    : m_innerIndex(
other.m_innerIndex)
 
   40    , m_array(
other.m_array)
 
 
   45template <
bool isConst>
 
   46template<
bool B, 
typename >
 
   48    : m_innerIndex(
other.m_innerIndex)
 
   49    , m_array(
other.m_array)
 
   51    static_assert (!
B && 
isConst, 
"This constructor is meant to be used to obtain a const element from a non const one.");
 
 
   55template <
bool isConst>
 
   58    m_innerIndex = 
other.m_innerIndex;
 
   59    m_array = 
other.m_array;
 
 
   64template <
bool isConst>
 
   65template<
bool B, 
typename >
 
   68    static_assert (!
B && 
isConst, 
"This operator is meant to be used to obtain a const element from a non const one.");
 
   70    m_innerIndex = 
other.m_innerIndex;
 
   71    m_array = 
other.m_array;
 
 
   76template <
bool isConst>
 
   77template<
bool B, 
typename >
 
   80    static_assert (!
B && 
isConst, 
"This operator is meant to be used to obtain a const element from a non const one.");
 
   82    bool ok = m_array->setElement(m_innerIndex, 
other);
 
   83    assert(
ok && 
"Failed to set the specified element to the input struct.");
 
 
   89template <
bool isConst>
 
   90template<
bool B, 
typename >
 
   93    static_assert ((
B == 
isConst) && !
B, 
"This method can be used only if the the element is not const.");
 
   97    if (m_array->numberOfFields() != elements.
size())
 
   99        std::cerr << 
"[ERROR][matioCpp::StructArrayElement::fromVectorOfVariables] The input vector is supposed to have size equal to the number of fields of the struct array." <<
std::endl;
 
  103    for (
size_t i = 0; 
i < m_array->numberOfFields(); ++
i)
 
  107            std::cerr << 
"[ERROR][matioCpp::StructArrayElement::operator=] The name " << elements[
i].name().c_str() << 
" of the input vector of variables at position " 
  109                      << 
". Cannot insert in a struct array a new field in a single element." <<
std::endl;
 
 
  124template <
bool isConst>
 
  127    return m_array->numberOfFields();
 
 
  130template <
bool isConst>
 
  133    return m_array->fields();
 
 
  136template <
bool isConst>
 
  139    return m_array->isFieldExisting(
field);
 
 
  142template <
bool isConst>
 
  145    return m_array->getFieldIndex(
field);
 
 
  148template <
bool isConst>
 
  149template<
bool B, 
typename >
 
  152    static_assert ((
B == 
isConst) && !
B, 
"This method can be used only if the the element is not const.");
 
  154    assert(index < numberOfFields() && 
"The index is out of bounds.");
 
  157        std::cerr << 
"[ERROR][matioCpp::StructArrayElement::setField] The input variable is not valid." << 
std::endl;
 
  161    return m_array->setStructField(index, 
newValue, m_innerIndex);
 
 
  164template <
bool isConst>
 
  165template<
bool B, 
typename >
 
  168    static_assert ((
B == 
isConst) && !
B, 
"This method can be used only if the the element is not const.");
 
  170    size_t index = getFieldIndex(
field);
 
  171    if (index == numberOfFields())
 
 
  180template <
bool isConst>
 
  181template<
bool B, 
typename >
 
  184    static_assert ((
B == 
isConst) && !
B, 
"This method can be used only if the the element is not const.");
 
 
  189template <
bool isConst>
 
  192    return m_array->getStructArrayElement(m_innerIndex);
 
 
  195template <
bool isConst>
 
  198    assert(
el < numberOfFields() && 
"The specified index is out of bounds");
 
  199    return m_array->getStructField(
el, m_innerIndex);
 
 
  202template <
bool isConst>
 
  205    size_t index = getFieldIndex(
el);
 
  206    assert(index < numberOfFields() && 
"The specified field does not exist.");
 
  207    return m_array->getStructField(index, m_innerIndex);
 
 
  210template <
bool isConst>
 
  213    assert(
el < numberOfFields() && 
"The specified index is out of bounds");
 
  214    return m_array->getStructField(
el, m_innerIndex);
 
 
  217template <
bool isConst>
 
  220    size_t index = getFieldIndex(
el);
 
  221    assert(index < numberOfFields() && 
"The specified field does not exist.");
 
  222    return m_array->getStructField(index, m_innerIndex);
 
 
MultiDimensionalArray is a particular type of Variable specialized for multidimensional arrays of a g...
 
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()=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.
 
StructArrayElement & operator=(const StructArrayElement &other)=delete
Deleted copy assignement since it is not clear whether the index or the content have to be copied.
 
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.
 
The matioCpp::Variable class is the equivalent of matvar_t in matio.
 
bool setStructField(size_t index, const Variable &newValue, size_t structPositionInArray=0)
Set the field of the struct at the specified position.
 
char *const * getStructFields() const
Get the list of fields in the variable, considered as a struct.
 
std::string name() const
Get the name of the Variable.
 
bool isValid() const
Check if the variable is valid.
 
void unused(Args &&...)
Utility metafunction to avoid compiler warnings about unused variables.