NDDEM
Public Types | Static Public Member Functions | Public Attributes | List of all members
cereal::detail::PolymorphicCasters Struct Reference

Holds registered mappings between base and derived types for casting. More...

#include <polymorphic_impl.hpp>

Public Types

using DerivedCasterMap = std::unordered_map< std::type_index, std::vector< PolymorphicCaster const * > >
 Maps from a derived type index to a set of chainable casters. More...
 

Static Public Member Functions

static std::pair< bool, std::vector< PolymorphicCaster const * > const & > lookup_if_exists (std::type_index const &baseIndex, std::type_index const &derivedIndex)
 Checks if the mapping object that can perform the upcast or downcast exists, and returns it if so. More...
 
template<class F >
static std::vector< PolymorphicCaster const * > constlookup (std::type_index const &baseIndex, std::type_index const &derivedIndex, F &&exceptionFunc)
 Gets the mapping object that can perform the upcast or downcast. More...
 
template<class Derived >
static const Derived * downcast (const void *dptr, std::type_info const &baseInfo)
 Performs a downcast to the derived type using a registered mapping. More...
 
template<class Derived >
static void * upcast (Derived *const dptr, std::type_info const &baseInfo)
 Performs an upcast to the registered base type using the given a derived type. More...
 
template<class Derived >
static std::shared_ptr< void > upcast (std::shared_ptr< Derived > const &dptr, std::type_info const &baseInfo)
 Upcasts for shared pointers. More...
 

Public Attributes

std::unordered_map< std::type_index, DerivedCasterMapmap
 Maps from base type index to a map from derived type index to caster. More...
 
std::multimap< std::type_index, std::type_index > reverseMap
 

Detailed Description

Holds registered mappings between base and derived types for casting.

This will be allocated as a StaticObject and holds a map containing all registered mappings between base and derived types.

Member Typedef Documentation

◆ DerivedCasterMap

using cereal::detail::PolymorphicCasters::DerivedCasterMap = std::unordered_map<std::type_index, std::vector<PolymorphicCaster const *> >

Maps from a derived type index to a set of chainable casters.

Member Function Documentation

◆ downcast()

template<class Derived >
static const Derived* cereal::detail::PolymorphicCasters::downcast ( const void *  dptr,
std::type_info const baseInfo 
)
inlinestatic

Performs a downcast to the derived type using a registered mapping.

◆ lookup()

template<class F >
static std::vector<PolymorphicCaster const *> const& cereal::detail::PolymorphicCasters::lookup ( std::type_index const baseIndex,
std::type_index const derivedIndex,
F &&  exceptionFunc 
)
inlinestatic

Gets the mapping object that can perform the upcast or downcast.

Uses the type index from the base and derived class to find the matching registered caster. If no matching caster exists, calls the exception function.

The returned PolymorphicCaster is capable of upcasting or downcasting between the two types.

◆ lookup_if_exists()

static std::pair<bool, std::vector<PolymorphicCaster const *> const &> cereal::detail::PolymorphicCasters::lookup_if_exists ( std::type_index const baseIndex,
std::type_index const derivedIndex 
)
inlinestatic

Checks if the mapping object that can perform the upcast or downcast exists, and returns it if so.

Uses the type index from the base and derived class to find the matching registered caster. If no matching caster exists, the bool in the pair will be false and the vector reference should not be used.

◆ upcast() [1/2]

template<class Derived >
static void* cereal::detail::PolymorphicCasters::upcast ( Derived *const  dptr,
std::type_info const baseInfo 
)
inlinestatic

Performs an upcast to the registered base type using the given a derived type.

The return is untyped because the final casting to the base type must happen in the polymorphic serialization function, where the type is known at compile time

◆ upcast() [2/2]

template<class Derived >
static std::shared_ptr<void> cereal::detail::PolymorphicCasters::upcast ( std::shared_ptr< Derived > const dptr,
std::type_info const baseInfo 
)
inlinestatic

Upcasts for shared pointers.

Member Data Documentation

◆ map

std::unordered_map<std::type_index, DerivedCasterMap> cereal::detail::PolymorphicCasters::map

Maps from base type index to a map from derived type index to caster.

◆ reverseMap

std::multimap<std::type_index, std::type_index> cereal::detail::PolymorphicCasters::reverseMap

The documentation for this struct was generated from the following file: