-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtti.cpp
53 lines (46 loc) · 1016 Bytes
/
rtti.cpp
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
#include "rtti.h"
#include <string.h>
void Rtti::finalise()
{
count = 0;
auto tmap = types->get();
for (auto &it : tmap)
{
Type *t = it.second;
indexes[t->classId()] = count;
count = count + strlen(t->name().c_str()) + 9;
while (count & 0x7)
{
count++;
}
}
data = new unsigned char[count];
memset(data, 0, count);
unsigned char *ptr = data;
for (auto &it : tmap)
{
Type *t = it.second;
wle64(ptr, t->classId());
strcpy((char *)ptr, t->name().c_str());
ptr += strlen(t->name().c_str()) + 1;
while ((uint64_t)ptr & 0x7)
{
ptr++;
}
}
}
uint64_t Rtti::lookup(uint64_t id)
{
if (!data)
{
printf("Lookup before data!\n");
assert(false);
}
auto it = indexes.find(id);
if (it == indexes.end())
{
printf("Couldn't find class id %ld!\n", id);
assert(false);
}
return (*it).second;
}