-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPointer.hpp
83 lines (67 loc) · 1.43 KB
/
Pointer.hpp
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
#pragma once
#include "Construct.hpp"
#define TEMPLATE_READ(type, member) \
if constexpr (std::is_class_v<type>) \
{ \
member.Read(reader, version, user, arg); \
} \
else \
{ \
member = reader.Read<type>(); \
}
#define TEMPLATE_WRITE(type, member) \
if constexpr (std::is_class_v<type>) \
{ \
member.Write(writer, version, user, arg); \
} \
else \
{ \
writer.Write(member); \
}
namespace nejlika::geometry {
template<typename T>
class Pointer : public Construct
{
private:
uint32_t m_Index;
public:
Pointer() : m_Index(0xFFFFFFFF)
{
}
Pointer(uint32_t index) : m_Index(index)
{
}
void Read(nejlika::Reader& reader, uint32_t version, uint32_t user, uint32_t arg)
{
m_Index = reader.Read<uint32_t>();
}
void Write(nejlika::Writer& writer, uint32_t version, uint32_t user, uint32_t arg) const
{
writer.Write(m_Index);
}
bool IsNull() const
{
return m_Index == 0xFFFFFFFF;
}
uint32_t GetIndex() const
{
return m_Index;
}
void SetIndex(uint32_t index)
{
m_Index = index;
}
void Reset()
{
m_Index = 0xFFFFFFFF;
}
T Query(const std::vector<nejlika::geometry::Construct*>& blocks) const
{
if (IsNull())
{
return nullptr;
}
return dynamic_cast<T>(blocks[m_Index]);
}
};
}