✨ add convenience function to create binary value with given subtype
This commit is contained in:
parent
2b39efd545
commit
421a084396
2 changed files with 100 additions and 8 deletions
|
@ -889,9 +889,25 @@ class basic_json
|
||||||
struct internal_binary_t : public BinaryType
|
struct internal_binary_t : public BinaryType
|
||||||
{
|
{
|
||||||
using BinaryType::BinaryType;
|
using BinaryType::BinaryType;
|
||||||
internal_binary_t() noexcept(noexcept(BinaryType())) : BinaryType() {}
|
internal_binary_t() noexcept(noexcept(BinaryType()))
|
||||||
internal_binary_t(BinaryType const& bint) noexcept(noexcept(BinaryType(bint))) : BinaryType(bint) {}
|
: BinaryType()
|
||||||
internal_binary_t(BinaryType&& bint) noexcept(noexcept(BinaryType(std::move(bint)))) : BinaryType(std::move(bint)) {}
|
{}
|
||||||
|
internal_binary_t(const BinaryType& bint) noexcept(noexcept(BinaryType(bint)))
|
||||||
|
: BinaryType(bint)
|
||||||
|
{}
|
||||||
|
internal_binary_t(BinaryType&& bint) noexcept(noexcept(BinaryType(std::move(bint))))
|
||||||
|
: BinaryType(std::move(bint))
|
||||||
|
{}
|
||||||
|
internal_binary_t(const BinaryType& bint, std::uint8_t st) noexcept(noexcept(BinaryType(bint)))
|
||||||
|
: BinaryType(bint)
|
||||||
|
, subtype(st)
|
||||||
|
, has_subtype(true)
|
||||||
|
{}
|
||||||
|
internal_binary_t(BinaryType&& bint, std::uint8_t st) noexcept(noexcept(BinaryType(std::move(bint))))
|
||||||
|
: BinaryType(std::move(bint))
|
||||||
|
, subtype(st)
|
||||||
|
, has_subtype(true)
|
||||||
|
{}
|
||||||
|
|
||||||
// TOOD: If minimum C++ version is ever bumped to C++17, this field
|
// TOOD: If minimum C++ version is ever bumped to C++17, this field
|
||||||
// deserves to be a std::optional
|
// deserves to be a std::optional
|
||||||
|
@ -1098,6 +1114,18 @@ class basic_json
|
||||||
binary = create<internal_binary_t>(std::move(value));
|
binary = create<internal_binary_t>(std::move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// constructor for binary arrays (internal type)
|
||||||
|
json_value(const internal_binary_t& value)
|
||||||
|
{
|
||||||
|
binary = create<internal_binary_t>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// constructor for rvalue binary arrays (internal type)
|
||||||
|
json_value(internal_binary_t&& value)
|
||||||
|
{
|
||||||
|
binary = create<internal_binary_t>(std::move(value));
|
||||||
|
}
|
||||||
|
|
||||||
void destroy(value_t t) noexcept
|
void destroy(value_t t) noexcept
|
||||||
{
|
{
|
||||||
// flatten the current json_value to a heap-allocated stack
|
// flatten the current json_value to a heap-allocated stack
|
||||||
|
@ -1655,7 +1683,7 @@ class basic_json
|
||||||
@since version 3.8.0
|
@since version 3.8.0
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary_array(binary_t const& init)
|
static basic_json binary_array(const binary_t& init)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
|
@ -1663,6 +1691,15 @@ class basic_json
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
|
static basic_json binary_array(const binary_t& init, std::uint8_t subtype)
|
||||||
|
{
|
||||||
|
auto res = basic_json();
|
||||||
|
res.m_type = value_t::binary;
|
||||||
|
res.m_value = internal_binary_t(init, subtype);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief explicitly create a binary array from an already constructed rvalue
|
@brief explicitly create a binary array from an already constructed rvalue
|
||||||
copy of its base type
|
copy of its base type
|
||||||
|
@ -1699,6 +1736,15 @@ class basic_json
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
|
static basic_json binary_array(binary_t&& init, std::uint8_t subtype)
|
||||||
|
{
|
||||||
|
auto res = basic_json();
|
||||||
|
res.m_type = value_t::binary;
|
||||||
|
res.m_value = internal_binary_t(std::move(init), subtype);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief explicitly create an array from an initializer list
|
@brief explicitly create an array from an initializer list
|
||||||
|
|
||||||
|
|
|
@ -16396,9 +16396,25 @@ class basic_json
|
||||||
struct internal_binary_t : public BinaryType
|
struct internal_binary_t : public BinaryType
|
||||||
{
|
{
|
||||||
using BinaryType::BinaryType;
|
using BinaryType::BinaryType;
|
||||||
internal_binary_t() noexcept(noexcept(BinaryType())) : BinaryType() {}
|
internal_binary_t() noexcept(noexcept(BinaryType()))
|
||||||
internal_binary_t(BinaryType const& bint) noexcept(noexcept(BinaryType(bint))) : BinaryType(bint) {}
|
: BinaryType()
|
||||||
internal_binary_t(BinaryType&& bint) noexcept(noexcept(BinaryType(std::move(bint)))) : BinaryType(std::move(bint)) {}
|
{}
|
||||||
|
internal_binary_t(const BinaryType& bint) noexcept(noexcept(BinaryType(bint)))
|
||||||
|
: BinaryType(bint)
|
||||||
|
{}
|
||||||
|
internal_binary_t(BinaryType&& bint) noexcept(noexcept(BinaryType(std::move(bint))))
|
||||||
|
: BinaryType(std::move(bint))
|
||||||
|
{}
|
||||||
|
internal_binary_t(const BinaryType& bint, std::uint8_t st) noexcept(noexcept(BinaryType(bint)))
|
||||||
|
: BinaryType(bint)
|
||||||
|
, subtype(st)
|
||||||
|
, has_subtype(true)
|
||||||
|
{}
|
||||||
|
internal_binary_t(BinaryType&& bint, std::uint8_t st) noexcept(noexcept(BinaryType(std::move(bint))))
|
||||||
|
: BinaryType(std::move(bint))
|
||||||
|
, subtype(st)
|
||||||
|
, has_subtype(true)
|
||||||
|
{}
|
||||||
|
|
||||||
// TOOD: If minimum C++ version is ever bumped to C++17, this field
|
// TOOD: If minimum C++ version is ever bumped to C++17, this field
|
||||||
// deserves to be a std::optional
|
// deserves to be a std::optional
|
||||||
|
@ -16605,6 +16621,18 @@ class basic_json
|
||||||
binary = create<internal_binary_t>(std::move(value));
|
binary = create<internal_binary_t>(std::move(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// constructor for binary arrays (internal type)
|
||||||
|
json_value(const internal_binary_t& value)
|
||||||
|
{
|
||||||
|
binary = create<internal_binary_t>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// constructor for rvalue binary arrays (internal type)
|
||||||
|
json_value(internal_binary_t&& value)
|
||||||
|
{
|
||||||
|
binary = create<internal_binary_t>(std::move(value));
|
||||||
|
}
|
||||||
|
|
||||||
void destroy(value_t t) noexcept
|
void destroy(value_t t) noexcept
|
||||||
{
|
{
|
||||||
// flatten the current json_value to a heap-allocated stack
|
// flatten the current json_value to a heap-allocated stack
|
||||||
|
@ -17162,7 +17190,7 @@ class basic_json
|
||||||
@since version 3.8.0
|
@since version 3.8.0
|
||||||
*/
|
*/
|
||||||
JSON_HEDLEY_WARN_UNUSED_RESULT
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
static basic_json binary_array(binary_t const& init)
|
static basic_json binary_array(const binary_t& init)
|
||||||
{
|
{
|
||||||
auto res = basic_json();
|
auto res = basic_json();
|
||||||
res.m_type = value_t::binary;
|
res.m_type = value_t::binary;
|
||||||
|
@ -17170,6 +17198,15 @@ class basic_json
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
|
static basic_json binary_array(const binary_t& init, std::uint8_t subtype)
|
||||||
|
{
|
||||||
|
auto res = basic_json();
|
||||||
|
res.m_type = value_t::binary;
|
||||||
|
res.m_value = internal_binary_t(init, subtype);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief explicitly create a binary array from an already constructed rvalue
|
@brief explicitly create a binary array from an already constructed rvalue
|
||||||
copy of its base type
|
copy of its base type
|
||||||
|
@ -17206,6 +17243,15 @@ class basic_json
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSON_HEDLEY_WARN_UNUSED_RESULT
|
||||||
|
static basic_json binary_array(binary_t&& init, std::uint8_t subtype)
|
||||||
|
{
|
||||||
|
auto res = basic_json();
|
||||||
|
res.m_type = value_t::binary;
|
||||||
|
res.m_value = internal_binary_t(std::move(init), subtype);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief explicitly create an array from an initializer list
|
@brief explicitly create an array from an initializer list
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue