Ark Server API (ASA) - Wiki
|
#include <TypeContainer.h>
Classes | |
struct | FThreadInstanceProvider |
class | IInstanceProvider |
struct | TFunctionInstanceProvider |
struct | TSharedInstanceProvider |
struct | TThreadInstanceProvider |
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) |
Private Attributes | |
FCriticalSection | CriticalSection |
TMap< FString, TSharedPtr< IInstanceProvider > > | Providers |
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.
Definition at line 66 of file TypeContainer.h.
|
inlineprotected |
Add an instance provider to the container.
Name | The name of the type to add the provider for. |
Provider | The instance provider. |
Definition at line 407 of file TypeContainer.h.
|
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. |
Definition at line 181 of file TypeContainer.h.
|
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. |
Definition at line 203 of file TypeContainer.h.
|
inline |
Check whether the specified class has been registered.
R | The type of registered class to check. |
Definition at line 215 of file TypeContainer.h.
|
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). |
Definition at line 233 of file TypeContainer.h.
|
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. |
Definition at line 282 of file TypeContainer.h.
|
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. |
Definition at line 306 of file TypeContainer.h.
|
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. |
Definition at line 329 of file TypeContainer.h.
|
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. |
Definition at line 377 of file TypeContainer.h.
|
inline |
Unregisters the instance or class for a previously registered class.
R | The type of class to unregister. |
Definition at line 391 of file TypeContainer.h.
|
mutableprivate |
Critical section for synchronizing access.
Definition at line 418 of file TypeContainer.h.
|
private |
Maps class names to instance providers.
Definition at line 421 of file TypeContainer.h.