MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::Composition::IComposable Class Reference

A base class which can bring type based class-composition to a derived class. More...

#include <Composition.h>

Public Member Functions

 IComposable ()=default
 
 IComposable (const IComposable &other)
 
 IComposable (IComposable &&other) noexcept
 
ranges::any_view< FAny * > GetComponentsDynamic (FTypeHash typeHash) const
 Get components determined at runtime.
 
template<typename MainType , typename Self >
requires CCompatibleComponent<MainType, Self>
void AddComponent (this Self &&self, MainType *newComponent, TAnyTypeFacilities< MainType > const &facilities={})
 Add a component to this composable class.
 
template<CDefaultInitializable MainType, typename Self >
requires CCompatibleComponent<MainType, Self>
void AddComponent (this Self &&self, TAnyTypeFacilities< MainType > const &facilities={})
 Add a default constructed component to this composable class.
 
template<typename... ValidAs>
void AddAlias ()
 Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
 
template<typename MainType , CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto With (this Self &&self, MainType *newComponent, TAnyTypeFacilities< MainType > const &facilities={})
 Add a component to this composable class with a fluent API.
 
template<typename MainType , CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto WithAnsi (this Self &&self, MainType *newComponent)
 Add a component to this composable class with a fluent API, enforcing standard memory allocators.
 
template<CDefaultInitializable MainType, CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto With (this Self &&self, TAnyTypeFacilities< MainType > const &facilities={})
 Add a default constructed component to this composable class with a fluent API.
 
template<CDefaultInitializable MainType, CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto WithAnsi (this Self &&self)
 Add a default constructed component to this composable class with a fluent API, enforcing standard memory allocators.
 
template<typename MainType , typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) With (this Self &&self, MainType *newComponent, TAnyTypeFacilities< MainType > const &facilities={})
 Add a component to this composable class with a fluent API.
 
template<typename MainType , typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) WithAnsi (this Self &&self, MainType *newComponent)
 Add a component to this composable class with a fluent API, enforcing standard memory allocators.
 
template<CDefaultInitializable MainType, typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) With (this Self &&self, TAnyTypeFacilities< MainType > const &facilities={})
 Add a default constructed component to this composable class with a fluent API.
 
template<CDefaultInitializable MainType, typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) WithAnsi (this Self &&self)
 Add a default constructed component to this composable class with a fluent API, enforcing standard memory allocators.
 
template<typename ValidAs , CSharedFromThis Self>
auto WithAlias (this Self &&self)
 Add a type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
 
template<typename ValidAs , typename Self >
requires (!CSharedFromThis<Self>)
decltype(auto) WithAlias (this Self &&self)
 Add a type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
 
template<CSharedFromThis Self, typename... ValidAs>
auto With (this Self &&self, TTypes< ValidAs... > &&)
 Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
 
template<typename Self , typename... ValidAs>
requires (!CSharedFromThis<Self>)
decltype(auto) With (this Self &&self, TTypes< ValidAs... > &&)
 Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
 
template<CSharedFromThis Self, CFunctionLike Function>
requires (TFunction_ArgCount<Function> == 1)
auto With (this Self &&self, Function &&function)
 Modify a component inline, with a lambda function. The component type is inferred from the function's first argument, and a reference of that component is passed into it. The component must exist before calling this method, or if it doesn't, the application will crash.
 
template<typename Self , CFunctionLike Function>
requires (!CSharedFromThis<Self> && TFunction_ArgCount<Function> == 1)
decltype(auto) With (this Self &&self, Function &&function)
 Modify a component inline, with a lambda function. The component type is inferred from the function's first argument, and a reference of that component is passed into it. The component must exist before calling this method, or if it doesn't, the application will crash.
 
template<typename T >
ranges::any_view< T * > GetComponents () const
 Get all components added matching~ or aliased by the given type.
 
template<typename T >
const T * TryGet () const
 Get the first component matching~ or aliased by the given type.
 
template<typename T >
T * TryGet ()
 Get the first component matching~ or aliased by the given type.
 
template<typename T >
T const & Get () const
 Get the first component matching~ or aliased by the given type.
 
template<typename T >
T & Get ()
 Get the first component matching~ or aliased by the given type.
 

Protected Attributes

TFunction< void(FAny &)> OnComponentAdded
 Override this function in your composable class to do custom logic when a component is added. A bit of dynamically typed programming is needed through the FAny API.
 

Detailed Description

A base class which can bring type based class-composition to a derived class.

This exists because indeed Unreal has its own composition model (actors / actor-components) or it has the subsystem architecture for non-actors, they still require to be used with UObjects. IComposable allows any C++ objects to have type-safe runtime managed optional components which can be configured separately for each instance.

The only requirement for components is that they need to be copy and move constructible (as is the default with plain-old-C++ objects, if they don't have members where either constructors are deleted or inaccessible). This limitation is imposed by FAny only for easier interfacing, but the API for managing components will never move or copy them by itself. The composable class doesn't have that limitation.

Usage:

//// Given the following types we want to use as components:
struct FSimpleComponent { int A = 0; };
struct IBaseComponent { int B; };
// | This allows us not repeating ourselves, more on this later
// V
struct FComponentImplementation : TInherit<IBaseComponent>
{
FComponentImplementation(int b, int c) : B(b), C(c) {}
int C;
};
struct IRegularBase { int D; };
// | We have to repeat this if we want to get components with this base class
// V
struct FRegularInherited : IRegularBase
{
FRegularInherited(int d, int e) : D(d), E(e) {}
int E;
};
//// Given the following composable type:
class FMyComposableType : public IComposable {};
//// Declare their composition at construction:
auto MyStuff = FMyComposableType()
.With<FSimpleComponent>() // <- Simply add components with their types
.With(new FComponentImplementation(1, 2)) // <- Or simply use new operator
// (IComposable assumes ownership)
// Because FComponentImplementation uses TInherit
// IBaseComponent is not needed to be repeated here
.With(new FRegularInherited(3, 4)) //
.WithAlias<IRegularBase>() // <- FRegularInherited cannot tell automatically that it
// inherits from IRegularBase so we need to specify
// that here explicitly in case we want to get
// FRegularInherited component via its base class
;
//// Get components at runtime:
int a = MyStuff.Get<FSimpleComponent>().A; //
// -> 0 //
int b = MyStuff.Get<IBaseComponent>().B; // <- We can get the component via base class here, only
// -> 1 // because it was exposed via TInherit
int d = MyStuff.Get<IRegularBase>().D; // <- We can get the component via base class here, because
// -> 3 // we explicitly specified it during registration
FVector* v = MyStuff.TryGet<FVector>(); // <- If there's any doubt that a component may not have
// -> nullptr; FVector wasn't a component // been registered, use TryGet instead.
auto With(this Self &&self, MainType *newComponent, TAnyTypeFacilities< MainType > const &facilities={})
Add a component to this composable class with a fluent API.

As mentioned earlier, components are not required to have any arbitrary type traits, but if they inherit from IComponent or IStrictComponent they can receive extra information when they're registered for a composable class. The difference between the two is that IComponent doesn't mind if it's attached to a composable class it doesn't know about, however it is a compile error if an IStrictComponent is attempted to be attached to an incompatible class.

For example

//// Given the following types we want to use as components:
struct FChillComponent : IComponent
{
void OnCreatedAt(FExpectedParent& to) {}
};
struct FStrictComponent : IStrictComponent
{
void OnCreatedAt(FExpectedParent& to) {}
};
//// Given the following composable types:
class FExpectedParent : public IComposable {};
class FSomeOtherParent : public IComposable {};
//// Declare their composition at construction:
auto MyOtherStuff = FExpectedParent()
.With<FChillComponent>() // OK, and OnCreatedAt is called
.With<FStrictComponent>() // OK, and OnCreatedAt is called
auto MyStuff = FSomeOtherParent()
.With<FChillComponent>() // OK, but OnCreatedAt won't be called.
.With<FStrictComponent>() // COMPILE ERROR, CCompatibleComponent concept is not satisfied because
// FSomeOtherParent is not convertible to FExpectedParent at
// OnCreatedAt(FExpectedParent& to)
;
Inherit from this empty interface to signal that the inheriting class knows that it's a component and...
Definition Composition.h:53

Explicit components can explicitly support multiple composable classes via function overloading or templating (with deduced type parameters).

If a component type uses TInherit template or has a using Bases = TTypes<...> member alias in a similar way:

class FMyComponent : public TInherit<IFoo, IBar, IEtc>
{
// ...
}
Inherit via this template to allow other API to reflect upon the base types of deriving class....

Then the specified base classes will be automatically registered as component aliases. When this is used for explicit components, IComponent or IStrictComponent is strongly discouraged to be used in TInherit's parameter pack. So declare inheritance the following way:

class FMyComponent
: public TInherit<IFoo, IBar, IEtc>
, public IComponent
{
// ...
}
Todo
OnCopiedAt and OnMovedAt doesn't seem reliable currently, the best would be if we could provide a safe way to keep components updated about their parents, with erasing the parent type on IComposable level, but keeping it fully typed with components.
Todo
C++ 26 has promising proposal for static value-based reflection, which can gather metadata from classes or even emit them. The best summary I found so far is a stack-overflow answer https://stackoverflow.com/a/77477029 Once that's available we can gather base classes in compile time, and do dynamic casting of objects without the need for intrusive extra syntax, or extra work at construction. Currently GCC's __bases would be perfect for the job, but other popular compilers don't have similar intrinsics. Once such a feature becomes widely available base classes can be automatically added as aliases for registered components.

Definition at line 269 of file Composition.h.

Constructor & Destructor Documentation

◆ IComposable() [1/3]

Mcro::Composition::IComposable::IComposable ( )
default

◆ IComposable() [2/3]

Mcro::Composition::IComposable::IComposable ( const IComposable & other)

◆ IComposable() [3/3]

Mcro::Composition::IComposable::IComposable ( IComposable && other)
noexcept

Member Function Documentation

◆ AddAlias()

template<typename... ValidAs>
void Mcro::Composition::IComposable::AddAlias ( )
inline

Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Warning
Calling this function before adding a component may result in a runtime crash!
Template Parameters
ValidAsThe list of other types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Definition at line 448 of file Composition.h.

◆ AddComponent() [1/2]

template<typename MainType , typename Self >
requires CCompatibleComponent<MainType, Self>
void Mcro::Composition::IComposable::AddComponent ( this Self && self,
MainType * newComponent,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a component to this composable class.

Template Parameters
MainTypeThe exact component type (deduced from newComponent
SelfDeducing this
Parameters
selfDeducing this
newComponentA pointer to the new component being added. IComposable will assume ownership of the new component adhering to RAII. Make sure the lifespan of the provided object is not managed by something else or the stack, in fact better to stick with the new operator.
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities

Definition at line 355 of file Composition.h.

◆ AddComponent() [2/2]

template<CDefaultInitializable MainType, typename Self >
requires CCompatibleComponent<MainType, Self>
void Mcro::Composition::IComposable::AddComponent ( this Self && self,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a default constructed component to this composable class.

Template Parameters
MainTypeThe exact component type
SelfDeducing this
Parameters
selfDeducing this
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities

Definition at line 430 of file Composition.h.

◆ Get() [1/2]

template<typename T >
T & Mcro::Composition::IComposable::Get ( )
inline

Get the first component matching~ or aliased by the given type.

The order of components are non-deterministic so this method only make sense when it is trivial that only one component will be available for that particular type.

Warning
If there may be the slightest doubt that the given component may not exist on this composable class, use TryGet instead as this function can crash at runtime.
Template Parameters
TDesired component type.
Returns
A reference to the desired component. It is a runtime crash if the component doesn't exist.

Definition at line 985 of file Composition.h.

◆ Get() [2/2]

template<typename T >
T const & Mcro::Composition::IComposable::Get ( ) const
inline

Get the first component matching~ or aliased by the given type.

The order of components are non-deterministic so this method only make sense when it is trivial that only one component will be available for that particular type.

Warning
If there may be the slightest doubt that the given component may not exist on this composable class, use TryGet instead as this function can crash at runtime.
Template Parameters
TDesired component type.
Returns
A reference to the desired component. It is a runtime crash if the component doesn't exist.

Definition at line 961 of file Composition.h.

◆ GetComponents()

template<typename T >
ranges::any_view< T * > Mcro::Composition::IComposable::GetComponents ( ) const
inline

Get all components added matching~ or aliased by the given type.

Template Parameters
TDesired component type.
Returns
A range-view containing all the matched components. Components are provided as pointers to ensure they're not copied even under intricate object plumbing situations, but invalid pointers are never returned. (as long as the composable class is alive of course)

Definition at line 900 of file Composition.h.

◆ GetComponentsDynamic()

ranges::any_view< FAny * > Mcro::Composition::IComposable::GetComponentsDynamic ( FTypeHash typeHash) const

Get components determined at runtime.

Parameters
typeHashThe runtime determined type-hash the desired components are represented with
Returns
A type erased range view for all the components matched with given type-hash

◆ TryGet() [1/2]

template<typename T >
T * Mcro::Composition::IComposable::TryGet ( )
inline

Get the first component matching~ or aliased by the given type.

The order of components are non-deterministic so this method only make sense when it is trivial that only one component will be available for that particular type.

Template Parameters
TDesired component type.
Returns
A pointer to the component if one at least exists, nullptr otherwise.

Definition at line 939 of file Composition.h.

◆ TryGet() [2/2]

template<typename T >
const T * Mcro::Composition::IComposable::TryGet ( ) const
inline

Get the first component matching~ or aliased by the given type.

The order of components are non-deterministic so this method only make sense when it is trivial that only one component will be available for that particular type.

Template Parameters
TDesired component type.
Returns
A pointer to the component if one at least exists, nullptr otherwise.

Definition at line 921 of file Composition.h.

◆ With() [1/8]

template<CSharedFromThis Self, CFunctionLike Function>
requires (TFunction_ArgCount<Function> == 1)
auto Mcro::Composition::IComposable::With ( this Self && self,
Function && function )
inline

Modify a component inline, with a lambda function. The component type is inferred from the function's first argument, and a reference of that component is passed into it. The component must exist before calling this method, or if it doesn't, the application will crash.

Template Parameters
SelfDeducing this
FunctionFunction type for modifying a component inline. The component type is deduced from the first parameter of the function. CV-ref qualifiers are not enforced but mutable-ref or const-ref are the only useful options. Function result is discarded when returning anything.
Parameters
selfDeducing this
functionFunction for modifying a component inline. The component type is deduced from the first parameter of the function. CV-ref qualifiers are not enforced but mutable-ref or const-ref are the only useful options. Function result is discarded when returning anything.
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 848 of file Composition.h.

◆ With() [2/8]

template<typename Self , CFunctionLike Function>
requires (!CSharedFromThis<Self> && TFunction_ArgCount<Function> == 1)
decltype(auto) Mcro::Composition::IComposable::With ( this Self && self,
Function && function )
inline

Modify a component inline, with a lambda function. The component type is inferred from the function's first argument, and a reference of that component is passed into it. The component must exist before calling this method, or if it doesn't, the application will crash.

Template Parameters
SelfDeducing this
FunctionFunction type for modifying a component inline. The component type is deduced from the first parameter of the function. CV-ref qualifiers are not enforced but mutable-ref or const-ref are the only useful options. Function result is discarded when returning anything.
Parameters
selfDeducing this
functionFunction for modifying a component inline. The component type is deduced from the first parameter of the function. CV-ref qualifiers are not enforced but mutable-ref or const-ref are the only useful options. Function result is discarded when returning anything.
Returns
Perfect-forwarded self.

Definition at line 882 of file Composition.h.

◆ With() [3/8]

template<typename MainType , CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto Mcro::Composition::IComposable::With ( this Self && self,
MainType * newComponent,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a component to this composable class with a fluent API.

This overload is available for composable classes which also inherit from TSharedFromThis.

Template Parameters
MainTypeThe exact component type (deduced from newComponent
SelfDeducing this
Parameters
selfDeducing this
newComponentA pointer to the new component being added. IComposable will assume ownership of the new component adhering to RAII. Make sure the lifespan of the provided object is not managed by something else or the stack, in fact better to stick with the new operator.
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 480 of file Composition.h.

◆ With() [4/8]

template<typename MainType , typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::With ( this Self && self,
MainType * newComponent,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a component to this composable class with a fluent API.

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Template Parameters
MainTypeThe exact component type (deduced from newComponent
SelfDeducing this
Parameters
selfDeducing this
newComponentA pointer to the new component being added. IComposable will assume ownership of the new component adhering to RAII. Make sure the lifespan of the provided object is not managed by something else or the stack, in fact better to stick with the new operator.
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities
Returns
Perfect-forwarded self.

Definition at line 584 of file Composition.h.

◆ With() [5/8]

template<CDefaultInitializable MainType, CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto Mcro::Composition::IComposable::With ( this Self && self,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a default constructed component to this composable class with a fluent API.

This overload is available for composable classes which also inherit from TSharedFromThis.

Template Parameters
MainTypeThe exact component type
SelfDeducing this
Parameters
selfDeducing this
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 530 of file Composition.h.

◆ With() [6/8]

template<CDefaultInitializable MainType, typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::With ( this Self && self,
TAnyTypeFacilities< MainType > const & facilities = {} )
inline

Add a default constructed component to this composable class with a fluent API.

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Template Parameters
MainTypeThe exact component type
SelfDeducing this
Parameters
selfDeducing this
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities
Returns
Perfect-forwarded self.

Definition at line 634 of file Composition.h.

◆ With() [7/8]

template<CSharedFromThis Self, typename... ValidAs>
auto Mcro::Composition::IComposable::With ( this Self && self,
TTypes< ValidAs... > &&  )
inline

Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Usage:

auto result = IComposable()
.With<FMyComponent>().With(TAlias<
FMyComponentBase,
IMyComponentInterface
>)
;

This overload is available for composable classes which also inherit from TSharedFromThis.

Warning
Calling this function before adding a component may result in a runtime crash!
Template Parameters
ValidAsThe list of other types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
SelfDeducing this
Parameters
selfDeducing this
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 776 of file Composition.h.

◆ With() [8/8]

template<typename Self , typename... ValidAs>
requires (!CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::With ( this Self && self,
TTypes< ValidAs... > &&  )
inline

Add a list of types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Usage:

auto result = IComposable()
.With<FMyComponent>().With(TAlias<
FMyComponentBase,
IMyComponentInterface
>)
;

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Warning
Calling this function before adding a component may result in a runtime crash!
Template Parameters
ValidAsThe list of other types the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
SelfDeducing this
Parameters
selfDeducing this
Returns
Perfect-forwarded self.

Definition at line 814 of file Composition.h.

◆ WithAlias() [1/2]

template<typename ValidAs , CSharedFromThis Self>
auto Mcro::Composition::IComposable::WithAlias ( this Self && self)
inline

Add a type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Only one alias may be specified this way because of templating syntax intricacies, but it may be called multiple times in a sequence to add multiple aliases for the same component.

Usage:

auto result = IComposable()
.With<FMyComponent>()
.WithAlias<IMyComponentInterface>()
;
auto WithAlias(this Self &&self)
Add a type, the last added component is convertible to and may be used to get the last component amon...

For declaring multiple aliases in one go, use With(TTypes<...>) member template method.

This overload is available for composable classes which also inherit from TSharedFromThis.

Warning
Calling this function before adding a component may result in a runtime crash!
Template Parameters
ValidAsA type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
SelfDeducing this
Parameters
selfDeducing this
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 697 of file Composition.h.

◆ WithAlias() [2/2]

template<typename ValidAs , typename Self >
requires (!CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::WithAlias ( this Self && self)
inline

Add a type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.

Only one alias may be specified this way because of templating syntax intricacies, but it may be called multiple times in a sequence to add multiple aliases for the same component.

Usage:

auto result = IComposable()
.With<FMyComponent>()
.WithAlias<IMyComponentInterface>()
;

For declaring multiple aliases in one go, use With(TTypes<...>) member template method.

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Warning
Calling this function before adding a component may result in a runtime crash!
Template Parameters
ValidAsA type, the last added component is convertible to and may be used to get the last component among others which may list the same aliases.
SelfDeducing this
Parameters
selfDeducing this
Returns
Perfect-forwarded self.

Definition at line 739 of file Composition.h.

◆ WithAnsi() [1/4]

template<CDefaultInitializable MainType, CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto Mcro::Composition::IComposable::WithAnsi ( this Self && self)
inline

Add a default constructed component to this composable class with a fluent API, enforcing standard memory allocators.

This overload is available for composable classes which also inherit from TSharedFromThis.

Template Parameters
MainTypeThe exact component type
SelfDeducing this
Parameters
selfDeducing this
facilitiesCustomization point for object copy/move and delete methods. See TAnyTypeFacilities
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 555 of file Composition.h.

◆ WithAnsi() [2/4]

template<CDefaultInitializable MainType, typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::WithAnsi ( this Self && self)
inline

Add a default constructed component to this composable class with a fluent API, enforcing standard memory allocators.

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Template Parameters
MainTypeThe exact component type
SelfDeducing this
Parameters
selfDeducing this
Returns
Perfect-forwarded self.

Definition at line 656 of file Composition.h.

◆ WithAnsi() [3/4]

template<typename MainType , CSharedFromThis Self>
requires CCompatibleComponent<MainType, Self>
auto Mcro::Composition::IComposable::WithAnsi ( this Self && self,
MainType * newComponent )
inline

Add a component to this composable class with a fluent API, enforcing standard memory allocators.

This overload is available for composable classes which also inherit from TSharedFromThis.

Template Parameters
MainTypeThe exact component type (deduced from newComponent
SelfDeducing this
Parameters
selfDeducing this
newComponentA pointer to the new component being added. IComposable will assume ownership of the new component adhering to RAII. Make sure the lifespan of the provided object is not managed by something else or the stack, in fact better to stick with the new operator.
Returns
If the composable class also inherits from TSharedFromThis return a shared ref.

Definition at line 506 of file Composition.h.

◆ WithAnsi() [4/4]

template<typename MainType , typename Self >
requires (CCompatibleComponent<MainType, Self> && !CSharedFromThis<Self>)
decltype(auto) Mcro::Composition::IComposable::WithAnsi ( this Self && self,
MainType * newComponent )
inline

Add a component to this composable class with a fluent API, enforcing standard memory allocators.

This overload is available for composable classes which are not explicitly meant to be used with shared pointers.

Template Parameters
MainTypeThe exact component type (deduced from newComponent
SelfDeducing this
Parameters
selfDeducing this
newComponentA pointer to the new component being added. IComposable will assume ownership of the new component adhering to RAII. Make sure the lifespan of the provided object is not managed by something else or the stack, in fact better to stick with the new operator.
Returns
Perfect-forwarded self.

Definition at line 610 of file Composition.h.

Field Documentation

◆ OnComponentAdded

TFunction<void(FAny&)> Mcro::Composition::IComposable::OnComponentAdded
protected

Override this function in your composable class to do custom logic when a component is added. A bit of dynamically typed programming is needed through the FAny API.

This is executed in AddComponent before IComponent::OnCreatedAt and after automatic aliases has been set up (if they're available). This is not executed with subsequent setup of manual aliases.

Parameters
componentThe component being added. Query component type with the FAny API

Definition at line 322 of file Composition.h.


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