ezEngine  Release 25.03
ezSingletonRegistry Class Reference

ezSingletonRegistry knows about all singleton instances of classes that use EZ_DECLARE_SINGLETON. More...

#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. More...
 
template<typename Interface >
static Interface * GetRequiredSingletonInstance ()
 Retrieves a singleton instance by type name. Asserts if no singleton instance is available.
 
static const ezMap< 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 ezSingletonRegistrar.
 
template<typename Interface >
static void Unregister ()
 Unregisters a singleton instance. This is automatically called by ezSingletonRegistrar.
 

Friends

template<typename >
class ezSingletonRegistrar
 

Detailed Description

ezSingletonRegistry knows about all singleton instances of classes that use EZ_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).

See EZ_DECLARE_SINGLETON and EZ_DECLARE_SINGLETON_OF_INTERFACE for details.

Member Function Documentation

◆ GetSingletonInstance()

template<typename Interface >
static Interface* ezSingletonRegistry::GetSingletonInstance ( )
inlinestatic

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

Todo:
Events for new/deleted singletons -> ezInspector integration

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