5050#include < vide/traits/underlying_archive.hpp>
5151#include < vide/types/memory.hpp>
5252#include < vide/types/string.hpp>
53+
5354#include < functional>
54- #include < typeindex>
55- #include < map>
5655#include < limits>
57- #include < set >
56+ #include < map >
5857#include < stack>
58+ #include < typeindex>
5959
6060// ! Helper macro to omit unused warning
6161#if defined(__GNUC__)
@@ -425,7 +425,6 @@ struct binding_name {};
425425 type, containing entries for every registered type that describe how to
426426 properly cast the type to its real type in polymorphic scenarios for
427427 shared_ptr, weak_ptr, and unique_ptr. */
428- template <class Archive >
429428struct OutputBindingMap {
430429 // ! A serializer function
431430 /* ! Serializer functions return nothing and take an archive as
@@ -442,7 +441,14 @@ struct OutputBindingMap {
442441 };
443442
444443 // ! A map of serializers for pointers of all registered types
445- std::map<std::type_index, Serializers> map;
444+ using Serializers_map = std::map<std::type_index, Serializers>;
445+ // ! A map of archive typeid -> map of serializers for given archive
446+ using Archives_map = std::map<std::type_index, Serializers_map>;
447+ Archives_map archives_map;
448+
449+ // ! Obtain serializers map for given archive
450+ template <typename Archive>
451+ Serializers_map& map () { return archives_map[typeid (Archive)]; }
446452};
447453
448454// ! An empty noop deleter
@@ -453,7 +459,6 @@ template <class T> struct EmptyDeleter { void operator()(T*) const {}};
453459 type, containing entries for every registered type that describe how to
454460 properly cast the type to its real type in polymorphic scenarios for
455461 shared_ptr, weak_ptr, and unique_ptr. */
456- template <class Archive >
457462struct InputBindingMap {
458463 // ! Shared ptr serializer function
459464 /* ! Serializer functions return nothing and take an archive as
@@ -472,17 +477,24 @@ struct InputBindingMap {
472477 };
473478
474479 // ! A map of serializers for pointers of all registered types
475- std::map<std::string, Serializers> map;
480+ using Serializers_map = std::map<std::string, Serializers>;
481+ // ! A map of archive typeid -> map of serializers for given archive
482+ using Archives_map = std::map<std::type_index, Serializers_map>;
483+ Archives_map archives_map;
484+
485+ // ! Obtain serializers map for given archive
486+ template <typename Archive>
487+ Serializers_map& map () { return archives_map[typeid (Archive)]; }
476488};
477489
478490template <typename Archive>
479491auto & getBindingMapOutput () {
480- return detail::StaticObject<detail::OutputBindingMap< underlying_archive_t <Archive>>> ::getInstance ().map ;
492+ return detail::StaticObject<detail::OutputBindingMap> ::getInstance ().map < underlying_archive_t <Archive>>() ;
481493}
482494
483495template <typename Archive>
484496auto & getBindingMapInput () {
485- return detail::StaticObject<detail::InputBindingMap< underlying_archive_t <Archive>>> ::getInstance ().map ;
497+ return detail::StaticObject<detail::InputBindingMap> ::getInstance ().map < underlying_archive_t <Archive>>() ;
486498}
487499
488500// forward decls for archives from vide.hpp
@@ -497,17 +509,15 @@ class OutputArchiveBase;
497509template <class Archive , class T > struct InputBindingCreator {
498510 // ! Initialize the binding
499511 InputBindingCreator () {
500- auto & map = StaticObject<InputBindingMap<Archive>>
501- ::getInstance ().map;
502- auto lock = StaticObject<InputBindingMap<Archive>>
503- ::lock ();
512+ auto & map = StaticObject<InputBindingMap>::getInstance ().map <Archive>();;
513+ auto lock = StaticObject<InputBindingMap>::lock ();
504514 auto key = std::string (binding_name<T>::name ());
505515 auto lb = map.lower_bound (key);
506516
507517 if (lb != map.end () && lb->first == key)
508518 return ;
509519
510- typename InputBindingMap<Archive> ::Serializers serializers;
520+ InputBindingMap::Serializers serializers;
511521
512522 serializers.shared_ptr =
513523 +[](void * arptr, std::shared_ptr<void >& dptr, const std::type_info& baseInfo) {
@@ -610,14 +620,14 @@ template <class Archive, class T> struct OutputBindingCreator {
610620
611621 // ! Initialize the binding
612622 OutputBindingCreator () {
613- auto & map = StaticObject<OutputBindingMap<Archive>> ::getInstance ().map ;
623+ auto & map = StaticObject<OutputBindingMap> ::getInstance ().map <Archive>() ;
614624 auto key = std::type_index (typeid (T));
615625 auto lb = map.lower_bound (key);
616626
617627 if (lb != map.end () && lb->first == key)
618628 return ;
619629
620- typename OutputBindingMap<Archive> ::Serializers serializers;
630+ OutputBindingMap::Serializers serializers;
621631
622632 serializers.shared_ptr =
623633 +[](void * arptr, const void * dptr, const std::type_info& baseInfo) {
0 commit comments