-
Notifications
You must be signed in to change notification settings - Fork 1
/
VariableList.h
63 lines (50 loc) · 1.74 KB
/
VariableList.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
#ifndef VariableList_h
#define VariableList_h
//////////////////////////////////////////////////////////////////////////////////////////////////
// A simple array of VariableID's
/////////////////
// OS Includes
//////////////
// Includes
#include "LightweightTypes.h"
/////////////
// Defines
////////////////////////
// Class Declarations
//////////////////////////////////////////////////////////////////////////////////////////////////
// Class Definitions
class VariableList {
public:
inline VariableList(int iMaxVars_);
~VariableList() { delete [] _aVariableList; }
inline void vClear() {_iVariableCount = 0;}
inline void vAdd(VariableID eID_) {_aVariableList[_iVariableCount++] = eID_;}
inline void vAppend(const VariableList& xMe_);
int iCount() const {return _iVariableCount;}
void vOutput(ostream&) const;
inline void vRemoveAtIndex(int iWhich_);
VariableID eTop() { if (_iVariableCount) { return _aVariableList[_iVariableCount-1]; } else return -1; }
VariableID ePop() { assert(_iVariableCount); return _aVariableList[--_iVariableCount]; }
VariableID iVariable(int iWhich_) const
{assert(iWhich_ < _iVariableCount); return _aVariableList[iWhich_];}
protected:
VariableID* _aVariableList;
int _iVariableCount;
};
//////////////////////////////////////////////////////////////////////////////////////////////////
// Inlines
inline VariableList::VariableList(int iMaxVars_)
: _iVariableCount(0),
_aVariableList(new VariableID[iMaxVars_])
{}
inline void VariableList::vRemoveAtIndex(int iWhich_)
{
_aVariableList[iWhich_] = _aVariableList[--_iVariableCount];
}
inline void VariableList::vAppend(const VariableList& xMe_)
{
for (int i=0; i<xMe_.iCount(); i++) {
vAdd(xMe_.iVariable(i));
}
}
#endif // VariableList_h