diff options
Diffstat (limited to 'src/T2DLL/T2OutObjArrayList.cpp')
-rw-r--r-- | src/T2DLL/T2OutObjArrayList.cpp | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/src/T2DLL/T2OutObjArrayList.cpp b/src/T2DLL/T2OutObjArrayList.cpp index 3948561..bf1b3fd 100644 --- a/src/T2DLL/T2OutObjArrayList.cpp +++ b/src/T2DLL/T2OutObjArrayList.cpp @@ -1,34 +1,114 @@ +#include "T2Archive.h" +#include "T2OutObjArray.h" #include "T2OutObjArrayList.h" -T2OutObjArrayList::T2OutObjArrayList() { +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*) { +void T2OutObjArrayList::Add(T2OutObjArray* inArray) { + InsertItemsAt(1, mItemCount + 1, &inArray); } -T2OutObjArray* T2OutObjArrayList::GetItemAt(int) { +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*) { +void T2OutObjArrayList::DispatchIdle(T2TowerDoc* inDoc) { + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + theArray->DispatchIdle(inDoc, 0); } -T2OutObj* T2OutObjArrayList::GetIndOutObj(unsigned int) { +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) { +T2OutObj* T2OutObjArrayList::GetOutObjByID(unsigned int inOutObjID) { + if (inOutObjID == 0) + return NULL; + else + return GetIndOutObj(inOutObjID - 1000); } -int T2OutObjArrayList::CalcMentenanceCost(T2TowerDoc*) const { +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&, T2TowerDoc*) { +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&) { +void T2OutObjArrayList::Write(T2Archive& inArchive) { + unsigned int groupCount = GetCount(); + inArchive << groupCount; + + LArrayIterator iterator(*this); + T2OutObjArray *theArray; + + while (iterator.Next(&theArray)) + theArray->Write(inArchive); } |