OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
domain_base.hpp
Go to the documentation of this file.
1#pragma once
2#include <ossia/network/domain/domain_base_impl.hpp>
6namespace ossia
7{
8#include <ossia/network/domain/domain_variant_impl.hpp>
22struct OSSIA_EXPORT domain
23{
24 domain_base_variant v;
25
26 domain() noexcept { }
27
28 template <typename T>
29 domain(const ossia::domain_base<T>& arg)
30 : v(arg)
31 {
32 }
33 template <typename T>
34 domain(ossia::domain_base<T>&& arg)
35 : v(std::move(arg))
36 {
37 }
38 domain(const vector_domain& arg)
39 : v(arg)
40 {
41 }
42 domain(vector_domain&& arg)
43 : v(std::move(arg))
44 {
45 }
46 template <std::size_t N>
47 domain(const vecf_domain<N>& arg)
48 : v(arg)
49 {
50 }
51 template <std::size_t N>
52 domain(vecf_domain<N>&& arg)
53 : v(std::move(arg))
54 {
55 }
56 domain(const domain& d)
57 : v{d.v}
58 {
59 }
60 domain(domain&& d)
61 : v{std::move(d.v)}
62 {
63 }
64 domain& operator=(const domain& d)
65 {
66 v = d.v;
67 return *this;
68 }
69 domain& operator=(domain&& d)
70 {
71 v = std::move(d.v);
72 return *this;
73 }
74
75 value get_min() const;
76 value get_max() const;
77
78 operator bool() const { return bool(v); }
79 auto which() const { return v.which(); }
80
81 template <typename T>
82 OSSIA_INLINE T get_min() const
83 {
84 return get_min().get<T>();
85 }
86 template <typename T>
87 OSSIA_INLINE T get_max() const
88 {
89 return get_max().get<T>();
90 }
91
92 template <typename T>
93 std::optional<T> maybe_min() const
94 {
95 auto val = get_min();
96 auto u = val.target<T>();
97 if(u)
98 return *u;
99 else
100 return {};
101 }
102
103 template <typename T>
104 std::optional<T> maybe_max() const
105 {
106 auto val = get_max();
107 auto u = val.target<T>();
108 if(u)
109 return *u;
110 else
111 return {};
112 }
113
114 template <typename T>
115 OSSIA_INLINE T convert_min() const
116 {
117 return ossia::convert<T>(get_min());
118 }
119 template <typename T>
120 OSSIA_INLINE T convert_max() const
121 {
122 return ossia::convert<T>(get_max());
123 }
124
125 void set_min(const ossia::value& val);
126 void set_max(const ossia::value& val);
127
128 value apply(bounding_mode b, const ossia::value& val) const;
129 value apply(bounding_mode b, ossia::value&& val) const;
130
131 std::string to_pretty_string() const;
132
133 friend bool operator==(const ossia::domain& d, const ossia::domain& other)
134 {
135 return d.v == other.v;
136 }
137
138 friend bool operator!=(const ossia::domain& d, const ossia::domain& other)
139 {
140 return d.v != other.v;
141 }
142
143 template <typename T>
144 friend bool operator==(const ossia::domain& d, const T& other)
145 {
146 return d.v == other;
147 }
148 template <typename T>
149 friend bool operator!=(const ossia::domain& d, const T& other)
150 {
151 return d.v != other;
152 }
153};
154
155template <typename Functor>
156auto apply(Functor&& functor, const domain& var) -> decltype(auto)
157{
158 return ossia::apply(std::forward<Functor>(functor), var.v);
159}
160template <typename Functor>
161auto apply(Functor&& functor, domain& var) -> decltype(auto)
162{
163 return ossia::apply(std::forward<Functor>(functor), var.v);
164}
165template <typename Functor>
166auto apply(Functor&& functor, domain&& var) -> decltype(auto)
167{
168 return ossia::apply(std::forward<Functor>(functor), std::move(var.v));
169}
170template <typename Functor>
171auto apply_nonnull(Functor&& functor, const domain& var) -> decltype(auto)
172{
173 return ossia::apply_nonnull(std::forward<Functor>(functor), var.v);
174}
175template <typename Functor>
176auto apply_nonnull(Functor&& functor, domain& var) -> decltype(auto)
177{
178 return ossia::apply_nonnull(std::forward<Functor>(functor), var.v);
179}
180template <typename Functor>
181auto apply_nonnull(Functor&& functor, domain&& var) -> decltype(auto)
182{
183 return ossia::apply_nonnull(std::forward<Functor>(functor), std::move(var.v));
184}
185}
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
std::string to_pretty_string(const value_with_unit &v)
to_pretty_string Pretty string of unit & value
Definition dataspace_visitors.cpp:242
domain A domain of values
Definition domain_base.hpp:23