1#ifndef NGEN_IO_MDFRAME_VARIABLE_HPP
2#define NGEN_IO_MDFRAME_VARIABLE_HPP
6#include "dimension.hpp"
7#include <initializer_list>
10#include "visitors.hpp"
23template<
typename... SupportedTypes>
40 using mdarray_variant =
typename types::template variant_container<ngen::mdarray>;
49 return std::hash<std::string>{}(v.m_name);
72 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
79 std::vector<size_type> dsizes;
82 dsizes.push_back(d.size());
96 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
109 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
112 this->
m_data = std::move(data);
125 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
128 return boost::get<mdarray<T>>(this->
m_data);
151 const std::string&
name() const noexcept {
161 std::vector<std::string> names;
164 names.push_back(dim.name());
201 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
202 void insert(boost::span<const size_type> index, T value)
205 auto visitor = std::bind(
207 std::placeholders::_1,
212 boost::apply_visitor(visitor, this->
m_data);
227 auto visitor = std::bind(
229 std::placeholders::_1,
233 return boost::apply_visitor(visitor, this->
m_data);
236 template<
typename T,
typename types::
template enable_if_supports<T,
bool> =
true>
237 T
at(boost::span<const size_type> index)
239 auto visitor = std::bind(
241 std::placeholders::_1,
246 T value = boost::get<T>(result);
250 boost::span<const size_type>
shape() const noexcept
Definition mdarray.hpp:13
Definition DomainLayer.hpp:9
Dimension Key.
Definition dimension.hpp:19
Definition variable.hpp:46
static std::size_t apply(const variable &d) noexcept
Definition variable.hpp:52
std::size_t operator()(const variable &v) const noexcept
Definition variable.hpp:47
Variable Key.
Definition variable.hpp:24
T at(boost::span< const size_type > index)
Definition variable.hpp:237
variable & set_data(mdarray< T > &&data)
Assign an mdarray to this variable.
Definition variable.hpp:110
variable() noexcept
Constructs an empty variable.
Definition variable.hpp:61
void insert(boost::span< const size_type > index, T value)
Construct and insert a mdvalue into the backing mdarray.
Definition variable.hpp:202
bool operator==(const variable &rhs) const
Equality operator to check equality between two variables.
Definition variable.hpp:141
typename types::variant_scalar element_type
Definition variable.hpp:42
static variable make(const std::string &name, const std::vector< dimension > &dimensions)
Constructs a named variable spanned over the given dimensions.
Definition variable.hpp:73
size_type size() const noexcept
Get the size of this variable.
Definition variable.hpp:177
element_type at(const boost::span< const size_type > index)
Access value at a given index.
Definition variable.hpp:225
std::vector< std::string > dimensions() const noexcept
Get the names of all dimensions associated with this variable.
Definition variable.hpp:160
variable & set_data(const mdarray< T > &data)
Assign an mdarray to this variable.
Definition variable.hpp:97
typename types::template variant_container< ngen::mdarray > mdarray_variant
A boost::variant type consisting of mdarrays of the support types, i.e.
Definition variable.hpp:40
const mdarray_variant & values() const noexcept
Get the values of this variable.
Definition variable.hpp:120
std::string m_name
Definition variable.hpp:257
boost::span< const size_type > shape() const noexcept
Definition variable.hpp:250
std::size_t size_type
Definition variable.hpp:25
mdarray_variant m_data
Definition variable.hpp:260
const std::string & name() const noexcept
Get the name of this variable.
Definition variable.hpp:151
size_type rank() const noexcept
Get the rank of this variable.
Definition variable.hpp:188
const mdarray< T > & values() const noexcept
Definition variable.hpp:126
std::vector< dimension > m_dimensions
Definition variable.hpp:263
mdarray visitor for indexed access
Definition visitors.hpp:73
mdarray visitor for inserting a value
Definition visitors.hpp:57
mdarray visitor for retrieving the rank of the mdarray
Definition visitors.hpp:31
mdarray visitor for retrieving the shape of the mdarray
Definition visitors.hpp:44
mdarray visitor for retrieving the size of the mdarray
Definition visitors.hpp:18
boost::variant< Ts... > variant_scalar
Provides a type alias for a boost::variant containing the types of this type list.
Definition traits.hpp:71