Chaste Commit::ca8ccdedf819b6e02855bc0e8e6f50bdecbc5208
SerializableSingleton< SINGLETON_CLASS > Class Template Reference

#include <SerializableSingleton.hpp>

+ Inheritance diagram for SerializableSingleton< SINGLETON_CLASS >:
+ Collaboration diagram for SerializableSingleton< SINGLETON_CLASS >:

Public Member Functions

SerializableSingleton< SINGLETON_CLASS > * GetSerializationWrapper () const
 

Private Member Functions

template<class Archive >
void save (Archive &archive, const unsigned int version) const
 
template<class Archive >
void load (Archive &archive, const unsigned int version)
 

Friends

class boost::serialization::access
 

Detailed Description

template<class SINGLETON_CLASS>
class SerializableSingleton< SINGLETON_CLASS >

This is a "wrapper" allowing more straightforward serialization of singleton classes. Any singleton class which needs to be serialized should inherit from this base. It provides both part of the "singleton-ness" (by inheriting from boost::noncopyable), and also a method GetSerializationWrapper(). Users of the singleton which wish to serialize it should not do so directly. Instead, they should call GetSerializationWrapper and serialize the returned pointer. Doing so will ensure that only a single global instance of the singleton is maintained when loading from an archive.

Note that if this is not done, and the singleton is serialized directly via the instance pointer, then objects loaded from the archive will refer to a different instance of the singleton from other code!

Usage examples:

For saving:

output_arch << p_wrapper;
SerializableSingleton< SINGLETON_CLASS > * GetSerializationWrapper() const

For loading:

input_arch >> p_wrapper;

Within a serialize method:

archive & p_wrapper;

Note that immediately after a load the wrapper pointer loaded into becomes invalid; call GetSerializationWrapper again if you need a new wrapper for a subsequent save.

Definition at line 80 of file SerializableSingleton.hpp.

Member Function Documentation

◆ GetSerializationWrapper()

◆ load()

template<class SINGLETON_CLASS >
template<class Archive >
void SerializableSingleton< SINGLETON_CLASS >::load ( Archive &  archive,
const unsigned int  version 
)
inlineprivate

Load the wrapped singleton.

Parameters
archivethe archive
versionthe saved version of this class

Definition at line 115 of file SerializableSingleton.hpp.

◆ save()

template<class SINGLETON_CLASS >
template<class Archive >
void SerializableSingleton< SINGLETON_CLASS >::save ( Archive &  archive,
const unsigned int  version 
) const
inlineprivate

Save the wrapped singleton.

Parameters
archivethe archive
versionthe current version of this class

Definition at line 101 of file SerializableSingleton.hpp.

Friends And Related Symbol Documentation

◆ boost::serialization::access

template<class SINGLETON_CLASS >
friend class boost::serialization::access
friend

Definition at line 92 of file SerializableSingleton.hpp.


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