blob: ae45dc324755523973040c563c7da41bef05c429 (
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
115
116
|
#include "StdAfx.h"
#include "T2Archive.h"
#include "T2RequestArray.h"
#include "T2RequestArrayList.h"
T2RequestArrayList::T2RequestArrayList()
: LArray(sizeof(T2RequestArray *))
{
T2RequestArray *requestArray = new T2RequestArray(1000);
Add(requestArray);
}
/*virtual*/ T2RequestArrayList::~T2RequestArrayList() {
LArrayIterator iterator(*this);
T2RequestArray *theRequestArray;
while (iterator.Next(&theRequestArray))
delete theRequestArray;
}
void T2RequestArrayList::Add(T2RequestArray* inRequestArray) {
InsertItemsAt(1, mItemCount + 1, &inRequestArray);
}
unsigned int T2RequestArrayList::GetItemCount() {
return GetCount();
}
T2RequestArray* T2RequestArrayList::GetItemAt(int inIndex) {
T2RequestArray *theRequestArray;
if (FetchItemAt(inIndex, &theRequestArray))
return theRequestArray;
else
return NULL;
}
T2Request* T2RequestArrayList::GetRequestByID(unsigned int inRequestID) {
if (inRequestID == 0)
return NULL;
if (inRequestID < 1000)
return NULL;
int group = (inRequestID - 1000) / 64;
int indexInGroup = (inRequestID - 1000) % 64;
T2RequestArray *requestArray = GetItemAt(group + 1);
if (requestArray)
return requestArray->GetIndexRequest(indexInGroup);
else
return NULL;
}
T2Request* T2RequestArrayList::FindUnusedRequest() {
T2Request *theRequest = NULL;
LArrayIterator iterator(*this);
T2RequestArray *theRequestArray = NULL;
while (!theRequest && iterator.Next(&theRequestArray)) {
theRequest = theRequestArray->FindUnusedRequest();
}
if (!theRequest) {
unsigned int newStartID = 1000;
if (theRequestArray)
newStartID = theRequestArray->GetStartID() + 64;
theRequestArray = new T2RequestArray(newStartID);
if (theRequestArray) {
Add(theRequestArray);
theRequest = theRequestArray->FindUnusedRequest();
}
}
return theRequest;
}
void T2RequestArrayList::BreakoutEmergency(T2TowerDoc* inDoc) {
LArrayIterator iterator(*this);
T2RequestArray *requestArray;
while (iterator.Next(&requestArray))
requestArray->BreakoutEmergency(inDoc);
}
void T2RequestArrayList::Read(T2Archive& inArchive, T2TowerDoc* inDoc) {
int count;
inArchive >> count;
RemoveItemsAt(GetCount(), 1);
unsigned int startID = 1000;
for (int i = 0; i < count; i++) {
T2RequestArray *theRequestArray = new T2RequestArray(startID);
theRequestArray->Read(inArchive, inDoc);
Add(theRequestArray);
startID += 64;
}
}
void T2RequestArrayList::Write(T2Archive& inArchive) {
int count = GetItemCount();
inArchive << count;
LArrayIterator iterator(*this);
T2RequestArray *theRequestArray;
while (iterator.Next(&theRequestArray))
theRequestArray->Write(inArchive);
}
void T2RequestArrayList::DispatchIdle(T2TowerDoc* inDoc) {
LArrayIterator iterator(*this);
T2RequestArray *theRequestArray;
while (iterator.Next(&theRequestArray))
theRequestArray->DispatchIdle(inDoc, 0);
}
|