#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); }