-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSObjectManager.cpp
More file actions
63 lines (55 loc) · 1.41 KB
/
Copy pathSObjectManager.cpp
File metadata and controls
63 lines (55 loc) · 1.41 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
#include "SObjectManager.h"
#include "SObject.h"
namespace sh::core
{
SH_CORE_API SObjectManager::SObjectManager()
{
}
SH_CORE_API SObjectManager::~SObjectManager()
{
}
SH_CORE_API void SObjectManager::RegisterSObject(SObject* obj)
{
std::unique_lock<std::shared_mutex> lock{ mu };
auto it = objIdxMap.find(obj->GetUUID());
if (it != objIdxMap.end())
return;
objIdxMap[obj->GetUUID()] = objs.size();
objs.push_back(obj);
objPtrs.insert(obj);
}
SH_CORE_API void SObjectManager::UnRegisterSObject(const SObject* obj)
{
std::unique_lock<std::shared_mutex> lock{ mu };
auto it = objIdxMap.find(obj->GetUUID());
if (it == objIdxMap.end())
return;
const std::size_t idx = it->second;
const std::size_t last = objs.size() - 1;
objIdxMap.erase(it);
objPtrs.erase(obj);
if (idx != last)
{
SObject* moved = objs[last];
objs[idx] = moved;
objIdxMap[moved->GetUUID()] = idx;
}
objs.pop_back();
}
SH_CORE_API auto SObjectManager::GetSObject(const UUID& uuid) -> SObject*
{
std::shared_lock<std::shared_mutex> lock{ mu };
auto it = objIdxMap.find(uuid);
if (it == objIdxMap.end())
return nullptr;
return objs[it->second];
}
SH_CORE_API auto SObjectManager::IsSObject(void* ptr) -> bool
{
std::shared_lock<std::shared_mutex> lock{ mu };
auto it = objPtrs.find(reinterpret_cast<SObject*>(ptr));
if (it == objPtrs.end())
return false;
return true;
}
}//namespace