message.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: MIT
  2. // SPDX-FileCopyrightText: 2022 Ivan Baidakou
  3. #pragma once
  4. #include "definitions.hpp"
  5. #include <algorithm>
  6. #include <cstddef>
  7. #include <cstdint>
  8. #include <initializer_list>
  9. #include <limits>
  10. #include <tuple>
  11. #include <type_traits>
  12. #pragma pack(push)
  13. #pragma pack(1)
  14. namespace rotor_light {
  15. struct ActorBase;
  16. struct SupervisorBase;
  17. struct Message {
  18. static constexpr MessageTypeId type_id = 0;
  19. Message() : to{0} {}
  20. Message(ActorId to_) : to{to_} {}
  21. Message(const Message &) = delete;
  22. Message(Message &&) = delete;
  23. inline virtual MessageTypeId get_type_id() const { return 0; }
  24. private:
  25. friend struct ActorBase;
  26. friend struct SupervisorBase;
  27. ActorId to;
  28. };
  29. namespace traits {
  30. template <size_t... Items>
  31. auto constexpr max =
  32. [] { return std::max(std::initializer_list<size_t>{Items...}); };
  33. template <typename... Ts> struct MessageStorage {
  34. static constexpr size_t item_size = max<sizeof(Ts)...>();
  35. static constexpr size_t item_alignment = max<alignof(Ts)...>();
  36. using Item = std::aligned_storage_t<item_size, item_alignment>;
  37. };
  38. } // namespace traits
  39. } // namespace rotor_light
  40. #pragma pack(pop)