23 #include <boost/type_index.hpp>
26 #include <type_traits>
52 template <
typename SerializedT,
typename ObjectT,
typename... AdditionalArgs>
56 SerializedT
serialize(
const ObjectT &input, AdditionalArgs &&... args)
const
60 auto type_index = boost::typeindex::type_id_runtime(input);
66 return itr->second(input, std::forward<AdditionalArgs>(args)...);
68 ASSERT_LOG(
false,
"Cannot find an appropriate serializer for " +
69 type_index.pretty_name());
77 std::function<SerializedT(
const ObjectT &, AdditionalArgs &&...)>;
82 template <
typename T,
typename Callable>
85 static_assert(std::is_base_of<ObjectT, T>::value,
86 "T is not a subclass of ObjectT");
89 auto type_index = boost::typeindex::type_id<T>();
91 "Already got a serializer for this type of object.");
95 auto wrapper = [callable](
const ObjectT &base_obj,
96 AdditionalArgs &&... args) -> SerializedT {
99 const T &concrete_object =
reinterpret_cast<const T &
>(base_obj);
102 const T &extra_safety = assert_cast<const T &>(base_obj);
104 std::addressof(extra_safety),
106 return callable(concrete_object, std::forward<AdditionalArgs>(args)...);
111 template <
typename T>
116 auto type_index = boost::typeindex::type_id<T>();
122 std::map<boost::typeindex::type_index, SerializationCallable>
serializers_;