ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
original::singleton< TYPE > Class Template Reference

Thread-safe singleton pattern implementation with ownership management. More...

#include <singleton.h>

Collaboration diagram for original::singleton< TYPE >:
Collaboration graph

Public Member Functions

 singleton (const singleton &)=delete
 Deleted copy constructor to prevent copying.
 
singletonoperator= (const singleton &)=delete
 Deleted copy assignment operator to prevent copying.
 
 singleton (singleton &&)=delete
 Deleted move constructor to prevent moving.
 
singletonoperator= (singleton &&)=delete
 Deleted move assignment operator to prevent moving.
 

Static Public Member Functions

static bool exist ()
 Checks if the singleton instance exists.
 
template<typename... Args>
static void init (Args &&... args)
 Initializes the singleton instance with provided arguments.
 
static TYPEinstance ()
 Provides access to the singleton instance.
 
static void clear ()
 Clears the singleton instance.
 
template<typename... Args>
static void reset (Args &&... args)
 Resets the singleton instance with new arguments.
 

Detailed Description

template<typename TYPE>
class original::singleton< TYPE >

Thread-safe singleton pattern implementation with ownership management.

Template Parameters
TYPEType of the singleton instance

Provides a global point of access to a single instance of TYPE while ensuring proper initialization, destruction, and ownership semantics. Uses ownerPtr for exclusive ownership and automatic cleanup.

Key Features:

Note
This implementation is not thread-safe for simultaneous init()/reset() calls. For thread-safe usage, ensure proper synchronization at the application level.
Examples
/home/runner/work/original/original/src/core/singleton.h.

Member Function Documentation

◆ clear()

template<typename TYPE >
void original::singleton< TYPE >::clear ( )
static

Clears the singleton instance.

Postcondition
instance_ becomes nullptr, existing instance is destroyed
Note
Safe to call even if instance doesn't exist
Examples
/home/runner/work/original/original/src/core/singleton.h.

◆ exist()

template<typename TYPE >
bool original::singleton< TYPE >::exist ( )
static

Checks if the singleton instance exists.

Returns
true if instance is initialized, false otherwise
Examples
/home/runner/work/original/original/src/core/singleton.h.

◆ init()

template<typename TYPE >
template<typename ... Args>
void original::singleton< TYPE >::init ( Args &&...  args)
static

Initializes the singleton instance with provided arguments.

Template Parameters
ArgsArgument types for TYPE constructor
Parameters
argsArguments to forward to TYPE constructor
Exceptions
valueErrorif instance already exists
singleton<MyClass>::init(arg1, arg2); // Initialize with constructor arguments
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
static void init(Args &&... args)
Initializes the singleton instance with provided arguments.
Definition singleton.h:164
Examples
/home/runner/work/original/original/src/core/singleton.h.

◆ instance()

template<typename TYPE >
TYPE & original::singleton< TYPE >::instance ( )
static

Provides access to the singleton instance.

Returns
Reference to the singleton instance of TYPE
Exceptions
nullPointerErrorif instance not initialized
auto& instance = singleton<MyClass>::instance(); // Access the instance
instance.someMethod();
static TYPE & instance()
Provides access to the singleton instance.
Definition singleton.h:173
Examples
/home/runner/work/original/original/src/core/singleton.h.

◆ reset()

template<typename TYPE >
template<typename ... Args>
void original::singleton< TYPE >::reset ( Args &&...  args)
static

Resets the singleton instance with new arguments.

Template Parameters
ArgsArgument types for TYPE constructor
Parameters
argsArguments to forward to TYPE constructor
Note
Destroys existing instance and creates a new one
singleton<MyClass>::reset(newArg1, newArg2); // Replace existing instance
static void reset(Args &&... args)
Resets the singleton instance with new arguments.
Definition singleton.h:189
Examples
/home/runner/work/original/original/src/core/singleton.h.

The documentation for this class was generated from the following file: