1 #ifndef BZS_DB_PROTOCOL_TDAP_FIELD_COMP_H
2 #define BZS_DB_PROTOCOL_TDAP_FIELD_COMP_H
21 #include <bzs/db/protocol/tdap/tdapcapi.h>
22 #include <bzs/env/crosscompile.h>
27 inline __int64 changeEndian2(__int64 v)
30 char* l = (
char*)&ret;
37 inline __int64 changeEndian3(__int64 v)
40 char* l = (
char*)&ret;
48 inline __int64 changeEndian4(__int64 v)
51 char* l = (
char*)&ret;
60 inline __int64 changeEndian5(__int64 v)
63 char* l = (
char*)&ret;
73 inline __int64 changeEndian6(__int64 v)
76 char* l = (
char*)&ret;
87 inline __int64 changeEndian7(__int64 v)
90 char* l = (
char*)&ret;
102 inline __int64 changeEndian8(__int64 v)
105 char* l = (
char*)&ret;
118 inline __int64 changeEndian(__int64 v,
int len)
123 case 2:
return changeEndian2(v);
124 case 3:
return changeEndian3(v);
125 case 4:
return changeEndian4(v);
126 case 5:
return changeEndian5(v);
127 case 6:
return changeEndian6(v);
128 case 7:
return changeEndian7(v);
129 case 8:
return changeEndian8(v);
134 inline int int24toInt(
const char* p)
136 return ((*((
int*)p) & 0xFFFFFF) << 8) / 0x100;
139 inline unsigned int int24toUint(
const char* p)
141 return *((
unsigned int*)p) & 0xFFFFFF;
144 inline __int64 myBittoInt64(
const char* p,
int len)
148 return changeEndian8(v);
151 inline void storeInt24(
int v,
char* p)
156 inline void storeUint24(
unsigned int v,
char* p)
161 inline int compareUint24(
const char* l,
const char* r)
163 unsigned int lv = int24toUint(l);
164 unsigned int rv = int24toUint(r);;
172 inline int compareInt24(
const char* l,
const char* r)
174 int lv = int24toInt(l);
175 int rv = int24toInt(r);
184 template <
class T>
inline int compare(
const char* l,
const char* r)
186 if (*((T*)l) < *((T*)r))
188 else if (*((T*)l) > *((T*)r))
193 template <
class T>
inline int bitMask(
const char* l,
const char* r)
195 T v = *((T*)l) & *((T*)r);
201 return (v > 0) ? 1 : ((v < 0) ? -1 : 0);
204 template <
class T>
inline int compare(T l, T r)
214 inline int compareVartype(
const char* l,
const char* r,
bool bin,
bool all,
bool incase)
218 int tmp = std::min<int>(llen, rlen);
220 tmp = _strnicmp(l +
sizeof(T), r +
sizeof(T), tmp);
222 tmp = memcmp(l +
sizeof(T), r +
sizeof(T), tmp);
224 tmp = strncmp(l +
sizeof(T), r +
sizeof(T), tmp);
227 return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
228 return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
232 inline int compareWvartype(
const char* l,
const char* r,
bool bin,
bool all,
bool incase)
234 int llen = (*(T*)l) /
sizeof(char16_t);
235 int rlen = (*(T*)r) /
sizeof(char16_t);
236 int tmp = std::min<int>(llen, rlen);
238 tmp = wcsnicmp16((char16_t*)(l +
sizeof(T)), (char16_t*)(r +
sizeof(T)),
242 wmemcmp16((char16_t*)(l +
sizeof(T)), (char16_t*)(r +
sizeof(T)), tmp);
244 tmp = wcsncmp16((char16_t*)(l +
sizeof(T)), (char16_t*)(r +
sizeof(T)),
247 return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
248 return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
251 inline int compareBlobType(
const char* l,
const char* r,
bool bin,
bool all,
bool incase,
256 memcpy(&llen, l, sizeByte);
257 memcpy(&rlen, r, sizeByte);
258 int tmp = std::min<int>(llen, rlen);
259 const char* lptr = *((
const char**)(l + sizeByte));
260 const char* rptr = r + sizeByte;
262 tmp = _strnicmp(lptr, rptr, tmp);
264 tmp = memcmp(lptr, rptr, tmp);
266 tmp = strncmp(lptr, rptr, tmp);
269 return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
270 return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
273 inline int compareBlobType2(
const char* l,
const char* r,
bool bin,
bool all,
bool incase,
278 memcpy(&llen, l, sizeByte);
279 memcpy(&rlen, r, sizeByte);
280 int tmp = std::min<int>(llen, rlen);
281 const char* lptr = *((
const char**)(l + sizeByte));
282 const char* rptr = *((
const char**)(r + sizeByte));
284 tmp = _strnicmp(lptr, rptr, tmp);
286 tmp = memcmp(lptr, rptr, tmp);
288 tmp = strncmp(lptr, rptr, tmp);
291 return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
292 return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
318 inline int nullComp(
bool lnull,
bool rnull,
char log)
321 return (log == eIsNull) ? 0 : -1;
323 return (log == eIsNull) ? 1 : 0;
328 inline int compBitAnd(
const char* l,
const char* r,
int len)
330 return bitMask<T>(l, r);
333 inline int compBitAnd24(
const char* l,
const char* r,
int len)
335 int lv = int24toInt(l);
336 int rv = int24toInt(r);
337 return bitMask<int>((
const char*)&lv, (
const char*)&rv);
340 inline int compBitAnd64(
const char* l,
const char* r,
int len)
346 return bitMask<__int64>((
const char*)&lv, (
const char*)&rv);
350 inline int compNumber(
const char* l,
const char* r,
int len)
352 return compare<T>(l, r);
355 inline int compNumber24(
const char* l,
const char* r,
int len)
357 return compareInt24(l, r);
360 inline int compNumberU24(
const char* l,
const char* r,
int len)
362 return compareUint24(l, r);
365 inline int compMem(
const char* l,
const char* r,
int len)
367 return memcmp(l, r, len);
370 inline int compString(
const char* l,
const char* r,
int len)
372 return strncmp(l, r, len);
375 inline int compiString(
const char* l,
const char* r,
int len)
377 return _strnicmp(l, r, len);
380 inline int compWString(
const char* l,
const char* r,
int len)
382 return wcsncmp16((char16_t*)l, (char16_t*)r, len/2);
385 inline int compiWString(
const char* l,
const char* r,
int len)
387 return wcsnicmp16((char16_t*)l, (char16_t*)r, len/2);
393 #define T_INCASE true
396 #define T_CMP_ALL true
397 #define T_CMP_PART false
400 template <
class T,
bool all>
401 inline int compVarString(
const char* l,
const char* r,
int len)
403 return compareVartype<T>(l, r, T_STR, all, T_CASE);
406 template <
class T,
bool all>
407 inline int compVarString_bin(
const char* l,
const char* r,
int len)
409 return compareVartype<T>(l, r, T_BIN, all, T_CASE);
411 template <
class T,
bool all>
412 inline int compVarString_i(
const char* l,
const char* r,
int len)
414 return compareVartype<T>(l, r, T_STR, all, T_INCASE);
417 template <
class T,
bool all>
418 inline int compVarString_bin_i(
const char* l,
const char* r,
int len)
420 return compareVartype<T>(l, r, T_BIN, all, T_INCASE);
423 template <
class T,
bool all>
424 inline int compWVarString(
const char* l,
const char* r,
int len)
426 return compareWvartype<T>(l, r, T_STR, all, T_CASE);
429 template <
class T,
bool all>
430 inline int compWVarString_bin(
const char* l,
const char* r,
int len)
432 return compareWvartype<T>(l, r, T_BIN, all, T_CASE);
435 template <
class T,
bool all>
436 inline int compWVarString_i(
const char* l,
const char* r,
int len)
438 return compareWvartype<T>(l, r, T_STR, all, T_INCASE);
441 template <
class T,
bool all>
442 inline int compWVarString_bin_i(
const char* l,
const char* r,
int len)
444 return compareWvartype<T>(l, r, T_BIN, all, T_INCASE);
447 template <
int sizeByte,
bool all>
448 inline int compBlob(
const char* l,
const char* r,
int len)
450 return compareBlobType(l, r, T_STR, all, T_CASE, sizeByte);
453 template <
int sizeByte,
bool all>
454 inline int compBlob_bin(
const char* l,
const char* r,
int len)
456 return compareBlobType(l, r, T_BIN, all, T_CASE, sizeByte);
459 template <
int sizeByte,
bool all>
460 inline int compBlob_i(
const char* l,
const char* r,
int len)
462 return compareBlobType(l, r, T_STR, all, T_INCASE, sizeByte);
465 template <
int sizeByte,
bool all>
466 inline int compBlob_bin_i(
const char* l,
const char* r,
int len)
468 return compareBlobType(l, r, T_BIN, all, T_INCASE, sizeByte);
471 template <
int sizeByte,
bool all>
472 inline int compBlob2(
const char* l,
const char* r,
int len)
474 return compareBlobType2(l, r, T_STR, all, T_CASE, sizeByte);
477 template <
int sizeByte,
bool all>
478 inline int compBlob2_bin(
const char* l,
const char* r,
int len)
480 return compareBlobType2(l, r, T_BIN, all, T_CASE, sizeByte);
483 template <
int sizeByte,
bool all>
484 inline int compBlob2_i(
const char* l,
const char* r,
int len)
486 return compareBlobType2(l, r, T_STR, all, T_INCASE, sizeByte);
489 template <
int sizeByte,
bool all>
490 inline int compBlob2_bin_i(
const char* l,
const char* r,
int len)
492 return compareBlobType2(l, r, T_BIN, all, T_INCASE, sizeByte);
496 typedef int (*comp1Func)(
const char* l,
const char* r,
int len);
498 typedef bool (*judgeFunc)(int);
500 inline comp1Func getCompFunc(uchar_td type, ushort_td len,
char logType,
int sizeByte)
502 bool compAll = (logType & CMPLOGICAL_VAR_COMP_ALL) != 0;
503 bool incase = (logType & CMPLOGICAL_CASEINSENSITIVE) != 0;
510 if (logType & (
char)eBitAnd)
515 return &compBitAnd<char>;
517 return &compBitAnd<short>;
519 return &compBitAnd24;
521 return &compBitAnd<int>;
523 return &compBitAnd<__int64>;
530 return &compNumber<char>;
532 return &compNumber<short>;
534 return &compNumber24;
536 return &compNumber<int>;
538 return &compNumber<__int64>;
554 case ft_autoIncUnsigned:
560 case ft_mytime_num_cmp:
561 case ft_mydatetime_num_cmp:
562 case ft_mytimestamp_num_cmp:
566 if (logType & (
char)eBitAnd)
571 return &compBitAnd<char>;
573 return &compBitAnd<short>;
575 return &compBitAnd24;
577 return &compBitAnd<int>;
579 return &compBitAnd<__int64>;
586 return &compNumber<unsigned char>;
588 return &compNumber<unsigned short>;
590 return &compNumberU24;
592 return &compNumber<unsigned int>;
594 return &compNumber<unsigned __int64>;
599 if (logType & (
char)eBitAnd)
600 return &compBitAnd64;
611 return &compNumber<float>;
613 return &compNumber<double>;
619 return &compiWString;
620 if ((type == ft_wstring) || (type == ft_mywchar))
630 return &compVarString_i<unsigned char, T_CMP_ALL>;
631 return &compVarString_i<unsigned char, T_CMP_PART>;
635 return &compVarString<unsigned char, T_CMP_ALL>;
636 return &compVarString<unsigned char, T_CMP_PART>;
642 return &compVarString_i<unsigned short, T_CMP_ALL>;
643 return &compVarString_i<unsigned short, T_CMP_PART>;
646 return &compVarString<unsigned short, T_CMP_ALL>;
647 return &compVarString<unsigned short, T_CMP_PART>;
654 return &compVarString_bin_i<unsigned char, T_CMP_ALL>;
655 return &compVarString_bin_i<unsigned char, T_CMP_PART>;
658 return &compVarString_bin<unsigned char, T_CMP_ALL>;
659 return &compVarString_bin<unsigned char, T_CMP_PART>;
664 return &compVarString_bin_i<unsigned short, T_CMP_ALL>;
665 return &compVarString_bin_i<unsigned short, T_CMP_PART>;
668 return &compVarString_bin<unsigned short, T_CMP_ALL>;
669 return &compVarString_bin<unsigned short, T_CMP_PART>;
676 return &compWVarString_i<unsigned char, T_CMP_ALL>;
677 return &compWVarString_i<unsigned char, T_CMP_PART>;
680 return &compWVarString<unsigned char, T_CMP_ALL>;
681 return &compWVarString<unsigned char, T_CMP_PART>;
686 return &compWVarString_i<unsigned short, T_CMP_ALL>;
687 return &compWVarString_i<unsigned short, T_CMP_PART>;
690 return &compWVarString<unsigned short, T_CMP_ALL>;
691 return &compWVarString<unsigned short, T_CMP_PART>;
692 case ft_mywvarbinary:
698 return &compWVarString_bin_i<unsigned char, T_CMP_ALL>;
699 return &compWVarString_bin_i<unsigned char, T_CMP_PART>;
702 return &compWVarString_bin<unsigned char, T_CMP_ALL>;
703 return &compWVarString_bin<unsigned char, T_CMP_PART>;
708 return &compWVarString_bin_i<unsigned short, T_CMP_ALL>;
709 return &compWVarString_bin_i<unsigned short, T_CMP_PART>;
712 return &compWVarString_bin<unsigned short, T_CMP_ALL>;
713 return &compWVarString_bin<unsigned short, T_CMP_PART>;
716 bool rblob = (logType & CMPLOGICAL_FIELD) != 0;
725 case 1:
return &compBlob2_i<1, T_CMP_ALL>;
726 case 2:
return &compBlob2_i<2, T_CMP_ALL>;
727 case 3:
return &compBlob2_i<3, T_CMP_ALL>;
728 case 4:
return &compBlob2_i<4, T_CMP_ALL>;
733 case 1:
return &compBlob2<1, T_CMP_ALL>;
734 case 2:
return &compBlob2<2, T_CMP_ALL>;
735 case 3:
return &compBlob2<3, T_CMP_ALL>;
736 case 4:
return &compBlob2<4, T_CMP_ALL>;
743 case 1:
return &compBlob2_i<1, T_CMP_PART>;
744 case 2:
return &compBlob2_i<2, T_CMP_PART>;
745 case 3:
return &compBlob2_i<3, T_CMP_PART>;
746 case 4:
return &compBlob2_i<4, T_CMP_PART>;
751 case 1:
return &compBlob2<1, T_CMP_PART>;
752 case 2:
return &compBlob2<2, T_CMP_PART>;
753 case 3:
return &compBlob2<3, T_CMP_PART>;
754 case 4:
return &compBlob2<4, T_CMP_PART>;
764 case 1:
return &compBlob_i<1, T_CMP_ALL>;
765 case 2:
return &compBlob_i<2, T_CMP_ALL>;
766 case 3:
return &compBlob_i<3, T_CMP_ALL>;
767 case 4:
return &compBlob_i<4, T_CMP_ALL>;
772 case 1:
return &compBlob<1, T_CMP_ALL>;
773 case 2:
return &compBlob<2, T_CMP_ALL>;
774 case 3:
return &compBlob<3, T_CMP_ALL>;
775 case 4:
return &compBlob<4, T_CMP_ALL>;
782 case 1:
return &compBlob_i<1, T_CMP_PART>;
783 case 2:
return &compBlob_i<2, T_CMP_PART>;
784 case 3:
return &compBlob_i<3, T_CMP_PART>;
785 case 4:
return &compBlob_i<4, T_CMP_PART>;
790 case 1:
return &compBlob<1, T_CMP_PART>;
791 case 2:
return &compBlob<2, T_CMP_PART>;
792 case 3:
return &compBlob<3, T_CMP_PART>;
793 case 4:
return &compBlob<4, T_CMP_PART>;
801 bool rblob = (logType & CMPLOGICAL_FIELD) != 0;
810 case 1:
return &compBlob2_bin_i<1, T_CMP_ALL>;
811 case 2:
return &compBlob2_bin_i<2, T_CMP_ALL>;
812 case 3:
return &compBlob2_bin_i<3, T_CMP_ALL>;
813 case 4:
return &compBlob2_bin_i<4, T_CMP_ALL>;
818 case 1:
return &compBlob2_bin<1, T_CMP_ALL>;
819 case 2:
return &compBlob2_bin<2, T_CMP_ALL>;
820 case 3:
return &compBlob2_bin<3, T_CMP_ALL>;
821 case 4:
return &compBlob2_bin<4, T_CMP_ALL>;
828 case 1:
return &compBlob2_bin_i<1, T_CMP_PART>;
829 case 2:
return &compBlob2_bin_i<2, T_CMP_PART>;
830 case 3:
return &compBlob2_bin_i<3, T_CMP_PART>;
831 case 4:
return &compBlob2_bin_i<4, T_CMP_PART>;
836 case 1:
return &compBlob2_bin<1, T_CMP_PART>;
837 case 2:
return &compBlob2_bin<2, T_CMP_PART>;
838 case 3:
return &compBlob2_bin<3, T_CMP_PART>;
839 case 4:
return &compBlob2_bin<4, T_CMP_PART>;
850 case 1:
return &compBlob_bin_i<1, T_CMP_ALL>;
851 case 2:
return &compBlob_bin_i<2, T_CMP_ALL>;
852 case 3:
return &compBlob_bin_i<3, T_CMP_ALL>;
853 case 4:
return &compBlob_bin_i<4, T_CMP_ALL>;
858 case 1:
return &compBlob_bin<1, T_CMP_ALL>;
859 case 2:
return &compBlob_bin<2, T_CMP_ALL>;
860 case 3:
return &compBlob_bin<3, T_CMP_ALL>;
861 case 4:
return &compBlob_bin<4, T_CMP_ALL>;
868 case 1:
return &compBlob_bin_i<1, T_CMP_PART>;
869 case 2:
return &compBlob_bin_i<2, T_CMP_PART>;
870 case 3:
return &compBlob_bin_i<3, T_CMP_PART>;
871 case 4:
return &compBlob_bin_i<4, T_CMP_PART>;
876 case 1:
return &compBlob_bin<1, T_CMP_PART>;
877 case 2:
return &compBlob_bin<2, T_CMP_PART>;
878 case 3:
return &compBlob_bin<3, T_CMP_PART>;
879 case 4:
return &compBlob_bin<4, T_CMP_PART>;
888 inline bool isMatch1(
int v)
893 inline bool isMatch2(
int v)
898 inline bool isMatch3(
int v)
903 inline bool isMatch4(
int v)
908 inline bool isMatch5(
int v)
913 inline bool isMatch6(
int v)
918 inline judgeFunc getJudgeFunc(eCompType log)
944 inline bool isEndComp(uchar_td opr,
bool ret)
946 return (opr == eCend) || (!ret && (opr == eCand)) || (ret && (opr == eCor));