|
sftools
2.0 dev
Bunch of tools for SFML application development
|
Non intruisive and customizable singleton system. More...
#include <Singleton.hpp>
Collaboration diagram for sftools::Singleton< T, F >:Static Public Member Functions | |
| static T & | getInstance () |
| Get the unique instance. | |
| static void | create (bool force=false, F const &factory=F()) |
| Initialise the instance. | |
| static void | destroy () |
| Destroy the instance if it exists. | |
| static bool | exists () |
| Tells if the instance was created. | |
Non intruisive and customizable singleton system.
Basic usage example :
Usually you don't have to specify a type for F; the default type should be enough. However if T can't be instanciated with new T(); (e.g. it need some parameters) you can create a factory type that :
T* operator()() const methodSometimes your might want to use a factory with custom parameters (i.e. using the default constructor for the factory doesn't fit your plan). In that case you can do as in the following example
T so the singleton object could be used everywhere T is used. However there might be issues with NonCopyable and NonInstanceable.| T | Type to be "singletonized" |
| F | Factory type used to create an instance of T. |
Definition at line 128 of file Singleton/Singleton.hpp.
|
static |
Initialise the instance.
F is used to generate a object of type T.
| force | if force is true then the instance is destroyed and recreated; otherwise the instance is only created if it doesn't exist yet. |
| factory | factory object used to create the instance. |
Definition at line 45 of file Singleton.tpp.
|
static |
|
static |
|
static |
Get the unique instance.
Calls create (with its default parameters) if the instance doesn't exist yet.
Definition at line 34 of file Singleton.tpp.
Referenced by sftools::loader::ResourceLoader< R >::operator()().
1.8.3