00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef CPL_BASE_H_INCLUDED
00032 #define CPL_BASE_H_INCLUDED
00033
00034
00035 #if defined(_MSC_VER)
00036 # pragma warning(disable:4251 4275 4786)
00037 #endif
00038
00046
00047
00048
00049
00050 #ifdef macintosh
00051 # define macos_pre10
00052 #endif
00053
00054
00055
00056
00057 #if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE)
00058 # define WIN32
00059 #endif
00060
00061 #if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE)
00062 # define WIN32
00063 #endif
00064
00065
00066
00067
00068 #if defined(_WIN32_WCE)
00069 # define WIN32CE
00070 #endif
00071
00072
00073
00074
00075
00076 #ifdef _MSC_VER
00077 # ifndef _CRT_SECURE_NO_DEPRECATE
00078 # define _CRT_SECURE_NO_DEPRECATE
00079 # endif
00080 # ifndef _CRT_NONSTDC_NO_DEPRECATE
00081 # define _CRT_NONSTDC_NO_DEPRECATE
00082 # endif
00083 # ifdef MSVC_USE_VLD
00084 # include <vld.h>
00085 # endif
00086 #endif
00087
00088 #include "cpl_config.h"
00089
00090
00091
00092
00093
00094
00095 #ifdef unix
00096 # undef WIN32
00097 # undef WIN32CE
00098 #endif
00099
00100 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
00101 # define _LARGEFILE64_SOURCE 1
00102 #endif
00103
00104
00105
00106
00107
00108 #include <stdio.h>
00109 #include <stdlib.h>
00110 #include <math.h>
00111 #include <stdarg.h>
00112 #include <string.h>
00113 #include <ctype.h>
00114 #include <limits.h>
00115
00116 #if !defined(WIN32CE)
00117 # include <time.h>
00118 #else
00119 # include <wce_time.h>
00120 # include <wce_errno.h>
00121 #endif
00122
00123
00124 #if defined(HAVE_ERRNO_H)
00125 # include <errno.h>
00126 #endif
00127
00128 #ifdef HAVE_LOCALE_H
00129 # include <locale.h>
00130 #endif
00131
00132 #ifdef HAVE_DIRECT_H
00133 # include <direct.h>
00134 #endif
00135
00136 #ifdef _AIX
00137 # include <strings.h>
00138 #endif
00139
00140 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
00141 # define DBMALLOC
00142 # include <dbmalloc.h>
00143 #endif
00144
00145 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
00146 # define USE_DMALLOC
00147 # include <dmalloc.h>
00148 #endif
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 #if UINT_MAX == 65535
00159 typedef long GInt32;
00160 typedef unsigned long GUInt32;
00161 #else
00162 typedef int GInt32;
00163 typedef unsigned int GUInt32;
00164 #endif
00165
00166 typedef short GInt16;
00167 typedef unsigned short GUInt16;
00168 typedef unsigned char GByte;
00169 typedef int GBool;
00170
00171
00172
00173
00174
00175 #if defined(WIN32) && defined(_MSC_VER)
00176
00177 #define VSI_LARGE_API_SUPPORTED
00178 typedef __int64 GIntBig;
00179 typedef unsigned __int64 GUIntBig;
00180 #define CPL_FRMT_GIB "%I64d"
00181 #define CPL_FRMT_GUIB "%I64u"
00182
00183 #elif HAVE_LONG_LONG
00184
00185 typedef long long GIntBig;
00186 typedef unsigned long long GUIntBig;
00187 #define CPL_FRMT_GIB "%lld"
00188 #define CPL_FRMT_GUIB "%llu"
00189
00190 #else
00191
00192 typedef long GIntBig;
00193 typedef unsigned long GUIntBig;
00194 #define CPL_FRMT_GIB "%ld"
00195 #define CPL_FRMT_GUIB "%lu"
00196
00197 #endif
00198
00199
00200
00201
00202 #ifdef __cplusplus
00203 # define CPL_C_START extern "C" {
00204 # define CPL_C_END }
00205 #else
00206 # define CPL_C_START
00207 # define CPL_C_END
00208 #endif
00209
00210 #ifndef CPL_DLL
00211 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
00212 # define CPL_DLL __declspec(dllexport)
00213 #else
00214 # if defined(USE_GCC_VISIBILITY_FLAG)
00215 # define CPL_DLL __attribute__ ((visibility("default")))
00216 # else
00217 # define CPL_DLL
00218 # endif
00219 #endif
00220 #endif
00221
00222
00223 #ifdef CPL_OPTIONAL_APIS
00224 # define CPL_ODLL CPL_DLL
00225 #else
00226 # define CPL_ODLL
00227 #endif
00228
00229 #ifndef CPL_STDCALL
00230 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
00231 # define CPL_STDCALL __stdcall
00232 #else
00233 # define CPL_STDCALL
00234 #endif
00235 #endif
00236
00237 #ifdef _MSC_VER
00238 # define FORCE_CDECL __cdecl
00239 #else
00240 # define FORCE_CDECL
00241 #endif
00242
00243
00244 #if defined(__GNUC__)
00245 #define CPL_INLINE inline
00246 #else
00247 #define CPL_INLINE
00248 #endif
00249
00250 #ifndef NULL
00251 # define NULL 0
00252 #endif
00253
00254 #ifndef FALSE
00255 # define FALSE 0
00256 #endif
00257
00258 #ifndef TRUE
00259 # define TRUE 1
00260 #endif
00261
00262 #ifndef MAX
00263 # define MIN(a,b) ((a<b) ? a : b)
00264 # define MAX(a,b) ((a>b) ? a : b)
00265 #endif
00266
00267 #ifndef ABS
00268 # define ABS(x) ((x<0) ? (-1*(x)) : x)
00269 #endif
00270
00271
00272
00273
00274
00275
00276 #ifndef CPLIsEqual
00277 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
00278 #endif
00279
00280 #ifndef EQUAL
00281 #if defined(WIN32) || defined(WIN32CE)
00282 # define EQUALN(a,b,n) (strnicmp(a,b,n)==0)
00283 # define EQUAL(a,b) (stricmp(a,b)==0)
00284 #else
00285 # define EQUALN(a,b,n) (strncasecmp(a,b,n)==0)
00286 # define EQUAL(a,b) (strcasecmp(a,b)==0)
00287 #endif
00288 #endif
00289
00290 #ifdef macos_pre10
00291 int strcasecmp(char * str1, char * str2);
00292 int strncasecmp(char * str1, char * str2, int len);
00293 char * strdup (char *instr);
00294 #endif
00295
00296 #ifndef CPL_THREADLOCAL
00297 # define CPL_THREADLOCAL
00298 #endif
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 #ifdef _MSC_VER
00310 # include <float.h>
00311 # define CPLIsNan(x) _isnan(x)
00312 # define CPLIsInf(x) (!_isnan(x) && !_finite(x))
00313 # define CPLIsFinite(x) _finite(x)
00314 #else
00315 # define CPLIsNan(x) isnan(x)
00316 # ifdef isinf
00317 # define CPLIsInf(x) isinf(x)
00318 # define CPLIsFinite(x) (!isnan(x) && !isinf(x))
00319 # else
00320 # define CPLIsInf(x) FALSE
00321 # define CPLIsFinite(x) (!isnan(x))
00322 # endif
00323 #endif
00324
00325
00326
00327
00328
00329
00330
00331
00332 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
00333 # define CPL_MSB
00334 #endif
00335
00336 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
00337 #define CPL_LSB
00338 #endif
00339
00340 #if defined(CPL_LSB)
00341 # define CPL_IS_LSB 1
00342 #else
00343 # define CPL_IS_LSB 0
00344 #endif
00345
00346
00347
00348
00349
00350 #define CPL_SWAP16(x) \
00351 ((GUInt16)( \
00352 (((GUInt16)(x) & 0x00ffU) << 8) | \
00353 (((GUInt16)(x) & 0xff00U) >> 8) ))
00354
00355 #define CPL_SWAP16PTR(x) \
00356 { \
00357 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00358 \
00359 byTemp = _pabyDataT[0]; \
00360 _pabyDataT[0] = _pabyDataT[1]; \
00361 _pabyDataT[1] = byTemp; \
00362 }
00363
00364 #define CPL_SWAP32(x) \
00365 ((GUInt32)( \
00366 (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
00367 (((GUInt32)(x) & (GUInt32)0x0000ff00UL) << 8) | \
00368 (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >> 8) | \
00369 (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
00370
00371 #define CPL_SWAP32PTR(x) \
00372 { \
00373 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00374 \
00375 byTemp = _pabyDataT[0]; \
00376 _pabyDataT[0] = _pabyDataT[3]; \
00377 _pabyDataT[3] = byTemp; \
00378 byTemp = _pabyDataT[1]; \
00379 _pabyDataT[1] = _pabyDataT[2]; \
00380 _pabyDataT[2] = byTemp; \
00381 }
00382
00383 #define CPL_SWAP64PTR(x) \
00384 { \
00385 GByte byTemp, *_pabyDataT = (GByte *) (x); \
00386 \
00387 byTemp = _pabyDataT[0]; \
00388 _pabyDataT[0] = _pabyDataT[7]; \
00389 _pabyDataT[7] = byTemp; \
00390 byTemp = _pabyDataT[1]; \
00391 _pabyDataT[1] = _pabyDataT[6]; \
00392 _pabyDataT[6] = byTemp; \
00393 byTemp = _pabyDataT[2]; \
00394 _pabyDataT[2] = _pabyDataT[5]; \
00395 _pabyDataT[5] = byTemp; \
00396 byTemp = _pabyDataT[3]; \
00397 _pabyDataT[3] = _pabyDataT[4]; \
00398 _pabyDataT[4] = byTemp; \
00399 }
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
00419
00420 #ifdef CPL_MSB
00421 # define CPL_MSBWORD16(x) (x)
00422 # define CPL_LSBWORD16(x) CPL_SWAP16(x)
00423 # define CPL_MSBWORD32(x) (x)
00424 # define CPL_LSBWORD32(x) CPL_SWAP32(x)
00425 # define CPL_MSBPTR16(x)
00426 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
00427 # define CPL_MSBPTR32(x)
00428 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
00429 # define CPL_MSBPTR64(x)
00430 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
00431 #else
00432 # define CPL_LSBWORD16(x) (x)
00433 # define CPL_MSBWORD16(x) CPL_SWAP16(x)
00434 # define CPL_LSBWORD32(x) (x)
00435 # define CPL_MSBWORD32(x) CPL_SWAP32(x)
00436 # define CPL_LSBPTR16(x)
00437 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
00438 # define CPL_LSBPTR32(x)
00439 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
00440 # define CPL_LSBPTR64(x)
00441 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
00442 #endif
00443
00445 #define CPL_LSBINT16PTR(x) ((*(GByte*)(x)) | ((*(GByte*)((x)+1)) << 8))
00446
00448 #define CPL_LSBINT32PTR(x) ((*(GByte*)(x)) | ((*(GByte*)((x)+1)) << 8) | \
00449 ((*(GByte*)((x)+2)) << 16) | ((*(GByte*)((x)+3)) << 24))
00450
00451
00452
00453 #ifndef UNREFERENCED_PARAM
00454 # ifdef UNREFERENCED_PARAMETER
00455 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
00456 # else
00457 # define UNREFERENCED_PARAM(param) ((void)param)
00458 # endif
00459 #endif
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 #ifndef DISABLE_CVSID
00470 # define CPL_CVSID(string) static char cpl_cvsid[] = string; \
00471 static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
00472 #else
00473 # define CPL_CVSID(string)
00474 #endif
00475
00476 #if defined(__GNUC__) && __GNUC__ >= 3
00477 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx)))
00478 #else
00479 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
00480 #endif
00481
00482 #endif