From 9cab30cfceda84aead05a78653dbb519fd00c2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Mon, 14 Aug 2017 18:22:49 +0200 Subject: [PATCH] add adl_serializer.hpp --- Makefile | 3 ++- src/adl_serializer.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++ src/json.hpp | 38 +-------------------------------- 3 files changed, 51 insertions(+), 38 deletions(-) create mode 100644 src/adl_serializer.hpp diff --git a/Makefile b/Makefile index a2c73dbfb..289080c75 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,8 @@ SRCS = ${SRCDIR}/json.hpp \ ${SRCDIR}/detail/parsing/binary_reader.hpp \ ${SRCDIR}/detail/parsing/binary_writer.hpp \ ${SRCDIR}/detail/serializer.hpp \ - ${SRCDIR}/detail/json_ref.hpp + ${SRCDIR}/detail/json_ref.hpp \ + ${SRCDIR}/adl_serializer.hpp # main target all: diff --git a/src/adl_serializer.hpp b/src/adl_serializer.hpp new file mode 100644 index 000000000..c2ad371cf --- /dev/null +++ b/src/adl_serializer.hpp @@ -0,0 +1,48 @@ +#ifndef NLOHMANN_JSON_ADL_SERIALIZER_HPP +#define NLOHMANN_JSON_ADL_SERIALIZER_HPP + +#include + +#include "detail/conversions/from_json.hpp" +#include "detail/conversions/to_json.hpp" + +namespace nlohmann +{ +template +struct adl_serializer +{ + /*! + @brief convert a JSON value to any value type + + This function is usually called by the `get()` function of the + @ref basic_json class (either explicit or via conversion operators). + + @param[in] j JSON value to read from + @param[in,out] val value to write to + */ + template + static void from_json(BasicJsonType&& j, ValueType& val) noexcept( + noexcept(::nlohmann::from_json(std::forward(j), val))) + { + ::nlohmann::from_json(std::forward(j), val); + } + + /*! + @brief convert any value type to a JSON value + + This function is usually called by the constructors of the @ref basic_json + class. + + @param[in,out] j JSON value to write to + @param[in] val value to read from + */ + template + static void to_json(BasicJsonType& j, ValueType&& val) noexcept( + noexcept(::nlohmann::to_json(j, std::forward(val)))) + { + ::nlohmann::to_json(j, std::forward(val)); + } +}; +} + +#endif diff --git a/src/json.hpp b/src/json.hpp index 32051d7e0..4eb7ec79c 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -70,6 +70,7 @@ SOFTWARE. #include "detail/parsing/binary_writer.hpp" #include "detail/serializer.hpp" #include "detail/json_ref.hpp" +#include "adl_serializer.hpp" /*! @brief namespace for Niels Lohmann @@ -78,42 +79,6 @@ SOFTWARE. */ namespace nlohmann { -template -struct adl_serializer -{ - /*! - @brief convert a JSON value to any value type - - This function is usually called by the `get()` function of the - @ref basic_json class (either explicit or via conversion operators). - - @param[in] j JSON value to read from - @param[in,out] val value to write to - */ - template - static void from_json(BasicJsonType&& j, ValueType& val) noexcept( - noexcept(::nlohmann::from_json(std::forward(j), val))) - { - ::nlohmann::from_json(std::forward(j), val); - } - - /*! - @brief convert any value type to a JSON value - - This function is usually called by the constructors of the @ref basic_json - class. - - @param[in,out] j JSON value to write to - @param[in] val value to read from - */ - template - static void to_json(BasicJsonType& j, ValueType&& val) noexcept( - noexcept(::nlohmann::to_json(j, std::forward(val)))) - { - ::nlohmann::to_json(j, std::forward(val)); - } -}; - class json_pointer { /// allow basic_json to access private members @@ -7969,7 +7934,6 @@ inline bool operator!=(json_pointer const& lhs, json_pointer const& rhs) noexcep } } // namespace nlohmann - /////////////////////// // nonmember support // ///////////////////////