![]() |
MCRO
C++23 utilities for Unreal Engine.
|
Auto Modular Features are a workflow with Modular Features where the developer doesn't have to rely on string identifiers. TAutoModularFeature template take care of naming the feature and introduces some common functionality, like getter functions and runtime validations. More...
#include <AutoModularFeature.h>
Public Types | |
| using | Feature = FeatureIn |
| using | AutoModularFeature = TAutoModularFeature |
Public Member Functions | |
| template<typename Implementation > requires CDerivedFrom<Implementation, Feature> | |
| void | Register (this Implementation &&self) |
| Call this function in implementation constructors. | |
| virtual | ~TAutoModularFeature () |
Static Public Member Functions | |
| static auto | OnRegistered () -> TBelatedEventDelegate< void(Feature *)> & |
| This event is triggered when an implementation of this feature is created. | |
| static FORCEINLINE FName | FeatureName () |
| Get the name of the feature. | |
| static FORCEINLINE int32 | ImplementationCount () |
| static FORCEINLINE Feature & | Get () |
| Get the first existing implementation of this feature. If there are no implementations a check will fail. | |
| static FORCEINLINE Feature * | TryGet (const int32 index) |
| Get the first existing implementation of this feature. Return nullptr If there are no implementations. | |
| static FORCEINLINE TArray< Feature * > | GetAll () |
| static FORCEINLINE TFuture< Feature * > | GetBelated () |
| Get the first implementation once it is registered, or return the first implementation immediately if there's already one registered. | |
Auto Modular Features are a workflow with Modular Features where the developer doesn't have to rely on string identifiers. TAutoModularFeature template take care of naming the feature and introduces some common functionality, like getter functions and runtime validations.
First a feature is defined with its interface class like so:
Then each implementation of this feature are defined like so:
Then instantiate the feature implementation when needed:
To access the feature implementations then just use
Internally the feature name will be identical to the class name. In this case IMyModularFeature will register as "IMyModularFeature". Technically one can get it via
but it is strongly discouraged for type safety and keeping code simple.
For globally available features you may use just simply a global variable, or if it's important to have the owning module fully initialized, TModuleBoundObject is recommended.
| FeatureIn | Curiously Recurring Template argument of the feature |
Definition at line 96 of file AutoModularFeature.h.
| using Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::AutoModularFeature = TAutoModularFeature |
Definition at line 100 of file AutoModularFeature.h.
| using Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::Feature = FeatureIn |
Definition at line 99 of file AutoModularFeature.h.
|
inlinevirtual |
Definition at line 166 of file AutoModularFeature.h.
|
inlinestatic |
Get the name of the feature.
Definition at line 110 of file AutoModularFeature.h.
|
inlinestatic |
Get the first existing implementation of this feature. If there are no implementations a check will fail.
Definition at line 125 of file AutoModularFeature.h.
|
inlinestatic |
Definition at line 137 of file AutoModularFeature.h.
|
inlinestatic |
Get the first implementation once it is registered, or return the first implementation immediately if there's already one registered.
OnRegistered() if your particular feature may never be created. Definition at line 183 of file AutoModularFeature.h.
|
inlinestatic |
Definition at line 116 of file AutoModularFeature.h.
|
inlinestatic |
This event is triggered when an implementation of this feature is created.
Definition at line 103 of file AutoModularFeature.h.
|
inline |
Call this function in implementation constructors.
This is a necessary boilerplate to maintain polymorphism of implementations. Otherwise, if the native registration function would be called directly in TAutoModularFeature default constructor, virtual function overrides are not yet known, and "deducing this" is not meant for constructors.
| Implementation | Derived type of the implementation |
| self | Pointer to implementation registering itself |
Definition at line 154 of file AutoModularFeature.h.
|
inlinestatic |
Get the first existing implementation of this feature. Return nullptr If there are no implementations.
Definition at line 131 of file AutoModularFeature.h.