全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド ページ
fieldComp.h
1 #ifndef BZS_DB_PROTOCOL_TDAP_FIELD_COMP_H
2 #define BZS_DB_PROTOCOL_TDAP_FIELD_COMP_H
3 /*=================================================================
4  Copyright (C) 2014 BizStation Corp All rights reserved.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19  02111-1307, USA.
20 =================================================================*/
21 #include <bzs/db/protocol/tdap/tdapcapi.h>
22 #include <bzs/env/crosscompile.h>
23 #include <algorithm>
24 #include <string.h>
25 
26 inline int compareUint24(const char* l, const char* r)
27 {
28  unsigned int lv = *((unsigned int*)l) & 0xFFFFFF;
29  unsigned int rv = *((unsigned int*)r) & 0xFFFFFF;
30  if (lv < rv)
31  return -1;
32  if (lv > rv)
33  return 1;
34  return 0;
35 }
36 
37 inline int compareInt24(const char* l, const char* r)
38 {
39  int lv = ((*((int*)l) & 0xFFFFFF) << 8) / 0x100;
40  int rv = ((*((int*)r) & 0xFFFFFF) << 8) / 0x100;
41 
42  if (lv < rv)
43  return -1;
44  else if (lv > rv)
45  return 1;
46  return 0;
47 }
48 
49 template <class T> inline int compare(const char* l, const char* r)
50 {
51  if (*((T*)l) < *((T*)r))
52  return -1;
53  else if (*((T*)l) > *((T*)r))
54  return 1;
55  return 0;
56 }
57 
58 template <class T> inline int bitMask(const char* l, const char* r)
59 {
60  T v = *((T*)l) & *((T*)r);
61  return (int)(*((T*)r) - v);
62 }
63 
64 template <class T> inline int compare(T l, T r)
65 {
66  if (l < r)
67  return -1;
68  else if (l > r)
69  return 1;
70  return 0;
71 }
72 
73 template <class T>
74 inline int compareVartype(const char* l, const char* r, bool bin, char logType)
75 {
76  int llen = (*(T*)l);
77  int rlen = (*(T*)r);
78  int tmp = std::min<int>(llen, rlen);
79  if (logType & CMPLOGICAL_CASEINSENSITIVE)
80  tmp = _strnicmp(l + sizeof(T), r + sizeof(T), tmp);
81  else if (bin)
82  tmp = memcmp(l + sizeof(T), r + sizeof(T), tmp);
83  else
84  tmp = strncmp(l + sizeof(T), r + sizeof(T), tmp);
85 
86  if (logType & CMPLOGICAL_VAR_COMP_ALL)
87  return (tmp == 0) ? compare<int>(llen, rlen) : tmp; // match complete
88  return (tmp == 0 && (llen < rlen)) ? -1 : tmp; // match a part
89 }
90 
91 template <class T>
92 inline int compareWvartype(const char* l, const char* r, bool bin, char logType)
93 {
94  int llen = (*(T*)l) / sizeof(char16_t);
95  int rlen = (*(T*)r) / sizeof(char16_t);
96  int tmp = std::min<int>(llen, rlen);
97  if (logType & CMPLOGICAL_CASEINSENSITIVE)
98  tmp = wcsnicmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)),
99  tmp);
100  else if (bin)
101  tmp =
102  wmemcmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)), tmp);
103  else
104  tmp = wcsncmp16((char16_t*)(l + sizeof(T)), (char16_t*)(r + sizeof(T)),
105  tmp);
106  if (logType & CMPLOGICAL_VAR_COMP_ALL)
107  return (tmp == 0) ? compare<int>(llen, rlen) : tmp; // match complete
108  return (tmp == 0 && (llen < rlen)) ? -1 : tmp; // match a part
109 }
110 
111 inline int compareBlobType(const char* l, const char* r, bool bin, char logType,
112  int sizeByte)
113 {
114  int llen = 0;
115  int rlen = 0;
116  memcpy(&llen, l, sizeByte);
117  memcpy(&rlen, r, sizeByte);
118  int tmp = std::min<int>(llen, rlen);
119  const char* lptr = *((const char**)(l + sizeByte));
120  const char* rptr = r + sizeByte;
121  if (logType & CMPLOGICAL_CASEINSENSITIVE)
122  tmp = _strnicmp(lptr, rptr, tmp);
123  else if (bin)
124  tmp = memcmp(lptr, rptr, tmp);
125  else
126  tmp = strncmp(lptr, rptr, tmp);
127 
128  if (logType & CMPLOGICAL_VAR_COMP_ALL)
129  return (tmp == 0) ? compare<int>(llen, rlen) : tmp;
130  return (tmp == 0 && (llen < rlen)) ? -1 : tmp;
131 }
132 
133 #endif

Transactd SDK 2015年09月08日(火) 19時13分35秒 doxygen