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

A barebones base class for types which may store their type-name as a string. More...

#include <Types.h>

Inheritance diagram for Mcro::Types::IHaveType:
Mcro::Types::IHaveTypeShareable Mcro::Types::THasTypeShareable< T > Mcro::Error::IError Mcro::Error::FAssertion Mcro::Error::FCppException Mcro::Error::FUnavailable Mcro::Error::IPlainTextComponent Mcro::Windows::Error::FHresultError Mcro::Windows::Error::FLastError Mcro::Error::TCppException< Exception > Mcro::Error::FBlueprintStackTrace Mcro::Error::FCppStackTrace

Public Types

template<typename Self >
using SelfRef = TSharedRef<std::decay_t<Self>>
 

Public Member Functions

virtual ~IHaveType ()=default
 
template<CSharedFromThis Self>
SelfRef< Self > WithType (this Self &&self)
 Fluent API for setting tpye for deferred initialization (for example in factory functions)
 
template<typename Self >
requires (!CSharedFromThis<Self>)
Self && WithType (this Self &&self)
 Fluent API for setting tpye for deferred initialization (for example in factory functions)
 
FORCEINLINE FType const & GetType () const
 
FORCEINLINE FName const & GetTypeFName () const
 
FORCEINLINE FString GetTypeString () const
 
template<typename Derived , CSharedFromThis Self>
TSharedPtr< Derived > As (this Self &&self)
 Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.
 
template<typename Derived , typename Self >
requires (!CSharedFromThis<Self>)
Derived * As (this Self &&self)
 Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.
 

Protected Member Functions

template<typename Self >
void SetType (this Self &&self)
 This function needs to be called on top level derived type for runtime reflection to work.
 

Protected Attributes

FName TypeName
 
FType TypeInfo
 

Detailed Description

A barebones base class for types which may store their type-name as a string.

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.
Warning
Do not use exact type comparison with serialized data or network communication, as the actual value of the type is different between compilers. Only use this for runtime data. For such scenarios just use Unreal's own UObjects.

Definition at line 49 of file Types.h.

Member Typedef Documentation

◆ SelfRef

template<typename Self >
using Mcro::Types::IHaveType::SelfRef = TSharedRef<std::decay_t<Self>>

Definition at line 68 of file Types.h.

Constructor & Destructor Documentation

◆ ~IHaveType()

virtual Mcro::Types::IHaveType::~IHaveType ( )
virtualdefault

Member Function Documentation

◆ As() [1/2]

template<typename Derived , CSharedFromThis Self>
TSharedPtr< Derived > Mcro::Types::IHaveType::As ( this Self && self)
inline

Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.

Template Parameters
DerivedOnly return the desired type when the current object is exactly that type, and doesn't have deeper inheritance. Proper dynamic casting regarding the entire inheritance tree still without RTTI will come once proposed C++26 value-typed reflection becomes wide-spread available among popular compilers. If top-level derived type used types in TInherit, those are also supported.
Returns
Object cast to desired type when that's possible (see Derived) or nullptr;

Definition at line 105 of file Types.h.

◆ As() [2/2]

template<typename Derived , typename Self >
requires (!CSharedFromThis<Self>)
Derived * Mcro::Types::IHaveType::As ( this Self && self)
inline

Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.

Template Parameters
DerivedOnly return the desired type when the current object is exactly that type, and doesn't have deeper inheritance. Proper dynamic casting regarding the entire inheritance tree still without RTTI will come once proposed C++26 value-typed reflection becomes wide-spread available among popular compilers. If top-level derived type used types in TInherit, those are also supported.
Returns
Object cast to desired type when that's possible (see Derived) or nullptr;

Definition at line 136 of file Types.h.

◆ GetType()

FORCEINLINE FType const & Mcro::Types::IHaveType::GetType ( ) const
inline

Definition at line 87 of file Types.h.

◆ GetTypeFName()

FORCEINLINE FName const & Mcro::Types::IHaveType::GetTypeFName ( ) const
inline

Definition at line 88 of file Types.h.

◆ GetTypeString()

FORCEINLINE FString Mcro::Types::IHaveType::GetTypeString ( ) const
inline

Definition at line 89 of file Types.h.

◆ SetType()

template<typename Self >
void Mcro::Types::IHaveType::SetType ( this Self && self)
inlineprotected

This function needs to be called on top level derived type for runtime reflection to work.

Definition at line 60 of file Types.h.

◆ WithType() [1/2]

template<CSharedFromThis Self>
SelfRef< Self > Mcro::Types::IHaveType::WithType ( this Self && self)
inline

Fluent API for setting tpye for deferred initialization (for example in factory functions)

Definition at line 72 of file Types.h.

◆ WithType() [2/2]

template<typename Self >
requires (!CSharedFromThis<Self>)
Self && Mcro::Types::IHaveType::WithType ( this Self && self)
inline

Fluent API for setting tpye for deferred initialization (for example in factory functions)

Definition at line 81 of file Types.h.

Field Documentation

◆ TypeInfo

FType Mcro::Types::IHaveType::TypeInfo
protected

Definition at line 56 of file Types.h.

◆ TypeName

FName Mcro::Types::IHaveType::TypeName
protected

Definition at line 55 of file Types.h.


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