KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
SubClassOf.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "Class.h"
14#include "Field.h"
15
16namespace Karma
17{
21 template<bool Predicate, typename TrueClass, typename FalseClass>
23
24 template<typename TrueClass, typename FalseClass>
25 class TChooseClass<true, TrueClass, FalseClass>
26 {
27 public:
28 typedef TrueClass Result;
29 };
30
31 template<typename TrueClass, typename FalseClass>
32 class TChooseClass<false, TrueClass, FalseClass>
33 {
34 public:
35 typedef FalseClass Result;
36 };
37
38 template <typename T>
40 {
41 enum { Value = false };
42 };
43
51 template<typename DerivedType, typename BaseType>
53 {
54 // Different size types so we can compare their sizes later.
56 typedef char No[1];
57
59 typedef char Yes[2];
60
61 // Overloading Test() s.t. only calling it with something that is
62 // a BaseType (or inherited from the BaseType) will return a Yes.
63
72 static Yes& Test(BaseType*);
73
82 static Yes& Test(const BaseType*);
83
92 static No& Test(...);
93
100 static DerivedType* DerivedTypePtr() { return nullptr; }
101
102 public:
107 static constexpr bool Value = sizeof(Test(DerivedTypePtr())) == sizeof(Yes);
108
109 static constexpr bool IsDerived = Value;
110 };
111
115 template<class TClass>
116 class TSubclassOf
117 {
118 public:
125
132
133 private:
134 template <class TClassA>
135 friend class TSubclassOf;
136
137 public:
143 inline TSubclassOf() :
144 Class(nullptr)
145 {
146 }
147
154 inline TSubclassOf(TClassType* From) :
155 Class(From)
156 {
157 }
158
205 template <
206 typename U,
207 std::enable_if_t<!TIsTSubclassOf<std::decay_t<U>>::Value, decltype(ImplicitConv<TClassType*>(std::declval<U>()))
208 >* = nullptr
209 >
210 inline TSubclassOf(U&& From)
211 : Class(From)
212 {
213 }
214
221 template <class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
222 inline TSubclassOf(const TSubclassOf<TClassA>& From) :
223 Class(*From)
224 {
225 }
226
233 template <class TClassA, class = decltype(ImplicitConv<TClass*>((TClassA*)nullptr))>
234 inline TSubclassOf& operator=(const TSubclassOf<TClassA>& From)
235 {
236 Class = *From;
237 return *this;
238 }
239
246 inline TSubclassOf& operator=(TClassType* From)
247 {
248 Class = From;
249 return *this;
250 }
251
258 template <
259 typename U,
260 std::enable_if_t<
262 decltype(ImplicitConv<TClassType*>(std::declval<U>()))
263 >* = nullptr
264 >
265 inline TSubclassOf& operator=(U&& From)
266 {
267 Class = From;
268 return *this;
269 }
270
277 inline TClassType* operator*() const
278 {
279 if (!Class || !Class->IsChildOf(TClass::StaticClass()))
280 {
281 return nullptr;
282 }
283 return Class;
284 }
285
291 inline TClassType* Get() const
292 {
293 return **this;
294 }
295
301 inline TClassType* operator->() const
302 {
303 return **this;
304 }
305
311 inline operator TClassType* () const
312 {
313 return **this;
314 }
315
322 inline TClass* GetDefaultObject() const
323 {
324 TBaseType* Result = nullptr;
325 if (Class)
326 {
327 Result = Class->GetDefaultObject();
328 KR_CORE_ASSERT(Result && Result->IsA(TClass::StaticClass()), "");
329 }
330 return (TClass*)Result;
331 }
332 /*
333 friend FArchive& operator<<(FArchive& Ar, TSubclassOf& SubclassOf)
334 {
335 Ar << SubclassOf.Class;
336 return Ar;
337 }
338
339 friend uint32 GetTypeHash(const TSubclassOf& SubclassOf)
340 {
341 return GetTypeHash(SubclassOf.Class);
342 }*/
343
344 private:
345 TClassType* Class;
346 };
347
348 template <typename T>
350 {
351 enum { Value = true };
352 };
353}
This file contains the class UField, UStruct, and UClass.
This file contains the class FField and relevant helpers.
Object representing a type of an FField struct. Mimics a subset of UObject reflection functions.
Definition Field.h:272
Base class of reflection data objects.
Definition Field.h:449
Chooses between two different classes based on a boolean.
Definition SubClassOf.h:22
TClassType * operator*() const
Definition SubClassOf.h:277
TClassType * operator->() const
Definition SubClassOf.h:301
TSubclassOf()
Definition SubClassOf.h:143
TSubclassOf(TClassType *From)
Definition SubClassOf.h:154
TClass * GetDefaultObject() const
Definition SubClassOf.h:322
TSubclassOf(const TSubclassOf< TClassA > &From)
Definition SubClassOf.h:222
TSubclassOf & operator=(TClassType *From)
Definition SubClassOf.h:246
TSubclassOf(U &&From)
Constructor that takes a UClass and does a runtime check to make sure this is a compatible class.
Definition SubClassOf.h:210
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...
Definition SubClassOf.h:131
TClassType * Get() const
Definition SubClassOf.h:291
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....
Definition SubClassOf.h:124
An object class.
Definition Class.h:158
The base class of all the game code relevant objects.
Definition Object.h:106
Is type DerivedType inherited from BaseType?
Definition SubClassOf.h:53
static Yes & Test(const BaseType *)
Handy variant function called when type-cast succeeds.
static No & Test(...)
Handy function called when type-cast does not succeed.
static constexpr bool Value
Definition SubClassOf.h:107
char Yes[2]
Definition SubClassOf.h:59
static Yes & Test(BaseType *)
Handy function called when type-cast succeeds.
static DerivedType * DerivedTypePtr()
Definition SubClassOf.h:100
char No[1]
Definition SubClassOf.h:56
Definition SubClassOf.h:40