5#ifndef LINE_API_SN_SN_FIELD_VIEW_H
6#define LINE_API_SN_SN_FIELD_VIEW_H
47 std::string
kind =
"opaque";
57 std::map<char, double>
dims;
58 std::map<std::string, SnFieldView>
fields;
76template <
class X,
class =
void>
77struct is_container : std::false_type {};
79struct is_container<X, std::void_t<typename X::value_type, decltype(std::declval<const X&>().begin()),
80 decltype(std::declval<const X&>().size())>> : std::true_type {};
82struct is_map : std::false_type {};
83template <
class K,
class V,
class C,
class A>
84struct is_map<std::map<K, V, C, A>> : std::true_type {};
86struct is_function : std::false_type {};
88struct is_function<std::function<S>> : std::true_type {};
90struct is_matrix : std::false_type {};
92struct is_matrix<Matrix<U>> : std::true_type {};
100long element_extent(
const X& x) {
101 if constexpr (is_matrix<X>::value || is_map<X>::value || is_function<X>::value ||
102 std::is_same<X, std::string>::value ||
103 (is_container<X>::value && !std::is_same<X, std::string>::value)) {
116 if constexpr (detail::is_matrix<X>::value) {
119 v.
rows =
static_cast<long>(x.rows());
120 v.
cols =
static_cast<long>(x.cols());
121 v.
empty = x.rows() == 0 || x.cols() == 0;
122 }
else if constexpr (std::is_same<X, std::string>::value) {
125 }
else if constexpr (detail::is_function<X>::value) {
127 v.
empty = !
static_cast<bool>(x);
128 }
else if constexpr (detail::is_map<X>::value) {
131 v.
rows =
static_cast<long>(x.size());
133 for (
const auto& kv : x) {
134 v.
elems.push_back(detail::element_extent(kv.second));
136 }
else if constexpr (detail::is_container<X>::value) {
139 v.
rows =
static_cast<long>(x.size());
140 v.
empty = x.size() == 0;
141 for (
const auto& e : x) {
142 using E =
typename std::decay<
decltype(e)>::type;
143 v.
elems.push_back(detail::element_extent(
static_cast<const E&
>(e)));
145 }
else if constexpr (std::is_arithmetic<X>::value || std::is_enum<X>::value) {
154template <
class R,
class F>
158 v.
rows =
static_cast<long>(records.size());
161 for (
const auto& r : records) {
176 if (v.
kind ==
"scalar") {
177 v.
empty = records.empty();
185 return {{
'M',
static_cast<double>(
sn.nstations)}, {
'K',
static_cast<double>(
sn.nclasses)},
186 {
'N',
static_cast<double>(
sn.nof_nodes())}, {
'S',
static_cast<double>(
sn.nof_stateful())},
187 {
'C',
static_cast<double>(
sn.nchains)}, {
'R',
static_cast<double>(
sn.regions.size())}};
A network plus its refreshed NetworkStruct.
Dense matrix and non-owning view.
SnFieldView sn_field_view(const X &x)
The view of one value; the kind follows its C++ type.
SnFieldView sn_field_rows(const std::vector< R > &records, F member)
One field made of a member of every record (Station, JobClass, NodeDef), in record order.
constexpr long kEmptyExtent
long sn_view_extent(const SnFieldView &v)
The 1-D extent of a field view: a container's size, a vector Matrix's length.
std::map< char, double > sn_contract_dims(const qn::NetworkStruct< T > &sn)
The dimensions the contract's shapes are written in.
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
int ndim
0 scalar-like, 1 container, 2 Matrix
std::vector< long > elems
per-element 1-D extent of a container
long rows
Matrix rows, container size.
The view of a whole struct: its dimensions and one view per contract field, by MATLAB name.
std::map< char, double > dims
std::map< std::string, SnFieldView > fields