OSSIA
Open Scenario System for Interactive Application
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
osc_1_1_policy.hpp
1#pragma once
2#include <ossia/network/osc/detail/osc_common_policy.hpp>
3#include <ossia/network/osc/detail/osc_utils.hpp>
4#include <ossia/network/value/value.hpp>
5
6#include <boost/endian/conversion.hpp>
7
8#include <oscpack/osc/OscOutboundPacketStream.h>
9#include <oscpack/osc/OscTypes.h>
10
11// OSC 1.1 adds T, F, I, N
12namespace ossia::net
13{
14
15struct osc_1_1_outbound_array_policy : osc_common_outbound_dynamic_policy
16{
17 using osc_common_outbound_dynamic_policy::operator();
18 void operator()(impulse) const { p << oscpack::Infinitum(); }
19
20 void operator()(bool b) const { p << b; }
21
22 void operator()(char c) const { p << int32_t(c); }
23
24 // Arrays are flattened
25 void operator()(const std::vector<value>& t) const
26 {
27 for(const auto& val : t)
28 {
29 val.apply(*this);
30 }
31 }
32
33 void operator()(const value_map_type& t) const { }
34};
35
36struct osc_1_1_outbound_value_policy : osc_common_outbound_static_policy
37{
38 using osc_common_outbound_static_policy::operator();
39 std::size_t operator()(
40 char* buffer, ossia::impulse v, const ossia::extended_type& t) const noexcept
41 {
42 // NOTE: this is a change wrt the old ossia::oscquery::osc_outbound_visitor
43 buffer[0] = ',';
44 if(t.empty())
45 buffer[1] = oscpack::INFINITUM_TYPE_TAG;
46 else if(t == "nil")
47 buffer[1] = oscpack::NIL_TYPE_TAG;
48 else if(t == "empty")
49 buffer[1] = '\0';
50 buffer[2] = '\0';
51 buffer[3] = '\0';
52
53 return 4;
54 }
55
56 std::size_t operator()(char* buffer, ossia::impulse v) const noexcept
57 {
58 // NOTE: this is a change wrt the old ossia::oscquery::osc_outbound_visitor
59 buffer[0] = ',';
60 buffer[1] = '\0';
61 buffer[2] = '\0';
62 buffer[3] = '\0';
63
64 return 4;
65 }
66
67 std::size_t operator()(char* buffer, bool v) const noexcept
68 {
69 buffer[0] = ',';
70 buffer[1] = v ? oscpack::TRUE_TYPE_TAG : oscpack::FALSE_TYPE_TAG;
71 buffer[2] = '\0';
72 buffer[3] = '\0';
73
74 return 4;
75 }
76
77 std::size_t operator()(char* buffer, char v) const noexcept
78 {
79 return osc_common_outbound_static_policy::operator()(buffer, int32_t{v});
80 }
81};
82
83struct osc_1_1_policy
84{
85 using static_policy = osc_1_1_outbound_value_policy;
86 using dynamic_policy = osc_1_1_outbound_array_policy;
87};
88
89}
std::string extended_type
How a low-level type should be interpreted.
Definition complex_type.hpp:9