![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <TypeContainer.h>
Public Member Functions | |
| template<class R > | |
| TSharedRef< R, Mode > | GetInstance () const |
| template<class R > | |
| TSharedRef< R, Mode > | GetInstanceRef () const |
| template<class R > | |
| bool | IsRegistered () const |
| template<class R , class T , typename... P> | |
| void | RegisterClass (ETypeContainerScope Scope=ETypeContainerScope::Process) |
| template<class R , class D , typename... P> | |
| void | RegisterDelegate (D Delegate) |
| template<class R > | |
| void | RegisterFactory (const TFunction< TSharedRef< R, Mode >()> &CreateFunc) |
| template<class R , typename P0 , typename... P> | |
| void | RegisterFactory (const TFunction< TSharedRef< R, Mode >(TSharedRef< P0, Mode >, TSharedRef< P, Mode >...)> &CreateFunc) |
| template<class R , class T > | |
| void | RegisterInstance (const TSharedRef< T, Mode > &Instance) |
| template<class R > | |
| void | Unregister () |
Protected Member Functions | |
| void | AddProvider (const TCHAR *Name, const TSharedPtr< IInstanceProvider > &Provider) |
Template for type containers.
Type containers allow for configuring objects and their dependencies without actually creating these objects. They fulfill a role similar to class factories, but without being locked to a particular type of class. When passed into class constructors or methods, type containers can facilitate the Inversion of Control (IoC) pattern.
Since UE neither uses run-time type information nor pre-processes plain old C++ classes, type names need to be exposed using the Expose_TNameOf macro in order to make them registrable with type containers, i.e. Expose_TNameOf(FMyClass).
Once a type is registered with a container, instances of that type can be retrieved from it. There are currently three life time scopes available for instance creation:
See the file TypeContainerTest.cpp for detailed examples on how to use each of these type registration methods.
In the interest of fast performance, the object pointers returned by type containers are not thread-safe by default. If you intend to use the same type container and share its objects from different threads, use TTypeContainer<ESPMode::ThreadSafe> instead, which will then manage and return thread-safe versions of all object pointers.
Note: Type containers depend on variadic templates and are therefore not available on XboxOne at this time, which means they should only be used for desktop applications.
|
inlineprotected |
Add an instance provider to the container.
| Name | The name of the type to add the provider for. |
| Provider | The instance provider. |
|
inline |
Gets a shared pointer to an instance of the specified class.
| R | The type of class to get an instance for. |
| A | shared reference to the instance. |
|
inline |
Gets a shared reference to an instance of the specified class.
Unlike GetInstance(), this function will assert if no instance was registered for the requested type of class using either RegisterClass() or RegisterInstance().
| R | The type of class that an instance is being requested for. |
| A | shared pointer to the instance. |
|
inline |
Check whether the specified class has been registered.
| R | The type of registered class to check. |
|
inline |
Registers a class for instances of the specified class.
| R | The type of class to register an instance class for. |
| T | Tye type of class to register (must be the same as or derived from R). |
| P | The constructor parameters that the class requires. |
| Scope | The scope at which instances must be unique (default = Process). |
|
inline |
Register a factory delegate for the specified class.
| R | The type of class to register an instance class for. |
| D | Tye type of factory delegate to register. |
| P | The parameters that the delegate requires. |
| Delegate | The delegate to register. |
|
inline |
Register a factory function for the specified class.
| R | The type of class to register the instance for. |
| P | Additional parameters that the factory function requires. |
| CreateFunc | The factory function that will create instances. |
|
inline |
Register a factory function for the specified class.
| R | The type of class to register the instance for. |
| P0 | The first parameter that the factory function requires. |
| P | Additional parameters that the factory function requires. |
| CreateFunc | The factory function that will create instances. |
|
inline |
Registers an existing instance for the specified class.
| R | The type of class to register the instance for. |
| T | The type of the instance to register (must be the same as or derived from R). |
| Instance | The instance of the class to register. |
|
inline |
Unregisters the instance or class for a previously registered class.
| R | The type of class to unregister. |