mirror of
https://github.com/nlohmann/json.git
synced 2024-08-22 04:52:35 +02:00
* ⚗️ move CI targets to CMake * ♻️ add target for cpplint * ♻️ add target for self-contained binaries * ♻️ add targets for iwyu and infer * 🔊 add version output * ♻️ add target for oclint * 🚨 fix warnings * ♻️ rename targets * ♻️ use iwyu properly * 🚨 fix warnings * ♻️ use iwyu properly * ♻️ add target for benchmarks * ♻️ add target for CMake flags * 👷 use GitHub Actions * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ add clang analyze target * 🔥 remove Google Benchmark * ⬆️ Google Benchmark 1.5.2 * 🔥 use fetchcontent * 🐧 add target to download a Linux version of CMake * 🔨 fix dependency * 🚨 fix includes * 🚨 fix comment * 🔧 adjust flags for GCC 11.0.0 20210110 (experimental) * 🐳 user Docker image to run CI * 🔧 add target for Valgrind * 👷 add target for Valgrind tests * ⚗️ add Dart * ⏪ remove Dart * ⚗️ do not call ctest in test subdirectory * ⚗️ download test data explicitly * ⚗️ only execute Valgrind tests * ⚗️ fix labels * 🔥 remove unneeded jobs * 🔨 cleanup * 🐛 fix OCLint call * ✅ add targets for offline and git-independent tests * ✅ add targets for C++ language versions and reproducible tests * 🔨 clean up * 👷 add CI steps for cppcheck and cpplint * 🚨 fix warnings from Clang-Tidy * 👷 add CI steps for Clang-Tidy * 🚨 fix warnings * 🔧 select proper binary * 🚨 fix warnings * 🚨 suppress some unhelpful warnings * 🚨 fix warnings * 🎨 fix format * 🚨 fix warnings * 👷 add CI steps for Sanitizers * 🚨 fix warnings * ⚡ add optimization to sanitizer build * 🚨 fix warnings * 🚨 add missing header * 🚨 fix warnings * 👷 add CI step for coverage * 👷 add CI steps for disabled exceptions and implicit conversions * 🚨 fix warnings * 👷 add CI steps for checking indentation * 🐛 fix variable use * 💚 fix build * ➖ remove CircleCI * 👷 add CI step for diagnostics * 🚨 fix warning * 🔥 clean Travis
167 lines
4.6 KiB
C++
167 lines
4.6 KiB
C++
#pragma once
|
|
|
|
#include <cstdint> // uint8_t
|
|
#include <tuple> // tie
|
|
#include <utility> // move
|
|
|
|
namespace nlohmann
|
|
{
|
|
|
|
/*!
|
|
@brief an internal type for a backed binary type
|
|
|
|
This type extends the template parameter @a BinaryType provided to `basic_json`
|
|
with a subtype used by BSON and MessagePack. This type exists so that the user
|
|
does not have to specify a type themselves with a specific naming scheme in
|
|
order to override the binary type.
|
|
|
|
@tparam BinaryType container to store bytes (`std::vector<std::uint8_t>` by
|
|
default)
|
|
|
|
@since version 3.8.0
|
|
*/
|
|
template<typename BinaryType>
|
|
class byte_container_with_subtype : public BinaryType
|
|
{
|
|
public:
|
|
/// the type of the underlying container
|
|
using container_type = BinaryType;
|
|
|
|
byte_container_with_subtype() noexcept(noexcept(container_type()))
|
|
: container_type()
|
|
{}
|
|
|
|
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
|
|
: container_type(b)
|
|
{}
|
|
|
|
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
|
|
: container_type(std::move(b))
|
|
{}
|
|
|
|
byte_container_with_subtype(const container_type& b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
|
|
: container_type(b)
|
|
, m_subtype(subtype_)
|
|
, m_has_subtype(true)
|
|
{}
|
|
|
|
byte_container_with_subtype(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)
|
|
{}
|
|
|
|
bool operator==(const byte_container_with_subtype& rhs) const
|
|
{
|
|
return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
|
|
std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
|
|
}
|
|
|
|
bool operator!=(const byte_container_with_subtype& rhs) const
|
|
{
|
|
return !(rhs == *this);
|
|
}
|
|
|
|
/*!
|
|
@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 see @ref subtype() -- return the binary subtype
|
|
@sa see @ref clear_subtype() -- clears the binary subtype
|
|
@sa see @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
|
|
{
|
|
m_subtype = subtype_;
|
|
m_has_subtype = true;
|
|
}
|
|
|
|
/*!
|
|
@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 see @ref set_subtype() -- sets the binary subtype
|
|
@sa see @ref clear_subtype() -- clears the binary subtype
|
|
@sa see @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
|
|
{
|
|
return m_subtype;
|
|
}
|
|
|
|
/*!
|
|
@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 see @ref subtype() -- return the binary subtype
|
|
@sa see @ref set_subtype() -- sets the binary subtype
|
|
@sa see @ref clear_subtype() -- clears the binary subtype
|
|
|
|
@since version 3.8.0
|
|
*/
|
|
constexpr bool has_subtype() const noexcept
|
|
{
|
|
return m_has_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 see @ref subtype() -- return the binary subtype
|
|
@sa see @ref set_subtype() -- sets the binary subtype
|
|
@sa see @ref has_subtype() -- returns whether or not the binary value has a
|
|
subtype
|
|
|
|
@since version 3.8.0
|
|
*/
|
|
void clear_subtype() noexcept
|
|
{
|
|
m_subtype = 0;
|
|
m_has_subtype = false;
|
|
}
|
|
|
|
private:
|
|
std::uint8_t m_subtype = 0;
|
|
bool m_has_subtype = false;
|
|
};
|
|
|
|
} // namespace nlohmann
|