diff --git a/code/json/marshaling.hxx b/code/json/marshaling.hxx index 9a2f539..f58cdee 100644 --- a/code/json/marshaling.hxx +++ b/code/json/marshaling.hxx @@ -179,6 +179,49 @@ namespace code::json return instance; } + template + 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{}}; + 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 diff --git a/code/json/traits.hxx b/code/json/traits.hxx index 45d5a0b..350d98c 100644 --- a/code/json/traits.hxx +++ b/code/json/traits.hxx @@ -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 #include -namespace code::json::marshaling { +namespace code::json { // is_optional. // @@ -67,6 +67,6 @@ struct function_traits< : function_traits { }; -} // namespace code::json::marshaling +} // namespace code::json #endif