Commit 7f359017 authored by Théo DELRIEU's avatar Théo DELRIEU

rename template argument Json -> BasicJsonType

parent 708eb961
This diff is collapsed.
This diff is collapsed.
...@@ -84,20 +84,20 @@ struct contact_book ...@@ -84,20 +84,20 @@ struct contact_book
namespace udt namespace udt
{ {
// templates because of the custom_json tests (see below) // templates because of the custom_json tests (see below)
template <typename Json> template <typename BasicJsonType>
void to_json(Json& j, age a) void to_json(BasicJsonType& j, age a)
{ {
j = a.m_val; j = a.m_val;
} }
template <typename Json> template <typename BasicJsonType>
void to_json(Json& j, const name& n) void to_json(BasicJsonType& j, const name& n)
{ {
j = n.m_val; j = n.m_val;
} }
template <typename Json> template <typename BasicJsonType>
void to_json(Json& j, country c) void to_json(BasicJsonType& j, country c)
{ {
switch (c) switch (c)
{ {
...@@ -113,10 +113,10 @@ void to_json(Json& j, country c) ...@@ -113,10 +113,10 @@ void to_json(Json& j, country c)
} }
} }
template <typename Json> template <typename BasicJsonType>
void to_json(Json& j, const person& p) void to_json(BasicJsonType& j, const person& p)
{ {
j = Json{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}}; j = BasicJsonType{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}};
} }
void to_json(nlohmann::json& j, const address& a) void to_json(nlohmann::json& j, const address& a)
...@@ -171,20 +171,20 @@ bool operator==(const contact_book& lhs, const contact_book& rhs) ...@@ -171,20 +171,20 @@ bool operator==(const contact_book& lhs, const contact_book& rhs)
// from_json methods // from_json methods
namespace udt namespace udt
{ {
template <typename Json> template <typename BasicJsonType>
void from_json(const Json& j, age& a) void from_json(const BasicJsonType& j, age& a)
{ {
a.m_val = j.template get<int>(); a.m_val = j.template get<int>();
} }
template <typename Json> template <typename BasicJsonType>
void from_json(const Json& j, name& n) void from_json(const BasicJsonType& j, name& n)
{ {
n.m_val = j.template get<std::string>(); n.m_val = j.template get<std::string>();
} }
template <typename Json> template <typename BasicJsonType>
void from_json(const Json& j, country& c) void from_json(const BasicJsonType& j, country& c)
{ {
const auto str = j.template get<std::string>(); const auto str = j.template get<std::string>();
static const std::map<std::string, country> m = static const std::map<std::string, country> m =
...@@ -199,8 +199,8 @@ void from_json(const Json& j, country& c) ...@@ -199,8 +199,8 @@ void from_json(const Json& j, country& c)
c = it->second; c = it->second;
} }
template <typename Json> template <typename BasicJsonType>
void from_json(const Json& j, person& p) void from_json(const BasicJsonType& j, person& p)
{ {
p.m_age = j["age"].template get<age>(); p.m_age = j["age"].template get<age>();
p.m_name = j["name"].template get<name>(); p.m_name = j["name"].template get<name>();
...@@ -493,20 +493,20 @@ struct pod_serializer ...@@ -493,20 +493,20 @@ struct pod_serializer
{ {
// use adl for non-pods, or scalar types // use adl for non-pods, or scalar types
template < template <
typename Json, typename U = T, typename BasicJsonType, typename U = T,
typename std::enable_if < typename std::enable_if <
not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 > not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
static void from_json(const Json& j, U& t) static void from_json(const BasicJsonType& j, U& t)
{ {
using nlohmann::from_json; using nlohmann::from_json;
from_json(j, t); from_json(j, t);
} }
// special behaviour for pods // special behaviour for pods
template <typename Json, typename U = T, template <typename BasicJsonType, typename U = T,
typename std::enable_if< typename std::enable_if<
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0> std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
static void from_json(const Json& j, U& t) static void from_json(const BasicJsonType& j, U& t)
{ {
std::uint64_t value; std::uint64_t value;
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue // TODO The following block is no longer relevant in this serializer, make another one that shows the issue
...@@ -529,19 +529,19 @@ struct pod_serializer ...@@ -529,19 +529,19 @@ struct pod_serializer
} }
template < template <
typename Json, typename U = T, typename BasicJsonType, typename U = T,
typename std::enable_if < typename std::enable_if <
not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 > not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
static void to_json(Json& j, const T& t) static void to_json(BasicJsonType& j, const T& t)
{ {
using nlohmann::to_json; using nlohmann::to_json;
to_json(j, t); to_json(j, t);
} }
template <typename Json, typename U = T, template <typename BasicJsonType, typename U = T,
typename std::enable_if< typename std::enable_if<
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0> std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
static void to_json(Json& j, const T& t) noexcept static void to_json(BasicJsonType& j, const T& t) noexcept
{ {
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t)); auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
std::uint64_t value = bytes[0]; std::uint64_t value = bytes[0];
...@@ -565,14 +565,14 @@ struct non_pod ...@@ -565,14 +565,14 @@ struct non_pod
std::string s; std::string s;
}; };
template <typename Json> template <typename BasicJsonType>
void to_json(Json& j, const non_pod& np) void to_json(BasicJsonType& j, const non_pod& np)
{ {
j = np.s; j = np.s;
} }
template <typename Json> template <typename BasicJsonType>
void from_json(const Json& j, non_pod& np) void from_json(const BasicJsonType& j, non_pod& np)
{ {
np.s = j.template get<std::string>(); np.s = j.template get<std::string>();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment