00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __STDTP_H__
00012 #define __STDTP_H__
00013
00014 #include "config.h"
00015
00016 #ifdef FASTDB_DLL
00017 #ifdef INSIDE_FASTDB
00018 #define FASTDB_DLL_ENTRY __declspec(dllexport)
00019 #else
00020 #define FASTDB_DLL_ENTRY __declspec(dllimport)
00021 #endif
00022 #else
00023 #define FASTDB_DLL_ENTRY
00024 #endif
00025
00026 #ifdef USE_NAMESPACES
00027 #define BEGIN_FASTDB_NAMESPACE namespace fastdb {
00028 #define END_FASTDB_NAMESPACE }
00029 #define USE_FASTDB_NAMESPACE using namespace fastdb;
00030 #define FASTDB_NS fastdb
00031 #else
00032 #define BEGIN_FASTDB_NAMESPACE
00033 #define END_FASTDB_NAMESPACE
00034 #define USE_FASTDB_NAMESPACE
00035 #define FASTDB_NS
00036 #endif
00037
00038 #if defined(AUTO_DETECT_PROCESS_CRASH) && !defined(RECOVERABLE_CRITICAL_SECTION)
00039 #define RECOVERABLE_CRITICAL_SECTION
00040 #endif
00041
00042 #define GNUC_BEFORE(major,minor) (defined(__GNUC__) && (major > __GNUC__ || (major == __GNUC__ && minor > __GNUC_MINOR__)))
00043
00044 #if defined(__MINGW32__) && !defined(_WIN32)
00045 #define _WIN32
00046 #endif
00047
00048 #if defined(_WIN32_WCE) && !defined(_WINCE)
00049 #define _WINCE
00050 #endif
00051
00052 #if defined(__APPLE__) && !defined(__FreeBSD__)
00053
00054 #define __FreeBSD__ 5
00055 #endif
00056
00057 #ifdef _WIN32
00058
00059 #ifdef USE_MFC
00060 #include <afx.h>
00061 #include <winsock2.h>
00062 #else
00063 #include <windows.h>
00064 #endif
00065
00066 #ifdef _MSC_VER
00067 #pragma warning(disable:4800 4355 4146 4251 4996)
00068 #endif
00069
00070 #else
00071 #ifdef _AIX
00072 #define INT8_IS_DEFINED
00073 #endif
00074 #ifndef NO_PTHREADS
00075 #ifndef _REENTRANT
00076 #define _REENTRANT
00077 #endif
00078 #endif
00079 #endif
00080
00081 #if defined(__VACPP_MULTI__) // IBM compiler produce a lot of stupid warnings
00082 #pragma report(disable, "CPPC1608")
00083 #pragma report(disable, "CPPC1281")
00084 #endif
00085
00086
00087 #ifdef _WINCE
00088 #include <stdio.h>
00089 #include <stdlib.h>
00090 #include <string.h>
00091 #include <limits.h>
00092 #include <stdarg.h>
00093 #include <tchar.h>
00094 #include "wince.h"
00095
00096 #else
00097
00098 #include <stdio.h>
00099 #include <stddef.h>
00100 #include <stdlib.h>
00101 #include <string.h>
00102 #include <limits.h>
00103 #include <assert.h>
00104 #include <stdarg.h>
00105 #include <time.h>
00106 #include <ctype.h>
00107
00108 #ifdef _WIN32
00109 #include <malloc.h>
00110 #endif
00111
00112 #endif
00113
00114 #ifdef PHAR_LAP
00115 #define PHAR_LAP 1
00116 #endif
00117
00118 #ifdef __QNX__
00119 #define USE_POSIX_API 1
00120 #define POSIX_1003_1d 1
00121 #endif
00122
00123 #if defined(__MINGW32__) && !defined(_WIN32)
00124 #define _WIN32
00125 #endif
00126
00127 #if defined(__APPLE__) && !defined(__FreeBSD__)
00128
00129 #define __FreeBSD__ 4
00130 #endif
00131
00132 #ifndef CLI_CALLBACK_CC
00133 #define CLI_CALLBACK_CC
00134 #endif
00135
00136 #define DEBUG_NONE 0
00137 #define DEBUG_CHECK 1
00138 #define DEBUG_TRACE_IMPORTANT 2
00139 #define DEBUG_TRACE_ALL 3
00140
00141 #if FASTDB_DEBUG >= DEBUG_TRACE_IMPORTANT
00142 #define TRACE_IMSG(x) dbTrace x
00143 #else
00144 #define TRACE_IMSG(x)
00145 #endif
00146
00147 #if FASTDB_DEBUG >= DEBUG_TRACE_ALL
00148 #define TRACE_MSG(x) dbTrace x
00149 #else
00150 #define TRACE_MSG(x)
00151 #endif
00152
00153 #ifndef EXTRA_DEBUG_NEW_PARAMS
00154 #define EXTRA_DEBUG_NEW_PARAMS
00155 #endif
00156
00157
00158 #ifndef HAS_TEMPLATE_FRIENDS
00159 #if (!defined(_MSC_VER) || _MSC_VER >= 1300) && !defined(NO_MEMBER_TEMPLATES)
00160 #define HAS_TEMPLATE_FRIENDS
00161 #endif
00162 #endif
00163
00164 #ifndef __IBMCPP__
00165 BEGIN_FASTDB_NAMESPACE
00166 #endif
00167
00168
00169 typedef void (CLI_CALLBACK_CC *dbTraceFunctionPtr)(char* message);
00170
00171
00172 extern FASTDB_DLL_ENTRY dbTraceFunctionPtr dbTraceFunction;
00173
00174 extern FASTDB_DLL_ENTRY void dbTrace(char* message, ...);
00175
00176 #if defined(_WINCE) || defined(UNICODE)
00177 inline wchar_t* convertStringToUnicode(wchar_t* dst, char const* src, size_t size) {
00178 mbstowcs(dst, src, size);
00179 return dst;
00180 }
00181 #define CNV_BUF_SIZE 256
00182 #define W32_STRING(s) (s == NULL ? (wchar_t*)NULL : convertStringToUnicode((wchar_t*)alloca(sizeof(wchar_t)*CNV_BUF_SIZE), s, CNV_BUF_SIZE))
00183 #else
00184 #define W32_STRING(s) s
00185 #endif
00186
00187
00188
00189 #define DOALIGN(x,b) (((x) + (b) - 1) & ~((b) - 1))
00190
00191 typedef signed char db_int1;
00192 typedef unsigned char db_nat1;
00193
00194 typedef signed short db_int2;
00195 typedef unsigned short db_nat2;
00196
00197 typedef unsigned char db_byte;
00198
00199 #if defined(_WIN32) && !defined(__MINGW32__)
00200 #if defined(_MSC_VER) || _MSC_VER < 1300
00201 typedef signed int db_int4;
00202 typedef unsigned int db_nat4;
00203 #else
00204 typedef signed __int32 db_int4;
00205 typedef unsigned __int32 db_nat4;
00206 #endif
00207 typedef unsigned __int64 db_nat8;
00208 typedef signed __int64 db_int8;
00209 #if defined(__IBMCPP__)
00210 #define INT8_FORMAT "%lld"
00211 #else
00212 #define INT8_FORMAT "%I64d"
00213 #endif
00214 #define CONST64(c) c
00215 #else
00216 typedef signed int db_int4;
00217 typedef unsigned int db_nat4;
00218 #if defined(__osf__ )
00219 typedef unsigned long db_nat8;
00220 typedef signed long db_int8;
00221 #define INT8_FORMAT "%ld"
00222 #define CONST64(c) c##L
00223 #ifndef SIZEOF_LONG
00224 #define SIZEOF_LONG 8
00225 #endif
00226 #else
00227 typedef unsigned long long db_nat8;
00228 typedef signed long long db_int8;
00229 #if defined(__MINGW32__) && __GNUG__<3
00230 #define INT8_FORMAT "%I64d"
00231 #else
00232 #define INT8_FORMAT "%lld"
00233 #endif
00234 #define CONST64(c) c##LL
00235 #endif
00236 #endif
00237
00238
00239 typedef db_int1 int1;
00240 typedef db_nat1 nat1;
00241 typedef db_int2 int2;
00242 typedef db_nat2 nat2;
00243 typedef db_int4 int4;
00244 typedef db_nat4 nat4;
00245
00246 typedef db_byte byte;
00247
00248 #ifndef INT8_IS_DEFINED
00249 typedef db_int8 int8;
00250 #endif
00251 typedef db_nat8 nat8;
00252
00253 typedef float real4;
00254 typedef double real8;
00255
00256
00257
00258
00259 #if !defined(bool) && (defined(__SUNPRO_CC) && __SUNPRO_CC_COMPAT < 5)
00260 #define bool char
00261 #define true (1)
00262 #define false (0)
00263 #endif
00264
00265 #define nat8_low_part(x) ((db_nat4)(x))
00266 #define int8_low_part(x) ((db_int4)(x))
00267 #if defined(_MSC_VER) && _MSC_VER < 1300 // bug in MVC 6.0
00268 #define nat8_high_part(x) (sizeof(x) < 8 ? 0 : ((db_nat4)((db_nat8)(x)>>32)))
00269 #define int8_high_part(x) (sizeof(x) < 8 ? 0 : ((db_int4)((db_int8)(x)>>32)))
00270 #else
00271 #define nat8_high_part(x) ((db_nat4)((db_nat8)(x)>>32))
00272 #define int8_high_part(x) ((db_int4)((db_int8)(x)>>32))
00273 #endif
00274
00275 #define cons_nat8(hi, lo) ((((nat8)(hi)) << 32) | (nat4)(lo))
00276 #define cons_int8(hi, lo) ((((db_int8)(hi)) << 32) | (nat4)(lo))
00277
00278 #define MAX_NAT8 nat8(-1)
00279
00280 #ifndef BIG_ENDIAN
00281 #define BIG_ENDIAN 4321
00282 #endif
00283 #ifndef LITTLE_ENDIAN
00284 #define LITTLE_ENDIAN 1234
00285 #endif
00286
00287 #ifndef BYTE_ORDER
00288 #if defined(__sparc__) || defined(__m68k__)
00289 #define BYTE_ORDER BIG_ENDIAN
00290 #else
00291 #define BYTE_ORDER LITTLE_ENDIAN
00292 #endif
00293 #endif
00294
00295 #ifdef _WIN32
00296 typedef HANDLE descriptor_t;
00297 #else
00298 typedef int descriptor_t;
00299 #endif
00300
00301 #if !defined(_fastcall) && (!defined(_WIN32) || defined(__IBMCPP__) || defined(__MINGW32__))
00302 #define _fastcall
00303 #endif
00304
00305 #if defined(_WIN32) || !defined(NO_PTHREADS)
00306 #define THREADS_SUPPORTED 1
00307 #else
00308 #define THREADS_SUPPORTED 0
00309 #endif
00310
00311 #define itemsof(array) (sizeof(array)/sizeof*(array))
00312
00313
00314 extern FASTDB_DLL_ENTRY bool dbTraceEnable;
00315
00316 extern FASTDB_DLL_ENTRY byte* dbMalloc(size_t size);
00317 extern FASTDB_DLL_ENTRY void dbFree(void* ptr);
00318
00319 #if defined(FUZZY_CHECKPOINT) && !defined(NO_MMAP)
00320 #define NO_MMAP 1
00321 #endif
00322
00323 #if !defined(USE_POSIX_MMAP) && defined(DISKLESS_CONFIGURATION)
00324
00325
00326 #define USE_POSIX_MMAP 0
00327 #endif
00328
00329 #if defined(USE_POSIX_MMAP) && !USE_POSIX_MMAP
00330
00331 #define USE_SYSV_SHARED_MEMORY 1
00332 #if !defined(NO_MMAP) && !defined(DISKLESS_CONFIGURATION)
00333 #define NO_MMAP 1
00334 #endif
00335 #endif
00336
00337 #if !defined(_WIN32)
00338 #define NO_STRICMP 1
00339 #define NO_STRICOLL 1
00340 #endif
00341
00342
00343 #if defined(_WINCE) && defined(USE_LOCALE_SETTINGS)
00344 #undef USE_LOCALE_SETTINGS
00345 #endif
00346
00347 #if defined(IGNORE_CASE) && defined(NO_STRICMP)
00348 inline int stricmp(const char* p, const char* q)
00349 {
00350 while (toupper(*(unsigned char*)p) == toupper(*(unsigned char*)q)) {
00351 if (*p == '\0') {
00352 return 0;
00353 }
00354 p += 1;
00355 q += 1;
00356 }
00357 return toupper(*(unsigned char*)p) - toupper(*(unsigned char*)q);
00358 }
00359 #else
00360 #ifdef _WIN32
00361 #define stricoll(x,y) _stricoll(x,y)
00362 #endif
00363 #endif
00364
00365 #ifndef STRINCMP_DEFINED
00366 inline int strincmp(const char* p, const char* q, size_t n)
00367 {
00368 while (n > 0) {
00369 int diff = toupper(*(unsigned char*)p) - toupper(*(unsigned char*)q);
00370 if (diff != 0) {
00371 return diff;
00372 } else if (*p == '\0') {
00373 return 0;
00374 }
00375 p += 1;
00376 q += 1;
00377 n -= 1;
00378 }
00379 return 0;
00380 }
00381 #endif
00382
00383 #if defined(IGNORE_CASE) && defined(USE_LOCALE_SETTINGS) && defined(NO_STRICOLL)
00384 inline int stricoll(const char* p, const char* q)
00385 {
00386 char p_buf[256];
00387 char q_buf[256];
00388 size_t p_len = strlen(p);
00389 size_t q_len = strlen(q);
00390 char* p_dst = p_buf;
00391 char* q_dst = q_buf;
00392 int i;
00393 if (p_len >= sizeof(p_buf)) {
00394 p_dst = new char[p_len+1];
00395 }
00396 if (q_len >= sizeof(q_buf)) {
00397 q_dst = new char[q_len+1];
00398 }
00399 for (i = 0; p[i] != '\0'; i++) {
00400 p_dst[i] = toupper(p[i] & 0xFF);
00401 }
00402 p_dst[i] = '\0';
00403
00404 for (i = 0; q[i] != '\0'; i++) {
00405 q_dst[i] = toupper(q[i] & 0xFF);
00406 }
00407 q_dst[i] = '\0';
00408
00409 int diff = strcoll(p_dst, q_dst);
00410 if (p_dst != p_buf) {
00411 delete[] p_dst;
00412 }
00413 if (q_dst != q_buf) {
00414 delete[] q_dst;
00415 }
00416 return diff;
00417 }
00418 #endif
00419
00420 #ifndef __IBMCPP__
00421 END_FASTDB_NAMESPACE
00422 #endif
00423
00424 #endif
00425
00426
00427
00428