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

#include <Types.h>

Inheritance diagram for Mcro::Types::IHaveType:
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<typename Self >
SelfRef< Self > WithType (this Self &&self)
 
FORCEINLINE FName const & GetType () const
 
template<typename Derived , typename Self >
TSharedPtr< Derived > AsExactly (this Self &&self)
 

Protected Member Functions

template<typename Self >
void SetType (this Self &&self)
 

Protected Attributes

FName TypeName
 

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.

Definition at line 41 of file Types.h.

Member Typedef Documentation

◆ SelfRef

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

Definition at line 58 of file Types.h.

Constructor & Destructor Documentation

◆ ~IHaveType()

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

Member Function Documentation

◆ AsExactly()

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

Very simple dynamic casting of this object to a derived top-level type.

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 available.
Returns
Object cast to desired type when that's possible (see Derived) or nullptr;

Definition at line 81 of file Types.h.

◆ GetType()

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

Definition at line 68 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 51 of file Types.h.

◆ WithType()

template<typename 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 62 of file Types.h.

Field Documentation

◆ TypeName

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

Definition at line 47 of file Types.h.


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