Singleton

Engine/source/core/util/tSingleton.h

This is a simple thread safe singleton class based on the design of boost::singleton_default (see http://www.boost.org/).

More...

Classes:

Private Static Attributes

SingletonCreator

Private Functions

This is private on purpose.

Public Static Functions

T *

Returns the singleton instance.

Detailed Description

This is a simple thread safe singleton class based on the design of boost::singleton_default (see http://www.boost.org/).

This singleton is guaranteed to be constructed before main() is called and destroyed after main() exits. It will also be created on demand if Singleton::instance() is called before main() begins.

This thread safety only works within the execution context of main(). Access to the singleton from multiple threads outside of main() is is not guaranteed to be thread safe.

To create a singleton you only need to access it once in your code:

Singleton::instance()->myFunction();

You do not need to derive from this class.

note:

Generally stay away from this class (!!) except if your class T has no meaningful constructor. Otherwise, it is very easy to make execution of global ctors ordering dependent.

Private Static Attributes

SingletonCreator smSingletonCreator 

Private Functions

Singleton()

This is private on purpose.

Public Static Functions

instance()

Returns the singleton instance.