Enable JSON marshaling inheritance
This commit is contained in:
parent
02ec014f35
commit
eae4a7cfa8
@ -179,6 +179,49 @@ namespace code::json
|
||||
return instance;
|
||||
}
|
||||
|
||||
template<typename... Bases>
|
||||
struct inherit_t
|
||||
{
|
||||
static_assert(sizeof...(Bases) > 0, "at least one base must be specified");
|
||||
|
||||
static
|
||||
void
|
||||
do_marshal(variant& v, T const& instance, marshaling_context_t* context)
|
||||
{
|
||||
((Bases::json::do_marshal(v, instance, context)), ...);
|
||||
First::marshal(v, instance, context);
|
||||
((Members::marshal(v, instance, context)), ...);
|
||||
}
|
||||
|
||||
static
|
||||
variant
|
||||
marshal(T const& instance, marshaling_context_t* context)
|
||||
{
|
||||
variant v{std::map<std::string, variant>{}};
|
||||
do_marshal(v, instance, context);
|
||||
return v;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
do_unmarshal(T& instance, variant const& v, marshaling_context_t* context)
|
||||
{
|
||||
((Bases::json::do_unmarshal(instance, v, context)), ...);
|
||||
First::unmarshal(instance, v, context);
|
||||
((Members::unmarshal(instance, v, context)), ...);
|
||||
}
|
||||
|
||||
static
|
||||
T
|
||||
unmarshal(variant const& v, marshaling_context_t* context)
|
||||
{
|
||||
T instance;
|
||||
do_unmarshal(instance, v, context);
|
||||
return instance;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef code__json__marshaling__traits_hxx_
|
||||
#define code__json__marshaling__traits_hxx_
|
||||
#ifndef code__json__traits_hxx_
|
||||
#define code__json__traits_hxx_
|
||||
|
||||
#include <code/json/optional.hxx>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace code::json::marshaling {
|
||||
namespace code::json {
|
||||
|
||||
// is_optional<T>.
|
||||
//
|
||||
@ -67,6 +67,6 @@ struct function_traits<
|
||||
: function_traits<decltype(&Callable::operator())> {
|
||||
};
|
||||
|
||||
} // namespace code::json::marshaling
|
||||
} // namespace code::json
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user