3 #include <ossia/detail/config.hpp>
5 #include <ossia/detail/apply.hpp>
6 #include <ossia/detail/flat_map.hpp>
8 #include <ossia/editor/state/detail/state_execution_visitor.hpp>
10 #include <ossia/network/base/parameter.hpp>
11 #include <ossia/network/dataspace/dataspace_variant_visitors.hpp>
13 #include <ossia/network/dataspace/detail/dataspace_convert.hpp>
14 #include <ossia/network/dataspace/detail/dataspace_merge.hpp>
15 #include <ossia/network/dataspace/detail/dataspace_parse.hpp>
16 #include <ossia/network/dataspace/detail/list_units.hpp>
17 #include <ossia/network/dataspace/detail/make_unit.hpp>
18 #include <ossia/network/dataspace/detail/make_value.hpp>
19 #include <ossia/network/dataspace/value_with_unit.hpp>
23 #include <ossia/detail/hash.hpp>
24 #include <ossia/detail/hash_map.hpp>
29 struct hash<std::pair<ossia::net::parameter_base*, ossia::unit_t>>
34 std::size_t operator()(
const T& t)
39 std::size_t operator()() {
return ossia::unit_variant::npos; }
42 operator()(
const std::pair<ossia::net::parameter_base*, ossia::unit_t>& k)
const
45 ossia::hash_combine(seed, k.first);
46 ossia::hash_combine(seed, k.second.v.which());
47 auto res = ossia::apply(vis{}, k.second.v);
48 ossia::hash_combine(seed, res);
72 OSSIA_EXPORT
friend bool operator==(
const state& lhs,
const state& rhs);
73 OSSIA_EXPORT
friend bool operator!=(
const state& lhs,
const state& rhs);
75 auto begin() {
return m_children.begin(); }
76 auto end() {
return m_children.end(); }
77 auto begin()
const {
return m_children.begin(); }
78 auto end()
const {
return m_children.end(); }
79 auto cbegin()
const {
return m_children.cbegin(); }
80 auto cend()
const {
return m_children.cend(); }
82 auto& children()
const {
return m_children; }
84 std::size_t size()
const {
return m_children.size(); }
86 bool empty()
const {
return m_children.empty(); }
90 for(
auto&
state : m_children)
92 ossia::apply(state_execution_visitor{}, std::move(
state.second));
102 m_children[std::make_pair(&e.dest.value.get(), e.get_unit())] = e;
107 m_children[std::make_pair(&e.dest.value.get(), e.get_unit())] = std::move(e);
109 void add(
const ossia::piecewise_message& e)
112 m_children[std::make_pair(&e.address.get(), e.get_unit())] = e;
114 template <std::
size_t N>
115 void add(piecewise_vec_message<N>&& e)
118 m_children[std::make_pair(&e.address.get(), e.get_unit())] = std::move(e);
120 template <std::
size_t N>
121 void add(
const piecewise_vec_message<N>& e)
124 m_children[std::make_pair(&e.address.get(), e.get_unit())] = e;
134 return add(*
static_cast<const ossia::piecewise_message*
>(e.target()));
136 return add(*
static_cast<const ossia::piecewise_vec_message<2>*
>(e.target()));
138 return add(*
static_cast<const ossia::piecewise_vec_message<3>*
>(e.target()));
140 return add(*
static_cast<const ossia::piecewise_vec_message<4>*
>(e.target()));
143 throw std::runtime_error(
"there shouldn't be a state here");
154 return add(std::move(*
static_cast<ossia::piecewise_message*
>(e.target())));
157 std::move(*
static_cast<ossia::piecewise_vec_message<2>*
>(e.target())));
160 std::move(*
static_cast<ossia::piecewise_vec_message<3>*
>(e.target())));
163 std::move(*
static_cast<ossia::piecewise_vec_message<4>*
>(e.target())));
166 throw std::runtime_error(
"there shouldn't be a state here");
173 return m_children.find({&e.dest.value.get(), e.get_unit()});
175 auto find(
const piecewise_message& e)
177 return m_children.find({&e.address.get(), e.get_unit()});
179 template <std::
size_t N>
180 auto find(
const piecewise_vec_message<N>& e)
182 return m_children.find({&e.address.get(), e.get_unit()});
187 m_children.erase(std::make_pair(&e.dest.value.get(), e.get_unit()));
190 void remove(
const ossia::piecewise_message& e)
192 m_children.erase(std::make_pair(&e.address.get(), e.get_unit()));
195 using map_t = ossia::hash_map<
196 std::pair<ossia::net::parameter_base*, ossia::unit_t>,
state_element>;
197 using iterator = map_t::iterator;
198 using const_iterator = map_t::const_iterator;
199 void remove(iterator it) { m_children.erase(it); }
200 void remove(const_iterator it) { m_children.erase(it); }
202 template <std::
size_t N>
203 void remove(
const ossia::piecewise_vec_message<N>& e)
205 m_children.erase(std::make_pair(&e.address.get(), e.get_unit()));
208 void reserve(std::size_t n) { m_children.reserve(n); }
209 void clear() { m_children.clear(); }
217 return iterator->second;
The flat_state class.
Definition: flat_state.hpp:70
The state class.
Definition: editor/state/state.hpp:25
void launch(state_element &e)
launch Launch a state_element
Definition: state_element.cpp:18
ossia::nullable_variant< message, state, piecewise_message, piecewise_vec_message< 2 >, piecewise_vec_message< 3 >, piecewise_vec_message< 4 > > state_element
Definition: state_element_fwd.hpp:28
The message struct.
Definition: message.hpp:29