summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2ToolDefDB.cpp
blob: 34d086b68758d415f2d79daa53e5e2e85ad47dec (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
#include "StdAfx.h"
#include "T2ToolDef.h"
#include "T2ToolDefDB.h"
#include "T2ToolDefList.h"

T2ToolDefDB::T2ToolDefDB()
    : LArray(sizeof(T2ToolDefList *))
{
}

/*virtual*/ T2ToolDefDB::~T2ToolDefDB() {
}

void T2ToolDefDB::AllClear() {
    RemoveItemsAt(mItemCount, 1);
}

void T2ToolDefDB::Regist(T2ToolDef* inToolDef) {
    if (!inToolDef)
        return;

    int categoryNo = inToolDef->GetCategory();
    int n = 1;
    LArrayIterator iterator(*this);
    T2ToolDefList *theToolDefList;
    BOOL added = false;

    while (!added && iterator.Next(&theToolDefList)) {
        int thisCategory = theToolDefList->GetCategory();
        if (thisCategory == categoryNo) {
            theToolDefList->Add(inToolDef);
            added = true;
        } else {
            if (thisCategory > categoryNo)
                break;
        }

        n++;
    }

    if (!added) {
        theToolDefList = new T2ToolDefList(categoryNo);
        theToolDefList->Add(inToolDef);
        InsertItemsAt(1, n, &theToolDefList);
    }
}

void T2ToolDefDB::Add(T2ToolDefList* inToolDefList) {
    LArrayIterator iterator(*this);
    T2ToolDefList *theToolDefList;
    BOOL added = false;

    while (!added && iterator.Next(&theToolDefList)) {
        if (theToolDefList->GetCategory() == inToolDefList->GetCategory()) {
            LArrayIterator toolDefIterator(*inToolDefList);
            T2ToolDef *theToolDef;

            while (toolDefIterator.Next(&theToolDef))
                theToolDefList->Add(theToolDef);

            added = true;
        }
    }

    if (!added)
        InsertItemsAt(1, mItemCount + 1, &inToolDefList);
}

T2ToolDefList* T2ToolDefDB::GetToolDefList(int inCategory) {
    LArrayIterator iterator(*this);
    T2ToolDefList *theToolDefList;

    while (iterator.Next(&theToolDefList)) {
        if (theToolDefList->GetCategory() == inCategory)
            return theToolDefList;
    }

    return NULL;
}

T2TenantDef* T2ToolDefDB::FindFloor() {
    LArrayIterator iterator(*this);
    T2ToolDefList *theToolDefList;
    T2TenantDef *theFloor = NULL;

    while (iterator.Next(&theToolDefList)) {
        theFloor = theToolDefList->FindFloor();
        if (theFloor)
            return theFloor;
    }

    return NULL;
}