-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericVariable.cpp
169 lines (149 loc) · 3.38 KB
/
GenericVariable.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "stdafx.h"
#include <string>
#include <map>
#include <vector>
#include "GenericVariable.h"
#include "Table.h"
#include "AtlasCore.h"
#include "AtlasExtension.h"
#include "Pointer.h"
#include "AtlasTypes.h"
using namespace std;
GenericVariable::GenericVariable(void* Data, unsigned int Type)
{
DataType = Type;
DataPointer = Data;
}
GenericVariable::GenericVariable()
{
DataType = P_INVALID;
DataPointer = NULL;
}
GenericVariable::~GenericVariable()
{
Free();
}
void GenericVariable::SetData(void* Data, unsigned int Type)
{
Free();
DataType = Type;
DataPointer = Data;
}
void* GenericVariable::GetData()
{
return DataPointer;
}
unsigned int GenericVariable::GetType()
{
return DataType;
}
bool GenericVariable::Free()
{
if(DataPointer == NULL)
return true;
switch(DataType)
{
case P_INVALID:
break;
case P_STRING:
delete (string*)DataPointer;
break;
case P_NUMBER:
delete (__int64*)DataPointer;
break;
case P_DOUBLE:
delete (double*)DataPointer;
break;
case P_TABLE:
delete (Table*)DataPointer;
break;
case P_POINTERTABLE:
delete (PointerTable*)DataPointer;
break;
case P_POINTERLIST:
delete (PointerList*)DataPointer;
break;
case P_CUSTOMPOINTER:
delete (CustomPointer*)DataPointer;
break;
case P_EXTENSION:
delete (AtlasExtension*)DataPointer;
break;
default:
return false;
}
return true;
}
VariableMap::VariableMap()
{
}
VariableMap::~VariableMap()
{
for(VarMapIt = VarMap.begin(); VarMapIt != VarMap.end(); VarMapIt++)
delete VarMapIt->second;
}
bool VariableMap::AddVar(string& Identifier, void* Data, unsigned int Type)
{
VarMapIt = VarMap.find(string(Identifier));
if(VarMapIt != VarMap.end()) // Already a variable under that Identifier
return false;
GenericVariable* CVar = new GenericVariable;
CVar->SetData(Data, Type);
VarMap[Identifier] = CVar;
return true;
}
bool VariableMap::Exists(string& Identifier)
{
VarMapIt = VarMap.find(Identifier);
if(VarMapIt == VarMap.end()) // Not found
return false;
return true;
}
bool VariableMap::Exists(string& Identifier, unsigned int Type)
{
VarMapIt = VarMap.find(Identifier);
if(VarMapIt == VarMap.end()) // Identifier not found
return false;
if(VarMap[string(Identifier)]->GetType() != Type)
return false;
return true;
}
GenericVariable* VariableMap::GetVar(string& Identifier)
{
VarMapIt = VarMap.find(Identifier);
if(VarMapIt == VarMap.end())
return NULL;
else
return VarMapIt->second;
}
void VariableMap::SetVar(string& Identifier, GenericVariable* Var)
{
VarMapIt = VarMap.lower_bound(Identifier);
if(VarMapIt != VarMap.end() && !(VarMap.key_comp()(Identifier, VarMapIt->first)))
{
delete VarMapIt->second;
VarMapIt->second = Var;
}
else // Add variable
VarMap.insert(VarMapIt, VariableMapValue(Identifier, Var));
}
void VariableMap::SetVarData(string& Identifier, void* Data, unsigned int Type)
{
VarMapIt = VarMap.lower_bound(Identifier);
if(VarMapIt != VarMap.end() && !(VarMap.key_comp()(Identifier, VarMapIt->first)))
(VarMapIt->second)->SetData(Data, Type);
else // Add variable
VarMap.insert(VarMapIt, VariableMapValue(Identifier, new GenericVariable(Data, Type)));
}
unsigned int VariableMap::GetVarType(string& Identifier)
{
if(!Exists(Identifier))
return P_INVALID;
return VarMap[string(Identifier)]->GetType();
}
void* VariableMap::GetData(string& Identifier)
{
if(!Exists(Identifier))
return NULL;
return VarMap[Identifier]->GetData();
}