OGLplus  (0.59.0) a C++ wrapper for rendering APIs

message_id.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_ID_HPP
10 #define EAGINE_MESSAGE_ID_HPP
11 
12 #include "identifier.hpp"
13 #include <tuple>
14 
15 namespace eagine {
16 //------------------------------------------------------------------------------
17 template <identifier_t ClassId, identifier_t MethodId>
19 //------------------------------------------------------------------------------
25 struct message_id : std::tuple<identifier_t, identifier_t> {
26  using base = std::tuple<identifier_t, identifier_t>;
27 
30  constexpr message_id() noexcept
31  : base{0U, 0U} {}
32 
34  constexpr message_id(identifier_t c, identifier_t m) noexcept
35  : base{c, m} {}
36 
38  constexpr message_id(identifier c, identifier m) noexcept
39  : base{c.value(), m.value()} {}
40 
42  constexpr message_id(std::tuple<identifier, identifier> t) noexcept
43  : message_id{std::get<0>(t), std::get<1>(t)} {}
44 
46  template <identifier_t ClassId, identifier_t MethodId>
48  : base{ClassId, MethodId} {}
49 
51  constexpr auto class_id() const noexcept -> identifier_t {
52  return std::get<0>(*this);
53  }
54 
56  constexpr auto class_() const noexcept -> identifier {
57  return identifier{class_id()};
58  }
59 
61  constexpr auto method_id() const noexcept -> identifier_t {
62  return std::get<1>(*this);
63  }
64 
66  constexpr auto method() const noexcept -> identifier {
67  return identifier{method_id()};
68  }
69 
71  constexpr auto is_valid() const noexcept {
72  return (class_id() != 0U) && (method_id() != 0U);
73  }
74 
78  constexpr auto id_tuple() const noexcept
79  -> std::tuple<identifier, identifier> {
80  return {class_(), method()};
81  }
82 
85  constexpr auto has_class(identifier id) const noexcept {
86  return class_id() == id.value();
87  }
88 
91  constexpr auto has_method(identifier id) const noexcept {
92  return method_id() == id.value();
93  }
94 };
95 //------------------------------------------------------------------------------
102 template <identifier_t ClassId, identifier_t MethodId>
103 struct static_message_id {
104  using type = static_message_id;
105 
107  static constexpr auto class_id() noexcept -> identifier_t {
108  return ClassId;
109  }
110 
112  static constexpr auto class_() noexcept -> identifier {
113  return identifier{class_id()};
114  }
115 
117  static constexpr auto method_id() noexcept -> identifier_t {
118  return MethodId;
119  }
120 
122  static constexpr auto method() noexcept -> identifier {
123  return identifier{method_id()};
124  }
125 };
126 //------------------------------------------------------------------------------
129 template <identifier_t ClassId, identifier_t MethodId>
130 inline auto
132  return l == message_id{r};
133 }
134 //------------------------------------------------------------------------------
140 #define EAGINE_MSG_TYPE(API, NAME) \
141  ::eagine::static_message_id<EAGINE_ID_V(API), EAGINE_ID_V(NAME)>
142 
148 #define EAGINE_MSG_ID(API, NAME) \
149  EAGINE_MSG_TYPE(API, NAME) {}
150 //------------------------------------------------------------------------------
151 } // namespace eagine
152 
153 #endif // EAGINE_MESSAGE_ID_HPP
Template with two identifier parameters representing class/method pair.
Definition: message_id.hpp:18
constexpr auto has_class(identifier id) const noexcept
Checks if the class identifier matches the argument.
Definition: message_id.hpp:85
constexpr message_id(const static_message_id< ClassId, MethodId > &) noexcept
Construction from static_message_id value.
Definition: message_id.hpp:47
static constexpr auto method() noexcept -> identifier
Returns the method identifier.
Definition: message_id.hpp:122
Common code is placed in this namespace.
Definition: eagine.hpp:21
constexpr auto class_id() const noexcept -> identifier_t
Returns the class identifier value.
Definition: message_id.hpp:51
constexpr auto has_method(identifier id) const noexcept
Checks if the method identifier matches the argument.
Definition: message_id.hpp:91
static constexpr auto class_() noexcept -> identifier
Returns the class identifier.
Definition: message_id.hpp:112
constexpr message_id(std::tuple< identifier, identifier > t) noexcept
Construction from a tuple of two identifier objects.
Definition: message_id.hpp:42
constexpr message_id() noexcept
Default constructor.
Definition: message_id.hpp:30
constexpr message_id(identifier_t c, identifier_t m) noexcept
Construction from two identifier values.
Definition: message_id.hpp:34
constexpr auto id_tuple() const noexcept -> std::tuple< identifier, identifier >
Returns the class and method identifiers in a tuple. See class_ See method.
Definition: message_id.hpp:78
constexpr message_id(identifier c, identifier m) noexcept
Construction from two identifier objects.
Definition: message_id.hpp:38
constexpr auto is_valid() const noexcept
Checks if the stored identifier values are non-zero.
Definition: message_id.hpp:71
static constexpr auto method_id() noexcept -> identifier_t
Returns the method identifier value.
Definition: message_id.hpp:117
static constexpr auto class_id() noexcept -> identifier_t
Returns the class identifier value.
Definition: message_id.hpp:107
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
auto operator==(message_id l, static_message_id< ClassId, MethodId > r) noexcept
Equality comparison between message_id and static_message_id.
Definition: message_id.hpp:131
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
constexpr auto class_() const noexcept -> identifier
Returns the class identifier.
Definition: message_id.hpp:56
constexpr auto method() const noexcept -> identifier
Returns the method identifier.
Definition: message_id.hpp:66
constexpr auto method_id() const noexcept -> identifier_t
Returns the method identifier value.
Definition: message_id.hpp:61

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).