-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSTypeInfo.cpp
More file actions
137 lines (130 loc) · 3.76 KB
/
Copy pathSTypeInfo.cpp
File metadata and controls
137 lines (130 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "Reflection/STypeInfo.hpp"
#include "Logger.h"
namespace sh::core::reflection
{
std::unordered_map<STypes::Info, STypeInfo*, STypes::InfoHasher> STypes::types{};
std::unordered_map<std::size_t, const core::reflection::STypeInfo*> STypeInfo::typeInfoMap;
STypeInfo::~STypeInfo()
{
STypes::Info info{};
info.hash = hash;
info.size = type.size;
// DLL 핫스왑용
STypes::types.erase(info);
typeInfoMap.erase(type.hash);
}
SH_CORE_API auto STypeInfo::AddProperty(std::unique_ptr<Property>&& prop) -> Property*
{
if (GetProperty(prop->GetName()) != nullptr)
return nullptr;
properties.push_back(std::move(prop));
auto propPtr = properties.back().get();
if (propPtr->isSObjectPointer)
sobjPtrs.push_back(propPtr);
else if (propPtr->isSObjectPointerContainer)
sobjPtrContainers.push_back(propPtr);
return propPtr;
}
SH_CORE_API auto STypeInfo::AddProperty(const Property& prop) -> Property*
{
if (GetProperty(prop.GetName()) != nullptr)
return nullptr;
properties.push_back(std::make_unique<Property>(prop));
auto propPtr = properties.back().get();
if (prop.isSObjectPointer)
sobjPtrs.push_back(propPtr);
else if (prop.isSObjectPointerContainer)
sobjPtrContainers.push_back(propPtr);
return propPtr;
}
SH_CORE_API auto STypeInfo::AddFunction(std::unique_ptr<Function>&& fn) -> Function*
{
for (auto& func : functions)
{
if (*func == *fn)
return nullptr;
}
functions.push_back(std::move(fn));
return functions.back().get();
}
SH_CORE_API auto STypeInfo::AddFunction(const Function& fn) -> Function*
{
return AddFunction(std::make_unique<Function>(fn));
}
SH_CORE_API auto STypeInfo::operator==(const STypeInfo& other) const -> bool
{
if (this == &other)
return true;
// 다른 dll 영역에 올라갈 경우 같은 클래스여도 주소가 다르다. 따라서 Hash값으로 비교한다.
return this->hash == other.hash;
}
SH_CORE_API auto STypeInfo::operator!=(const STypeInfo& other) const -> bool
{
return !operator==(other);
}
SH_CORE_API auto STypeInfo::IsChildOf(const STypeInfo& other) const -> bool
{
if (operator==(other))
return true;
const STypeInfo* superType = super;
while (superType != nullptr)
{
if (superType->operator==(other))
return true;
superType = superType->super;
}
return false;
}
SH_CORE_API auto STypeInfo::GetProperty(const core::Name& name) const -> Property*
{
for (auto& prop : properties)
{
if (prop->GetName() == name)
return prop.get();
}
return nullptr;
}
SH_CORE_API auto STypeInfo::GetProperty(std::string_view name) const -> Property*
{
return GetProperty(core::Name{ name });
}
SH_CORE_API auto STypeInfo::GetProperties() const -> const std::vector<std::unique_ptr<Property>>&
{
return properties;
}
SH_CORE_API auto STypeInfo::GetSObjectPtrProperties() const -> const std::vector<Property*>&
{
return sobjPtrs;
}
SH_CORE_API auto STypeInfo::GetSObjectPtrContainerProperties() const -> const std::vector<Property*>&
{
return sobjPtrContainers;
}
SH_CORE_API auto STypeInfo::GetFunction(const core::Name& name) const -> Function*
{
for (auto& fn : functions)
if (fn->GetName() == name)
return fn.get();
const STypeInfo* superType = this->super;
while (superType != nullptr)
{
Function* fn = superType->GetFunction(name);
if (fn != nullptr)
return fn;
superType = superType->super;
}
return nullptr;
}
SH_CORE_API auto STypeInfo::GetFunction(std::string_view name) const -> Function*
{
core::Name key{ name };
return GetFunction(key);
}
SH_CORE_API auto STypeInfo::ConvertFromTypeInfo(const core::reflection::TypeInfo& typeInfo) -> const STypeInfo*
{
auto it = typeInfoMap.find(typeInfo.hash);
if (it == typeInfoMap.end())
return nullptr;
return it->second;
}
}//namespace