Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
TFunctionRef< FuncType > Class Template Reference

#include <Function.h>

+ Inheritance diagram for TFunctionRef< FuncType >:
+ Collaboration diagram for TFunctionRef< FuncType >:

Public Member Functions

template<typename FunctorType , typename = typename TEnableIf<!TIsFunction<FunctorType>::Value && !TAreTypesEqual<TFunctionRef, FunctorType>::Value>::Type>
 TFunctionRef (FunctorType &Functor)
 
template<typename FunctorType , typename = typename TEnableIf<!TIsFunction<FunctorType>::Value && !TAreTypesEqual<TFunctionRef, FunctorType>::Value>::Type>
 TFunctionRef (const FunctorType &Functor)
 
template<typename FunctionType , typename = typename TEnableIf<TIsFunction<FunctionType>::Value>::Type>
 TFunctionRef (FunctionType *Function)
 
 TFunctionRef (const TFunctionRef &Other)
 
TFunctionRefoperator= (const TFunctionRef &) const =delete
 
 ~TFunctionRef ()=default
 

Private Types

typedef UE4Function_Private::TFunctionRefBase< TFunctionRef< FuncType >, FuncType > Super
 

Private Member Functions

template<typename FunctorType >
void Set (FunctorType *Functor)
 
void CopyAndReseat (const TFunctionRef &Other, void *Functor)
 
void * GetPtr () const
 

Private Attributes

void * Ptr
 

Friends

struct UE4Function_Private::TFunctionRefBase< TFunctionRef< FuncType >, FuncType >
 

Detailed Description

template<typename FuncType>
class TFunctionRef< FuncType >

TFunctionRef<FuncType>

See the class definition for intended usage.

TFunctionRef<FuncType>

A class which represents a reference to something callable. The important part here is reference - if you bind it to a lambda and the lambda goes out of scope, you will be left with an invalid reference.

FuncType represents a function type and so TFunctionRef should be defined as follows:

// A function taking a string and float and returning int32. Parameter names are optional. TFunctionRef<int32 (const FString& Name, float Scale)>

If you also want to take ownership of the callable thing, e.g. you want to return a lambda from a function, you should use TFunction. TFunctionRef does not concern itself with ownership because it's intended to be FAST.

TFunctionRef is most useful when you want to parameterize a function with some caller-defined code without making it a template.

Example:

// Something.h void DoSomethingWithConvertingStringsToInts(TFunctionRef<int32 (const FString& Str)> Convert);

// Something.cpp void DoSomethingWithConvertingStringsToInts(TFunctionRef<int32 (const FString& Str)> Convert) { for (const FString& Str : SomeBunchOfStrings) { int32 Int = Convert(Str); DoSomething(Int); } }

// SomewhereElse.cpp #include "Something.h"

void Func() { // First do something using string length DoSomethingWithConvertingStringsToInts([](const FString& Str) { return Str.Len(); });

// Then do something using string conversion DoSomethingWithConvertingStringsToInts([](const FString& Str) { int32 Result; TTypeFromString<int32>::FromString(Result, *Str); return Result; }); }

Definition at line 380 of file Function.h.

Member Typedef Documentation

◆ Super

template<typename FuncType >
typedef UE4Function_Private::TFunctionRefBase<TFunctionRef<FuncType>, FuncType> TFunctionRef< FuncType >::Super
private

Definition at line 384 of file Function.h.

Constructor & Destructor Documentation

◆ TFunctionRef() [1/4]

template<typename FuncType >
template<typename FunctorType , typename = typename TEnableIf<!TIsFunction<FunctorType>::Value && !TAreTypesEqual<TFunctionRef, FunctorType>::Value>::Type>
TFunctionRef< FuncType >::TFunctionRef ( FunctorType & Functor)
inline

Constructor which binds a TFunctionRef to a non-const lvalue function object.

Definition at line 391 of file Function.h.

◆ TFunctionRef() [2/4]

template<typename FuncType >
template<typename FunctorType , typename = typename TEnableIf<!TIsFunction<FunctorType>::Value && !TAreTypesEqual<TFunctionRef, FunctorType>::Value>::Type>
TFunctionRef< FuncType >::TFunctionRef ( const FunctorType & Functor)
inline

Constructor which binds a TFunctionRef to an rvalue or const lvalue function object.

Definition at line 404 of file Function.h.

◆ TFunctionRef() [3/4]

template<typename FuncType >
template<typename FunctionType , typename = typename TEnableIf<TIsFunction<FunctionType>::Value>::Type>
TFunctionRef< FuncType >::TFunctionRef ( FunctionType * Function)
inline

Constructor which binds a TFunctionRef to a function pointer.

Definition at line 417 of file Function.h.

◆ TFunctionRef() [4/4]

template<typename FuncType >
TFunctionRef< FuncType >::TFunctionRef ( const TFunctionRef< FuncType > & Other)
inline

Copy constructor.

Definition at line 430 of file Function.h.

+ Here is the call graph for this function:

◆ ~TFunctionRef()

template<typename FuncType >
TFunctionRef< FuncType >::~TFunctionRef ( )
default

Member Function Documentation

◆ CopyAndReseat()

template<typename FuncType >
void TFunctionRef< FuncType >::CopyAndReseat ( const TFunctionRef< FuncType > & Other,
void * Functor )
inlineprivate

Copies another TFunctionRef and rebinds it to another object of the same type which was originally bound. Only intended to be used by TFunction's copy constructor/assignment operator.

Definition at line 480 of file Function.h.

+ Here is the caller graph for this function:

◆ GetPtr()

template<typename FuncType >
void * TFunctionRef< FuncType >::GetPtr ( ) const
inlineprivate

Returns a pointer to the callable object - needed by TFunctionRefBase.

Definition at line 489 of file Function.h.

◆ operator=()

template<typename FuncType >
TFunctionRef & TFunctionRef< FuncType >::operator= ( const TFunctionRef< FuncType > & ) const
delete

◆ Set()

template<typename FuncType >
template<typename FunctorType >
void TFunctionRef< FuncType >::Set ( FunctorType * Functor)
inlineprivate

Sets the state of the TFunctionRef given a pointer to a callable thing.

Definition at line 467 of file Function.h.

Friends And Related Symbol Documentation

◆ UE4Function_Private::TFunctionRefBase< TFunctionRef< FuncType >, FuncType >

template<typename FuncType >
friend struct UE4Function_Private::TFunctionRefBase< TFunctionRef< FuncType >, FuncType >
friend

Definition at line 323 of file Function.h.

Member Data Documentation

◆ Ptr

template<typename FuncType >
void* TFunctionRef< FuncType >::Ptr
private

Definition at line 495 of file Function.h.


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