code reorg and moving files to csql base directory
[csql.git] / src / base / TypeCompare.cxx
blobf1f716e91e3bc9420f6e074c5e4f2534172772f4
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<os.h>
17 #include<DataType.h>
18 #include<Debug.h>
20 bool AllDataType::compareIntVal(void* src1, void *src2, ComparisionOp op)
22 printf("This function should never be called by anyone\n");
23 if (OpEquals == op) {
24 if (*(int*)src1 == *(int*)src2) return true;
25 else return false;
26 }else if (OpGreaterThan == op) {
27 if (*(int*)src1 > *(int*)src2) return true;
28 else return false;
29 }else if (OpLessThan == op) {
30 if (*(int*)src1 < *(int*)src2) return true;
31 else return false;
32 }else if (OpLessThanEquals == op) {
33 if (*(int*)src1 <= *(int*)src2) return true;
34 else return false;
35 }else if (OpGreaterThanEquals == op) {
36 if (*(int*)src1 >= *(int*)src2) return true;
37 else return false;
38 }else if (OpNotEquals == op) {
39 if (*(int*)src1 != *(int*)src2) return true;
40 else return false;
42 return false;
45 bool AllDataType::compareLongVal(void* src1, void *src2, ComparisionOp op)
47 bool result = false;
48 switch(op)
50 case OpEquals:
51 if (*(long*)src1 == *(long*)src2) result = true;
52 else result = false;
53 break;
54 case OpNotEquals:
55 if (*(long*)src1 != *(long*)src2) result = true;
56 else result = false;
57 break;
58 case OpLessThan:
59 if (*(long*)src1 < *(long*)src2) result = true;
60 else result = false;
61 break;
62 case OpLessThanEquals:
63 if (*(long*)src1 <= *(long*)src2) result = true;
64 else result = false;
65 break;
66 case OpGreaterThan:
67 if (*(long*)src1 > *(long*)src2) result = true;
68 else result = false;
69 break;
70 case OpGreaterThanEquals:
71 if (*(long*)src1 >= *(long*)src2) result = true;
72 else result = false;
73 break;
75 return result;
78 bool AllDataType::compareLongLongVal(void* src1, void *src2,
79 ComparisionOp op)
81 bool result = false;
82 switch(op)
84 case OpEquals:
85 if (*(long long*)src1 == *(long long*)src2) result = true;
86 else result = false;
87 break;
88 case OpNotEquals:
89 if (*(long long*)src1 != *(long long*)src2) result = true;
90 else result = false;
91 break;
92 case OpLessThan:
93 if (*(long long*)src1 < *(long long*)src2) result = true;
94 else result = false;
95 break;
96 case OpLessThanEquals:
97 if (*(long long*)src1 <= *(long long*)src2) result = true;
98 else result = false;
99 break;
100 case OpGreaterThan:
101 if (*(long long*)src1 > *(long long*)src2) result = true;
102 else result = false;
103 break;
104 case OpGreaterThanEquals:
105 if (*(long long*)src1 >= *(long long*)src2) result = true;
106 else result = false;
107 break;
109 return result;
112 bool AllDataType::compareShortVal(void* src1, void *src2, ComparisionOp op)
114 bool result = false;
115 switch(op)
117 case OpEquals:
118 if (*(short*)src1 == *(short*)src2) result = true;
119 else result = false;
120 break;
121 case OpNotEquals:
122 if (*(short*)src1 != *(short*)src2) result = true;
123 else result = false;
124 break;
125 case OpLessThan:
126 if (*(short*)src1 < *(short*)src2) result = true;
127 else result = false;
128 break;
129 case OpLessThanEquals:
130 if (*(short*)src1 <= *(short*)src2) result = true;
131 else result = false;
132 break;
133 case OpGreaterThan:
134 if (*(short*)src1 > *(short*)src2) result = true;
135 else result = false;
136 break;
137 case OpGreaterThanEquals:
138 if (*(short*)src1 >= *(short*)src2) result = true;
139 else result = false;
140 break;
142 return result;
145 bool AllDataType::compareByteIntVal(void* src1, void *src2, ComparisionOp op)
147 bool result = false;
148 switch(op)
150 case OpEquals:
151 if (*(ByteInt*)src1 == *(ByteInt*)src2) result = true;
152 else result = false;
153 break;
154 case OpNotEquals:
155 if (*(ByteInt*)src1 != *(ByteInt*)src2) result = true;
156 else result = false;
157 break;
158 case OpLessThan:
159 if (*(ByteInt*)src1 < *(ByteInt*)src2) result = true;
160 else result = false;
161 break;
162 case OpLessThanEquals:
163 if (*(ByteInt*)src1 <= *(ByteInt*)src2) result = true;
164 else result = false;
165 break;
166 case OpGreaterThan:
167 if (*(ByteInt*)src1 > *(ByteInt*)src2) result = true;
168 else result = false;
169 break;
170 case OpGreaterThanEquals:
171 if (*(ByteInt*)src1 >= *(ByteInt*)src2) result = true;
172 else result = false;
173 break;
175 return result;
178 bool AllDataType::compareDoubleVal(void* src1, void *src2, ComparisionOp op)
180 bool result = false;
181 switch(op)
183 case OpEquals:
184 if (*(double*)src1 == *(double*)src2) result = true;
185 else result = false;
186 break;
187 case OpNotEquals:
188 if (*(double*)src1 != *(double*)src2) result = true;
189 else result = false;
190 break;
191 case OpLessThan:
192 if (*(double*)src1 < *(double*)src2) result = true;
193 else result = false;
194 break;
195 case OpLessThanEquals:
196 if (*(double*)src1 <= *(double*)src2) result = true;
197 else result = false;
198 break;
199 case OpGreaterThan:
200 if (*(double*)src1 > *(double*)src2) result = true;
201 else result = false;
202 break;
203 case OpGreaterThanEquals:
204 if (*(double*)src1 >= *(double*)src2) result = true;
205 else result = false;
206 break;
208 return result;
211 bool AllDataType::compareFloatVal(void* src1, void *src2, ComparisionOp op)
213 bool result = false;
214 switch(op)
216 case OpEquals:
217 if (*(float*)src1 == *(float*)src2) result = true;
218 else result = false;
219 break;
220 case OpNotEquals:
221 if (*(float*)src1 != *(float*)src2) result = true;
222 else result = false;
223 break;
224 case OpLessThan:
225 if (*(float*)src1 < *(float*)src2) result = true;
226 else result = false;
227 break;
228 case OpLessThanEquals:
229 if (*(float*)src1 <= *(float*)src2) result = true;
230 else result = false;
231 break;
232 case OpGreaterThan:
233 if (*(float*)src1 > *(float*)src2) result = true;
234 else result = false;
235 break;
236 case OpGreaterThanEquals:
237 if (*(float*)src1 >= *(float*)src2) result = true;
238 else result = false;
239 break;
241 return result;
244 bool AllDataType::compareDateVal(void* src1, void *src2, ComparisionOp op)
246 bool result = false;
247 switch(op)
249 case OpEquals:
250 if (*(Date*)src1 == *(Date*)src2) result = true;
251 else result = false;
252 break;
253 case OpNotEquals:
254 if (*(Date*)src1 != *(Date*)src2) result = true;
255 else result = false;
256 break;
257 case OpLessThan:
258 if (*(Date*)src1 < *(Date*)src2) result = true;
259 else result = false;
260 break;
261 case OpLessThanEquals:
262 if (*(Date*)src1 <= *(Date*)src2) result = true;
263 else result = false;
264 break;
265 case OpGreaterThan:
266 if (*(Date*)src1 > *(Date*)src2) result = true;
267 else result = false;
268 break;
269 case OpGreaterThanEquals:
270 if (*(Date*)src1 >= *(Date*)src2) result = true;
271 else result = false;
272 break;
274 return result;
277 bool AllDataType::compareTimeVal(void* src1, void *src2, ComparisionOp op)
279 bool result = false;
280 switch(op)
282 case OpEquals:
283 if (*(Time*)src1 == *(Time*)src2) result = true;
284 else result = false;
285 break;
286 case OpNotEquals:
287 if (*(Time*)src1 != *(Time*)src2) result = true;
288 else result = false;
289 break;
290 case OpLessThan:
291 if (*(Time*)src1 < *(Time*)src2) result = true;
292 else result = false;
293 break;
294 case OpLessThanEquals:
295 if (*(Time*)src1 <= *(Time*)src2) result = true;
296 else result = false;
297 break;
298 case OpGreaterThan:
299 if (*(Time*)src1 > *(Time*)src2) result = true;
300 else result = false;
301 break;
302 case OpGreaterThanEquals:
303 if (*(Time*)src1 >= *(Time*)src2) result = true;
304 else result = false;
305 break;
307 return result;
310 bool AllDataType::compareTimeStampVal(void* src1, void *src2, ComparisionOp op)
312 bool result = false;
313 switch(op)
315 case OpEquals:
316 if (*(TimeStamp*)src1 == *(TimeStamp*)src2) result = true;
317 else result = false;
318 break;
319 case OpNotEquals:
320 if (*(TimeStamp*)src1 != *(TimeStamp*)src2) result = true;
321 else result = false;
322 break;
323 case OpLessThan:
324 if (*(TimeStamp*)src1 < *(TimeStamp*)src2) result = true;
325 else result = false;
326 break;
327 case OpLessThanEquals:
328 if (*(TimeStamp*)src1 <= *(TimeStamp*)src2) result = true;
329 else result = false;
330 break;
331 case OpGreaterThan:
332 if (*(TimeStamp*)src1 > *(TimeStamp*)src2) result = true;
333 else result = false;
334 break;
335 case OpGreaterThanEquals:
336 if (*(TimeStamp*)src1 >= *(TimeStamp*)src2) result = true;
337 else result = false;
338 break;
340 return result;
343 bool AllDataType::compareStringVal(void* src1, void *src2, ComparisionOp op)
345 if (OpEquals == op) {
346 if (strcmp((char*)src1, (char*)src2) ==0) return true;
347 else return false;
348 }else if (OpGreaterThan == op) {
349 if (strcmp((char*)src1, (char*)src2) >0) return true;
350 else return false;
351 }else if (OpLessThan == op) {
352 if (strcmp((char*)src1, (char*)src2) <0 ) return true;
353 else return false;
354 }else if (OpLessThanEquals == op) {
355 // printf("Illegal Operator:Not Supported for String\n");
356 // return false;
357 if (strcmp((char*)src1, (char*)src2)<= 0) return true;
358 else return false;
359 }else if (OpGreaterThanEquals == op) {
360 // printf("Illegal Operator:Not Supported for String\n");
361 // return false;
362 if (strcmp((char*)src1, (char*)src2) >=0) return true;
363 else return false;
364 }else if (OpNotEquals == op) {
365 if (strcmp((char*)src1, (char*)src2) != 0) return true;
366 else return false;
367 }else if (OpLike == op) {
368 return !os::strmatch((char*)src2, (char*)src1);
370 printf("Illegeal Operator:Not supported for String\n");
371 return false;
374 bool AllDataType::compareBinaryVal(void* src1, void *src2,
375 ComparisionOp op, int length)
377 bool result = false;
378 int ret = os::memcmp(src1, src2, length);
379 switch(op)
381 case OpEquals:
382 if (ret == 0 ) result= true; else result = false;
383 break;
384 case OpNotEquals:
385 if (ret != 0 ) result= true; else result = false;
386 break;
387 case OpLessThan:
388 if (ret < 0 ) result= true; else result = false;
389 break;
390 case OpLessThanEquals:
391 printf("Illegal Operator:Not Supported for Binary\n");
392 break;
393 case OpGreaterThan:
394 if (ret > 0 ) result= true; else result = false;
395 break;
396 case OpGreaterThanEquals:
397 printf("Illegal Operator:Not Supported for Binary\n");
398 break;
400 return result;