XII Release 0.1.0
Loading...
Searching...
No Matches
xiiSingletonRegistry Class Reference

#include <Singleton.h>

Classes

struct  SingletonEntry

Static Public Member Functions

template<typename Interface>
static Interface * GetSingletonInstance ()
 Retrieves a singleton instance by type name. Returns nullptr if no singleton instance is available.
template<typename Interface>
static Interface * GetRequiredSingletonInstance ()
 Retrieves a singleton instance by type name. Asserts if no singleton instance is available.
static const xiiMap< size_t, SingletonEntry > & GetAllRegisteredSingletons ()
 Allows to inspect all known singletons.
template<typename Interface>
static void Register (Interface *pSingletonInstance)
 Registers a singleton instance under a given type name. This is automatically called by xiiSingletonRegistrar.
template<typename Interface>
static void Unregister ()
 Unregisters a singleton instance. This is automatically called by xiiSingletonRegistrar.

Friends

template<typename>
class xiiSingletonRegistrar

Detailed Description

xiiSingletonRegistry knows about all singleton instances of classes that use XII_DECLARE_SINGLETON.

It allows to query for a specific interface implementation by type name only, which makes it possible to get rid of unwanted library dependencies and use pure virtual interface classes, without singleton code (and thus link dependencies).

Storage is initialized on first use, including registration by global constructors. Concurrent access requires external synchronization when any thread registers or unregisters.

See XII_DECLARE_SINGLETON and XII_DECLARE_SINGLETON_OF_INTERFACE for details.

Member Function Documentation

◆ GetSingletonInstance()

template<typename Interface>
Interface * xiiSingletonRegistry::GetSingletonInstance ( )
inlinestatic

Retrieves a singleton instance by type name. Returns nullptr if no singleton instance is available.

Todo
Events for new/deleted singletons -> xiiInspector integration

The documentation for this class was generated from the following files:
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Configuration/Singleton.h
  • /home/runner/work/XII/XII/Source/Engine/Foundation/Configuration/Implementation/Singleton.cpp