KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::TSubclassOf< TClass > Class Template Reference

Template to allow TClassType's to be passed around with type safety. More...

#include <SubClassOf.h>

Public Types

typedef TChooseClass< TIsDerivedFrom< TClass, FField >::IsDerived, FFieldClass, UClass >::Result TClassType
 Since I don't think I understand the purpose of this typedef, I may attempt to parse the code. Seems like if TClass is derived from FField then TClassType is FFieldClass, else, UClass (for most scenarios). The pointer variable is of this type, i.e TClassType.
 
typedef TChooseClass< TIsDerivedFrom< TClass, FField >::IsDerived, FField, UObject >::Result TBaseType
 Again, on parsing, I understand the meaning to be, if TClass is derived from FField then TBaseType is FField else UObject (for most scenarios). The return type of GetDefaultObject() is of this type, again UObject for majority of the cases.
 

Public Member Functions

 TSubclassOf ()
 
 TSubclassOf (TClassType *From)
 
template<typename U, std::enable_if_t<!TIsTSubclassOf< std::decay_t< U > >::Value, decltype(ImplicitConv< TClassType * >(std::declval< U >())) > * = nullptr>
 TSubclassOf (U &&From)
 Constructor that takes a UClass and does a runtime check to make sure this is a compatible class.
 
template<class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
 TSubclassOf (const TSubclassOf< TClassA > &From)
 
template<class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
TSubclassOfoperator= (const TSubclassOf< TClassA > &From)
 
TSubclassOfoperator= (TClassType *From)
 
template<typename U, std::enable_if_t< !TIsTSubclassOf< std::decay_t< U > >::Value, decltype(ImplicitConv< TClassType * >(std::declval< U >())) > * = nullptr>
TSubclassOfoperator= (U &&From)
 
TClassTypeoperator* () const
 
TClassTypeGet () const
 
TClassTypeoperator-> () const
 
 operator TClassType * () const
 
TClass * GetDefaultObject () const
 

Detailed Description

template<class TClass>
class Karma::TSubclassOf< TClass >

Template to allow TClassType's to be passed around with type safety.

Constructor & Destructor Documentation

◆ TSubclassOf() [1/4]

template<class TClass>
Karma::TSubclassOf< TClass >::TSubclassOf ( )
inline

Default Constructor, defaults to null

Since
Karma 1.0.0

◆ TSubclassOf() [2/4]

template<class TClass>
Karma::TSubclassOf< TClass >::TSubclassOf ( TClassType * From)
inline

Constructor that takes a UClass and does a runtime check to make sure this is a compatible class

Parameters
FromUsually a UClass
Since
Karma 1.0.0

◆ TSubclassOf() [3/4]

template<class TClass>
template<typename U, std::enable_if_t<!TIsTSubclassOf< std::decay_t< U > >::Value, decltype(ImplicitConv< TClassType * >(std::declval< U >())) > * = nullptr>
Karma::TSubclassOf< TClass >::TSubclassOf ( U && From)
inline

Constructor that takes a UClass and does a runtime check to make sure this is a compatible class.

Understanding by-parts

  1. std::decay_t: allowing the "pass by reference" of parameter (https://stackoverflow.com/a/25732651). Basically an equivalence is established between, for instance, int(&)[2] and int* (reference to an array, even whole array, and pointer to appropriate data type)
  2. std::declval: Converts any type U to a reference type, allowing the use of class (struct) functions of U without actually initializing an object (simillar to that of static functions, in the sense no object is needed). For instance:

    struct NonDefault
    {
    NonDefault() = delete;
    int foo() const { return 1; }
    };
    decltype(Default().foo()) n1 = 1;

    Note the usage of foo() function without creating the object

  3. ImplicitConv<TClassType*>: An Unreal Engine function, uses implicit conversion to create an instance of a specific type. Not functional here yet
  4. decltype: The decltype keyword inspects the declared type of an entity or the type of an expression. ‘auto’ lets you declare a variable with a particular type whereas decltype lets you extract the type from the variable so decltype is sort of an operator that evaluates the type of passed expression.
  5. std::enable_if_t: Consider the following statement

    template< bool B, class T = void >
    struct enable_if;

    then, If B is true, std::enable_if has a public member typedef type, equal to T; otherwise, there is no member typedef.

    template< bool B, class T = void >
    using enable_if_t = typename enable_if<B,T>::type;

Parameters
FromA (mostly) UClass pointer with runtime check (which I don't practically understand)
Todo
Definition for ImplicitConv needs to be provided
Since
Karma 1.0.0

◆ TSubclassOf() [4/4]

template<class TClass>
template<class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
Karma::TSubclassOf< TClass >::TSubclassOf ( const TSubclassOf< TClassA > & From)
inline

Copy Constructor, will only compile if types are compatible

Parameters
FromA derived TClassA
Since
Karma 1.0.0

Member Function Documentation

◆ Get()

template<class TClass>
TClassType * Karma::TSubclassOf< TClass >::Get ( ) const
inline

Dereference back into a UClass

Since
Karma 1.0.0

◆ GetDefaultObject()

template<class TClass>
TClass * Karma::TSubclassOf< TClass >::GetDefaultObject ( ) const
inline

Get the CDO if we are referencing a valid class

Returns
the CDO, or null if class is null
Since
Karma 1.0.0

◆ operator TClassType *()

template<class TClass>
Karma::TSubclassOf< TClass >::operator TClassType * ( ) const
inline

Implicit conversion to UClass

Since
Karma 1.0.0

◆ operator*()

template<class TClass>
TClassType * Karma::TSubclassOf< TClass >::operator* ( ) const
inline

Dereference back into a UClass, does runtime type checking

Note
Not seen practical example
Since
Karma 1.0.0

◆ operator->()

template<class TClass>
TClassType * Karma::TSubclassOf< TClass >::operator-> ( ) const
inline

Dereference back into a UClass

Since
Karma 1.0.0

◆ operator=() [1/3]

template<class TClass>
template<class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
TSubclassOf & Karma::TSubclassOf< TClass >::operator= ( const TSubclassOf< TClassA > & From)
inline

Assignment operator, will only compile if types are compatible

Parameters
FromThe object to copy from
Since
Karma 1.0.0

◆ operator=() [2/3]

template<class TClass>
TSubclassOf & Karma::TSubclassOf< TClass >::operator= ( TClassType * From)
inline

Assignment operator from UClass, the type is checked on get not on set

Parameters
FromThe object to copy from
Since
Karma 1.0.0

◆ operator=() [3/3]

template<class TClass>
template<typename U, std::enable_if_t< !TIsTSubclassOf< std::decay_t< U > >::Value, decltype(ImplicitConv< TClassType * >(std::declval< U >())) > * = nullptr>
TSubclassOf & Karma::TSubclassOf< TClass >::operator= ( U && From)
inline

Assignment operator from UClass, the type is checked on get not on set

Parameters
FromObject to copy from
Since
Karma 1.0.0

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