Singleton¶
High-level singleton handling utilities.
Overview¶
Typical use cases:
Managing singleton instances of classes.
Header¶
<RaeptorCogs/Singleton.hpp>
Metadata¶
- Author
Estorc
- Version
v1.0
- Copyright
Copyright (c) 2025 Estorc MIT License.
Structs¶
Struct |
Description |
|---|---|
|
SingletonAccessor struct. |
-
template<typename T>
struct SingletonAccessor¶ SingletonAccessor struct.
Provides access to singleton instances of classes.
class MySingleton { private: MySingleton() = default; // Prevent direct instantiation public: void doSomething() {} friend RaeptorCogs::SingletonAccessor<MySingleton>; }; // Access the singleton instance MySingleton& instance = RaeptorCogs::SingletonAccessor<MySingleton>::get(); instance.doSomething();
- Template Parameters:
T – The class type to manage as a singleton.
Public Static Functions
-
static inline T &get()¶
Get the singleton instance of the class T.
Note
The constructor of T must be private or protected, and SingletonAccessor must be declared as a friend of T. Accessing this method will create the instance on first call and return a reference to it.
- Returns:
Reference to the singleton instance of T.