A barebones base class for types which may store their type-name as a string.
More...
#include <Types.h>
|
| template<typename Self > |
| using | SelfRef = TSharedRef<std::decay_t<Self>> |
| |
|
| 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.
|
| |
|
| template<typename Self > |
| void | SetType (this Self &&self) |
| | This function needs to be called on top level derived type for runtime reflection to work.
|
| |
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.
◆ SelfRef
◆ ~IHaveType()
| virtual Mcro::Types::IHaveType::~IHaveType |
( |
| ) |
|
|
virtualdefault |
◆ 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
-
| Derived | Only 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
-
| Derived | Only 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 |
◆ GetTypeFName()
| FORCEINLINE FName const & Mcro::Types::IHaveType::GetTypeFName |
( |
| ) |
const |
|
inline |
◆ GetTypeString()
| FORCEINLINE FString Mcro::Types::IHaveType::GetTypeString |
( |
| ) |
const |
|
inline |
◆ 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.
◆ TypeInfo
| FType Mcro::Types::IHaveType::TypeInfo |
|
protected |
◆ TypeName
| FName Mcro::Types::IHaveType::TypeName |
|
protected |
The documentation for this class was generated from the following file: