OSSIA
Open Scenario System for Interactive Application
outbound_visitor.hpp
1 #pragma once
2 #include <ossia/network/dataspace/color.hpp>
3 #include <ossia/network/value/value.hpp>
4 
5 #include <oscpack/osc/OscOutboundPacketStream.h>
6 namespace oscpack
7 {
8 class OutboundPacketStream;
9 }
10 namespace ossia::oscquery
11 {
12 struct osc_outbound_visitor
13 {
14 public:
15  explicit osc_outbound_visitor(oscpack::OutboundPacketStream& stream)
16  : p{stream}
17  {
18  }
19 
20  oscpack::OutboundPacketStream& p;
21  void operator()(impulse) const
22  {
23  if(m_depth > 0)
24  p << oscpack::Infinitum();
25  }
26 
27  void operator()(int32_t i) const { p << i; }
28 
29  void operator()(float f) const { p << f; }
30 
31  void operator()(bool b) const { p << b; }
32 
33  void operator()(char c) const { p << c; }
34 
35  void operator()(const std::string& str) const { p << std::string_view{str}; }
36 
37  void operator()(vec2f vec) const
38  {
39  if(m_depth > 0)
40  {
41  p << oscpack::BeginArray();
42  }
43 
44  p << vec[0] << vec[1];
45 
46  if(m_depth > 0)
47  {
48  p << oscpack::EndArray();
49  }
50  }
51 
52  void operator()(vec3f vec) const
53  {
54  if(m_depth > 0)
55  {
56  p << oscpack::BeginArray();
57  }
58 
59  p << vec[0] << vec[1] << vec[2];
60 
61  if(m_depth > 0)
62  {
63  p << oscpack::EndArray();
64  }
65  }
66 
67  void operator()(vec4f vec) const
68  {
69  if(m_depth > 0)
70  {
71  p << oscpack::BeginArray();
72  }
73 
74  p << vec[0] << vec[1] << vec[2] << vec[3];
75 
76  if(m_depth > 0)
77  {
78  p << oscpack::EndArray();
79  }
80  }
81 
82  void operator()(const std::vector<value>& t) const
83  {
84  if(m_depth > 0)
85  {
86  p << oscpack::BeginArray();
87  }
88 
89  m_depth++;
90  for(const auto& val : t)
91  {
92  val.apply(*this);
93  }
94  m_depth--;
95 
96  if(m_depth > 0)
97  {
98  p << oscpack::EndArray();
99  }
100  }
101 
102  void operator()(const value_map_type& t) const { }
103 
104  template <typename T, typename U>
105  void operator()(const T& t, const U& u) const
106  {
107  (*this)(t);
108  }
109 
110  void operator()(const vec4f& t, const ossia::rgba8_u& u) const
111  {
112  uint32_t r = (uint32_t)t[0] << 24;
113  uint32_t g = (uint32_t)t[1] << 16;
114  uint32_t b = (uint32_t)t[2] << 8;
115  uint32_t a = (uint32_t)t[3];
116  p << oscpack::RgbaColor(r + g + b + a);
117  }
118 
119  void operator()() const { }
120 
121 private:
122  mutable int m_depth = 0;
123 };
124 }