♻️ rename internal_binary_t with binary_t

This commit is contained in:
Niels Lohmann 2020-05-17 22:50:27 +02:00
parent dead99eb0e
commit 904642f261
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
59 changed files with 536 additions and 457 deletions

View file

@ -228,7 +228,7 @@ 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 std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value and
not is_basic_json<ConstructibleArrayType>::value,
int > = 0 >
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
@ -246,14 +246,14 @@ void())
}
template <typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::internal_binary_t& bin)
void from_json(const BasicJsonType& j, typename BasicJsonType::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*>();
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
}
template<typename BasicJsonType, typename ConstructibleObjectType,

View file

@ -71,19 +71,19 @@ template<>
struct external_constructor<value_t::binary>
{
template<typename BasicJsonType>
static void construct(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& b)
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::internal_binary_t value{b};
typename BasicJsonType::binary_t value{b};
j.m_value = value;
j.assert_invariant();
}
template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::internal_binary_t&& b)
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::internal_binary_t value{std::move(b)};
typename BasicJsonType::binary_t value{std::move(b)};
j.m_value = value;
j.assert_invariant();
}
@ -280,7 +280,7 @@ template <typename BasicJsonType, typename CompatibleArrayType,
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 std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value and
not is_basic_json<CompatibleArrayType>::value,
int> = 0>
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
@ -289,7 +289,7 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
}
template <typename BasicJsonType>
void to_json(BasicJsonType& j, const typename BasicJsonType::internal_binary_t& bin)
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
{
external_constructor<value_t::binary>::construct(j, bin);
}

View file

@ -52,7 +52,7 @@ class binary_reader
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
using json_sax_t = SAX;
public:
@ -219,7 +219,7 @@ class binary_reader
@return `true` if the byte array was successfully parsed
*/
template<typename NumberType>
bool get_bson_binary(const NumberType len, internal_binary_t& result)
bool get_bson_binary(const NumberType len, binary_t& result)
{
if (JSON_HEDLEY_UNLIKELY(len < 0))
{
@ -276,7 +276,7 @@ class binary_reader
case 0x05: // binary
{
std::int32_t len;
internal_binary_t value;
binary_t value;
return get_number<std::int32_t, true>(input_format_t::bson, len) and get_bson_binary(len, value) and sax->binary(value);
}
@ -532,7 +532,7 @@ class binary_reader
case 0x5B: // Binary data (eight-byte uint64_t for n follow)
case 0x5F: // Binary data (indefinite length)
{
internal_binary_t b;
binary_t b;
return get_cbor_binary(b) and sax->binary(b);
}
@ -862,7 +862,7 @@ class binary_reader
@return whether byte array creation completed
*/
bool get_cbor_binary(internal_binary_t& result)
bool get_cbor_binary(binary_t& result)
{
if (JSON_HEDLEY_UNLIKELY(not unexpect_eof(input_format_t::cbor, "binary")))
{
@ -932,7 +932,7 @@ class binary_reader
{
while (get() != 0xFF)
{
internal_binary_t chunk;
binary_t chunk;
if (not get_cbor_binary(chunk))
{
return false;
@ -1282,7 +1282,7 @@ class binary_reader
case 0xD7: // fixext 8
case 0xD8: // fixext 16
{
internal_binary_t b;
binary_t b;
return get_msgpack_binary(b) and sax->binary(b);
}
@ -1505,7 +1505,7 @@ class binary_reader
@return whether byte array creation completed
*/
bool get_msgpack_binary(internal_binary_t& result)
bool get_msgpack_binary(binary_t& result)
{
// helper function to set the subtype
auto assign_and_return_true = [&result](std::int8_t subtype)
@ -2223,7 +2223,7 @@ class binary_reader
template<typename NumberType>
bool get_binary(const input_format_t format,
const NumberType len,
internal_binary_t& result)
binary_t& result)
{
bool success = true;
std::generate_n(std::back_inserter(result), len, [this, &success, &format]()

View file

@ -27,7 +27,7 @@ struct json_sax
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
/*!
@brief a null value was read
@ -78,7 +78,7 @@ struct json_sax
@return whether parsing should proceed
@note It is safe to move the passed binary.
*/
virtual bool binary(internal_binary_t& val) = 0;
virtual bool binary(binary_t& val) = 0;
/*!
@brief the beginning of an object was read
@ -154,7 +154,7 @@ class json_sax_dom_parser
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
/*!
@param[in, out] r reference to a JSON value that is manipulated while
@ -208,7 +208,7 @@ class json_sax_dom_parser
return true;
}
bool binary(internal_binary_t& val)
bool binary(binary_t& val)
{
handle_value(std::move(val));
return true;
@ -343,7 +343,7 @@ class json_sax_dom_callback_parser
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
using parser_callback_t = typename BasicJsonType::parser_callback_t;
using parse_event_t = typename BasicJsonType::parse_event_t;
@ -398,7 +398,7 @@ class json_sax_dom_callback_parser
return true;
}
bool binary(internal_binary_t& val)
bool binary(binary_t& val)
{
handle_value(std::move(val));
return true;
@ -654,7 +654,7 @@ class json_sax_acceptor
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
bool null()
{
@ -686,7 +686,7 @@ class json_sax_acceptor
return true;
}
bool binary(internal_binary_t& /*unused*/)
bool binary(binary_t& /*unused*/)
{
return true;
}

View file

@ -19,7 +19,7 @@ template<typename BasicJsonType> struct internal_iterator
/// iterator for JSON arrays
typename BasicJsonType::array_t::iterator array_iterator {};
/// iterator for JSON binary arrays
typename BasicJsonType::binary_t::iterator binary_iterator {};
typename BasicJsonType::binary_t::container_type::iterator binary_iterator {};
/// generic iterator for all other types
primitive_iterator_t primitive_iterator {};
};

View file

@ -27,7 +27,7 @@ template<typename BasicJsonType, typename CharType>
class binary_writer
{
using string_t = typename BasicJsonType::string_t;
using internal_binary_t = typename BasicJsonType::internal_binary_t;
using binary_t = typename BasicJsonType::binary_t;
public:
/*!
@ -1080,7 +1080,7 @@ class binary_writer
/*!
@return The size of the BSON-encoded binary array @a value
*/
static std::size_t calc_bson_binary_size(const typename BasicJsonType::internal_binary_t& value)
static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)
{
return sizeof(std::int32_t) + value.size() + 1ul;
}
@ -1108,7 +1108,7 @@ class binary_writer
@brief Writes a BSON element with key @a name and binary value @a value
*/
void write_bson_binary(const string_t& name,
const internal_binary_t& value)
const binary_t& value)
{
write_bson_entry_header(name, 0x05);

View file

@ -45,7 +45,7 @@ class serializer
using number_float_t = typename BasicJsonType::number_float_t;
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using binary_t = typename BasicJsonType::binary_t;
using binary_char_t = typename BasicJsonType::binary_t::value_type;
static constexpr std::uint8_t UTF8_ACCEPT = 0;
static constexpr std::uint8_t UTF8_REJECT = 1;
@ -624,7 +624,7 @@ class serializer
template<typename NumberType, detail::enable_if_t<
std::is_same<NumberType, number_unsigned_t>::value or
std::is_same<NumberType, number_integer_t>::value or
std::is_same<NumberType, typename binary_t::value_type>::value,
std::is_same<NumberType, binary_char_t>::value,
int> = 0>
void dump_integer(NumberType x)
{

View file

@ -19,36 +19,51 @@ template<typename BinaryType>
class wrapped_binary_t : public BinaryType
{
public:
using binary_t = BinaryType;
/// the type of the underlying container
using container_type = BinaryType;
wrapped_binary_t() noexcept(noexcept(binary_t()))
: binary_t()
wrapped_binary_t() noexcept(noexcept(container_type()))
: container_type()
{}
wrapped_binary_t(const binary_t& b) noexcept(noexcept(binary_t(b)))
: binary_t(b)
wrapped_binary_t(const container_type& b) noexcept(noexcept(container_type(b)))
: container_type(b)
{}
wrapped_binary_t(binary_t&& b) noexcept(noexcept(binary_t(std::move(b))))
: binary_t(std::move(b))
wrapped_binary_t(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b))
{}
wrapped_binary_t(const binary_t& b,
std::uint8_t subtype) noexcept(noexcept(binary_t(b)))
: binary_t(b)
wrapped_binary_t(const container_type& b,
std::uint8_t subtype) noexcept(noexcept(container_type(b)))
: container_type(b)
, m_subtype(subtype)
, m_has_subtype(true)
{}
wrapped_binary_t(binary_t&& b, std::uint8_t subtype) noexcept(noexcept(binary_t(std::move(b))))
: binary_t(std::move(b))
wrapped_binary_t(container_type&& b, std::uint8_t subtype) noexcept(noexcept(container_type(std::move(b))))
: container_type(std::move(b))
, m_subtype(subtype)
, m_has_subtype(true)
{}
/*!
@brief set the subtype
@param subtype subtype to set (implementation specific)
@brief sets the binary subtype
Sets the binary subtype of the value, also flags a binary JSON value as
having a subtype, which has implications for serialization.
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
void set_subtype(std::uint8_t subtype) noexcept
{
@ -57,8 +72,25 @@ class wrapped_binary_t : public BinaryType
}
/*!
@brief get the subtype
@return subtype (implementation specific)
@brief return the binary subtype
Returns the numerical subtype of the value if it has a subtype. If it does
not have a subtype, this function will return size_t(-1) as a sentinel
value.
@return the numerical subtype of the binary value
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
constexpr std::uint8_t subtype() const noexcept
{
@ -66,8 +98,20 @@ class wrapped_binary_t : public BinaryType
}
/*!
@brief get whether a subtype was set
@return whether a subtype was set
@brief return whether the value has a subtype
@return whether the value has a subtype
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref clear_subtype() -- clears the binary subtype
@since version 3.8.0
*/
constexpr bool has_subtype() const noexcept
{
@ -75,7 +119,23 @@ class wrapped_binary_t : public BinaryType
}
/*!
@brief clear the subtype
@brief clears the binary subtype
Clears the binary subtype and flags the value as not having a subtype, which
has implications for serialization; for instance MessagePack will prefer the
bin family over the ext family.
@complexity Constant.
@exceptionsafety No-throw guarantee: this member function never throws
exceptions.
@sa @ref subtype() -- return the binary subtype
@sa @ref set_subtype() -- sets the binary subtype
@sa @ref has_subtype() -- returns whether or not the binary value has a
subtype
@since version 3.8.0
*/
void clear_subtype() noexcept
{