#include <SerializableSingleton.hpp>
Inherits boost::noncopyable.
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 |
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:
SerializableSingleton<RandomNumberGenerator>* const p_wrapper = p_gen->GetSerializationWrapper(); output_arch << p_wrapper;
For loading:
SerializableSingleton<RandomNumberGenerator>* p_wrapper; input_arch >> p_wrapper;
Within a serialize method:
SerializableSingleton<RandomNumberGenerator>* p_wrapper = p_gen->GetSerializationWrapper(); 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 73 of file SerializableSingleton.hpp.
SerializableSingleton<SINGLETON_CLASS>* SerializableSingleton< SINGLETON_CLASS >::GetSerializationWrapper | ( | ) | const [inline] |
Get the wrapper object to use to serialize the related singleton instance.
Definition at line 79 of file SerializableSingleton.hpp.
Referenced by StochasticWntCellCycleModel::serialize(), AbstractCellBasedSimulation< DIM >::serialize(), RandomCellKiller< DIM >::serialize(), StochasticOxygenBasedCellCycleModel::serialize(), StochasticDurationGenerationBasedCellCycleModel::serialize(), StochasticDurationCellCycleModel::serialize(), and AbstractCellCycleModel::serialize().
void SerializableSingleton< SINGLETON_CLASS >::load | ( | Archive & | archive, | |
const unsigned int | version | |||
) | [inline, private] |
Load the wrapped singleton.
archive | the archive | |
version | the saved version of this class |
Reimplemented in RandomNumberGenerator.
Definition at line 108 of file SerializableSingleton.hpp.
void SerializableSingleton< SINGLETON_CLASS >::save | ( | Archive & | archive, | |
const unsigned int | version | |||
) | const [inline, private] |
Save the wrapped singleton.
archive | the archive | |
version | the current version of this class |
Reimplemented in RandomNumberGenerator.
Definition at line 94 of file SerializableSingleton.hpp.