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