async_mqtt 4.1.0
Loading...
Searching...
No Matches
subopts.hpp
Go to the documentation of this file.
1// Copyright Takatoshi Kondo 2015
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PACKET_SUBOPTS_HPP)
8#define ASYNC_MQTT_PACKET_SUBOPTS_HPP
9
10#include <cstdint>
11#include <ostream>
12
14
16
17namespace async_mqtt {
18
19namespace sub {
20
26enum class retain_handling : std::uint8_t
27{
28 send = 0b00000000,
29 send_only_new_subscription = 0b00010000,
30 not_send = 0b00100000,
31};
32
38enum class rap : std::uint8_t
39{
40 dont = 0b00000000,
41 retain = 0b00001000,
42};
43
49enum class nl : std::uint8_t
50{
51 no = 0b00000000,
52 yes = 0b00000100,
53};
54
60struct opts final {
61 constexpr opts() = delete;
62 ~opts() = default;
63 constexpr opts(opts &&) = default;
64 constexpr opts(opts const&) = default;
65 constexpr opts& operator=(opts &&) = default;
66 constexpr opts& operator=(opts const&) = default;
67
72 explicit constexpr opts(std::uint8_t value) : data_(value) { }
73
78 constexpr opts(retain_handling value) : data_(static_cast<std::uint8_t>(value)) { }
79
84 constexpr opts(rap value) : data_(static_cast<std::uint8_t>(value)) { }
85
90 constexpr opts(nl value) : data_(static_cast<std::uint8_t>(value)) { }
91
96 constexpr opts(qos value) : data_(static_cast<std::uint8_t>(value)) { }
97
101 constexpr opts operator|(opts rhs) const { return opts(data_ | rhs.data_); }
105 constexpr opts operator|(retain_handling rhs) const { return *this | opts(rhs); }
109 constexpr opts operator|(rap rhs) const { return *this | opts(rhs); }
113 constexpr opts operator|(nl rhs) const { return *this | opts(rhs); }
117 constexpr opts operator|(qos rhs) const { return *this | opts(rhs); }
118
122 constexpr opts& operator|=(opts rhs) { return (*this = (*this | rhs)); }
126 constexpr opts& operator|=(retain_handling rhs) { return (*this = (*this | rhs)); }
130 constexpr opts& operator|=(rap rhs) { return (*this = (*this | rhs)); }
134 constexpr opts& operator|=(nl rhs) { return (*this = (*this | rhs)); }
138 constexpr opts& operator|=(qos rhs) { return (*this = (*this | rhs)); }
139
146 { return static_cast<enum retain_handling>(data_ & 0b00110000); }
147
153 constexpr rap get_rap() const
154 { return static_cast<enum rap>(data_ & 0b00001000); }
155
161 constexpr nl get_nl() const
162 { return static_cast<enum nl>(data_ & 0b00000100); }
163
169 constexpr qos get_qos() const
170 { return static_cast<enum qos>(data_ & 0b00000011); }
171
177 explicit constexpr operator std::uint8_t() const { return data_; }
178
182 constexpr bool operator==(opts rhs) const { return data_ == rhs.data_; }
183
187 constexpr bool operator<(opts rhs) const { return data_ < rhs.data_; }
188
189private:
190 std::uint8_t data_;
191};
192
197constexpr opts operator|(retain_handling lhs, rap rhs) { return opts(lhs) | rhs; }
202constexpr opts operator|(retain_handling lhs, nl rhs) { return opts(lhs) | rhs; }
207constexpr opts operator|(retain_handling lhs, qos rhs) { return opts(lhs) | rhs; }
208
213constexpr opts operator|(rap lhs, retain_handling rhs) { return opts(lhs) | rhs; }
218constexpr opts operator|(rap lhs, nl rhs) { return opts(lhs) | rhs; }
223constexpr opts operator|(rap lhs, qos rhs) { return opts(lhs) | rhs; }
224
229constexpr opts operator|(nl lhs, retain_handling rhs) { return opts(lhs) | rhs; }
234constexpr opts operator|(nl lhs, rap rhs) { return opts(lhs) | rhs; }
239constexpr opts operator|(nl lhs, qos rhs) { return opts(lhs) | rhs; }
240
245constexpr opts operator|(qos lhs, retain_handling rhs) { return opts(lhs) | rhs; }
250constexpr opts operator|(qos lhs, rap rhs) { return opts(lhs) | rhs; }
255constexpr opts operator|(qos lhs, nl rhs) { return opts(lhs) | rhs; }
256
262 switch(v) {
263 case retain_handling::send: return "send";
264 case retain_handling::send_only_new_subscription: return "send_only_new_subscription";
265 case retain_handling::not_send: return "not_send";
266 default: return "invalid_retain_handling";
267 }
268}
269
274inline
275std::ostream& operator<<(std::ostream& os, retain_handling val)
276{
277 os << retain_handling_to_str(val);
278 return os;
279}
280
285constexpr char const* rap_to_str(rap v) {
286 switch(v) {
287 case rap::dont: return "dont";
288 case rap::retain: return "retain";
289 default: return "invalid_rap";
290 }
291}
292
297inline
298std::ostream& operator<<(std::ostream& os, rap val)
299{
300 os << rap_to_str(val);
301 return os;
302}
303
308constexpr char const* nl_to_str(nl v) {
309 switch(v) {
310 case nl::no: return "no";
311 case nl::yes: return "yes";
312 default: return "invalid_nl";
313 }
314}
315
320inline
321std::ostream& operator<<(std::ostream& os, nl val)
322{
323 os << nl_to_str(val);
324 return os;
325}
326
327} // namespace sub
328
329} // namespace async_mqtt
330
331#endif // ASYNC_MQTT_PACKET_SUBOPTS_HPP
Definition packet_variant.hpp:49
qos
MQTT QoS.
Definition qos.hpp:23
MQTT SubscribeOptions.
Definition subopts.hpp:60
constexpr opts & operator|=(rap rhs)
Combine opts operator.
Definition subopts.hpp:130
constexpr char const * nl_to_str(nl v)
stringize nl
Definition subopts.hpp:308
constexpr char const * retain_handling_to_str(retain_handling v)
stringize retain_handling
Definition subopts.hpp:261
constexpr bool operator<(opts rhs) const
less than operator
Definition subopts.hpp:187
constexpr opts operator|(retain_handling rhs) const
Combine opts operator.
Definition subopts.hpp:105
constexpr opts(qos value)
constructor
Definition subopts.hpp:96
constexpr opts & operator|=(retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:126
constexpr opts operator|(nl lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:229
std::ostream & operator<<(std::ostream &os, nl val)
output to the stream nl
Definition subopts.hpp:321
constexpr opts operator|(retain_handling lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:202
constexpr opts(std::uint8_t value)
constructor
Definition subopts.hpp:72
std::ostream & operator<<(std::ostream &os, rap val)
output to the stream rap
Definition subopts.hpp:298
constexpr opts operator|(rap rhs) const
Combine opts operator.
Definition subopts.hpp:109
constexpr opts operator|(qos rhs) const
Combine opts operator.
Definition subopts.hpp:117
constexpr opts operator|(rap lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:213
constexpr bool operator==(opts rhs) const
equal operator
Definition subopts.hpp:182
constexpr opts operator|(qos lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:245
constexpr opts & operator|=(opts rhs)
Combine opts operator.
Definition subopts.hpp:122
constexpr opts operator|(nl rhs) const
Combine opts operator.
Definition subopts.hpp:113
constexpr opts & operator|=(nl rhs)
Combine opts operator.
Definition subopts.hpp:134
std::ostream & operator<<(std::ostream &os, retain_handling val)
output to the stream retain_handling
Definition subopts.hpp:275
constexpr opts operator|(rap lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:218
constexpr opts operator|(qos lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:250
constexpr opts operator|(retain_handling lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:207
constexpr opts(rap value)
constructor
Definition subopts.hpp:84
constexpr operator std::uint8_t() const
Get byte image.
Definition subopts.hpp:177
constexpr opts operator|(retain_handling lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:197
constexpr opts & operator|=(qos rhs)
Combine opts operator.
Definition subopts.hpp:138
constexpr char const * rap_to_str(rap v)
stringize rap
Definition subopts.hpp:285
constexpr opts operator|(opts rhs) const
Combine opts operator.
Definition subopts.hpp:101
constexpr opts(retain_handling value)
constructor
Definition subopts.hpp:78
constexpr retain_handling get_retain_handling() const
Get retain_handling.
Definition subopts.hpp:145
constexpr opts operator|(nl lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:234
constexpr qos get_qos() const
Get qos.
Definition subopts.hpp:169
constexpr opts operator|(nl lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:239
constexpr rap get_rap() const
Get rap.
Definition subopts.hpp:153
constexpr nl get_nl() const
Get nl.
Definition subopts.hpp:161
constexpr opts operator|(rap lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:223
constexpr opts operator|(qos lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:255
constexpr opts(nl value)
constructor
Definition subopts.hpp:90
nl
MQTT NoLocal.
Definition subopts.hpp:50
rap
MQTT RetainAsPublished.
Definition subopts.hpp:39
@ dont
Retain is set to 0 delivery on publish by the broker. Same as MQTT v.3.1.1.
retain_handling
MQTT RetainHandling.
Definition subopts.hpp:27
@ send_only_new_subscription
Only new subscription. Not overwrite.
@ send
Always send. Same as MQTT v.3.1.1.