2020-05-15 20:12:32 +08:00
|
|
|
#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
|
2020-05-17 19:51:59 +08:00
|
|
|
detail. 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.
|
2020-05-15 20:12:32 +08:00
|
|
|
*/
|
|
|
|
template<typename BinaryType>
|
2020-05-16 05:21:49 +08:00
|
|
|
class wrapped_binary_t : public BinaryType
|
2020-05-15 20:12:32 +08:00
|
|
|
{
|
2020-05-16 05:21:49 +08:00
|
|
|
public:
|
2020-05-15 20:12:32 +08:00
|
|
|
using binary_t = BinaryType;
|
|
|
|
|
2020-05-16 04:38:18 +08:00
|
|
|
wrapped_binary_t() noexcept(noexcept(binary_t()))
|
|
|
|
: binary_t()
|
|
|
|
{}
|
2020-05-15 20:12:32 +08:00
|
|
|
|
2020-05-17 19:51:59 +08:00
|
|
|
wrapped_binary_t(const binary_t& b) noexcept(noexcept(binary_t(b)))
|
|
|
|
: binary_t(b)
|
2020-05-15 20:12:32 +08:00
|
|
|
{}
|
|
|
|
|
2020-05-17 19:51:59 +08:00
|
|
|
wrapped_binary_t(binary_t&& b) noexcept(noexcept(binary_t(std::move(b))))
|
|
|
|
: binary_t(std::move(b))
|
2020-05-15 20:12:32 +08:00
|
|
|
{}
|
|
|
|
|
2020-05-17 19:51:59 +08:00
|
|
|
wrapped_binary_t(const binary_t& b,
|
|
|
|
std::uint8_t subtype) noexcept(noexcept(binary_t(b)))
|
|
|
|
: binary_t(b)
|
|
|
|
, m_subtype(subtype)
|
2020-05-16 05:21:49 +08:00
|
|
|
, m_has_subtype(true)
|
2020-05-15 20:12:32 +08:00
|
|
|
{}
|
|
|
|
|
2020-05-17 19:51:59 +08:00
|
|
|
wrapped_binary_t(binary_t&& b, std::uint8_t subtype) noexcept(noexcept(binary_t(std::move(b))))
|
|
|
|
: binary_t(std::move(b))
|
|
|
|
, m_subtype(subtype)
|
2020-05-16 05:21:49 +08:00
|
|
|
, m_has_subtype(true)
|
2020-05-15 20:12:32 +08:00
|
|
|
{}
|
|
|
|
|
2020-05-16 05:21:49 +08:00
|
|
|
/*!
|
|
|
|
@brief set the subtype
|
|
|
|
@param subtype subtype to set (implementation specific)
|
|
|
|
*/
|
|
|
|
void set_subtype(std::uint8_t subtype) noexcept
|
|
|
|
{
|
|
|
|
m_subtype = subtype;
|
|
|
|
m_has_subtype = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@brief get the subtype
|
|
|
|
@return subtype (implementation specific)
|
|
|
|
*/
|
|
|
|
constexpr std::uint8_t subtype() const noexcept
|
|
|
|
{
|
|
|
|
return m_subtype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@brief get whether a subtype was set
|
|
|
|
@return whether a subtype was set
|
|
|
|
*/
|
|
|
|
constexpr bool has_subtype() const noexcept
|
|
|
|
{
|
|
|
|
return m_has_subtype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@brief clear the subtype
|
|
|
|
*/
|
|
|
|
void clear_subtype() noexcept
|
|
|
|
{
|
|
|
|
m_subtype = 0;
|
|
|
|
m_has_subtype = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::uint8_t m_subtype = 0;
|
|
|
|
bool m_has_subtype = false;
|
2020-05-15 20:12:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace nlohmann
|