summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2MatterArrayList.cpp
blob: 56113735e5186a455637b7d6fed92ae55c14b24c (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
#include "T2MatterArray.h"
#include "T2MatterArrayList.h"

T2MatterArrayList::T2MatterArrayList()
    : LArray(sizeof(T2MatterArray *))
{
    T2MatterArray *theArray = new T2MatterArray(0, T2MatterArray::kGroupSize, 1);
    Add(theArray);
}

/*virtual*/ T2MatterArrayList::~T2MatterArrayList() {
    LArrayIterator iterator(*this);
    T2MatterArray *theArray;

    while (iterator.Next(&theArray))
        delete theArray;
}

void T2MatterArrayList::Add(T2MatterArray* inArray) {
    InsertItemsAt(1, mItemCount + 1, &inArray);
}

unsigned int T2MatterArrayList::GetItemCount() {
    return GetCount();
}

T2MatterArray* T2MatterArrayList::GetItemAt(long inIndex) {
    T2MatterArray *theArray;
    if (FetchItemAt(inIndex, &theArray))
        return theArray;
    return NULL;
}

T2Matter* T2MatterArrayList::FindUnusedMatter(unsigned int inJobType, unsigned int inValidRange) {
    LArrayIterator iterator(*this);
    unsigned int lastStartID = 1;
    T2MatterArray *theArray;

    while (iterator.Next(&theArray)) {
        if (theArray->GetJobType() == inJobType) {
            T2Matter *theMatter = theArray->FindUnusedMatter(inValidRange);
            if (theMatter)
                return theMatter;

            lastStartID = theArray->mStartID;
        }
    }

    if (inValidRange > 0) {
        theArray = new T2MatterArray(inJobType, inValidRange, lastStartID + T2MatterArray::kGroupSize);
        if (theArray) {
            Add(theArray);
            return theArray->FindUnusedMatter(0);
        }
        return NULL;
    }

    return NULL;
}