summaryrefslogtreecommitdiff
path: root/src/T2DLL/LComparator.cpp
blob: 649075d13dd967205109d70478026a6abada9cd1 (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
#include "LComparator.h"

LComparator* LComparator::sComparator;

LComparator::LComparator() {
	sComparator = NULL;
}

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

/*virtual*/ int LComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
	const unsigned char *a = (const unsigned char *) inItemOne;
	const unsigned char *b = (const unsigned char *) inItemTwo;
	unsigned int size = inSizeOne;
	if (inSizeTwo < inSizeOne)
		size = inSizeTwo;

	while (size > 0) {
		if (*a != *b)
			return *a - *b;
		a++;
		b++;
		size--;
	}

	return inSizeOne - inSizeTwo;
}

/*virtual*/ BOOL LComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
	return Compare(inItemOne, inItemTwo, inSizeOne, inSizeTwo) == 0;
}

/*virtual*/ int LComparator::CompareToKey(const void* inItem, unsigned int inSize, const void* inKey) const {
#line 86
	_ASSERT("CompareToKey not implemented");
	return 1;
}

/*virtual*/ BOOL LComparator::IsEqualToKey(const void* inItem, unsigned int inSize, const void* inKey) const {
	return CompareToKey(inItem, inSize, inKey) == 0;
}

LComparator* LComparator::GetComparator() {
	if (!sComparator)
		sComparator = new LComparator;
	return sComparator;
}

/*virtual*/ LComparator* LComparator::Clone() {
	return new LComparator;
}

LLongComparator* LLongComparator::sLongComparator;

LLongComparator::LLongComparator() {
	sLongComparator = NULL;
}

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

/*virtual*/ int LLongComparator::Compare(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
	return *((const long *) inItemOne) - *((const long *) inItemTwo);
}

/*virtual*/ BOOL LLongComparator::IsEqualTo(const void* inItemOne, const void* inItemTwo, unsigned int inSizeOne, unsigned int inSizeTwo) const {
	return *((const long *) inItemOne) == *((const long *) inItemTwo);
}

LLongComparator* LLongComparator::GetComparator() {
	if (!sLongComparator)
		sLongComparator = new LLongComparator;
	return sLongComparator;
}

/*virtual*/ LComparator* LLongComparator::Clone() {
	return new LLongComparator;
}