A singleton that wraps a pointer provided by a storage.
More...
#include <gf/Singleton.h>
template<typename T>
class gf::Singleton< T >
A singleton that wraps a pointer provided by a storage.
This class should be used with a global variable. It acts as an access to a singleton which storage is provided by a gf::SingletonStorage<T>.
int main() {
gFoo().bar();
}
A singleton that wraps a pointer provided by a storage.
Definition: Singleton.h:55
A storage for a singleton.
Definition: Singleton.h:148
- See also
- gf::SingletonStorage
◆ Singleton() [1/3]
Default constructor.
It initialize the underlying pointer to nullptr
. The actual initialization is done when the storage is allocated.
◆ Singleton() [2/3]
Deleted copy constructor.
◆ Singleton() [3/3]
Deleted move constructor.
◆ isValid()
Check if the singleton has been initialized.
- Returns
- True if the singleton is valid
◆ operator()()
Access the singleton.
The access of the singleton must be done after a storage has been provided. Otherwise, the behaviour is undefined (and may result in a crash).
- Returns
- a reference to the stored singleton
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ reset()
Reset the singleton.
After a call to this function, the singleton must be accessed anymore.