async_mqtt 5.0.0
Loading...
Searching...
No Matches
packet_variant_operator.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_UTIL_PACKET_VARIANT_OPERATOR_HPP)
8#define ASYNC_MQTT_UTIL_PACKET_VARIANT_OPERATOR_HPP
9
10#include <algorithm>
11
12#include <async_mqtt/packet/packet_variant.hpp>
13#include <async_mqtt/packet/packet_traits.hpp>
14
15namespace async_mqtt {
16
17namespace as = boost::asio;
18
19template <std::size_t PacketIdBytes>
20inline bool basic_packet_variant_equal(
21 basic_packet_variant<PacketIdBytes> const& lhs,
22 basic_packet_variant<PacketIdBytes> const& rhs
23) {
24 auto lhs_cbs = lhs.const_buffer_sequence();
25 auto [lhs_b, lhs_e] = make_packet_range(lhs_cbs);
26
27 auto rhs_cbs = rhs.const_buffer_sequence();
28 auto [rhs_b, rhs_e] = make_packet_range(rhs_cbs);
29
30 return std::equal(lhs_b, lhs_e, rhs_b, rhs_e);
31}
32
33inline bool packet_variant_equal(
34 packet_variant const& lhs,
35 packet_variant const& rhs
36) {
37 return basic_packet_variant_equal<2>(lhs, rhs);
38}
39
40template <std::size_t PacketIdBytes>
41inline bool operator==(
42 basic_packet_variant<PacketIdBytes> const& lhs,
43 basic_packet_variant<PacketIdBytes> const& rhs
44) {
45 return basic_packet_variant_equal<PacketIdBytes>(lhs, rhs);
46}
47
48inline bool operator==(
49 packet_variant const& lhs,
50 packet_variant const& rhs
51) {
52 return packet_variant_equal(lhs, rhs);
53}
54
55template <std::size_t PacketIdBytes>
56inline bool basic_packet_variant_less_than(
57 basic_packet_variant<PacketIdBytes> const& lhs,
58 basic_packet_variant<PacketIdBytes> const& rhs
59) {
60 auto lhs_cbs = lhs.const_buffer_sequence();
61 auto [lhs_b, lhs_e] = make_packet_range(lhs_cbs);
62
63 auto rhs_cbs = rhs.const_buffer_sequence();
64 auto [rhs_b, rhs_e] = make_packet_range(rhs_cbs);
65
66 return std::lexicographical_compare(lhs_b, lhs_e, rhs_b, rhs_e);
67}
68
69inline bool packet_variant_less_than(
70 packet_variant const& lhs,
71 packet_variant const& rhs
72) {
73 return basic_packet_variant_less_than<2>(lhs, rhs);
74}
75
76template <std::size_t PacketIdBytes>
77inline bool operator<(
78 basic_packet_variant<PacketIdBytes> const& lhs,
79 basic_packet_variant<PacketIdBytes> const& rhs
80) {
81 return basic_packet_variant_less_than<PacketIdBytes>(lhs, rhs);
82}
83
84inline bool operator<(
85 packet_variant const& lhs,
86 packet_variant const& rhs
87) {
88 return packet_variant_less_than(lhs, rhs);
89}
90
91} // namespace async_mqtt
92
93#endif // ASYNC_MQTT_UTIL_PACKET_VARIANT_OPERATOR_HPP
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
Definition packet_variant.hpp:166