2#include <ossia/detail/for_each.hpp>
4#include <ossia/detail/string_view.hpp>
5#include <ossia/network/dataspace/dataspace.hpp>
6#include <ossia/network/dataspace/dataspace_parse.hpp>
8#include <ossia/network/dataspace/detail/dataspace_list.hpp>
12using unit_map = string_view_map<ossia::unit_t>;
14template <
typename Arg,
typename... Args>
15struct unit_map_factory
17 void operator()(unit_map& m)
19 for(std::string_view v :
ossia::unit_traits<Arg>::text())
20 m.emplace(v,
ossia::unit_t{Arg{}});
21 unit_map_factory<Args...>{}(m);
25template <
typename Arg>
26struct unit_map_factory<Arg>
28 void operator()(unit_map& m)
30 for(std::string_view v :
ossia::unit_traits<Arg>::text())
31 m.emplace(v,
ossia::unit_t{Arg{}});
35template <
typename... Args>
41 unit_map_factory<Args...>{}(map);
46struct unit_factory_visitor
48 std::string_view text;
50 template <
typename Dataspace_T>
53 static const auto units = boost::mp11::mp_rename<
54 typename matching_unit_u_list<Dataspace_T>::type, make_unit_map>{}();
55 auto it = units.find(text);
62template <
typename Unit>
63using enable_if_multidimensional = std::enable_if_t<Unit::is_multidimensional::value>;
65template <
typename Dataspace,
typename Unit,
typename =
void>
66struct make_unit_symbols_sub_helper
68 void operator()(unit_parse_symbols_t& map)
70 using unit_type = Unit;
75 for(
auto ds : dataspace_traits<Dataspace>::text())
78 for(
auto un : unit_traits<unit_type>::text())
82 res.append(ds.data(), ds.size());
85 res.append(un.data(), un.size());
88 map.add(res, {{}, unit_type{}});
94template <
typename Dataspace,
typename Unit>
95struct make_unit_symbols_sub_helper<Dataspace, Unit, enable_if_multidimensional<Unit>>
97 void operator()(unit_parse_symbols_t& map)
99 using unit_type = Unit;
104 for(
auto ds : dataspace_traits<Dataspace>::text())
107 for(
auto un : unit_traits<unit_type>::text())
111 res.append(ds.data(), ds.size());
114 res.append(un.data(), un.size());
117 map.add(res, {{}, unit_type{}});
122 const auto& params = unit_type::array_parameters();
123 const auto n = params.size();
124 for(std::size_t i = 0; i < n; i++)
127 res[res.size() - 1] = params[i];
128 map.add(res, {{(uint8_t)i}, unit_type{}});
135struct make_unit_symbols_helper
137 unit_parse_symbols_t map;
139 make_unit_symbols_helper()
141 ossia::for_each_tagged(dataspace_u_list{}, [&](
auto t) {
142 using dataspace_type =
typename decltype(t)::type;
143 ossia::for_each_tagged(dataspace_type{}, [&](
auto u) {
144 using unit_type =
typename decltype(u)::type;
145 make_unit_symbols_sub_helper<dataspace_type, unit_type>{}(map);
Definition transitive_closure.hpp:27
Definition dataspace.hpp:24