@@ -122,6 +122,26 @@ namespace cereal
122
122
"Make sure you either serialize the base class at some point via cereal::base_class or cereal::virtual_base_class.\n" \
123
123
"Alternatively, manually register the association with CEREAL_REGISTER_POLYMORPHIC_RELATION.");
124
124
125
+ // ! Checks if the mapping object that can perform the upcast or downcast
126
+ /* ! Uses the type index from the base and derived class to find the matching
127
+ registered caster. If no matching caster exists, returns false. */
128
+ static bool exists ( std::type_index const & baseIndex, std::type_index const & derivedIndex )
129
+ {
130
+ // First phase of lookup - match base type index
131
+ auto & baseMap = StaticObject<PolymorphicCasters>::getInstance ().map ;
132
+ auto baseIter = baseMap.find ( baseIndex );
133
+ if (baseIter == baseMap.end ())
134
+ return false ;
135
+
136
+ // Second phase - find a match from base to derived
137
+ auto & derivedMap = baseIter->second ;
138
+ auto derivedIter = derivedMap.find ( derivedIndex );
139
+ if (derivedIter == derivedMap.end ())
140
+ return false ;
141
+
142
+ return true ;
143
+ }
144
+
125
145
// ! Gets the mapping object that can perform the upcast or downcast
126
146
/* ! Uses the type index from the base and derived class to find the matching
127
147
registered caster. If no matching caster exists, calls the exception function.
@@ -141,7 +161,7 @@ namespace cereal
141
161
auto derivedIter = derivedMap.find ( derivedIndex );
142
162
if ( derivedIter == derivedMap.end () )
143
163
exceptionFunc ();
144
-
164
+
145
165
return derivedIter->second ;
146
166
}
147
167
@@ -215,9 +235,9 @@ namespace cereal
215
235
{
216
236
auto checkRelation = [](std::type_index const & baseInfo, std::type_index const & derivedInfo)
217
237
{
218
- bool exists = true ;
219
- auto const & mapping = PolymorphicCasters::lookup ( baseInfo, derivedInfo, [& ](){ exists = false ; } );
220
- return std::make_pair ( exists, exists ? mapping : std::vector<PolymorphicCaster const *>{} );
238
+ const bool exists = PolymorphicCasters::exists ( baseInfo, derivedInfo ) ;
239
+ return std::make_pair ( exists, exists ? PolymorphicCasters::lookup ( baseInfo, derivedInfo, [](){} ) :
240
+ std::vector<PolymorphicCaster const *>{} );
221
241
};
222
242
223
243
for ( auto baseIt : baseMap )
@@ -599,6 +619,7 @@ namespace cereal
599
619
#endif // _MSC_VER
600
620
};
601
621
622
+ // #if defined(_WINDLL)
602
623
// instantiate implementation
603
624
template <class Archive , class T >
604
625
CEREAL_DLL_EXPORT void polymorphic_serialization_support<Archive,T>::instantiate()
@@ -611,6 +632,7 @@ namespace cereal
611
632
std::is_base_of<detail::InputArchiveBase, Archive>::value &&
612
633
traits::is_input_serializable<T, Archive>::value>{} );
613
634
}
635
+ // #endif
614
636
615
637
// ! Begins the binding process of a type to all registered archives
616
638
/* ! Archives need to be registered prior to this struct being instantiated via
0 commit comments