1 /*
2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3 *
4 * Distributable under the terms of either the Apache License (Version 2.0) or
5 * the GNU Lesser General Public License, as specified in the COPYING file.
6 *
7 * Changes are Copyright(C) 2007, 2008 by Nokia Corporation and/or its subsidiary(-ies), all rights reserved.
8 */
9 #include "CLucene/StdHeader.h"
10 #include "Equators.h"
11
CL_NS_DEF(util)12 CL_NS_DEF(util)
13
14 bool Equals::Int32::operator()(const int32_t val1, const int32_t val2) const
15 {
16 return (val1)==(val2);
17 }
18
operator ()(const char * val1,const char * val2) const19 bool Equals::Char::operator()(const char* val1, const char* val2) const
20 {
21 if ( val1 == val2 )
22 return true;
23 return (strcmp(val1, val2) == 0);
24 }
25
26 #ifdef _UCS2
operator ()(const wchar_t * val1,const wchar_t * val2) const27 bool Equals::WChar::operator()(const wchar_t* val1, const wchar_t* val2) const
28 {
29 if (val1 == val2)
30 return true;
31 return (_tcscmp(val1, val2) == 0);
32 }
33 #endif
34
operator ()(const QString & val1,const QString & val2) const35 bool Equals::Qstring::operator()(const QString& val1, const QString& val2) const
36 {
37 return (val1 == val2);
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////
41 // Comparors
42 ///////////////////////////////////////////////////////////////////////////////
43
getValue() const44 int32_t Compare::Int32::getValue() const
45 {
46 return value;
47 }
48
Int32(int32_t val)49 Compare::Int32::Int32(int32_t val)
50 {
51 value = val;
52 }
53
Int32()54 Compare::Int32::Int32()
55 {
56 value = 0;
57 }
58
compareTo(void * o)59 int32_t Compare::Int32::compareTo(void* o)
60 {
61 try {
62 Int32* other = (Int32*)o;
63 if (value == other->value)
64 return 0;
65 // Returns just -1 or 1 on inequality; doing math might overflow.
66 return value > other->value ? 1 : -1;
67 } catch(...) {
68 _CLTHROWA(CL_ERR_Runtime, "Couldnt compare types");
69 }
70 }
71
operator ()(int32_t t1,int32_t t2) const72 bool Compare::Int32::operator()(int32_t t1, int32_t t2) const
73 {
74 return t1 > t2 ? true : false;
75 }
76
operator ()(int32_t t) const77 size_t Compare::Int32::operator()(int32_t t) const
78 {
79 return t;
80 }
81
getValue() const82 qreal Compare::Float::getValue() const
83 {
84 return value;
85 }
86
Float(qreal val)87 Compare::Float::Float(qreal val)
88 {
89 value = val;
90 }
91
compareTo(void * o)92 int32_t Compare::Float::compareTo(void* o)
93 {
94 try {
95 Float* other = (Float*)o;
96 if (value == other->value)
97 return 0;
98 // Returns just -1 or 1 on inequality; doing math might overflow.
99 return value > other->value ? 1 : -1;
100 } catch(...) {
101 _CLTHROWA(CL_ERR_Runtime,"Couldnt compare types");
102 }
103 }
104
operator ()(const char * val1,const char * val2) const105 bool Compare::Char::operator()(const char* val1, const char* val2) const
106 {
107 if ( val1 == val2)
108 return false;
109 return (strcmp(val1, val2) < 0);
110 }
111
operator ()(const char * val1) const112 size_t Compare::Char::operator()(const char* val1) const
113 {
114 return CL_NS(util)::Misc::ahashCode(val1);
115 }
116
117 #ifdef _UCS2
operator ()(const wchar_t * val1,const wchar_t * val2) const118 bool Compare::WChar::operator()(const wchar_t* val1, const wchar_t* val2) const
119 {
120 if ( val1==val2)
121 return false;
122 return (_tcscmp(val1, val2) < 0);
123 }
124
operator ()(const wchar_t * val1) const125 size_t Compare::WChar::operator()(const wchar_t* val1) const
126 {
127 return CL_NS(util)::Misc::whashCode(val1);
128 }
129 #endif
130
getValue() const131 const TCHAR* Compare::TChar::getValue() const
132 {
133 return s;
134 }
135
TChar()136 Compare::TChar::TChar()
137 {
138 s = NULL;
139 }
140
TChar(const TCHAR * str)141 Compare::TChar::TChar(const TCHAR* str)
142 {
143 this->s = str;
144 }
145
compareTo(void * o)146 int32_t Compare::TChar::compareTo(void* o)
147 {
148 try {
149 TChar* os = (TChar*)o;
150 return _tcscmp(s, os->s);
151 } catch(...) {
152 _CLTHROWA(CL_ERR_Runtime,"Couldnt compare types");
153 }
154
155 }
156
operator ()(const TCHAR * val1,const TCHAR * val2) const157 bool Compare::TChar::operator()(const TCHAR* val1, const TCHAR* val2) const
158 {
159 if (val1 == val2)
160 return false;
161
162 return (_tcscmp(val1, val2) < 0);
163 }
164
operator ()(const TCHAR * val1) const165 size_t Compare::TChar::operator()(const TCHAR* val1) const
166 {
167 return CL_NS(util)::Misc::thashCode(val1);
168 }
169
operator ()(const QString & val1,const QString & val2) const170 bool Compare::Qstring::operator()(const QString& val1, const QString& val2) const
171 {
172 return (val1 < val2);
173 }
174
operator ()(const QString & val1) const175 size_t Compare::Qstring::operator ()(const QString& val1) const
176 {
177 return CL_NS(util)::Misc::qhashCode(val1);
178 }
179
180 CL_NS_END
181