OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
message_generator.hpp
1#pragma once
2#include <ossia/detail/small_vector.hpp>
4#include <ossia/network/base/parameter.hpp>
5#include <ossia/network/base/parameter_data.hpp>
6
7#include <oscpack/osc/OscOutboundPacketStream.h>
8
9#include <array>
10#include <vector>
11namespace oscpack
12{
13inline oscpack::OutboundPacketStream&
14operator<<(oscpack::OutboundPacketStream& p, const std::vector<std::string_view>& values)
15{
16 for(auto val : values)
17 {
18 p << val;
19 }
20
21 return p;
22}
23
24inline oscpack::OutboundPacketStream&
25operator<<(oscpack::OutboundPacketStream& p, const ossia::net::parameter_base& address)
26{
27 p << address.get_node().osc_address();
28
29 return p;
30}
31
32inline oscpack::OutboundPacketStream&
33operator<<(oscpack::OutboundPacketStream& p, const std::vector<std::string>& values)
34{
35 for(const auto& val : values)
36 {
37 p << std::string_view(val);
38 }
39
40 return p;
41}
42
43template <typename ValueWriter>
44class osc_message_generator
45{
46public:
47 osc_message_generator(oscpack::OutboundPacketStream& stream)
48 : p{stream}
49 {
50 }
51
52 const oscpack::OutboundPacketStream& operator()(std::string_view name, const char* v)
53 = delete;
54
55 void write(const char* arg) { p << std::string_view(arg); }
56
57 template <typename Arg>
58 void write(const Arg& arg)
59 {
60 p << arg;
61 }
62 void write(const ossia::value& v) { v.apply(ValueWriter{{p, ossia::unit_t{}}}); };
63 void write(const std::vector<ossia::value>& v)
64 {
65 ValueWriter{{p, ossia::unit_t{}}}(v);
66 };
67
68 template <typename... Args>
69 const oscpack::OutboundPacketStream&
70 operator()(std::string_view name, const Args&... args)
71 {
72 p << oscpack::BeginMessageN(name);
73 (write(args), ...);
74 p << oscpack::EndMessage();
75 return p;
76 }
77
78 const oscpack::OutboundPacketStream& stream() const { return p; }
79
80 oscpack::OutboundPacketStream& p;
81};
82
83}
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The value class.
Definition value.hpp:173
Definition dataspace.hpp:24