2018-01-10 12:18:31 +03:00
|
|
|
#pragma once
|
2017-08-14 19:22:49 +03:00
|
|
|
|
2021-01-09 02:08:27 +03:00
|
|
|
#include <type_traits>
|
2017-08-14 19:22:49 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2018-01-29 13:21:11 +03:00
|
|
|
#include <nlohmann/detail/conversions/from_json.hpp>
|
|
|
|
#include <nlohmann/detail/conversions/to_json.hpp>
|
2021-01-10 21:23:32 +03:00
|
|
|
#include <nlohmann/detail/meta/identity_tag.hpp>
|
2021-01-09 02:08:27 +03:00
|
|
|
#include <nlohmann/detail/meta/type_traits.hpp>
|
2017-08-14 19:22:49 +03:00
|
|
|
|
|
|
|
namespace nlohmann
|
|
|
|
{
|
2018-10-28 11:15:41 +03:00
|
|
|
|
2021-12-29 15:41:01 +03:00
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/
|
2021-01-09 02:08:27 +03:00
|
|
|
template<typename ValueType, typename>
|
2017-08-14 19:22:49 +03:00
|
|
|
struct adl_serializer
|
|
|
|
{
|
2021-12-29 15:41:01 +03:00
|
|
|
/// @brief convert a JSON value to any value type
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
2021-01-09 19:45:56 +03:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
|
|
|
static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
|
2018-10-28 11:15:41 +03:00
|
|
|
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
|
|
|
|
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
|
2017-08-14 19:22:49 +03:00
|
|
|
{
|
|
|
|
::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:41:01 +03:00
|
|
|
/// @brief convert a JSON value to any value type
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
|
2021-01-09 19:45:56 +03:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
2021-01-09 02:08:27 +03:00
|
|
|
static auto from_json(BasicJsonType && j) noexcept(
|
2021-01-10 21:23:32 +03:00
|
|
|
noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
|
|
|
|
-> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
|
2021-01-09 02:08:27 +03:00
|
|
|
{
|
2021-01-10 21:23:32 +03:00
|
|
|
return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
|
2021-01-09 02:08:27 +03:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:41:01 +03:00
|
|
|
/// @brief convert any value type to a JSON value
|
|
|
|
/// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
|
2021-01-09 19:45:56 +03:00
|
|
|
template<typename BasicJsonType, typename TargetType = ValueType>
|
|
|
|
static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
|
|
|
|
noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
|
|
|
|
-> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
|
2017-08-14 19:22:49 +03:00
|
|
|
{
|
2021-01-09 19:45:56 +03:00
|
|
|
::nlohmann::to_json(j, std::forward<TargetType>(val));
|
2017-08-14 19:22:49 +03:00
|
|
|
}
|
|
|
|
};
|
2018-10-07 19:39:18 +03:00
|
|
|
} // namespace nlohmann
|