summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2NameList.cpp
blob: 8fda1d65fdc60d979a31829fc6b4c6910f6dfb65 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "T2Archive.h"
#include "T2Mover.h"
#include "T2MoverModule.h"
#include "T2Name.h"
#include "T2NameComparator.h"
#include "T2NameList.h"
#include "T2People.h"
#include "T2Tenant.h"

T2NameList::T2NameList()
    : LArray(sizeof(T2Name *))
{
    SetComparator(T2NameComparator::GetComparator());
    mOwnsComparator = false;

    SetKeepSorted(true);
}

/*virtual*/ T2NameList::~T2NameList() {
    LArrayIterator iterator(*this);
    T2Name *name;
    while (iterator.Next(&name))
        delete name;
}

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

void T2NameList::Clear() {
    RemoveItemsAt(mItemCount, 1);
}

void T2NameList::Add(T2Name* name) {
    InsertItemsAt(1, mItemCount + 1, &name);
}

void T2NameList::RemoveName(T2Name* name) {
    Remove(&name);
}

T2Name* T2NameList::Search(const T2Tenant* tenant, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *name;

    while (iterator.Next(&name)) {
        if (
            name->IsFavorite() == isFavorite &&
            name->GetType() == kTenantNameType &&
            name->GetID() == tenant->GetEquipID()
            )
            return name;
    }

    return NULL;
}

T2Name* T2NameList::Search(const T2Mover* mover, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *name;

    while (iterator.Next(&name)) {
        if (
            name->IsFavorite() == isFavorite &&
            name->GetType() == kMoverNameType &&
            name->GetID() == mover->GetEquipID()
            )
            return name;
    }

    return NULL;
}

T2Name* T2NameList::Search(const T2MoverModule* moverModule, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *name;

    while (iterator.Next(&name)) {
        if (
            name->IsFavorite() == isFavorite &&
            name->GetType() == kMoverModuleNameType &&
            name->GetID() == moverModule->GetModuleID()
            )
            return name;
    }

    return NULL;
}

T2Name* T2NameList::Search(const T2People* people, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *name;

    while (iterator.Next(&name)) {
        if (
            name->IsFavorite() == isFavorite &&
            name->GetType() == kPeopleNameType &&
            name->GetID() == people->mMatterID
            )
            return name;
    }

    return NULL;
}

T2Name* T2NameList::Search(const CString& str, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *theFoundName = NULL;
    T2Name *theName = NULL;

    while (iterator.Next(&theName)) {
        if (theName->IsFavorite() == isFavorite && *theName == str) {
            theFoundName = theName;
            break;
        }
    }

    return theFoundName;
}

T2Name* T2NameList::FullNameSearch(T2TowerDoc* towerDoc, const CString& str, BOOL isFavorite) const {
    LArrayIterator iterator(*this);
    T2Name *theFoundName = NULL;
    T2Name *theName = NULL;

    while (iterator.Next(&theName)) {
        CString fullName;
        theName->MakeFullName(towerDoc, fullName);
        BOOL isMatch = (str == fullName);
        if (theName->IsFavorite() == isFavorite && isMatch) {
            theFoundName = theName;
            break;
        }
    }

    return theFoundName;
}

void T2NameList::Read(T2Archive& archive) {
    int count;
    archive >> count;

    for (int i = 0; i < count; i++) {
        T2Name *name = new T2Name(archive);
        Add(name);
    }
}

void T2NameList::Write(T2Archive& archive) const {
    int count = GetCount();
    archive << count;

    LArrayIterator iterator(*this);
    T2Name *theName;

    while (iterator.Next(&theName))
        theName->Write(archive);
}