Skip to content

Commit 4aa83f1

Browse files
committed
Update Catch to 2.13.2 and nlohmann_json to 3.9.1
1 parent bfd9fd9 commit 4aa83f1

File tree

5 files changed

+2508
-0
lines changed

5 files changed

+2508
-0
lines changed
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#pragma once
2+
3+
#include <cstdint> // uint8_t
4+
#include <tuple> // tie
5+
#include <utility> // move
6+
7+
namespace nlohmann
8+
{
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+
*/
23+
template<typename BinaryType>
24+
class byte_container_with_subtype : public BinaryType
25+
{
26+
public:
27+
/// the type of the underlying container
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+
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
84+
{
85+
m_subtype = subtype;
86+
m_has_subtype = true;
87+
}
88+
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
111+
{
112+
return m_subtype;
113+
}
114+
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+
*/
131+
constexpr bool has_subtype() const noexcept
132+
{
133+
return m_has_subtype;
134+
}
135+
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+
*/
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

vendor/nlohmann/detail/hash.hpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#pragma once
2+
3+
#include <cstddef> // size_t, uint8_t
4+
#include <functional> // hash
5+
6+
namespace nlohmann
7+
{
8+
namespace detail
9+
{
10+
11+
// boost::hash_combine
12+
inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
13+
{
14+
seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
15+
return seed;
16+
}
17+
18+
/*!
19+
@brief hash a JSON value
20+
21+
The hash function tries to rely on std::hash where possible. Furthermore, the
22+
type of the JSON value is taken into account to have different hash values for
23+
null, 0, 0U, and false, etc.
24+
25+
@tparam BasicJsonType basic_json specialization
26+
@param j JSON value to hash
27+
@return hash value of j
28+
*/
29+
template<typename BasicJsonType>
30+
std::size_t hash(const BasicJsonType& j)
31+
{
32+
using string_t = typename BasicJsonType::string_t;
33+
using number_integer_t = typename BasicJsonType::number_integer_t;
34+
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
35+
using number_float_t = typename BasicJsonType::number_float_t;
36+
37+
const auto type = static_cast<std::size_t>(j.type());
38+
switch (j.type())
39+
{
40+
case BasicJsonType::value_t::null:
41+
case BasicJsonType::value_t::discarded:
42+
{
43+
return combine(type, 0);
44+
}
45+
46+
case BasicJsonType::value_t::object:
47+
{
48+
auto seed = combine(type, j.size());
49+
for (const auto& element : j.items())
50+
{
51+
const auto h = std::hash<string_t> {}(element.key());
52+
seed = combine(seed, h);
53+
seed = combine(seed, hash(element.value()));
54+
}
55+
return seed;
56+
}
57+
58+
case BasicJsonType::value_t::array:
59+
{
60+
auto seed = combine(type, j.size());
61+
for (const auto& element : j)
62+
{
63+
seed = combine(seed, hash(element));
64+
}
65+
return seed;
66+
}
67+
68+
case BasicJsonType::value_t::string:
69+
{
70+
const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
71+
return combine(type, h);
72+
}
73+
74+
case BasicJsonType::value_t::boolean:
75+
{
76+
const auto h = std::hash<bool> {}(j.template get<bool>());
77+
return combine(type, h);
78+
}
79+
80+
case BasicJsonType::value_t::number_integer:
81+
{
82+
const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
83+
return combine(type, h);
84+
}
85+
86+
case nlohmann::detail::value_t::number_unsigned:
87+
{
88+
const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
89+
return combine(type, h);
90+
}
91+
92+
case nlohmann::detail::value_t::number_float:
93+
{
94+
const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
95+
return combine(type, h);
96+
}
97+
98+
case nlohmann::detail::value_t::binary:
99+
{
100+
auto seed = combine(type, j.get_binary().size());
101+
const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
102+
seed = combine(seed, h);
103+
seed = combine(seed, j.get_binary().subtype());
104+
for (const auto byte : j.get_binary())
105+
{
106+
seed = combine(seed, std::hash<std::uint8_t> {}(byte));
107+
}
108+
return seed;
109+
}
110+
111+
default: // LCOV_EXCL_LINE
112+
JSON_ASSERT(false); // LCOV_EXCL_LINE
113+
}
114+
}
115+
116+
} // namespace detail
117+
} // namespace nlohmann

0 commit comments

Comments
 (0)