♻️ move wrapped binary type to separate file
This commit is contained in:
parent
bcf4f3ce9a
commit
daf2d296dd
8 changed files with 192 additions and 154 deletions
|
|
@ -228,9 +228,9 @@ template <typename BasicJsonType, typename ConstructibleArrayType,
|
|||
is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and
|
||||
not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and
|
||||
not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and
|
||||
not std::is_same<ConstructibleArrayType, typename BasicJsonType::internal_binary_t>::value and
|
||||
not is_basic_json<ConstructibleArrayType>::value,
|
||||
int > = 0 >
|
||||
|
||||
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
|
||||
-> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
|
||||
j.template get<typename ConstructibleArrayType::value_type>(),
|
||||
|
|
@ -245,6 +245,17 @@ void())
|
|||
from_json_array_impl(j, arr, priority_tag<3> {});
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, typename BasicJsonType::internal_binary_t& bin)
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(not j.is_binary()))
|
||||
{
|
||||
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name())));
|
||||
}
|
||||
|
||||
bin = *j.template get_ptr<const typename BasicJsonType::internal_binary_t*>();
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename ConstructibleObjectType,
|
||||
enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
|
||||
void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ template<>
|
|||
struct external_constructor<value_t::binary>
|
||||
{
|
||||
template<typename BasicJsonType>
|
||||
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
|
||||
static void construct(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& b)
|
||||
{
|
||||
j.m_type = value_t::binary;
|
||||
typename BasicJsonType::internal_binary_t value{b};
|
||||
|
|
@ -80,7 +80,7 @@ struct external_constructor<value_t::binary>
|
|||
}
|
||||
|
||||
template<typename BasicJsonType>
|
||||
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
|
||||
static void construct(BasicJsonType& j, typename BasicJsonType::internal_binary_t&& b)
|
||||
{
|
||||
j.m_type = value_t::binary;
|
||||
typename BasicJsonType::internal_binary_t value{std::move(b)};
|
||||
|
|
@ -278,9 +278,9 @@ void to_json(BasicJsonType& j, const std::vector<bool>& e)
|
|||
template <typename BasicJsonType, typename CompatibleArrayType,
|
||||
enable_if_t<is_compatible_array_type<BasicJsonType,
|
||||
CompatibleArrayType>::value and
|
||||
not is_compatible_object_type<
|
||||
BasicJsonType, CompatibleArrayType>::value and
|
||||
not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and
|
||||
not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
|
||||
not std::is_same<typename BasicJsonType::internal_binary_t, CompatibleArrayType>::value and
|
||||
not is_basic_json<CompatibleArrayType>::value,
|
||||
int> = 0>
|
||||
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
|
||||
|
|
@ -288,6 +288,12 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
|
|||
external_constructor<value_t::array>::construct(j, arr);
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& bin)
|
||||
{
|
||||
external_constructor<value_t::binary>::construct(j, bin);
|
||||
}
|
||||
|
||||
template<typename BasicJsonType, typename T,
|
||||
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
|
||||
void to_json(BasicJsonType& j, const std::valarray<T>& arr)
|
||||
|
|
|
|||
|
|
@ -23,13 +23,9 @@ input.
|
|||
template<typename BasicJsonType>
|
||||
struct json_sax
|
||||
{
|
||||
/// type for (signed) integers
|
||||
using number_integer_t = typename BasicJsonType::number_integer_t;
|
||||
/// type for unsigned integers
|
||||
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
|
||||
/// type for floating-point numbers
|
||||
using number_float_t = typename BasicJsonType::number_float_t;
|
||||
/// type for strings
|
||||
using string_t = typename BasicJsonType::string_t;
|
||||
using binary_t = typename BasicJsonType::binary_t;
|
||||
|
||||
|
|
|
|||
52
include/nlohmann/detail/wrapped_binary_t.hpp
Normal file
52
include/nlohmann/detail/wrapped_binary_t.hpp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint> // uint8_t
|
||||
#include <utility> // move
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*!
|
||||
@brief an internal type for a backed binary type
|
||||
|
||||
This type is designed to be `binary_t` but with the subtype implementation
|
||||
detail. This type exists so that the user does not have to specify a struct
|
||||
his- or herself with a specific naming scheme in order to override the
|
||||
binary type. I.e. it's for ease of use.
|
||||
*/
|
||||
template<typename BinaryType>
|
||||
struct wrapped_binary_t : public BinaryType
|
||||
{
|
||||
using binary_t = BinaryType;
|
||||
|
||||
wrapped_binary_t() noexcept(noexcept(binary_t())) = default;
|
||||
|
||||
wrapped_binary_t(const binary_t& bint) noexcept(noexcept(binary_t(bint)))
|
||||
: binary_t(bint)
|
||||
{}
|
||||
|
||||
wrapped_binary_t(binary_t&& bint) noexcept(noexcept(binary_t(std::move(bint))))
|
||||
: binary_t(std::move(bint))
|
||||
{}
|
||||
|
||||
wrapped_binary_t(const binary_t& bint,
|
||||
std::uint8_t st) noexcept(noexcept(binary_t(bint)))
|
||||
: binary_t(bint)
|
||||
, subtype(st)
|
||||
, has_subtype(true)
|
||||
{}
|
||||
|
||||
wrapped_binary_t(binary_t&& bint, std::uint8_t st) noexcept(noexcept(binary_t(std::move(bint))))
|
||||
: binary_t(std::move(bint))
|
||||
, subtype(st)
|
||||
, has_subtype(true)
|
||||
{}
|
||||
|
||||
std::uint8_t subtype = 0;
|
||||
bool has_subtype = false;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace nlohmann
|
||||
Loading…
Add table
Add a link
Reference in a new issue