summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2RegistedTenantDB.cpp
blob: 81d0339bcf18ebe7524103e219604fc90e874b38 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "T2EquipPtrList.h"
#include "T2RegistedTenantDB.h"
#include "T2RouteNavigator.h"
#include "T2Tenant.h"
#include "T2TenantArray.h"
#include "T2TenantArrayList.h"

T2RegistedTenantDB::T2RegistedTenantDB()
    : LArray(sizeof(T2EquipPtrList *))
{
}

/*virtual*/ T2RegistedTenantDB::~T2RegistedTenantDB() {
    LArrayIterator iterator(*this);
    T2EquipPtrList *equipPtrList;

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

void T2RegistedTenantDB::Init(T2TenantArrayList* tenantArrayList) {
    LArrayIterator iterator(*tenantArrayList);
    T2TenantArray *tenantArray;

    while (iterator.Next(&tenantArray)) {
        for (int i = 0; i < 128; i++) {
            T2Tenant *tenant = tenantArray->GetIndexTenant(i);
            if (tenant->IsUsed() && !tenant->IsFloor())
                AddItem(tenant);
        }
    }
}

void T2RegistedTenantDB::AddItem(T2Tenant* tenant) {
    if (tenant->IsRegist()) {
        unsigned int registID = tenant->GetRegistID();
        T2EquipPtrList *list = GetList(registID);

        if (list) {
            list->AddItem(tenant);
        } else {
            list = new T2EquipPtrList(registID);
#line 55
            _ASSERT(list);
            list->AddItem(tenant);
            InsertItemsAt(1, mItemCount + 1, &list);
        }
    }
}

void T2RegistedTenantDB::RemoveItem(T2Tenant* tenant) {
    if (tenant->IsRegist()) {
        unsigned int registID = tenant->GetRegistID();
        T2EquipPtrList *list = GetList(registID);

        if (list)
            list->RemoveItem(tenant);
    }
}

T2EquipPtrList* T2RegistedTenantDB::GetList(unsigned int registID) const {
    T2EquipPtrList *result = NULL;
    LArrayIterator iterator(*this);

    T2EquipPtrList *list;
    while (!result && iterator.Next(&list)) {
        if (list->GetAttribute() == registID)
            result = list;
    }

    return result;
}

T2Tenant* T2RegistedTenantDB::GetFirstTenant(unsigned int registID) const {
    T2Tenant *tenant = NULL;
    T2EquipPtrList *list = GetList(registID);
    if (list)
        tenant = (T2Tenant *) list->GetItem(1);
    return tenant;
}

T2Tenant* T2RegistedTenantDB::SearchToilet(const T2RouteNavigator* routeNav, POINT pt, int& outVar) const {
    T2Tenant *result = NULL;
    outVar = -1;

    T2EquipPtrList *list = GetList(kTenantRegistID7);
    if (list) {
        LArrayIterator iterator(*list);
        T2Tenant *tenant;
        while (outVar != 0 && iterator.Next(&tenant)) {
            POINT entrancePt = tenant->GetEntrancePt();
            if (routeNav->CheckRoute(pt, entrancePt, tenant->GetCustomerSearchScore())) {
                int status = tenant->GetStatus();
                if (status > kTenantStatus9 && status < kTenantStatus10000) {
                    if (!tenant->WillBeFull()) {
                        result = tenant;
                        outVar = 0;
                    } else {
                        outVar = -2;
                    }
                }
            }
        }
    }

    return result;
}

T2Tenant* T2RegistedTenantDB::FindEmptyParking() const {
    T2Tenant *result = NULL;

    T2EquipPtrList *list = GetList(kTenantRegistID3);
    if (list) {
        LArrayIterator iterator(*list);
        T2Tenant *tenant;
        while (!result && iterator.Next(&tenant)) {
            if (tenant->IsEmptyParking())
                result = tenant;
        }
    }

    return result;
}

T2Tenant* T2RegistedTenantDB::FindHisParking(T2People* people) const {
    T2Tenant *result = NULL;

    T2EquipPtrList *list = GetList(kTenantRegistID3);
    if (list) {
        LArrayIterator iterator(*list);
        T2Tenant *tenant;
        while (!result && iterator.Next(&tenant)) {
            if (tenant->IsBelongPeople(people))
                result = tenant;
        }
    }

    return result;
}