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));
89 requires std::is_aggregate_v<F>
90 void operator()(F& f) { boost::pfr::for_each_field(f, *
this); }
93 requires(std::is_arithmetic_v<F>)
void operator()(F& f) { r.stream().stream >> f; }
95 template <std::size_t I,
typename... Args>
96 bool write_variant(std::variant<Args...>& f)
98 auto& elt = f.template emplace<I>();
103 template <
typename... Args>
104 void operator()(std::variant<Args...>& f)
109 [&]<std::size_t... I>(std::index_sequence<I...>)
111 (((index == I) && write_variant<I>(f)) || ...);
113 (std::make_index_sequence<
sizeof...(Args)>{});
116 void operator()(
auto& f) { r.stream() >> f; }
123 template <
typename T>
124 requires std::is_trivial_v<T>
125 void operator()(T& msg)
128 memcpy(&msg, mess.data(), mess.size());
130 template <
typename T>
131 requires(!std::is_trivial_v<T> && avnd::relocatable<T>)
132 void operator()(T& msg)
134 auto src =
reinterpret_cast<T*
>(mess.data());
135 msg = std::move(*src);
136 std::destroy_at(src);
139 template <
typename T>
140 requires(!std::is_trivial_v<T> && !avnd::relocatable<T>)
141 void operator()(T& msg)
Definition: DataStreamVisitor.hpp:27
Definition: DataStreamVisitor.hpp:202
Definition: MessageBus.hpp:85
Definition: MessageBus.hpp:120
Definition: MessageBus.hpp:37
Definition: MessageBus.hpp:13