OSSIA
Open Scenario System for Interactive Application
message.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
5 #include <ossia/network/value/value.hpp>
6 
7 #include <bitset>
8 #include <memory>
9 #include <utility>
10 
14 namespace ossia
15 {
16 namespace net
17 {
18 class parameter_base;
19 }
28 struct OSSIA_EXPORT message
29 {
30  ossia::destination dest;
31  ossia::value message_value;
32 
33  const ossia::unit_t& get_unit() const { return dest.unit; }
34  void launch();
35 
36  friend bool operator==(const message& lhs, const message& rhs)
37  {
38  return lhs.dest == rhs.dest && lhs.message_value == rhs.message_value;
39  }
40 
41  friend bool operator!=(const message& lhs, const message& rhs)
42  {
43  return lhs.dest != rhs.dest || lhs.message_value != rhs.message_value;
44  }
45 
46  message() = delete;
47  message(const message&) = default;
48  message(message&&) = default;
49  message& operator=(const message&) = default;
50  message& operator=(message&&) = default;
51 
52  message(const destination& d, const ossia::value& v)
53  : dest{d}
54  , message_value{v}
55  {
56  }
57  message(const destination& d, ossia::value&& v)
58  : dest{d}
59  , message_value{std::move(v)}
60  {
61  }
62  message(const destination& d, const ossia::value& v, const ossia::unit_t& u)
63  : dest{d.value, d.index, u}
64  , message_value{v}
65  {
66  }
67  message(const destination& d, ossia::value&& v, const ossia::unit_t& u)
68  : dest{d.value, d.index, u}
69  , message_value{std::move(v)}
70  {
71  }
72 };
73 
74 struct OSSIA_EXPORT piecewise_message
75 {
76  std::reference_wrapper<ossia::net::parameter_base> address;
77  std::vector<ossia::value> message_value;
78  ossia::unit_t unit;
79 
80  const ossia::unit_t& get_unit() const { return unit; }
81  void launch();
82 
83  friend bool operator==(const piecewise_message& lhs, const piecewise_message& rhs)
84  {
85  return &lhs.address.get() == &rhs.address.get()
86  && lhs.message_value == rhs.message_value && lhs.unit == rhs.unit;
87  }
88 
89  friend bool operator!=(const piecewise_message& lhs, const piecewise_message& rhs)
90  {
91  return &lhs.address.get() != &rhs.address.get()
92  || lhs.message_value != rhs.message_value || lhs.unit != rhs.unit;
93  }
94 };
95 
96 template <std::size_t N>
97 struct piecewise_vec_message
98 {
99  std::reference_wrapper<ossia::net::parameter_base> address;
100  std::array<float, N> message_value;
101  ossia::unit_t unit;
102  std::bitset<N> used_values; // True for each value that has been set.
103 
104  const ossia::unit_t& get_unit() const { return unit; }
105  void launch();
106 
107  friend bool
108  operator==(const piecewise_vec_message& lhs, const piecewise_vec_message& rhs)
109  {
110  return &lhs.address.get() == &rhs.address.get()
111  && lhs.message_value == rhs.message_value && lhs.unit == rhs.unit
112  && lhs.used_values == rhs.used_values;
113  }
114 
115  friend bool
116  operator!=(const piecewise_vec_message& lhs, const piecewise_vec_message& rhs)
117  {
118  return &lhs.address.get() != &rhs.address.get()
119  || lhs.message_value != rhs.message_value || lhs.unit != rhs.unit
120  || lhs.used_values != rhs.used_values;
121  }
122 };
123 }
The value class.
Definition: value.hpp:173
Definition: git_info.h:7
void launch(state_element &e)
launch Launch a state_element
Definition: state_element.cpp:18
The message struct.
Definition: message.hpp:29
Definition: dataspace.hpp:24