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