Skip to content

SingletonInterface

#include <mrx/core/SingletonInterface.hpp>
template<typename T>
class mrx::core::SingletonInterface

Provides lazy singleton construction for service-style classes.

To use this helper, the target type T should:

  • inherit from SingletonInterface<T>
  • keep its constructors private to enforce singleton-only construction
  • declare friend class SingletonInterface<T>; so the helper can instantiate it

Service types are also expected to inherit QObject so they cooperate correctly with the Qt ownership and pointer patterns used throughout the SDK.

  • T Concrete singleton service type managed by this helper.
ReturnNameDescription
T*instance static inlineReturns the singleton instance for the concrete service type.

static inline
static inline T* instance()

Returns the singleton instance for the concrete service type.

The instance is constructed on first use and then reused for the remainder of the process lifetime, subject to the lifetime semantics of the static shared pointer.

Pointer to the shared singleton instance.

ReturnNameDescription
SingletonInterface inline explicitConstructs the singleton base portion of the derived service type.

inline explicit
inline explicit SingletonInterface()

Constructs the singleton base portion of the derived service type.

The constructor is protected so only derived singleton service classes can create instances through SingletonInterface<T>.