2022-07-20 12:38:07 +02:00
|
|
|
// __ _____ _____ _____
|
|
|
|
// __| | __| | | | JSON for Modern C++
|
2022-08-01 23:27:58 +02:00
|
|
|
// | | |__ | | | | | | version 3.11.1
|
2022-07-20 12:38:07 +02:00
|
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
//
|
|
|
|
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-05-15 14:12:32 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-08-08 13:24:17 +02:00
|
|
|
#include <cstdint> // uint8_t, uint64_t
|
2020-05-19 13:30:22 +02:00
|
|
|
#include <tuple> // tie
|
2020-05-15 14:12:32 +02:00
|
|
|
#include <utility> // move
|
|
|
|
|
2022-07-30 21:59:13 +02:00
|
|
|
#include <nlohmann/detail/abi_macros.hpp>
|
|
|
|
|
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
2020-05-15 14:12:32 +02:00
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @brief an internal type for a backed binary type
|
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/
|
2020-05-15 14:12:32 +02:00
|
|
|
template<typename BinaryType>
|
2020-05-19 13:08:18 +02:00
|
|
|
class byte_container_with_subtype : public BinaryType
|
2020-05-15 14:12:32 +02:00
|
|
|
{
|
2020-05-15 23:21:49 +02:00
|
|
|
public:
|
2020-05-17 22:50:27 +02:00
|
|
|
using container_type = BinaryType;
|
2021-08-06 13:26:00 +02:00
|
|
|
using subtype_type = std::uint64_t;
|
2020-05-15 14:12:32 +02:00
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
2020-05-19 13:08:18 +02:00
|
|
|
byte_container_with_subtype() noexcept(noexcept(container_type()))
|
2020-05-17 22:50:27 +02:00
|
|
|
: container_type()
|
2020-05-15 22:38:18 +02:00
|
|
|
{}
|
2020-05-15 14:12:32 +02:00
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
2020-05-19 13:08:18 +02:00
|
|
|
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
|
2020-05-17 22:50:27 +02:00
|
|
|
: container_type(b)
|
2020-05-15 14:12:32 +02:00
|
|
|
{}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
2020-05-19 13:08:18 +02:00
|
|
|
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
|
2020-05-17 22:50:27 +02:00
|
|
|
: container_type(std::move(b))
|
2020-05-15 14:12:32 +02:00
|
|
|
{}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
2021-08-01 22:00:57 +02:00
|
|
|
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
|
2020-05-17 22:50:27 +02:00
|
|
|
: container_type(b)
|
2020-12-11 13:43:17 +01:00
|
|
|
, m_subtype(subtype_)
|
2020-05-15 23:21:49 +02:00
|
|
|
, m_has_subtype(true)
|
2020-05-15 14:12:32 +02:00
|
|
|
{}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
2021-08-01 22:00:57 +02:00
|
|
|
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
|
2020-05-17 22:50:27 +02:00
|
|
|
: container_type(std::move(b))
|
2020-12-11 13:43:17 +01:00
|
|
|
, m_subtype(subtype_)
|
2020-05-15 23:21:49 +02:00
|
|
|
, m_has_subtype(true)
|
2020-05-15 14:12:32 +02:00
|
|
|
{}
|
|
|
|
|
2020-05-19 13:30:22 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @brief sets the binary subtype
|
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/
|
2021-08-01 22:00:57 +02:00
|
|
|
void set_subtype(subtype_type subtype_) noexcept
|
2020-05-15 23:21:49 +02:00
|
|
|
{
|
2020-12-11 13:43:17 +01:00
|
|
|
m_subtype = subtype_;
|
2020-05-15 23:21:49 +02:00
|
|
|
m_has_subtype = true;
|
|
|
|
}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @brief return the binary subtype
|
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/
|
2021-08-01 22:00:57 +02:00
|
|
|
constexpr subtype_type subtype() const noexcept
|
2020-05-15 23:21:49 +02:00
|
|
|
{
|
2021-12-29 09:47:05 +01:00
|
|
|
return m_has_subtype ? m_subtype : static_cast<subtype_type>(-1);
|
2020-05-15 23:21:49 +02:00
|
|
|
}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @brief return whether the value has a subtype
|
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/
|
2020-05-15 23:21:49 +02:00
|
|
|
constexpr bool has_subtype() const noexcept
|
|
|
|
{
|
|
|
|
return m_has_subtype;
|
|
|
|
}
|
|
|
|
|
2021-12-29 13:41:01 +01:00
|
|
|
/// @brief clears the binary subtype
|
|
|
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/
|
2020-05-15 23:21:49 +02:00
|
|
|
void clear_subtype() noexcept
|
|
|
|
{
|
|
|
|
m_subtype = 0;
|
|
|
|
m_has_subtype = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-08-01 22:00:57 +02:00
|
|
|
subtype_type m_subtype = 0;
|
2020-05-15 23:21:49 +02:00
|
|
|
bool m_has_subtype = false;
|
2020-05-15 14:12:32 +02:00
|
|
|
};
|
|
|
|
|
2022-07-30 21:59:13 +02:00
|
|
|
NLOHMANN_JSON_NAMESPACE_END
|