Library of Assembled Shared Sources
|
non-intrusive singleton holder. More...
#include <singleton.h>
Static Public Member Functions | |
static TInstance * | instance () |
Return pointer to singleton instance. | |
Protected Member Functions | |
void | subscribeInstance (int iDestructionPriority) |
Subscribe to the singleton guard. | |
Related Symbols | |
(Note that these are not member symbols.) | |
enum | DestructionPriorities |
Destruction priority constants. More... | |
non-intrusive singleton holder.
With this class, it's possible to create a singleton of a class Foo. It's a non-instrusive singleton because it's not required to derive Foo from this Singleton class. Instead, this class will be a holder to a singleton object of Foo. To use class Foo as a singleton is very straight forward, but can be done in a couple of ways:
Foo
. To access the singleton, you must now use the instance()
method on that new type:Both ways only differ in how to access the instance. All other properties are common:
TFooSingleton::instance()
or foo()
is called, a new object of Foo
is allocated on the heap, and a pointer to it is returned. All the following calls will return that same pointer. This is the way how to control the order of construction: on first access.The order of destruction can be set by the DestructionPriority
. Singletons with a smaller destruction priority will be destructed later than those with a higher destruction priority. It's not specified in which order singletons with identical destruction priorities will be destructed (i.e. its not guaranteed for such singletons that the last one constructed will be the first to be destroyed). You can set the destruction priority by the second template argument of Singleton:
lass::util::Singleton<Foo,2000>
will specify the singleton to have a destruction priority of 2000. The default destruction priority is set to be 1000. Priorities below 500 are reserved for the Lass implementation (and for you who know what you're doing ;)
warning: lass::io::proxyMan() is a proxy man that is needed for the implementation of all logging activities etc. Its destruction priority is set to 0 and there should be no other singleton have a destruction priority lower or equal than this.
Foo:
Since it has to be constructed on the heap without any parameters in the neighbourhoud, it has to have a default constructor.Reference:
Definition at line 140 of file singleton.h.
|
static |
Return pointer to singleton instance.
An instance is created on first call. Return NULL if instance is dead already (after first destruction of singletons).
Definition at line 82 of file singleton.inl.
References instance(), and lass::util::impl::SingletonBase::subscribeInstance().
Referenced by instance(), lass::util::processPriorityDictionary(), and lass::io::proxyMan().
|
protectedinherited |
Subscribe to the singleton guard.
Do this only once for each singleton, and in fact, don't do it yourself at all since Singleton<> already does it :)
Definition at line 207 of file singleton_impl.cpp.
References lass::util::destructionPriorityNever.
Referenced by lass::util::Singleton< T, destructPriority >::instance().
|
Destruction priority constants.
Priorities levels below singletonDestructionPriorityBeginUserRange (=500) are reserved for the implementation of Lass, and should not be used by user code (unless you know what you're doing of course ;)
Definition at line 124 of file singleton.h.