summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/clucene/src/CLucene/util/Equators.cpp
blob: e112bd2341816ebc328a71c6f0b38748464a96e6 (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
 *
 * Distributable under the terms of either the Apache License (Version 2.0) or 
 * the GNU Lesser General Public License, as specified in the COPYING file.
 *
 * Changes are Copyright(C) 2007, 2008 by Nokia Corporation and/or its subsidiary(-ies), all rights reserved.
*/
#include "CLucene/StdHeader.h"
#include "Equators.h"

CL_NS_DEF(util)

bool Equals::Int32::operator()(const int32_t val1, const int32_t val2) const
{
    return (val1)==(val2);
}

bool Equals::Char::operator()(const char* val1, const char* val2) const
{
    if ( val1 == val2 )
        return true;
    return (strcmp(val1, val2) == 0);
}

#ifdef _UCS2
bool Equals::WChar::operator()(const wchar_t* val1, const wchar_t* val2) const
{
    if (val1 == val2)
        return true;
    return (_tcscmp(val1, val2) == 0);
}
#endif

bool Equals::Qstring::operator()(const QString& val1, const QString& val2) const
{
    return (val1 == val2);
}

///////////////////////////////////////////////////////////////////////////////
// Comparors
///////////////////////////////////////////////////////////////////////////////

int32_t Compare::Int32::getValue() const
{
    return value;
}

Compare::Int32::Int32(int32_t val)
{
    value = val;
}

Compare::Int32::Int32()
{
    value = 0;
}

int32_t Compare::Int32::compareTo(void* o)
{
    try {
        Int32* other = (Int32*)o;
        if (value == other->value)
            return 0;
        // Returns just -1 or 1 on inequality; doing math might overflow.
        return value > other->value ? 1 : -1;
    } catch(...) {
        _CLTHROWA(CL_ERR_Runtime, "Couldnt compare types");
    }  
}

bool Compare::Int32::operator()(int32_t t1, int32_t t2) const
{
    return t1 > t2 ? true : false;
}

size_t Compare::Int32::operator()(int32_t t) const
{
    return t;
}

qreal Compare::Float::getValue() const
{
    return value;
}

Compare::Float::Float(qreal val)
{
    value = val;
}

int32_t Compare::Float::compareTo(void* o)
{
    try {
        Float* other = (Float*)o;
        if (value == other->value)
            return 0;
        // Returns just -1 or 1 on inequality; doing math might overflow.
        return value > other->value ? 1 : -1;
    } catch(...) {
        _CLTHROWA(CL_ERR_Runtime,"Couldnt compare types");
    }  
}

bool Compare::Char::operator()(const char* val1, const char* val2) const
{
    if ( val1 == val2)
        return false;
    return (strcmp(val1, val2) < 0);
}

size_t Compare::Char::operator()(const char* val1) const
{
    return CL_NS(util)::Misc::ahashCode(val1);
}

#ifdef _UCS2
bool Compare::WChar::operator()(const wchar_t* val1, const wchar_t* val2) const
{
    if ( val1==val2)
        return false;
    return (_tcscmp(val1, val2) < 0);
}

size_t Compare::WChar::operator()(const wchar_t* val1) const
{
    return CL_NS(util)::Misc::whashCode(val1);
}
#endif

const TCHAR* Compare::TChar::getValue() const
{
    return s;
}

Compare::TChar::TChar()
{
    s = NULL;
}

Compare::TChar::TChar(const TCHAR* str)
{
    this->s = str;
}

int32_t Compare::TChar::compareTo(void* o)
{
    try {
        TChar* os = (TChar*)o;
        return _tcscmp(s, os->s);
    } catch(...) {
        _CLTHROWA(CL_ERR_Runtime,"Couldnt compare types");
    }  

}

bool Compare::TChar::operator()(const TCHAR* val1, const TCHAR* val2) const
{
    if (val1 == val2)
        return false;

    return (_tcscmp(val1, val2) < 0);
}

size_t Compare::TChar::operator()(const TCHAR* val1) const
{
    return CL_NS(util)::Misc::thashCode(val1);
}

bool Compare::Qstring::operator()(const QString& val1, const QString& val2) const
{
    return (val1 < val2);
}

size_t Compare::Qstring::operator ()(const QString& val1) const
{
    return CL_NS(util)::Misc::qhashCode(val1);
}

CL_NS_END