|
Schnek
|
#include <singleton.hpp>
Static Public Member Functions | |
| static TYPE & | instance () |
Protected Member Functions | |
| ~Singleton () | |
A singleton template class
The singleton has an instance type specified by TYPE and a creation policy specified by CreationPolicy<TYPE>.
The singleton instance should make the constructors, destructors and copy operators private, so no two instances can be generated at any time. The CreationPolicy<TYPE> should be made the only friend to the instance class. Only the default constructor and the destructor then normally need to be implemented. (This of course can depend on the CreationPolicy)
The CreationPolicy should define the method "static TYPE* create()" which returns a new instance of the singleton instance class.
Access to the singleton instance is through the static instance() method.
The Singleton class itself can not be instantiated because all constructors are private.
|
inlineprotected |
Destructor made private and not implemented
|
inlinestatic |
Access to the singleton instance.
If no instance exists the CreationPolicy<TYPE>::create() method is called to create one.