Horizon
byte_container_with_subtype.hpp
1 #pragma once
2 
3 #include <cstdint> // uint8_t
4 #include <tuple> // tie
5 #include <utility> // move
6 
7 namespace nlohmann
8 {
9 
23 template<typename BinaryType>
24 class byte_container_with_subtype : public BinaryType
25 {
26  public:
28  using container_type = BinaryType;
29 
30  byte_container_with_subtype() noexcept(noexcept(container_type()))
31  : container_type()
32  {}
33 
34  byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
35  : container_type(b)
36  {}
37 
38  byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
39  : container_type(std::move(b))
40  {}
41 
42  byte_container_with_subtype(const container_type& b, std::uint8_t subtype) noexcept(noexcept(container_type(b)))
43  : container_type(b)
44  , m_subtype(subtype)
45  , m_has_subtype(true)
46  {}
47 
48  byte_container_with_subtype(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b))))
49  : container_type(std::move(b))
50  , m_subtype(subtype)
51  , m_has_subtype(true)
52  {}
53 
54  bool operator==(const byte_container_with_subtype& rhs) const
55  {
56  return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
57  std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
58  }
59 
60  bool operator!=(const byte_container_with_subtype& rhs) const
61  {
62  return !(rhs == *this);
63  }
64 
84  {
85  m_subtype = subtype;
86  m_has_subtype = true;
87  }
88 
110  constexpr std::uint8_t subtype() const noexcept
111  {
112  return m_subtype;
113  }
114 
131  constexpr bool has_subtype() const noexcept
132  {
133  return m_has_subtype;
134  }
135 
155  void clear_subtype() noexcept
156  {
157  m_subtype = 0;
158  m_has_subtype = false;
159  }
160 
161  private:
162  std::uint8_t m_subtype = 0;
163  bool m_has_subtype = false;
164 };
165 
166 } // namespace nlohmann
an internal type for a backed binary type
Definition: byte_container_with_subtype.hpp:25
BinaryType container_type
the type of the underlying container
Definition: byte_container_with_subtype.hpp:28
void clear_subtype() noexcept
clears the binary subtype
Definition: byte_container_with_subtype.hpp:155
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition: byte_container_with_subtype.hpp:131
void set_subtype(std::uint8_t subtype) noexcept
sets the binary subtype
Definition: byte_container_with_subtype.hpp:83
constexpr std::uint8_t subtype() const noexcept
return the binary subtype
Definition: byte_container_with_subtype.hpp:110
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78
namespace for Niels Lohmann
Definition: adl_serializer.hpp:9