LkEngine 0.1.2
 
Loading...
Searching...
No Matches
ObjectBase.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <concepts>
8
10#include "LkEngine/Core/Log/Log.h"
11
12#include "Enum.h"
13
14namespace LkEngine {
15
16 class LClass;
17
18 enum class EInitFlag
19 {
20 NoInit = 0, /* Do not initialize the object. */
21 True, /* Initialize the object. */
22 };
23
29 enum class EObjectFlag : uint32_t
30 {
31 None = 0, /* No flags. */
32 NeedInitialization, /* Need to be initialized. */
33 NeedLoad, /* Needs to get loaded to memory. */
34 BeginDestroy, /* Begin object destruction. */
35 FinishDestroy, /* Object destroyed. */
36 Garbage, /* Object deemed garbage and should get deleted. */
37 };
38 LK_ENUM_CLASS(EObjectFlag);
39
40
42 template<typename TObject>
43 concept LObjectCore = requires(TObject Object)
44 {
45 { Object.GetName() } -> std::same_as<std::string>;
46 };
47
57 {
58 public:
62 template<typename OtherClassType>
63 FORCEINLINE bool IsA(OtherClassType OtherObject) const
64 {
65 const LClass* OtherClass = OtherObject;
66 LK_CORE_ASSERT(OtherClass, "IsA failed, other class object is nullptr");
67
68 const LClass* ThisClass = GetClass();
69
70 /* Stop the compiler doing unnecessary branching for nullptr checks. */
71 LK_ASSUME(OtherClass);
72 LK_ASSUME(ThisClass);
73
74 return IsChildOf(ThisClass, OtherClass);
75 }
76
81 template<typename ClassType>
82 static FORCEINLINE bool IsChildOf(const ClassType* InObjectClass, const ClassType* InOtherClass)
83 {
84 LK_CORE_ASSERT(InObjectClass);
85 return InObjectClass->IsChildOf(InOtherClass);
86 }
87
88 protected:
94 void SetClass(LClass* InClass);
95
99 FORCEINLINE const LClass* GetClass() const
100 {
101 return ClassPrivate;
102 }
103
108 FORCEINLINE bool IsClassValid() const
109 {
110 return (ClassPrivate != nullptr);
111 }
112
113 private:
117 LClass* ClassPrivate = nullptr;
118 };
124 template<typename, typename = void>
125 struct HasGetClass : std::false_type {};
126
127 template<typename T>
128 struct HasGetClass<T, std::void_t<decltype(std::declval<T>().GetClass())>> : std::true_type {};
129
133 template<typename T>
134 concept HasLClassMacro = requires
135 {
136 { T::StaticClassName() } -> std::convertible_to<std::string_view>;
137 { T::StaticClass() } -> std::same_as<const LClass*>;
138 { std::declval<T>().ClassName() } -> std::convertible_to<std::string>;
139 { std::declval<T>().ClassRegistration() } -> std::same_as<const LClass*>;
140 typename T::BaseClass;
141 typename T::ThisClass;
142 };
143
144}
Core types.
Definition Class.h:17
Definition ObjectBase.h:57
static FORCEINLINE bool IsChildOf(const ClassType *InObjectClass, const ClassType *InOtherClass)
Check if the object is a child of another class.
Definition ObjectBase.h:82
FORCEINLINE const LClass * GetClass() const
Get the private class member.
Definition ObjectBase.h:99
FORCEINLINE bool IsA(OtherClassType OtherObject) const
Check if the object is the same type as the passed object's.
Definition ObjectBase.h:63
void SetClass(LClass *InClass)
Set the class.
Definition ObjectBase.cpp:9
FORCEINLINE bool IsClassValid() const
Check if LObjectBase has a valid LClass object.
Definition ObjectBase.h:108
Definition ObjectBase.h:134
Definition ObjectBase.h:43
Definition Asset.h:11
Definition UUID.h:33
Definition ObjectBase.h:125