rotor_light
real-time C++ actor micro-framework for embedded systems, supervisable
message.hpp
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2022 Ivan Baidakou
3
4#pragma once
5
6#include "definitions.hpp"
7#include <algorithm>
8#include <cstddef>
9#include <cstdint>
10#include <initializer_list>
11#include <limits>
12#include <tuple>
13#include <type_traits>
14
15namespace rotor_light {
16
17struct ActorBase;
18struct SupervisorBase;
19
22struct Message {
23 Message() : to{0} {}
24
26 Message(ActorId to_) : to{to_} {}
27
28 Message(const Message &) = delete;
29 Message(Message &&) = delete;
30
32 MessageTypeId type;
33
34private:
35 friend struct ActorBase;
36 friend struct SupervisorBase;
37 ActorId to;
38};
39
40namespace traits {
41
42template <size_t... Items>
43auto constexpr max =
44 [] { return std::max(std::initializer_list<size_t>{Items...}); };
45
50template <typename... Ts> struct MessageStorage {
52 static constexpr size_t item_size = max<sizeof(Ts)...>();
53
55 static constexpr size_t item_alignment = max<alignof(Ts)...>();
56
58 using Item = std::aligned_storage_t<item_size, item_alignment>;
59};
60
61} // namespace traits
62
63} // namespace rotor_light
base interface and implementation for all actors, including supervisors
Definition: actor.hpp:19
base class for all rotor-light messages
Definition: message.hpp:22
MessageTypeId type
Definition: message.hpp:32
Message(ActorId to_)
Definition: message.hpp:26
base interface and implementation for all supervisors
Definition: supervisor.hpp:29
properly allocated & sized space for any user-defined message type
Definition: message.hpp:50
static constexpr size_t item_size
Definition: message.hpp:52
static constexpr size_t item_alignment
Definition: message.hpp:55
std::aligned_storage_t< item_size, item_alignment > Item
Definition: message.hpp:58