MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Mcro::UObjects::Init Namespace Reference

Namespaces

namespace  Detail
 

Data Structures

struct  FConstructObjectParameters
 Mirror of FStaticConstructObjectParameters but it's a plain C++ object and doesn't have a constructor so designated initialization with named members is possible. More...
 
struct  TScopeObject
 A struct to emulate regular C++ RAII object behavior with UObjects. When this struct is instantiated the given object type is also created. An object wrapped in this struct is never invalid, and doesn't get garbage collected until it's in scope. More...
 

Concepts

concept  CUObjectInitializable
 

Functions

template<CUObject T, typename... Args>
T * NewInit (FConstructObjectParameters &&params, Args &&... args)
 Create a new object which can also be initialized with an Initialize function if it has one. In case it has an Initialize function the args parameters should match them. This is an equivalent to the template Mcro::SharedObjects::MakeShareableInit.
 
template<CFunctorObject Initializer, typename TArg = TFunction_Arg<Initializer, 0>, CUObject T = std::decay_t<TArg>>
requires std::is_lvalue_reference_v<TArg>
T * ConstructObject (FConstructObjectParameters &&params, Initializer &&init)
 Equivalent to Mcro::Construct::Construct but for UObjects.
 
template<CFunctorObject Initializer, typename... Args, typename TArg = TFunction_Arg<Initializer, 0>, CUObject T = std::decay_t<TArg>>
requires std::is_lvalue_reference_v<TArg>
T * ConstructInit (FConstructObjectParameters &&params, Initializer &&init, Args &&... args)
 Equivalent to Mcro::Construct::Construct but for UObjects. If the constructed UObject type also has an Initialize function call that too after the lambda initializer. The args parameters should match the signature of Initialize in that case.
 

Function Documentation

◆ ConstructInit()

template<CFunctorObject Initializer, typename... Args, typename TArg = TFunction_Arg<Initializer, 0>, CUObject T = std::decay_t<TArg>>
requires std::is_lvalue_reference_v<TArg>
T * Mcro::UObjects::Init::ConstructInit ( FConstructObjectParameters && params,
Initializer && init,
Args &&... args )

Equivalent to Mcro::Construct::Construct but for UObjects. If the constructed UObject type also has an Initialize function call that too after the lambda initializer. The args parameters should match the signature of Initialize in that case.

Usage:

using namespace Mcro::UObjects::Init;
auto myObject = Construct({}, [](UMyObject& _)
{
_.Foo = 42;
_.Bar();
// etc...
});
static_assert(std::is_same_v<decltype(myObject), UMyObject*>);

Notice how the object type is deduced from the argument of the initializer.

Template Parameters
InitializerInitializer function type
ArgsArguments for the Initialize function
Parameters
paramsParameters for every new object
initA setup function for the newly created UObject
argsArguments for the Initialize function
Returns
The new object

Definition at line 211 of file Init.h.

◆ ConstructObject()

template<CFunctorObject Initializer, typename TArg = TFunction_Arg<Initializer, 0>, CUObject T = std::decay_t<TArg>>
requires std::is_lvalue_reference_v<TArg>
T * Mcro::UObjects::Init::ConstructObject ( FConstructObjectParameters && params,
Initializer && init )

Equivalent to Mcro::Construct::Construct but for UObjects.

Usage:

using namespace Mcro::UObjects::Init;
auto myObject = Construct({}, [](UMyObject& _)
{
_.Foo = 42;
_.Bar();
// etc...
});
static_assert(std::is_same_v<decltype(myObject), UMyObject*>);

Notice how the object type is deduced from the argument of the initializer.

Template Parameters
InitializerInitializer function type
Parameters
paramsParameters for every new object
initA setup function for the newly created UObject
Returns
The new object

Definition at line 160 of file Init.h.

◆ NewInit()

template<CUObject T, typename... Args>
T * Mcro::UObjects::Init::NewInit ( FConstructObjectParameters && params,
Args &&... args )

Create a new object which can also be initialized with an Initialize function if it has one. In case it has an Initialize function the args parameters should match them. This is an equivalent to the template Mcro::SharedObjects::MakeShareableInit.

Template Parameters
TType of initializable UObject
ArgsArguments for the Initialize function
Parameters
paramsParameters for every new object
argsArguments for the Initialize function
Returns
The new object

Definition at line 114 of file Init.h.