1
1
#pragma once
2
2
3
- #include < cstdint> // uint8_t
3
+ #include < cstdint> // uint8_t, uint64_t
4
4
#include < tuple> // tie
5
5
#include < utility> // move
6
6
7
7
namespace nlohmann
8
8
{
9
9
10
- /* !
11
- @brief an internal type for a backed binary type
12
-
13
- This type extends the template parameter @a BinaryType provided to `basic_json`
14
- with a subtype used by BSON and MessagePack. This type exists so that the user
15
- does not have to specify a type themselves with a specific naming scheme in
16
- order to override the binary type.
17
-
18
- @tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by
19
- default)
20
-
21
- @since version 3.8.0
22
- */
10
+ // / @brief an internal type for a backed binary type
11
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/
23
12
template <typename BinaryType>
24
13
class byte_container_with_subtype : public BinaryType
25
14
{
26
15
public:
27
- // / the type of the underlying container
28
16
using container_type = BinaryType;
17
+ using subtype_type = std::uint64_t ;
29
18
19
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
30
20
byte_container_with_subtype () noexcept (noexcept (container_type()))
31
21
: container_type()
32
22
{}
33
23
24
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
34
25
byte_container_with_subtype (const container_type& b) noexcept (noexcept (container_type(b)))
35
26
: container_type(b)
36
27
{}
37
28
29
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
38
30
byte_container_with_subtype (container_type&& b) noexcept (noexcept (container_type(std::move(b))))
39
31
: container_type(std::move(b))
40
32
{}
41
33
42
- byte_container_with_subtype (const container_type& b, std::uint8_t subtype) noexcept (noexcept (container_type(b)))
34
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
35
+ byte_container_with_subtype (const container_type& b, subtype_type subtype_) noexcept (noexcept (container_type(b)))
43
36
: container_type(b)
44
- , m_subtype(subtype )
37
+ , m_subtype(subtype_ )
45
38
, m_has_subtype(true )
46
39
{}
47
40
48
- byte_container_with_subtype (container_type&& b, std::uint8_t subtype) noexcept (noexcept (container_type(std::move(b))))
41
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
42
+ byte_container_with_subtype (container_type&& b, subtype_type subtype_) noexcept (noexcept (container_type(std::move(b))))
49
43
: container_type(std::move(b))
50
- , m_subtype(subtype )
44
+ , m_subtype(subtype_ )
51
45
, m_has_subtype(true )
52
46
{}
53
47
@@ -62,104 +56,38 @@ class byte_container_with_subtype : public BinaryType
62
56
return !(rhs == *this );
63
57
}
64
58
65
- /* !
66
- @brief sets the binary subtype
67
-
68
- Sets the binary subtype of the value, also flags a binary JSON value as
69
- having a subtype, which has implications for serialization.
70
-
71
- @complexity Constant.
72
-
73
- @exceptionsafety No-throw guarantee: this member function never throws
74
- exceptions.
75
-
76
- @sa @ref subtype() -- return the binary subtype
77
- @sa @ref clear_subtype() -- clears the binary subtype
78
- @sa @ref has_subtype() -- returns whether or not the binary value has a
79
- subtype
80
-
81
- @since version 3.8.0
82
- */
83
- void set_subtype (std::uint8_t subtype) noexcept
59
+ // / @brief sets the binary subtype
60
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/
61
+ void set_subtype (subtype_type subtype_) noexcept
84
62
{
85
- m_subtype = subtype ;
63
+ m_subtype = subtype_ ;
86
64
m_has_subtype = true ;
87
65
}
88
66
89
- /* !
90
- @brief return the binary subtype
91
-
92
- Returns the numerical subtype of the value if it has a subtype. If it does
93
- not have a subtype, this function will return size_t(-1) as a sentinel
94
- value.
95
-
96
- @return the numerical subtype of the binary value
97
-
98
- @complexity Constant.
99
-
100
- @exceptionsafety No-throw guarantee: this member function never throws
101
- exceptions.
102
-
103
- @sa @ref set_subtype() -- sets the binary subtype
104
- @sa @ref clear_subtype() -- clears the binary subtype
105
- @sa @ref has_subtype() -- returns whether or not the binary value has a
106
- subtype
107
-
108
- @since version 3.8.0
109
- */
110
- constexpr std::uint8_t subtype () const noexcept
67
+ // / @brief return the binary subtype
68
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/
69
+ constexpr subtype_type subtype () const noexcept
111
70
{
112
- return m_subtype;
71
+ return m_has_subtype ? m_subtype : static_cast <subtype_type>(- 1 ) ;
113
72
}
114
73
115
- /* !
116
- @brief return whether the value has a subtype
117
-
118
- @return whether the value has a subtype
119
-
120
- @complexity Constant.
121
-
122
- @exceptionsafety No-throw guarantee: this member function never throws
123
- exceptions.
124
-
125
- @sa @ref subtype() -- return the binary subtype
126
- @sa @ref set_subtype() -- sets the binary subtype
127
- @sa @ref clear_subtype() -- clears the binary subtype
128
-
129
- @since version 3.8.0
130
- */
74
+ // / @brief return whether the value has a subtype
75
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/
131
76
constexpr bool has_subtype () const noexcept
132
77
{
133
78
return m_has_subtype;
134
79
}
135
80
136
- /* !
137
- @brief clears the binary subtype
138
-
139
- Clears the binary subtype and flags the value as not having a subtype, which
140
- has implications for serialization; for instance MessagePack will prefer the
141
- bin family over the ext family.
142
-
143
- @complexity Constant.
144
-
145
- @exceptionsafety No-throw guarantee: this member function never throws
146
- exceptions.
147
-
148
- @sa @ref subtype() -- return the binary subtype
149
- @sa @ref set_subtype() -- sets the binary subtype
150
- @sa @ref has_subtype() -- returns whether or not the binary value has a
151
- subtype
152
-
153
- @since version 3.8.0
154
- */
81
+ // / @brief clears the binary subtype
82
+ // / @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/
155
83
void clear_subtype () noexcept
156
84
{
157
85
m_subtype = 0 ;
158
86
m_has_subtype = false ;
159
87
}
160
88
161
89
private:
162
- std:: uint8_t m_subtype = 0 ;
90
+ subtype_type m_subtype = 0 ;
163
91
bool m_has_subtype = false ;
164
92
};
165
93
0 commit comments