async_mqtt 5.0.0
Loading...
Searching...
No Matches
topic_sharename.hpp
1// Copyright Takatoshi Kondo 2022
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_TOPIC_SHARENAME_HPP)
8#define ASYNC_MQTT_PACKET_TOPIC_SHARENAME_HPP
9
10#include <boost/assert.hpp>
11
12#include <async_mqtt/buffer.hpp>
13
14namespace async_mqtt {
15
20public:
21
28 ): all_topic_{force_move(all_topic)} {
29 BOOST_ASSERT(all_topic_.size() <= 0xffff);
30 auto const shared_prefix = string_view("$share/");
31 if (all_topic_.substr(0, shared_prefix.size()) == shared_prefix) {
32 // must have sharename
33 sharename_ = all_topic_.substr(shared_prefix.size());
34
35 auto const idx = sharename_.find_first_of('/');
36 if (idx == 0 || idx == string_view::npos) return;
37
38 topic_ = sharename_.substr(idx + 1);
39 sharename_.remove_suffix(sharename_.size() - idx);
40 }
41 else {
42 topic_ = all_topic_;
43 }
44 }
45
50 buffer const& topic() const {
51 return topic_;
52 }
53
58 buffer const& sharename() const {
59 return sharename_;
60 }
61
68 buffer const& all_topic() const {
69 return all_topic_;
70 }
71
77 operator bool() const {
78 return !topic_.empty();
79 }
80
84 friend
86 return
87 std::tie(lhs.topic_, lhs.sharename_) <
88 std::tie(rhs.topic_, rhs.sharename_);
89 }
90
94 friend
96 return
97 std::tie(lhs.topic_, lhs.sharename_) ==
98 std::tie(rhs.topic_, rhs.sharename_);
99 }
100
101private:
102 buffer all_topic_;
103 buffer topic_;
104 buffer sharename_;
105};
106
107} // namespace async_mqtt
108
109#endif // ASYNC_MQTT_PACKET_TOPIC_SHARENAME_HPP
Definition packet_variant.hpp:49
buffer that has string_view interface This class provides string_view interface. This class hold stri...
Definition buffer.hpp:30
buffer substr(size_type pos=0, size_type count=npos) const &
get substring The returned buffer ragnge is the same as string_view::substr(). In addition the lifeti...
Definition buffer.hpp:201
topic and sharename
Definition topic_sharename.hpp:19
buffer const & sharename() const
Get sharename.
Definition topic_sharename.hpp:58
buffer const & all_topic() const
Get all_topic.
Definition topic_sharename.hpp:68
friend bool operator==(topic_sharename const &lhs, topic_sharename const &rhs)
equal operator
Definition topic_sharename.hpp:95
topic_sharename(buffer all_topic)
constructor
Definition topic_sharename.hpp:26
friend bool operator<(topic_sharename const &lhs, topic_sharename const &rhs)
less than operator
Definition topic_sharename.hpp:85
buffer const & topic() const
Get topic.
Definition topic_sharename.hpp:50