diff --git a/include/cereal/details/polymorphic_impl.hpp b/include/cereal/details/polymorphic_impl.hpp index b1b9b4d0..5867c142 100644 --- a/include/cereal/details/polymorphic_impl.hpp +++ b/include/cereal/details/polymorphic_impl.hpp @@ -464,7 +464,6 @@ namespace cereal type, containing entries for every registered type that describe how to properly cast the type to its real type in polymorphic scenarios for shared_ptr, weak_ptr, and unique_ptr. */ - template struct OutputBindingMap { //! A serializer function @@ -483,7 +482,14 @@ namespace cereal }; //! A map of serializers for pointers of all registered types - std::map map; + using Serializers_map = std::map; + //! A map of archive typeid -> map of serializers for given archive + using Archives_map = std::map; + Archives_map archives_map; + + //! Obtain serializers map for given archive + template + Serializers_map& map() { return archives_map[typeid(Archive)]; } }; //! An empty noop deleter @@ -494,7 +500,6 @@ namespace cereal type, containing entries for every registered type that describe how to properly cast the type to its real type in polymorphic scenarios for shared_ptr, weak_ptr, and unique_ptr. */ - template struct InputBindingMap { //! Shared ptr serializer function @@ -515,7 +520,14 @@ namespace cereal }; //! A map of serializers for pointers of all registered types - std::map map; + using Serializers_map = std::map; + //! A map of archive typeid -> map of serializers for given archive + using Archives_map = std::map; + Archives_map archives_map; + + //! Obtain serializers map for given archive + template + Serializers_map& map() { return archives_map[typeid(Archive)]; } }; // forward decls for archives from cereal.hpp @@ -532,15 +544,15 @@ namespace cereal //! Initialize the binding InputBindingCreator() { - auto & map = StaticObject>::getInstance().map; - auto lock = StaticObject>::lock(); + auto & map = StaticObject::getInstance().map(); + auto lock = StaticObject::lock(); auto key = std::string(binding_name::name()); auto lb = map.lower_bound(key); if (lb != map.end() && lb->first == key) return; - typename InputBindingMap::Serializers serializers; + typename InputBindingMap::Serializers serializers; serializers.shared_ptr = [](void * arptr, std::shared_ptr & dptr, std::type_info const & baseInfo) @@ -652,14 +664,15 @@ namespace cereal //! Initialize the binding OutputBindingCreator() { - auto & map = StaticObject>::getInstance().map; + auto & map = StaticObject::getInstance().map(); + auto lock = StaticObject::lock(); auto key = std::type_index(typeid(T)); auto lb = map.lower_bound(key); if (lb != map.end() && lb->first == key) return; - typename OutputBindingMap::Serializers serializers; + typename OutputBindingMap::Serializers serializers; serializers.shared_ptr = [&](void * arptr, void const * dptr, std::type_info const & baseInfo) diff --git a/include/cereal/types/polymorphic.hpp b/include/cereal/types/polymorphic.hpp index e4398c8f..3bf6eca0 100644 --- a/include/cereal/types/polymorphic.hpp +++ b/include/cereal/types/polymorphic.hpp @@ -194,12 +194,12 @@ namespace cereal //! Get an input binding from the given archive by deserializing the type meta data /*! @internal */ template inline - typename ::cereal::detail::InputBindingMap::Serializers getInputBinding(Archive & ar, std::uint32_t const nameid) + typename ::cereal::detail::InputBindingMap::Serializers getInputBinding(Archive & ar, std::uint32_t const nameid) { // If the nameid is zero, we serialized a null pointer if(nameid == 0) { - typename ::cereal::detail::InputBindingMap::Serializers emptySerializers; + typename ::cereal::detail::InputBindingMap::Serializers emptySerializers; emptySerializers.shared_ptr = [](void*, std::shared_ptr & ptr, std::type_info const &) { ptr.reset(); }; emptySerializers.unique_ptr = [](void*, std::unique_ptr> & ptr, std::type_info const &) { ptr.reset( nullptr ); }; return emptySerializers; @@ -214,7 +214,7 @@ namespace cereal else name = ar.getPolymorphicName(nameid); - auto const & bindingMap = detail::StaticObject>::getInstance().map; + auto const & bindingMap = detail::StaticObject::getInstance().map(); auto binding = bindingMap.find(name); if(binding == bindingMap.end()) @@ -317,7 +317,7 @@ namespace cereal // of an abstract object // this implies we need to do the lookup - auto const & bindingMap = detail::StaticObject>::getInstance().map; + auto const & bindingMap = detail::StaticObject::getInstance().map(); auto binding = bindingMap.find(std::type_index(ptrinfo)); if(binding == bindingMap.end()) @@ -352,7 +352,7 @@ namespace cereal return; } - auto const & bindingMap = detail::StaticObject>::getInstance().map; + auto const & bindingMap = detail::StaticObject::getInstance().map(); auto binding = bindingMap.find(std::type_index(ptrinfo)); if(binding == bindingMap.end()) @@ -416,7 +416,7 @@ namespace cereal // of an abstract object // this implies we need to do the lookup - auto const & bindingMap = detail::StaticObject>::getInstance().map; + auto const & bindingMap = detail::StaticObject::getInstance().map(); auto binding = bindingMap.find(std::type_index(ptrinfo)); if(binding == bindingMap.end()) @@ -451,7 +451,7 @@ namespace cereal return; } - auto const & bindingMap = detail::StaticObject>::getInstance().map; + auto const & bindingMap = detail::StaticObject::getInstance().map(); auto binding = bindingMap.find(std::type_index(ptrinfo)); if(binding == bindingMap.end())