Leosac  0.8.0
Open Source Access Control
Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs > Class Template Reference

Provides dynamic serializers management for a given object's hierarchy. More...

#include <ExtensibleSerializer.hpp>

+ Collaboration diagram for Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >:

Public Types

using SerializationCallable = std::function< SerializedT(const ObjectT &, AdditionalArgs &&...)>
 Callable type for serialization. More...
 

Public Member Functions

SerializedT serialize (const ObjectT &input, AdditionalArgs &&... args) const
 
template<typename T , typename Callable >
void register_serializer (Callable &&callable)
 Register a serializer for T. More...
 
template<typename T >
void unregister_serializer ()
 

Private Attributes

std::recursive_mutex mutex_
 
std::map< boost::typeindex::type_index, SerializationCallableserializers_
 

Detailed Description

template<typename SerializedT, typename ObjectT, typename... AdditionalArgs>
class Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >

Provides dynamic serializers management for a given object's hierarchy.

Clients are able to add serializers for a concrete subtype of ObjectT. They can also remove serializers, and call the serialize() method.

Note
: The ExtensibleSerializer is thread safe. Management of user-defined serializers, aswell as invocation of serializers is performed while holding an internal recursive mutex. It is therefore allowed for a serializer implementation to make call to the ExtensibleSerializer. However, be careful to avoid deadlock if using multiple ExtensibleSerializer.
Template Parameters
SerializedTThe type of serialization output.
ObjectTThe base type of the class hierarchy this serializer will be able to handle.
AdditionalArgsA variadic parameter that let the serialize() method accepts additional arguments and forward them to the user-provided serialization callable.

Definition at line 53 of file ExtensibleSerializer.hpp.

Member Typedef Documentation

◆ SerializationCallable

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
using Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::SerializationCallable = std::function<SerializedT(const ObjectT &, AdditionalArgs &&...)>

Callable type for serialization.

Definition at line 77 of file ExtensibleSerializer.hpp.

Member Function Documentation

◆ register_serializer()

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
template<typename T , typename Callable >
void Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::register_serializer ( Callable &&  callable)
inline

Register a serializer for T.

Definition at line 83 of file ExtensibleSerializer.hpp.

◆ serialize()

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
SerializedT Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::serialize ( const ObjectT &  input,
AdditionalArgs &&...  args 
) const
inline

Definition at line 56 of file ExtensibleSerializer.hpp.

◆ unregister_serializer()

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
template<typename T >
void Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::unregister_serializer ( )
inline

Definition at line 112 of file ExtensibleSerializer.hpp.

Member Data Documentation

◆ mutex_

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
std::recursive_mutex Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::mutex_
mutableprivate

Definition at line 121 of file ExtensibleSerializer.hpp.

◆ serializers_

template<typename SerializedT , typename ObjectT , typename... AdditionalArgs>
std::map<boost::typeindex::type_index, SerializationCallable> Leosac::ExtensibleSerializer< SerializedT, ObjectT, AdditionalArgs >::serializers_
private

Definition at line 122 of file ExtensibleSerializer.hpp.


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