OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
value_set_domain.hpp
1#pragma once
4
5namespace ossia
6{
7
8template <typename T>
9struct domain_base;
10
11template <typename Domain>
12struct value_set_clamp
13{
14 const Domain& domain;
15 template <typename U>
16 value operator()(bounding_mode b, U&& val)
17 {
18 const auto& values = domain.values;
19 if(b == bounding_mode::FREE || values.empty())
20 {
21 return std::forward<U>(val);
22 }
23 else
24 {
25 auto it = ossia::find(values, val);
26 return (it != values.end()) ? ossia::value{std::forward<U>(val)} : ossia::value{};
27 }
28 }
29};
30
31struct value_set_get_visitor
32{
33 template <typename T>
34 std::vector<ossia::value> operator()(const ossia::domain_base<T>& dom)
35 {
36 return std::vector<ossia::value>(dom.values.begin(), dom.values.end());
37 }
38
39 std::vector<ossia::value> operator()(const ossia::domain_base<bool>&)
40 {
41 return std::vector<ossia::value>{ossia::value{false}, ossia::value{true}};
42 }
43
44 std::vector<ossia::value> operator()(const ossia::domain_base<ossia::impulse>& dom)
45 {
46 return std::vector<ossia::value>{};
47 }
48
49 std::vector<ossia::value> operator()(const ossia::vector_domain& dom)
50 {
51 std::vector<ossia::value> v(dom.values.size());
52 for(std::size_t i = 0; i < dom.values.size(); i++)
53 {
54 v[i] = std::vector<ossia::value>(dom.values[i].begin(), dom.values[i].end());
55 }
56 return v;
57 }
58
59 template <std::size_t N>
60 std::vector<ossia::value> operator()(const ossia::vecf_domain<N>& dom)
61 {
62 std::vector<ossia::value> v(N);
63#if !defined(OSSIA_FREESTANDING)
64 for(std::size_t i = 0; i < N; i++)
65 {
66 v[i] = std::vector<ossia::value>(dom.values[i].begin(), dom.values[i].end());
67 }
68#endif
69 return v;
70 }
71};
72
73struct value_set_update_visitor
74{
75 const std::vector<ossia::value>& values;
76 template <typename T>
77 void operator()(ossia::domain_base<T>& dom)
78 {
79 dom.values.clear();
80 dom.values.reserve(values.size());
81 for(auto& value : values)
82 {
83 if(auto r = value.target<T>())
84 dom.values.push_back(*r);
85 }
86 }
87
88 void operator()(ossia::vector_domain& dom)
89 {
90 for(auto& set : dom.values)
91 {
92 set.clear();
93 for(auto& value : values)
94 {
95 dom.values[0].insert(value);
96 }
97 }
98 }
99
100 void operator()(ossia::domain_base<ossia::value>& dom)
101 {
102#if !defined(OSSIA_FREESTANDING)
103 dom.values.clear();
104 for(auto& value : values)
105 {
106 dom.values.push_back(value);
107 }
108#endif
109 }
110
111 template <std::size_t N>
112 void operator()(ossia::vecf_domain<N>& dom)
113 {
114#if !defined(OSSIA_FREESTANDING)
115 for(std::size_t i = 0; i < N; i++)
116 dom.values[i].clear();
117
118 for(auto& value : values)
119 {
120 if(auto r = value.target<float>())
121 {
122 for(std::size_t i = 0; i < N; i++)
123 {
124 dom.values[i].insert(*r);
125 }
126 }
127 }
128#endif
129 }
130
131 void operator()(ossia::domain_base<impulse>&) { }
132
133 void operator()(ossia::domain_base<bool>&) { }
134};
135}
The value class.
Definition value.hpp:173
Definition git_info.h:7
bounding_mode
Address behaviors at crossing domain boundaries.
Definition parameter_properties.hpp:56