#include "StdAfx.h" #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); }