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#ifndef _lucene_util_Equators_
10#define _lucene_util_Equators_
11
12#if defined(_LUCENE_PRAGMA_ONCE)
13# pragma once
14#endif
15
16#include <QtCore/QString>
17
18//#ifdef QT_LINUXBASE
19// we are going to use qreal now, we basically maintain our own clucene anyway
20//// LSB doesn't define float_t - see http://bugs.linuxbase.org/show_bug.cgi?id=2374
21//typedef float float_t;
22//#endif
23
24CL_NS_DEF(util)
25
26///////////////////////////////////////////////////////////////////////////////
27// Equators
28///////////////////////////////////////////////////////////////////////////////
29
30class Equals{
31public:
32 class Int32:public CL_NS_STD(binary_function)<const int32_t*,const int32_t*,bool>
33 {
34 public:
35 bool operator()( const int32_t val1, const int32_t val2 ) const;
36 };
37
38 class Char:public CL_NS_STD(binary_function)<const char*,const char*,bool>
39 {
40 public:
41 bool operator()( const char* val1, const char* val2 ) const;
42 };
43#ifdef _UCS2
44 class WChar: public CL_NS_STD(binary_function)<const wchar_t*,const wchar_t*,bool>
45 {
46 public:
47 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const;
48 };
49 class TChar: public WChar{
50 };
51#else
52 class TChar: public Char{
53 };
54#endif
55
56 template<typename _cl>
57 class Void:public CL_NS_STD(binary_function)<const void*,const void*,bool>
58 {
59 public:
60 bool operator()( _cl* val1, _cl* val2 ) const{
61 return val1==val2;
62 }
63 };
64
65 class Qstring : public CL_NS_STD(binary_function)<const QString&, const QString&, bool>
66 {
67 public:
68 bool operator() (const QString& val1, const QString& val2) const;
69 };
70};
71
72
73///////////////////////////////////////////////////////////////////////////////
74// Comparors
75///////////////////////////////////////////////////////////////////////////////
76
77class Comparable : LUCENE_BASE
78{
79public:
80 virtual ~Comparable(){
81 }
82
83 virtual int32_t compareTo(void* o) = 0;
84};
85
86/** @internal */
87class Compare{
88public:
89 class _base
90 { // traits class for hash containers
91 public:
92 enum
93 { // parameters for hash table
94 bucket_size = 4, // 0 < bucket_size
95 min_buckets = 8
96 }; // min_buckets = 2 ^^ N, 0 < N
97
98 _base()
99 {
100 }
101 };
102
103 class Int32:public _base, public Comparable{
104 int32_t value;
105 public:
106 int32_t getValue() const;
107 Int32(int32_t val);
108 Int32();
109 int32_t compareTo(void* o);
110 bool operator()( int32_t t1, int32_t t2 ) const;
111 size_t operator()( int32_t t ) const;
112 };
113
114
115 class Float:public Comparable{
116 qreal value;
117 public:
118 qreal getValue() const;
119 Float(qreal val);
120 int32_t compareTo(void* o);
121 };
122
123
124 class Char: public _base //<char*>
125 {
126 public:
127 bool operator()( const char* val1, const char* val2 ) const;
128 size_t operator()( const char* val1) const;
129 };
130
131#ifdef _UCS2
132 class WChar: public _base //<wchar_t*>
133 {
134 public:
135 bool operator()( const wchar_t* val1, const wchar_t* val2 ) const;
136 size_t operator()( const wchar_t* val1) const;
137 };
138#endif
139
140 class TChar: public _base, public Comparable{
141 const TCHAR* s;
142 public:
143 const TCHAR* getValue() const;
144
145 TChar();
146 TChar(const TCHAR* str);
147 int32_t compareTo(void* o);
148 bool operator()( const TCHAR* val1, const TCHAR* val2 ) const;
149 size_t operator()( const TCHAR* val1) const;
150 };
151
152
153 template<typename _cl>
154 class Void:public _base //<const void*,const void*,bool>
155 {
156 public:
157 int32_t compareTo(_cl* o){
158 if ( this == o )
159 return o;
160 else
161 return this > o ? 1 : -1;
162 }
163 bool operator()( _cl* t1, _cl* t2 ) const{
164 return t1 > t2 ? true : false;
165 }
166 size_t operator()( _cl* t ) const{
167 return (size_t)t;
168 }
169 };
170
171 class Qstring : public _base
172 {
173 public:
174 bool operator() (const QString& val1, const QString& val2) const;
175 size_t operator() (const QString& val1) const;
176 };
177};
178
179///////////////////////////////////////////////////////////////////////////////
180// allocators
181///////////////////////////////////////////////////////////////////////////////
182
183class Deletor
184{
185public:
186
187 template<typename _kt>
188 class Array{
189 public:
190 static void doDelete(_kt* arr){
191 _CLDELETE_LARRAY(arr);
192 }
193 };
194 class tcArray{
195 public:
196 static void doDelete(const TCHAR* arr){
197 _CLDELETE_CARRAY(arr);
198 }
199 };
200 class acArray{
201 public:
202 static void doDelete(const char* arr){
203 _CLDELETE_CaARRAY(arr);
204 }
205 };
206
207 class Unintern{
208 public:
209 static void doDelete(TCHAR* arr);
210 };
211 template<typename _kt>
212 class Object{
213 public:
214 static void doDelete(_kt* obj){
215 _CLLDELETE(obj);
216 }
217 };
218 template<typename _kt>
219 class Void{
220 public:
221 static void doDelete(_kt* obj){
222 _CLVDELETE(obj);
223 }
224 };
225 class Dummy{
226 public:
227 static void doDelete(const void* nothing)
228 {
229 // TODO: remove all occurances where it hits this point
230 // CND_WARNING(false, "Deletor::Dummy::doDelete run, set deleteKey
231 // or deleteValue to false");
232 }
233 };
234 class DummyInt32{
235 public:
236 static void doDelete(const int32_t nothing){
237 }
238 };
239 class DummyFloat{
240 public:
241 static void doDelete(const qreal nothing){
242 }
243 };
244 template <typename _type>
245 class ConstNullVal{
246 public:
247 static void doDelete(const _type nothing)
248 {
249 // TODO: remove all occurances where it hits this point
250 // CND_WARNING(false, "Deletor::Dummy::doDelete run, set deleteKey
251 // or deleteValue to false");
252 }
253 };
254
255 template <typename _type>
256 class NullVal{
257 public:
258 static void doDelete(_type nothing)
259 {
260 // TODO: remove all occurances where it hits this point
261 // CND_WARNING(false, "Deletor::Dummy::doDelete run, set deleteKey
262 // or deleteValue to false");
263 }
264 };
265 class DummyQString {
266 public:
267 static void doDelete(const QString& nothing) {
268 }
269 };
270};
271////////////////////////////////////////////////////////////////////////////////
272
273CL_NS_END
274#endif
275