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 GIGABASE_DLL
00017 #ifdef INSIDE_GIGABASE
00018 #define GIGABASE_DLL_ENTRY __declspec(dllexport)
00019 #else
00020 #define GIGABASE_DLL_ENTRY __declspec(dllimport)
00021 #endif
00022 #else
00023 #define GIGABASE_DLL_ENTRY
00024 #endif
00025
00026 #ifdef USE_NAMESPACES
00027 #define BEGIN_GIGABASE_NAMESPACE namespace gigabase {
00028 #define END_GIGABASE_NAMESPACE }
00029 #define USE_GIGABASE_NAMESPACE using namespace gigabase;
00030 #define GB_NS gigabase
00031 #else
00032 #define BEGIN_GIGABASE_NAMESPACE
00033 #define END_GIGABASE_NAMESPACE
00034 #define USE_GIGABASE_NAMESPACE
00035 #define GB_NS
00036 #endif
00037
00038 #define GNUC_BEFORE(major,minor) (defined(__GNUC__) && (major > __GNUC__ || (major == __GNUC__ && minor > __GNUC_MINOR__)))
00039
00040 #if defined(__MINGW32__) && !defined(_WIN32)
00041 #define _WIN32
00042 #endif
00043
00044 #if defined(_WIN32_WCE) && !defined(_WINCE)
00045 #define _WINCE
00046 #endif
00047
00048 #if defined(__APPLE__) && !defined(__FreeBSD__)
00049
00050 #define __FreeBSD__ 5
00051 #endif
00052
00053 #ifdef __SYMBIAN_OS__
00054 #include <unistd.h>
00055 #undef remove
00056 typedef long ssize_t;
00057 #endif
00058
00059
00060 #if defined(USE_MFC_STRING) && !defined(USE_MFC) && !defined(USE_ATL)
00061 #define USE_ATL 1
00062 #endif
00063
00064 #if defined(USE_MFC_STRING)
00065 #ifndef MFC_STRING
00066 #define MFC_STRING CString
00067 #endif
00068 #endif
00069
00070 #ifdef USE_STD_STRING
00071 #include <string>
00072 #endif
00073
00074 #if defined(_WIN32)
00075
00076 #ifdef USE_MFC
00077 #include <afx.h>
00078 #include <winsock2.h>
00079 #else
00080 #include <windows.h>
00081 #if defined(USE_ATL) && defined(USE_MFC_STRING)
00082 #include <atlstr.h>
00083 #endif
00084 #endif
00085
00086 #ifdef _MSC_VER
00087 #pragma warning(disable:4800 4355 4146 4251 4996)
00088 #endif
00089 #else
00090 #ifdef _AIX
00091 #define INT8_IS_DEFINED
00092 #endif
00093 #ifndef NO_PTHREADS
00094 #ifndef _REENTRANT
00095 #define _REENTRANT
00096 #endif
00097 #endif
00098 #endif
00099
00100
00101
00102 #if defined(__VACPP_MULTI__) // IBM compiler produce a lot of stupid warnings
00103 #pragma report(disable, "CPPC1608")
00104 #pragma report(disable, "CPPC1281")
00105 #endif
00106
00107
00108 #ifdef _WINCE
00109 #include <stdio.h>
00110 #include <stdlib.h>
00111 #include <string.h>
00112 #include <limits.h>
00113 #include <stdarg.h>
00114 #include <tchar.h>
00115 #include "wince.h"
00116
00117 #else
00118
00119 #include <stdio.h>
00120 #include <stddef.h>
00121 #include <stdlib.h>
00122 #include <string.h>
00123 #include <limits.h>
00124 #include <assert.h>
00125 #include <stdarg.h>
00126 #include <time.h>
00127 #ifdef UNICODE
00128 #include <wchar.h>
00129 #include <wctype.h>
00130 #else
00131 #include <ctype.h>
00132 #endif
00133
00134 #endif
00135
00136 #ifndef __IBMCPP__
00137 BEGIN_GIGABASE_NAMESPACE
00138 #endif
00139
00140
00141 #if !defined(_WIN32) && !defined(__cdecl)
00142 #define __cdecl
00143 #endif
00144
00145
00146
00147 #define DOALIGN(x,b) (((x) + (b) - 1) & ~((b) - 1))
00148
00149
00150 #ifdef UNICODE
00151 typedef wchar_t char_t;
00152 #define STRLEN(x) wcslen(x)
00153 #define STRCMP(x, y) wcscmp(x, y)
00154 #define STRCHR(x, y) wcschr(x, y)
00155 #define STRCPY(x, y) wcscpy(x, y)
00156 #define STRNCPY(x,y,z) wcsncpy(x, y, z)
00157 #define STRCOLL(x, y) wcscoll(x, y)
00158 #define STRNCMP(x,y,z) wcsncmp(x, y, z)
00159 #define STRLITERAL(x) (wchar_t*)L##x
00160 #define PRINTF wprintf
00161 #define FPRINTF fwprintf
00162 #ifdef _WIN32
00163 #define mbstowcs(_dst, _src, _size) MultiByteToWideChar(CP_UTF8, 0, (_src), -1, (_dst), (_size))
00164 #define wcstombs(_dst, _src, _size) WideCharToMultiByte(CP_UTF8, 0, (_src), -1, (_dst), (_size), NULL, NULL)
00165 #ifdef _SWPRINTFS_DEPRECATED
00166 #define SPRINTF _swprintf
00167 #else
00168 #define SPRINTF swprintf
00169 #endif
00170 #define SPRINTF_BUFFER(buf) buf
00171 #else
00172 #define SPRINTF swprintf
00173 #define SPRINTF_BUFFER(buf) buf, 0x1000000
00174 #endif
00175 #define VSPRINTF vswprintf
00176 #define FSCANF fwscanf
00177 #define SSCANF swscanf
00178 #define GETC(x) getwc(x)
00179 #define UNGETC(x, y) ungetwc(x, y)
00180 #define TOLOWER(x) towlower((x) & 0xFFFF)
00181 #define TOUPPER(x) towlower((x) & 0xFFFF)
00182 #define ISALNUM(x) iswalnum((x) & 0xFFFF)
00183 #define STRSTR(x, y) wcsstr(x, y)
00184 #define STRXFRM(x,y,z) wcsxfrm(x, y, z)
00185 #define STRFTIME(a,b,c,d) wcsftime(a,b,c,d)
00186 #ifdef _WINCE
00187 #define REMOVE_FILE(s) DeleteFile(s)
00188 #define RENAME_FILE(p, q) MoveFile(p, q)
00189 #else
00190 #define REMOVE_FILE(s) _wremove(s)
00191 #define RENAME_FILE(p, q) _wrename(p, q)
00192 #endif
00193 #define GETENV(x) _wgetenv(x)
00194 #define T_EOF WEOF
00195 #ifndef STD_STRING
00196 #define STD_STRING std::wstring
00197 #endif
00198 #ifndef _T
00199 #define _T(x) L##x
00200 #endif
00201 #else
00202 typedef char char_t;
00203 #define STRLEN(x) strlen(x)
00204 #define STRCHR(x, y) strchr(x, y)
00205 #define STRCMP(x, y) strcmp(x, y)
00206 #define STRCPY(x, y) strcpy(x, y)
00207 #define STRNCPY(x,y,z) strncpy(x, y, z)
00208 #define STRCOLL(x, y) strcoll(x, y)
00209 #define STRNCMP(x,y,z) strncmp(x, y, z)
00210 #define STRLITERAL(x) (char*)x
00211 #define PRINTF printf
00212 #define FPRINTF fprintf
00213 #define SPRINTF sprintf
00214 #define SPRINTF_BUFFER(buf) buf
00215 #define VSPRINTF vsprintf
00216 #define FSCANF fscanf
00217 #define SSCANF sscanf
00218 #define GETC(x) getc(x)
00219 #define UNGETC(x, y) ungetc(x, y)
00220 #define TOLOWER(x) tolower((x) & 0xFF)
00221 #define TOUPPER(x) toupper((x) & 0xFF)
00222 #define ISALNUM(x) isalnum((x) & 0xFF)
00223 #define STRSTR(x, y) strstr(x, y)
00224 #define STRXFRM(x,y,z) strxfrm(x, y, z)
00225 #define STRFTIME(a,b,c,d) strftime(a,b,c,d)
00226 #ifdef _WIN32
00227 #define REMOVE_FILE(s) remove(s)
00228 #else
00229 #define REMOVE_FILE(s) unlink(s)
00230 #endif
00231 #define RENAME_FILE(p, q) rename(p, q)
00232 #define GETENV(x) getenv(x)
00233 #ifndef STD_STRING
00234 #define STD_STRING std::string
00235 #endif
00236 #define T_EOF EOF
00237 #ifdef _T
00238 #undef _T
00239 #endif
00240 #define _T(x) x
00241 #endif
00242
00243 inline void strlower(char_t* dst, const char_t* src)
00244 {
00245 int ch;
00246 do {
00247 ch = *src++;
00248 *dst++ = TOLOWER(ch);
00249 } while (ch != 0);
00250 }
00251
00252 typedef signed char db_int1;
00253 typedef unsigned char db_nat1;
00254
00255 typedef signed short db_int2;
00256 typedef unsigned short db_nat2;
00257
00258 typedef unsigned char db_byte;
00259
00260 typedef float db_real4;
00261 typedef double db_real8;
00262
00263 #if !defined(SIZEOF_LONG) && defined(L64) && ! defined(WIN64)
00264 #define SIZEOF_LONG 8
00265 #endif
00266
00267 #if defined(_WIN32) && !defined(__MINGW32__)
00268 #if defined(_MSC_VER) || _MSC_VER < 1300
00269 typedef signed int db_int4;
00270 typedef unsigned int db_nat4;
00271 #else
00272 typedef signed __int32 db_int4;
00273 typedef unsigned __int32 db_nat4;
00274 #endif
00275 typedef unsigned __int64 db_nat8;
00276 typedef signed __int64 db_int8;
00277 #if defined(__IBMCPP__)
00278 #define INT8_FORMAT_PREFIX "%ll"
00279 #define T_INT8_FORMAT_PREFIX _T("%ll")
00280 #else
00281 #define INT8_FORMAT_PREFIX "%I64"
00282 #define T_INT8_FORMAT_PREFIX _T("%I64")
00283 #endif
00284 #define CONST64(c) c
00285 #else
00286 typedef signed int db_int4;
00287 typedef unsigned int db_nat4;
00288 #if SIZEOF_LONG == 8
00289 typedef unsigned long db_nat8;
00290 typedef signed long db_int8;
00291 #define INT8_FORMAT_PREFIX "%l"
00292 #define T_INT8_FORMAT_PREFIX _T("%l")
00293 #define CONST64(c) c##L
00294 #else
00295 typedef unsigned long long db_nat8;
00296 typedef signed long long db_int8;
00297 #ifdef __MINGW32__
00298 #define INT8_FORMAT_PREFIX "%I64"
00299 #define T_INT8_FORMAT_PREFIX _T("%I64")
00300 #else
00301 #define INT8_FORMAT_PREFIX "%ll"
00302 #define T_INT8_FORMAT_PREFIX _T("%ll")
00303 #endif
00304 #define CONST64(c) c##LL
00305 #endif
00306 #endif
00307
00308 #define INT8_FORMAT INT8_FORMAT_PREFIX "d"
00309 #define T_INT8_FORMAT T_INT8_FORMAT_PREFIX _T("d")
00310
00311
00312
00313 typedef db_int1 int1;
00314 typedef db_nat1 nat1;
00315 typedef db_int2 int2;
00316 typedef db_nat2 nat2;
00317 typedef db_int4 int4;
00318 typedef db_nat4 nat4;
00319
00320 typedef db_byte byte;
00321
00322 typedef db_real4 real4;
00323 typedef db_real8 real8;
00324
00325 typedef db_nat8 nat8;
00326
00327 #ifndef INT8_IS_DEFINED
00328 typedef db_int8 int8;
00329 #endif
00330
00331
00332
00333
00334 #if !defined(bool) && (defined(__SUNPRO_CC) && __SUNPRO_CC_COMPAT < 5)
00335 #define bool char
00336 #define true (1)
00337 #define false (0)
00338 #endif
00339
00340 #define nat8_low_part(x) ((db_nat4)(x))
00341 #define int8_low_part(x) ((db_int4)(x))
00342 #if defined(_MSC_VER) && _MSC_VER < 1300 // bug in MVC 6.0
00343 #define nat8_high_part(x) (sizeof(x) < 8 ? 0 : ((db_nat4)((db_nat8)(x)>>32)))
00344 #define int8_high_part(x) (sizeof(x) < 8 ? 0 : ((db_int4)((db_int8)(x)>>32)))
00345 #else
00346 #define nat8_high_part(x) ((db_nat4)((db_nat8)(x)>>32))
00347 #define int8_high_part(x) ((db_int4)((db_int8)(x)>>32))
00348 #endif
00349
00350 #define cons_nat8(hi, lo) ((((db_nat8)(hi)) << 32) | (db_nat4)(lo))
00351 #define cons_int8(hi, lo) ((((db_int8)(hi)) << 32) | (db_nat4)(lo))
00352
00353 #define MAX_NAT8 db_nat8(-1)
00354
00355 #ifndef BIG_ENDIAN
00356 #define BIG_ENDIAN 4321
00357 #endif
00358 #ifndef LITTLE_ENDIAN
00359 #define LITTLE_ENDIAN 1234
00360 #endif
00361
00362 #ifndef BYTE_ORDER
00363 #if defined(__sparc__) || defined(__m68k__)
00364 #define BYTE_ORDER BIG_ENDIAN
00365 #else
00366 #define BYTE_ORDER LITTLE_ENDIAN
00367 #endif
00368 #endif
00369
00370 #if defined(_WIN32)
00371 typedef HANDLE descriptor_t;
00372 #else
00373 typedef int descriptor_t;
00374 #endif
00375
00376 #if !defined(_fastcall) && (!defined(_WIN32) || defined(__IBMCPP__) || defined(__MINGW32__))
00377 #define _fastcall
00378 #endif
00379
00380 #if defined(_WIN32) || !defined(NO_PTHREADS)
00381 #define THREADS_SUPPORTED 1
00382 #else
00383 #define THREADS_SUPPORTED 0
00384 #endif
00385
00386 #define itemsof(array) (sizeof(array)/sizeof*(array))
00387
00388 #define DEBUG_NONE 0
00389 #define DEBUG_CHECK 1
00390 #define DEBUG_TRACE 2
00391
00392 #if GIGABASE_DEBUG == DEBUG_TRACE
00393 #define TRACE_MSG(x) dbTrace x
00394 #else
00395 #define TRACE_MSG(x)
00396 #endif
00397
00398
00399 typedef void (*dbTraceFunctionPtr)(char_t* message);
00400
00401
00402 extern dbTraceFunctionPtr dbTraceFunction;
00403
00404
00405 extern bool dbTraceEnable;
00406
00407 extern GIGABASE_DLL_ENTRY void dbTrace(char_t* message, ...);
00408
00409 extern GIGABASE_DLL_ENTRY byte* dbMalloc(size_t size);
00410 extern GIGABASE_DLL_ENTRY void dbFree(void* ptr);
00411
00412 #if defined(__BCPLUSPLUS__)
00413 #define qsort(arr, n, s, cmp) std::qsort(arr, n, s, cmp)
00414 #endif
00415
00416 #ifndef __IBMCPP__
00417 END_GIGABASE_NAMESPACE
00418 #endif
00419
00420 #endif
00421
00422