MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn > Class Template Reference

#include <AutoModularFeature.h>

Inheritance diagram for Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >:
Mcro::AutoModularFeature::IAutoModularFeature

Public Types

using Feature = FeatureIn
 
using AutoModularFeature = TAutoModularFeature
 

Public Member Functions

template<typename Implementation >
requires CDerivedFrom<Implementation, Feature>
void Register (this Implementation &&self)
 
virtual ~TAutoModularFeature ()
 

Static Public Member Functions

static FORCEINLINE const FName & FeatureName ()
 
static FORCEINLINE int32 ImplementationCount ()
 
static FORCEINLINE FeatureGet ()
 
static FORCEINLINE FeatureTryGet (const int32 index)
 
static FORCEINLINE TArray< Feature * > GetAll ()
 
static FORCEINLINE TFuture< Feature * > GetBelated ()
 

Detailed Description

template<typename FeatureIn>
class Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >

Auto Modular Features are a workflow with Modular Features where the developer doesn't have to rely on string identifiers. TAutoModularFeature and TFeatureImplementation templates take care of naming the feature and introduces some common functionality, like getter functions and runtime validations.

Remarks
First a feature is defined with its interface class like so:
class IMyModularFeature : public TAutoModularFeature<IMyModularFeature>
{
// ...
}
Then each implementations of this feature are defined like so:
class FMyFeatureImplementation : public IMyModularFeature, public IFeatureImplementation
{
FMyFeatureImplementation()
{
// See the inline docs for why this needs to be done
Register()
}
}
Then instantiate the feature implementation when needed:
class FMyModule
{
TPimplPtr<FMyFeatureImplementation> MyImplementation;
}
if (...)
{
MyImplementation = MakePimpl<FMyFeatureImplementation>();
}
To access the feature implementations then just use
if (IMyModularFeature::ImplementationCount() > 0)
{
IMyModularFeature::Get().MyStuff();
}
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
IModularFeatures::Get().GetModularFeature<IMyModularFeature>(TEXT("IMyModularFeature"))
but it is strongly discouraged for type safety and keeping code simple.
IMyModularFeature::FeatureName() and TTypeName<FMyFeatureImplementation>() can be used for runtime comparison / validation. See TFeatureImplementation::CastChecked which helps handling implementation specific structures and their runtime polymorphism.
Template Parameters
FeatureInCuriously Recurring Template argument of the feature

Definition at line 89 of file AutoModularFeature.h.

Member Typedef Documentation

◆ AutoModularFeature

template<typename FeatureIn >
using Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::AutoModularFeature = TAutoModularFeature

Definition at line 93 of file AutoModularFeature.h.

◆ Feature

template<typename FeatureIn >
using Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::Feature = FeatureIn

Definition at line 92 of file AutoModularFeature.h.

Constructor & Destructor Documentation

◆ ~TAutoModularFeature()

template<typename FeatureIn >
virtual Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::~TAutoModularFeature ( )
inlinevirtual

Definition at line 154 of file AutoModularFeature.h.

Member Function Documentation

◆ FeatureName()

template<typename FeatureIn >
static FORCEINLINE const FName & Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::FeatureName ( )
inlinestatic

Gert the name of the feature

Definition at line 96 of file AutoModularFeature.h.

◆ Get()

template<typename FeatureIn >
static FORCEINLINE Feature & Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::Get ( )
inlinestatic

Get the first existing implementation of this feature. If there are no implementations a check will fail.

Definition at line 112 of file AutoModularFeature.h.

◆ GetAll()

template<typename FeatureIn >
static FORCEINLINE TArray< Feature * > Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::GetAll ( )
inlinestatic
Returns
An array of all implementations of this feature

Definition at line 128 of file AutoModularFeature.h.

◆ GetBelated()

template<typename FeatureIn >
static FORCEINLINE TFuture< Feature * > Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::GetBelated ( )
inlinestatic

Get the first implementation once it is registered, or return the first implementation immediately if there's already one registered.

Returns
A future completed when the first implementation becomes available, or there's already one

Definition at line 165 of file AutoModularFeature.h.

◆ ImplementationCount()

template<typename FeatureIn >
static FORCEINLINE int32 Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::ImplementationCount ( )
inlinestatic
Returns
The number of implementations created for this feature

Definition at line 104 of file AutoModularFeature.h.

◆ Register()

template<typename FeatureIn >
template<typename Implementation >
requires CDerivedFrom<Implementation, Feature>
void Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::Register ( this Implementation && self)
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.

Template Parameters
ImplementationDerived type of the implementation
Parameters
selfPointer to implementation registering itself

Definition at line 143 of file AutoModularFeature.h.

◆ TryGet()

template<typename FeatureIn >
static FORCEINLINE Feature * Mcro::AutoModularFeature::TAutoModularFeature< FeatureIn >::TryGet ( const int32 index)
inlinestatic

Get the first existing implementation of this feature. Return nullptr If there are no implementations.

Definition at line 120 of file AutoModularFeature.h.


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