blob: bf1b3fd4ad4b9a2029a382427fbb6138645e3020 (
plain)
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
|
#include "T2Archive.h"
#include "T2OutObjArray.h"
#include "T2OutObjArrayList.h"
T2OutObjArrayList::T2OutObjArrayList()
: LArray(sizeof(T2OutObjArray *))
{
T2OutObjArray *theArray = new T2OutObjArray;
Add(theArray);
}
/*virtual*/ T2OutObjArrayList::~T2OutObjArrayList() {
LArrayIterator iterator(*this);
T2OutObjArray *theArray;
while (iterator.Next(&theArray))
delete theArray;
}
void T2OutObjArrayList::Add(T2OutObjArray* inArray) {
InsertItemsAt(1, mItemCount + 1, &inArray);
}
T2OutObjArray* T2OutObjArrayList::GetItemAt(int inIndex) {
T2OutObjArray *theArray;
if (FetchItemAt(inIndex, &theArray))
return theArray;
return NULL;
}
T2OutObj* T2OutObjArrayList::FindUnusedOutObj() {
LArrayIterator iterator(*this);
unsigned int lastStartID = 1;
T2OutObjArray *theArray;
while (iterator.Next(&theArray)) {
T2OutObj *theOutObj = theArray->FindUnusedOutObj();
if (theOutObj)
return theOutObj;
lastStartID = theArray->mStartID;
}
theArray = new T2OutObjArray(lastStartID + T2OutObjArray::kGroupSize);
if (theArray) {
Add(theArray);
return theArray->FindUnusedOutObj();
}
return NULL;
}
void T2OutObjArrayList::DispatchIdle(T2TowerDoc* inDoc) {
LArrayIterator iterator(*this);
T2OutObjArray *theArray;
while (iterator.Next(&theArray))
theArray->DispatchIdle(inDoc, 0);
}
T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int inIndex) {
int groupNum = inIndex / T2OutObjArray::kGroupSize;
int indexInGroup = inIndex % T2OutObjArray::kGroupSize;
T2OutObjArray *theArray = GetItemAt(groupNum + 1);
if (theArray)
return theArray->GetIndexOutObj(indexInGroup);
else
return NULL;
}
T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int inOutObjID) {
if (inOutObjID == 0)
return NULL;
else
return GetIndOutObj(inOutObjID - 1000);
}
int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc* inDoc) const {
int totalCost = 0;
LArrayIterator iterator(*this);
T2OutObjArray *theArray;
while (iterator.Next(&theArray))
totalCost += theArray->CalcMentenanceCost(inDoc);
return totalCost;
}
void T2OutObjArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) {
unsigned int groupCount;
inArchive >> groupCount;
RemoveItemsAt(GetCount(), 1);
unsigned int startID = 1000;
for (unsigned int i = 0; i < groupCount; i++) {
T2OutObjArray *theArray = new T2OutObjArray(startID);
theArray->Read(inArchive, inDoc);
Add(theArray);
startID += T2OutObjArray::kGroupSize;
}
}
void T2OutObjArrayList::Write(T2Archive& inArchive) {
unsigned int groupCount = GetCount();
inArchive << groupCount;
LArrayIterator iterator(*this);
T2OutObjArray *theArray;
while (iterator.Next(&theArray))
theArray->Write(inArchive);
}
|