-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVariableSet.h
123 lines (103 loc) · 3.22 KB
/
VariableSet.h
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
#ifndef VariableSet_h
#define VariableSet_h
//////////////////////////////////////////////////////////////////////////////////////////////////
// This class allows us to manipulate a set of VariableID's.
/////////////////
// OS Includes
//////////////
// Includes
#include "LightweightTypes.h"
#include "VariableList.h"
/////////////
// Defines
////////////////////////
// Class Declarations
//////////////////////////////////////////////////////////////////////////////////////////////////
// Class Definitions
class VariableSet : public VariableList {
public:
VariableSet(int iMaxVars_) : VariableList(iMaxVars_),
_aHasVariable(new VariableID[iMaxVars_])
{ for (int i=0; i<iMaxVars_; i++) _aHasVariable[i]=-1;}
~VariableSet() {delete [] _aHasVariable;}
inline void vClear();
inline void vRemoveVariable(VariableID eID_);
inline void vRemoveVariableCheck(VariableID eID_);
inline void vAddVariableNoCheck(VariableID eID_);
inline void vAddVariable(VariableID eID_);
inline void vAppendVariables(const VariableList&);
inline void vAppendNoCheck(const VariableList&);
inline void vRemove(const VariableList& xThese_);
inline boolean bAddVariable(VariableID eID_);
boolean bHasVariable(VariableID eID_) const {return (_aHasVariable[eID_]!=-1);}
private:
VariableID* _aHasVariable;
};
//////////////////////////////////////////////////////////////////////////////////////////////////
// Inlines
inline void VariableSet::vRemove(const VariableList& xThese_)
{
for (int i=0; i<xThese_.iCount(); i++) {
vRemoveVariableCheck(xThese_.iVariable(i));
}
}
inline void VariableSet::vAppendVariables(const VariableList& xMe_)
{
for (int i=0; i<xMe_.iCount(); i++) {
vAddVariable(xMe_.iVariable(i));
}
}
inline void VariableSet::vAppendNoCheck(const VariableList& xMe_)
{
for (int i=0; i<xMe_.iCount(); i++) {
vAddVariableNoCheck(xMe_.iVariable(i));
}
}
inline void VariableSet::vClear()
{
for (int i=0; i < _iVariableCount; i++) {
assert(_aHasVariable[_aVariableList[i]] != -1);
_aHasVariable[_aVariableList[i]] = -1;
}
_iVariableCount = 0;
}
inline void VariableSet::vRemoveVariable(VariableID eID_)
{
assert(eID_ >= 0);
assert(bHasVariable(eID_));
_aVariableList[_aHasVariable[eID_]] = _aVariableList[--_iVariableCount];
_aHasVariable[_aVariableList[_iVariableCount]] = _aHasVariable[eID_];
_aHasVariable[eID_] = -1;
}
inline void VariableSet::vRemoveVariableCheck(VariableID eID_)
{
assert(eID_ >= 0);
if (_aHasVariable[eID_] != -1) {
_aVariableList[_aHasVariable[eID_]] = _aVariableList[--_iVariableCount];
_aHasVariable[_aVariableList[_iVariableCount]] = _aHasVariable[eID_];
_aHasVariable[eID_] = -1;
}
}
inline void VariableSet::vAddVariableNoCheck(VariableID eID_)
{
// Add a variable without checking for duplicates.
assert(eID_ >= 0);
assert(_aHasVariable[eID_] == -1);
_aHasVariable[eID_] = _iVariableCount;
_aVariableList[_iVariableCount++] = eID_;
}
inline void VariableSet::vAddVariable(VariableID eID_)
{
if (_aHasVariable[eID_] == -1) {
vAddVariableNoCheck(eID_);
}
}
inline boolean VariableSet::bAddVariable(VariableID eID_)
{
if (_aHasVariable[eID_] == -1) {
vAddVariableNoCheck(eID_);
return 1;
}
return 0;
}
#endif // VariableSet_h