summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2NameComparator.cpp
blob: 4df0b79456ba4016c59604e565ee6172d36f1599 (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
#include "StdAfx.h"
#include "T2Name.h"
#include "T2NameComparator.h"

/*virtual*/ int T2NameComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
    T2Name *a = *((T2Name **) inItemOne);
    T2Name *b = *((T2Name **) inItemTwo);

    if (!b)
        return -1;
    else if (!a)
        return 1;

    return (a->IsFavorite() != b->IsFavorite()) ? (a->IsFavorite() - b->IsFavorite())
                                                : (a->GetType() != b->GetType()) ? (a->GetType() - b->GetType())
                                                                                 : (a->GetID() - b->GetID());
}

/*virtual*/ BOOL T2NameComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
    T2Name *a = *((T2Name **) inItemOne);
    T2Name *b = *((T2Name **) inItemTwo);
    return (a->IsFavorite() == b->IsFavorite()) && (a->GetType() == b->GetType()) && (a->GetID() == b->GetID());
}

/*static*/ T2NameComparator* T2NameComparator::sT2NameComparator;

/*static*/ T2NameComparator* T2NameComparator::GetComparator() {
    if (!sT2NameComparator)
        sT2NameComparator = new T2NameComparator;
    return sT2NameComparator;
}