Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Interface< T > Class Template Referencefinal

#include <Interface.h>

Inherited by AZ::Internal::IdHandler< Interface, Traits, ContainerType >, AZ::Internal::MultiHandler< Interface, Traits, ContainerType >, and AZ::Internal::NonIdHandler< Interface, Traits, ContainerType >.

Classes

class  Registrar
 

Public Types

using ErrorString = InterfaceErrorString
 
using RegisterOutcome = InterfaceRegisterOutcome
 

Static Public Member Functions

static RegisterOutcome Register (T *type)
 
static RegisterOutcome Unregister (T *type)
 
static T * Get ()
 

Detailed Description

template<typename T>
class AZ::Interface< T >

Interface class for accessing registered singletons across module boundaries. The raw interface pointer is handed to you; the assumption is that the registered system will outlive cached references. A system must register itself with the interface at initialization time by calling Register(); and unregister at shutdown by calling Unregister(). The provided Registrar class will do this for you automatically. Registration will only succeed after the AZ::Environment has been attached and is ready.

Example Usage:

class ISystem
{
public:
virtual ~ISystem();
virtual void DoSomething() = 0;
};
class System
: public AZ::Interface<ISystem>::Registrar
{
public:
void DoSomething() override;
};
// In client code.
// Check that the pointer is valid before use.
if (ISystem* system = AZ::Interface<ISystem>::Get())
{
system->DoSomething();
}
Definition: Interface.h:62

Member Function Documentation

◆ Get()

template<typename T >
T * AZ::Interface< T >::Get
static

Returns the registered interface pointer, if it exists. This method is thread-safe in that you can call Get from multiple threads. Likewise, calls to Register / Unregister are guarded, but it is highly recommended to restrict Register / Unregister to a dedicated serial code path.

◆ Register()

template<typename T >
auto AZ::Interface< T >::Register ( T *  type)
static

Registers an instance pointer to the interface. Only one instance is allowed to register at a time.

◆ Unregister()

template<typename T >
auto AZ::Interface< T >::Unregister ( T *  type)
static

Unregisters from the interface. An unregister must occur in the same module as the original Register call; the pointer must match the original call to Register.


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