OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
dataspace_text.hpp
1#pragma once
2#include <ossia/detail/for_each.hpp>
3#include <ossia/detail/hash_map.hpp>
4#include <ossia/network/dataspace/dataspace.hpp>
5#include <ossia/network/dataspace/detail/dataspace_list.hpp>
6
7namespace ossia::detail
8{
9
10struct unit_text_visitor
11{
12 OSSIA_INLINE std::string_view operator()(const angle_u& dataspace)
13 {
14 return ossia::apply(*this, dataspace);
15 }
16 OSSIA_INLINE std::string_view operator()(const color_u& dataspace)
17 {
18 return ossia::apply(*this, dataspace);
19 }
20 OSSIA_INLINE std::string_view operator()(const distance_u& dataspace)
21 {
22 return ossia::apply(*this, dataspace);
23 }
24 OSSIA_INLINE std::string_view operator()(const gain_u& dataspace)
25 {
26 return ossia::apply(*this, dataspace);
27 }
28 OSSIA_INLINE std::string_view operator()(const position_u& dataspace)
29 {
30 return ossia::apply(*this, dataspace);
31 }
32 OSSIA_INLINE std::string_view operator()(const orientation_u& dataspace)
33 {
34 return ossia::apply(*this, dataspace);
35 }
36 OSSIA_INLINE std::string_view operator()(const speed_u& dataspace)
37 {
38 return ossia::apply(*this, dataspace);
39 }
40 OSSIA_INLINE std::string_view operator()(const timing_u& dataspace)
41 {
42 return ossia::apply(*this, dataspace);
43 }
44
45 template <typename Unit>
46 OSSIA_INLINE std::string_view operator()(Unit)
47 {
48 constexpr_return(ossia::unit_traits<Unit>::text()[0]);
49 }
50
51 OSSIA_INLINE std::string_view operator()(const ossia::value&) { return {}; }
52
53 OSSIA_INLINE std::string_view operator()() { return {}; }
54};
55
56struct unit_accessor_visitor
57{
58 OSSIA_INLINE std::string_view operator()(const angle_u& dataspace) { return {}; }
59 OSSIA_INLINE std::string_view operator()(const color_u& dataspace)
60 {
61 return ossia::apply(*this, dataspace);
62 }
63 OSSIA_INLINE std::string_view operator()(const distance_u& dataspace) { return {}; }
64 OSSIA_INLINE std::string_view operator()(const gain_u& dataspace) { return {}; }
65 OSSIA_INLINE std::string_view operator()(const position_u& dataspace)
66 {
67 return ossia::apply(*this, dataspace);
68 }
69 OSSIA_INLINE std::string_view operator()(const orientation_u& dataspace)
70 {
71 return ossia::apply(*this, dataspace);
72 }
73 OSSIA_INLINE std::string_view operator()(const speed_u& dataspace) { return {}; }
74 OSSIA_INLINE std::string_view operator()(const timing_u& dataspace) { return {}; }
75
76 template <typename Unit>
77 OSSIA_INLINE std::string_view operator()(Unit)
78 {
79 return Unit::array_parameters();
80 }
81
82 OSSIA_INLINE std::string_view operator()() { return {}; }
83};
84
85struct dataspace_text_visitor
86{
87 template <typename Dataspace>
88 OSSIA_INLINE std::string_view operator()(const Dataspace& dataspace)
89 {
90 constexpr_return(ossia::dataspace_traits<Dataspace>::text()[0]);
91 }
92
93 OSSIA_INLINE std::string_view operator()() { return {}; }
94};
95
96using unit_pretty_text_map = ossia::hash_map<ossia::unit_t, std::string>;
97template <typename Dataspace, typename Unit>
98std::string make_pretty_unit_text()
99{
100 using unit_type = Unit;
101
102 std::string res;
103 res.reserve(20);
104
105 constexpr auto ds = dataspace_traits<Dataspace>::text()[0];
106 constexpr auto un = unit_traits<unit_type>::text()[0];
107
108 res.append(ds.data(), ds.size()); // color
109 res += '.'; // color.
110
111 res.append(un.data(), un.size()); // color.rgb
112
113 return res;
114}
115
116struct unit_pretty_texts
117{
118 unit_pretty_text_map map;
119
120 unit_pretty_texts()
121 {
122 ossia::for_each_tagged(dataspace_u_list{}, [&](auto t) {
123 using dataspace_type = typename decltype(t)::type;
124 using dataspace_t = typename matching_unit_u_list<dataspace_type>::type;
125 map[dataspace_t{}] = dataspace_traits<dataspace_type>::text()[0];
126 ossia::for_each_tagged(dataspace_type{}, [&](auto u) {
127 using unit_type = typename decltype(u)::type;
128 map[unit_type{}] = make_pretty_unit_text<dataspace_type, unit_type>();
129 });
130 });
131 }
132};
133
134}
The value class.
Definition value.hpp:173
Definition transitive_closure.hpp:27