cereal
A C++11 library for serialization
Classes | Macros | Functions
polymorphic_impl.hpp File Reference

Internal polymorphism support. More...

#include <cereal/details/static_object.hpp>
#include <cereal/types/memory.hpp>
#include <cereal/types/string.hpp>
#include <functional>
#include <typeindex>
#include <map>

Go to the source code of this file.

Classes

struct  cereal::detail::binding_name< T >
 Binds a compile time type with a user defined string. More...
 
struct  cereal::detail::OutputBindingMap< Archive >
 A structure holding a map from type_indices to output serializer functions. More...
 
struct  cereal::detail::OutputBindingMap< Archive >::Serializers
 Struct containing the serializer functions for all pointer types. More...
 
struct  cereal::detail::EmptyDeleter< T >
 An empty noop deleter. More...
 
struct  cereal::detail::InputBindingMap< Archive >
 A structure holding a map from type name strings to input serializer functions. More...
 
struct  cereal::detail::InputBindingMap< Archive >::Serializers
 Struct containing the serializer functions for all pointer types. More...
 
struct  cereal::detail::InputBindingCreator< Archive, T >
 Creates a binding (map entry) between an input archive type and a polymorphic type. More...
 
struct  cereal::detail::OutputBindingCreator< Archive, T >
 Creates a binding (map entry) between an output archive type and a polymorphic type. More...
 
class  cereal::detail::OutputBindingCreator< Archive, T >::PolymorphicSharedPointerWrapper
 Holds a properly typed shared_ptr to the polymorphic type. More...
 
struct  cereal::detail::adl_tag
 
struct  cereal::detail::create_bindings< Archive, T >
 Causes the static object bindings between an archive type and a serializable type T. More...
 
struct  cereal::detail::instantiate_function<>
 When specialized, causes the compiler to instantiate its parameter. More...
 
struct  cereal::detail::polymorphic_serialization_support< Archive, T >
 
struct  cereal::detail::bind_to_archives< T, Tag >
 Begins the binding process of a type to all registered archives. More...
 
struct  cereal::detail::init_binding< T, Tag >
 Used to hide the static object used to bind T to registered archives. More...
 

Macros

#define CEREAL_BIND_TO_ARCHIVES(T)
 Binds a polymorhic type to all registered archives. More...
 

Functions

template<class T , typename BindingTag >
void cereal::detail::instantiate_polymorphic_binding (T *, int, BindingTag, adl_tag)
 Base case overload for instantiation. More...
 

Detailed Description

Internal polymorphism support.

Macro Definition Documentation

#define CEREAL_BIND_TO_ARCHIVES (   T)
Value:
namespace cereal { \
namespace detail { \
template<> \
struct init_binding<T> { \
static bind_to_archives<T> const & b; \
static void unused() { (void)b; } \
}; \
bind_to_archives<T> const & init_binding<T>::b = \
bind_to_archives<T> \
>::getInstance().bind(); \
}} /* end namespaces */
Definition: access.hpp:39
A static, pre-execution object.
Definition: static_object.hpp:61

Binds a polymorhic type to all registered archives.

This binds a polymorphic type to all compatible registered archives that have been registered with CEREAL_REGISTER_ARCHIVE. This must be called after all archives are registered (usually after the archives themselves have been included).

Function Documentation

template<class T , typename BindingTag >
void cereal::detail::instantiate_polymorphic_binding ( T *  ,
int  ,
BindingTag  ,
adl_tag   
)

Base case overload for instantiation.

This will end up always being the best overload due to the second parameter always being passed as an int. All other overloads will accept pointers to archive types and have lower precedence than int.

Since the compiler needs to check all possible overloads, the other overloads created via CEREAL_REGISTER_ARCHIVE, which will have lower precedence due to requring a conversion from int to (Archive*), will cause their return types to be instantiated through the static object mechanisms even though they are never called.

See the documentation for the other functions to try and understand this