4 #include <boost/pfr.hpp>
6 #include <avnd/common/tag.hpp>
7 #include <avnd/concepts/message_bus.hpp>
17 requires std::is_aggregate_v<F>
18 void operator()(
const F& f) { boost::pfr::for_each_field(f, *
this); }
21 requires(std::is_arithmetic_v<F>)
void operator()(
const F& f)
23 r.stream().stream << f;
26 template <
typename... Args>
27 void operator()(
const std::variant<Args...>& f)
29 r.stream() << (int)f.index();
30 std::visit([&](
const auto& arg) { r.stream() << arg; }, f);
33 void operator()(
const auto& f) { r.stream() << f; }
38 std::function<void(QByteArray)>& bus;
41 requires std::is_trivial_v<T>
42 void operator()(
const T& msg)
45 this->bus(QByteArray((
const char*)&msg,
sizeof(msg)));
49 requires(!std::is_trivial_v<T> && avnd::relocatable<T>)
50 void operator()(
const T& msg)
52 QByteArray b(msg.size(), Qt::Uninitialized);
53 auto dst =
reinterpret_cast<T*
>(b.data());
56 this->bus(std::move(b));
60 requires(!std::is_trivial_v<T> && avnd::relocatable<T>)
61 void operator()(T&& msg)
63 QByteArray b(
sizeof(msg), Qt::Uninitialized);
64 auto dst =
reinterpret_cast<T*
>(b.data());
65 std::construct_at(dst, std::move(msg));
67 this->bus(std::move(b));
71 requires(!std::is_trivial_v<T> && !avnd::relocatable<T>)
72 void operator()(
const T& msg)
80 this->bus(std::move(buf));
84 void operator()(
const std::shared_ptr<T>& msg)
87 return (*
this)(std::move(*msg));
90 void operator()(std::unique_ptr<T> msg)
93 return (*
this)(std::move(*msg));
101 template <
typename F>
102 requires std::is_aggregate_v<F>
103 void operator()(F& f) { boost::pfr::for_each_field(f, *
this); }
105 template <
typename F>
106 requires(std::is_arithmetic_v<F>)
void operator()(F& f) { r.stream().stream >> f; }
108 template <std::size_t I,
typename... Args>
109 bool write_variant(std::variant<Args...>& f)
111 auto& elt = f.template emplace<I>();
116 template <
typename... Args>
117 void operator()(std::variant<Args...>& f)
122 [&]<std::size_t... I>(std::index_sequence<I...>)
124 (((index == I) && write_variant<I>(f)) || ...);
126 (std::make_index_sequence<
sizeof...(Args)>{});
129 void operator()(
auto& f) { r.stream() >> f; }
136 template <
typename T>
137 requires std::is_trivial_v<T>
138 void operator()(T& msg)
141 memcpy(&msg, mess.data(), mess.size());
143 template <
typename T>
144 requires(!std::is_trivial_v<T> && avnd::relocatable<T>)
145 void operator()(T& msg)
147 auto src =
reinterpret_cast<T*
>(mess.data());
148 msg = std::move(*src);
149 std::destroy_at(src);
152 template <
typename T>
153 requires(!std::is_trivial_v<T> && !avnd::relocatable<T>)
154 void operator()(T& msg)
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Definition: Factories.hpp:19
Definition: MessageBus.hpp:98
Definition: MessageBus.hpp:133
Definition: MessageBus.hpp:37
Definition: MessageBus.hpp:13