-
Notifications
You must be signed in to change notification settings - Fork 20
/
structHandler.cpp
66 lines (51 loc) · 1.56 KB
/
structHandler.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
54
55
56
57
58
59
60
61
62
63
64
65
#include <structHandler.h>
#include <global.h>
void StructHandler::convertToAmx(cell& value, long standardReturn, ConvertMode convertMode)
{
value = (cell)standardReturn;
Global::StructManagerObj->add(value, this);
}
StructHandler::StructHandler(StructInfo structInfo) :LongHandler()
{
this->structInfo = structInfo;
this->name = structInfo.type;
for (int i=0; i < structInfo.membersCount; ++i)
{
memberNameToMember.insert(structInfo.members[i].name.chars(), i);
}
}
int StructHandler::getMemberID(char* memberName)
{
int ID;
if (memberNameToMember.retrieve(memberName, &ID))
{
return ID;
}
return -1;
}
TypeHandler* StructHandler::getMemberTypeHandler(unsigned int memberID)
{
return structInfo.members[memberID].type;
}
long StructHandler::convertMemberToAmx(AMX* amx, cell* params, int memberID, long structureAddress)
{
Member member = this->structInfo.members[memberID];
long memberAddress = structureAddress + member.offset;
return member.type->convertToAmxFromStructure(amx, params, (void*)memberAddress);
}
void StructHandler::convertMemberFromAmx(AMX* amx, cell* params, int memberID, long structureAddress)
{
Member member = this->structInfo.members[memberID];
long memberAddress = structureAddress + member.offset;
return member.type->convertFromAmxToStructure(amx, *params, (void*)memberAddress);
}
long StructHandler::allocate()
{
long structureAddress = (long)allocateMemoryBySize(structInfo.size);
memset((void*)structureAddress, 0, structInfo.size);
return structureAddress;
}
int StructHandler::getStructSize()
{
return structInfo.size;
}