00001 // File: $Id$ 00002 // Author: John Wu <John.Wu at acm.org> 00003 // Lawrence Berkeley National Laboratory 00004 // Copyright 2000-2009 the Regents of the University of California 00005 #ifndef IBIS_CONST_H 00006 #define IBIS_CONST_H 00007 // Primary contact: John Wu <John.Wu at acm.org> 00008 // 00014 00015 #if defined(DEBUG) && !defined(_DEBUG) 00016 # define _DEBUG DEBUG 00017 #elif !defined(DEBUG) && defined(_DEBUG) && _DEBUG + 0 > 1 00018 # define DEBUG _DEBUG - 1 00019 #endif 00020 // gcc's stl header files needs this one to work correctly 00021 #ifndef _PTHREADS 00022 # define _PTHREADS 00023 #endif 00024 // machine related feature selection 00025 #ifndef _REENTRANT 00026 # define _REENTRANT 00027 #endif 00028 #if defined(__SUNPRO_CC) 00029 # ifndef __EXTENSIONS__ 00030 # define __EXTENSIONS__ 00031 # endif 00032 #elif defined(__KCC) 00033 // the following combination appears to get the right functions 00034 # ifdef _POSIX_C_SOURCE 00035 # undef _POSIX_C_SOURCE 00036 # endif 00037 # ifndef _XOPEN_VERSION 00038 # define _XOPEN_VERSION 4 00039 # else 00040 # undef _XOPEN_VERSION 00041 # define _XOPEN_VERSION 4 00042 # endif 00043 #endif 00044 // #if defined(unix) && !defined(__USE_UNIX98) 00045 // #define __USE_UNIX98 00046 // #endif 00047 #if defined(__CYGWIN__) && !defined(HAVE_STRUCT_TIMESPEC) 00048 # define HAVE_STRUCT_TIMESPEC 00049 #endif 00050 // // require every compiler to support mutable keyword 00051 // #if __cplusplus >= 199711L 00052 // # define HAVE_MUTABLE 1 00053 // #elif defined(__GNUC__) 00054 // # define HAVE_MUTABLE (__GNUC__>2 || (__GNUC__>1 && __GNUC_MINOR__-0>=95)) 00055 // #elif defined(__SUNPROC_CC) 00056 // # define HAVE_MUTABLE (__SUNPRO_CC >= 0x500) 00057 // #elif defined(_MSC_VER) 00058 // # define HAVE_MUTABLE (_MSC_VER >= 1200) 00059 // #elif defined(__PGI) 00060 // # define HAVE_MUTABLE 1 00061 // #elif defined(__sgi) 00062 // # define HAVE_MUTABLE (_COMPILER_VERSION > 600) 00063 // #else 00064 // # define HAVE_MUTABLE 0 00065 // #endif 00066 00067 // 00068 // common headers needed 00069 #include <errno.h> // errno 00070 #include <pthread.h> // mutex lock, rwlock, conditional variables 00071 #if !defined(WITHOUT_FASTBIT_CONFIG_H) && !(defined(_WIN32)&&defined(_MSC_VER)) 00072 # include "fastbit-config.h" // macros defined by the configure script 00073 # ifdef HAVE_STRING_H 00074 # if !STDC_HEADERS && HAVE_MEMORY_H 00075 # include <memory.h> 00076 # endif 00077 # include <string.h> // strerr, strcasecmp, strcmp, memcpy 00078 # endif 00079 # ifdef HAVE_SYS_TYPES_H 00080 # include <sys/types.h> // timespec, etc 00081 # endif 00082 # ifdef HAVE_STDINT_H 00083 # include <stdint.h> 00084 # endif 00085 #else 00086 # if defined(unix)||defined(linux)||defined(__APPLE__)||defined(__CYGWIN__) 00087 # define HAVE_VPRINTF 1 00088 # define HAVE_DIRENT_H 1 00089 # endif 00090 # if !defined(_MSC_VER) 00091 # include <sys/types.h> 00092 # endif 00093 # include <string.h> 00094 #endif 00095 #ifndef FASTBIT_STRING 00096 #define FASTBIT_STRING "FastBit ibis" 00097 #endif 00098 #include <vector> // std::vector 00099 #include <functional> // std::less, std::binary_function<> 00100 00101 // section to handle errno in a multithread program 00102 #if defined(__SUNPRO_CC) 00103 # if defined(_REENTRANT) 00104 # ifdef errno 00105 # undef errno 00106 # endif 00107 # define errno (*(::___errno())) 00108 # endif // defined(_REENTRANT) 00109 // #elif defined(_WIN32) 00110 // # if defined(_MT) || defined(_DLL) 00111 // extern int * __cdecl _errno(void); 00112 // # define errno (*_errno(void)) 00113 // # else /* ndef _MT && ndef _DLL */ 00114 // extern int errno; 00115 // # endif /* _MT || _DLL */ 00116 #endif /* errno */ 00117 00118 // Compiler independent definitions: 00119 //#define TIME_BUF_LEN 32 00120 #ifndef MAX_LINE 00121 #define MAX_LINE 2048 00122 #endif 00123 // #ifndef mmax 00124 // #define mmax(x,y) ((x)>(y))?(x):(y) 00125 // #endif 00126 00132 #ifndef PREFERRED_BLOCK_SIZE 00133 #define PREFERRED_BLOCK_SIZE 1048576 00134 //#define PREFERRED_BLOCK_SIZE 262144 00135 #endif 00136 00137 #if defined(__SUNPRO_CC) 00138 #if (__SUNPRO_CC < 0x500) 00139 # include <iostream.h> 00140 typedef int bool; 00141 # define false 0 00142 # define true 1 00143 # define std 00144 # define mutable 00145 # define explicit 00146 #else 00147 # include <iosfwd> // std::cout, std::clog 00148 #endif 00149 //#elif _MSC_VER <= 1200 00150 //#include <iostream.h> 00151 #else 00152 # include <iosfwd> // std::cout, std::clog 00153 #endif 00154 00155 // 00156 // Compiler dependent definitions: 00157 #if defined(_CRAY) | defined(__KCC) 00158 # define __LIM_H_PARAM_ 00159 # include <sys/param.h> 00160 00161 #elif defined(sun) 00162 # include <limits.h> // PATH_MAX, OPEN_MAX 00163 # include <inttypes.h> // int32_t, ... 00164 00165 // use rwlock_t to simulate pthread_rwlock_t 00166 # ifndef PTHREAD_RWLOCK_INITIALIZER 00167 # include <synch.h> // rwlock 00168 # define pthread_rwlock_t rwlock_t 00169 # define pthread_rwlock_init(lk, attr) rwlock_init(lk, attr, 0) 00170 # define pthread_rwlock_destroy rwlock_destroy 00171 # define pthread_rwlock_rdlock rw_rdlock 00172 # define pthread_rwlock_wrlock rw_wrlock 00173 # define pthread_rwlock_tryrdlock rw_tryrdlock 00174 # define pthread_rwlock_trywrlock rw_trywrlock 00175 # define pthread_rwlock_unlock rw_unlock 00176 # define PTHREAD_RWLOCK_INITIALIZER DEFAULTRWLOCK; 00177 # endif 00178 00179 #elif defined(unix) || defined(__HOS_AIX__) 00180 # include <stdint.h> // int32_t, ... 00181 # include <limits.h> // PATH_MAX, OPEN_MAX 00182 # ifdef __CYGWIN__ // cygwin port of gcc compiler 00183 //commented out 2005/04/12 # define __INSIDE_CYGWIN__ 00184 # include <cygwin/types.h> 00185 # endif 00186 00187 #elif defined(_WIN32) 00188 // don't need too many things from Windows header files 00189 # define WIN32_LEAN_AND_MEAN 00190 // if WINVER is not define, pretend to be on windows vista 00191 # ifndef WINVER 00192 # ifdef _WIN32_WINNT 00193 # define WINVER _WIN32_WINNT 00194 # else 00195 # define WINVER 0x0600 00196 # endif 00197 # endif 00198 # include <limits.h> // PATH_MAX, OPEN_MAX 00199 # include <windows.h> 00200 # include <direct.h> // _mkdir 00201 # define mkdir(x,y) _mkdir(x) 00202 # define chmod _chmod 00203 # if defined(_DEBUG) 00204 # include <crtdbg.h> 00205 # endif 00206 00207 // MS windows has its own exact-width types, use them 00208 # ifndef int16_t 00209 # define int16_t __int16 00210 # endif 00211 # ifndef uint16_t 00212 # define uint16_t unsigned __int16 00213 # endif 00214 # ifndef int32_t 00215 # define int32_t __int32 00216 # endif 00217 # ifndef uint32_t 00218 # define uint32_t unsigned __int32 00219 # endif 00220 # ifndef int64_t 00221 # define int64_t __int64 00222 # endif 00223 # ifndef uint64_t 00224 # define uint64_t unsigned __int64 00225 # endif 00226 00227 #elif defined(__APPLE__) 00228 # include <stdint.h> // int32_t, ... 00229 # include <sys/syslimits.h> 00230 00231 #else 00232 # include <stdint.h> // int32_t, ... 00233 # include <syslimits.h> // PATH_MAX 00234 00235 #endif 00236 00237 // a hack to check for exact-width data types -- according the Open Group's 00238 // defiition of stdint.h, when the exact-width integer types are defined, 00239 // their corresponding MAX values are also defined with #define. Since the 00240 // types themselves may be typedefs, the corresponding INTx_MAX are more 00241 // reliable checks. 00242 #if !(defined(HAVE_STDINT_H) || defined(unix) || defined(_WIN32) || defined(__APPLE__) || defined(__x86_64__) || defined(_STDINT_H)) 00243 # ifndef INT16_MAX 00244 # define int16_t short int 00245 # define INT16_MAX (32767) 00246 # endif 00247 # ifndef UINT16_MAX 00248 # define uint16_t unsigned short int 00249 # define UINT16_MAX (65535) 00250 # endif 00251 # ifndef INT32_MAX 00252 # define int32_t int 00253 # define INT32_MAX (2147483647) 00254 # endif 00255 # ifndef UINT32_MAX 00256 # define uint32_t unsigned int 00257 # define UINT32_MAX (4294967295UL) 00258 # endif 00259 # ifndef INT64_MAX 00260 # define int64_t long long int 00261 # define INT64_MAX (9223372036854775807LL) 00262 # endif 00263 # ifndef UINT64_MAX 00264 # define uint64_t unsigned long long int 00265 # define UINT64_MAX (18446744073709551615ULL) 00266 # endif 00267 #endif 00268 00269 #ifndef PATH_MAX 00270 # define PATH_MAX 512 00271 #endif 00272 00273 // things for MS Windows only 00274 // FASTBIT_DIRSEP == the directory name separator 00275 // FASTBIT_CXX_DLLSPEC == export/import symbols to/from DLL library under windows system 00276 #if defined(_WIN32) && defined(_MSC_VER) 00277 # define FASTBIT_DIRSEP '\\' 00278 #else 00279 # define FASTBIT_DIRSEP '/' 00280 #endif 00281 #if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__)) 00282 # if defined(_USRDLL) || defined(CXX_USE_DLL) 00283 # if defined(DLL_EXPORT) 00284 # define FASTBIT_CXX_DLLSPEC __declspec(dllexport) 00285 # else 00286 # define FASTBIT_CXX_DLLSPEC __declspec(dllimport) 00287 # endif 00288 # else 00289 # define FASTBIT_CXX_DLLSPEC 00290 # endif 00291 #else 00292 # define FASTBIT_CXX_DLLSPEC 00293 #endif 00294 00295 /* causes problems on solaris 2.8 00296 #ifdef PTHREAD_RWLOCK_INITIALIZER 00297 #if xPTHREAD_RWLOCK_INITIALIZER == x 00298 #undef PTHREAD_RWLOCK_INITIALIZER 00299 #endif 00300 #endif 00301 */ 00302 #if defined(__APPLE__) && !defined(PTHREAD_RWLOCK_INITIALIZER) 00303 #define PTHREAD_RWLOCK_INITIALIZER 00304 #endif 00305 // still don't have correct RWLOCK, then use mutex lock instead 00306 #ifndef PTHREAD_RWLOCK_INITIALIZER 00307 #define IBIS_REPLACEMENT_RWLOCK 00308 #define THREAD_RWLOCK_INITIALIZER \ 00309 {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \ 00310 PTHREAD_COND_INITIALIZER, 0, 0} 00311 typedef struct _rwlock { 00312 pthread_mutex_t lock; // lock for structure 00313 pthread_cond_t readers; // waiting readers 00314 pthread_cond_t writers; // waiting writers 00315 int state; // -1:writer,0:free,>0:readers 00316 int waiters; // number of waiting writers 00317 } pthread_rwlock_t; 00318 int pthread_rwlock_init(pthread_rwlock_t *rwlock, void*); 00319 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); 00320 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); 00321 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); 00322 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); 00323 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); 00324 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); 00325 #endif 00326 00327 // 00328 // functions for case-insensitive string comparisons 00329 // 00330 #ifdef _WIN32 00331 # if _MSC_VER >= 1500 00332 # define strnicmp _strnicmp 00333 # define stricmp _stricmp 00334 # endif 00335 #else 00336 # include <strings.h> // strcasecmp, strncasecmp 00337 # define MessageBox(x1,x2,x3,x4); {} // fake message box 00338 # define strnicmp strncasecmp 00339 # define stricmp strcasecmp 00340 #endif 00341 00342 // #ifndef REASON 00343 // # define REASON " " << strerror(errno) << std::endl; 00344 // #endif // ifndef REASON 00345 00346 // namespace of ibis contains most of the useful classes of the implementation 00347 namespace ibis { // forward definition of all the classes in IBIS 00350 class part; 00351 class query; 00352 class qExpr; 00353 00354 00355 template<class T> class array_t; 00357 typedef FASTBIT_CXX_DLLSPEC std::vector< part* > partList; 00358 00360 union FASTBIT_CXX_DLLSPEC rid_t { 00361 uint64_t value; 00362 00363 struct name { 00364 uint32_t run; 00365 uint32_t event; 00366 } num; 00367 00368 bool operator<(const rid_t& r) const { 00369 return((num.run < r.num.run) | 00370 (num.run == r.num.run && num.event < r.num.event));} 00371 bool operator>(const rid_t& r) const { 00372 return((num.run > r.num.run) | 00373 (num.run == r.num.run && num.event > r.num.event));} 00374 bool operator<=(const rid_t& r) const { 00375 return((num.run < r.num.run) | 00376 (num.run == r.num.run && num.event <= r.num.event));} 00377 bool operator>=(const rid_t& r) const { 00378 return((num.run > r.num.run) | 00379 (num.run == r.num.run && num.event >= r.num.event));} 00380 bool operator==(const rid_t& r) const {return(value == r.value);} 00381 bool operator!=(const rid_t& r) const {return(value != r.value);} 00382 }; 00383 00386 struct lessi : 00387 public std::binary_function< const char*, const char*, bool > { 00388 bool operator()(const char* x, const char* y) const { 00389 return (x && y ? stricmp(x, y) < 0 : false); 00390 } 00391 }; 00392 00395 extern FASTBIT_CXX_DLLSPEC int gVerbose; 00396 } // namespace ibis 00397 #endif // ifndef IBIS_CONST_H
![]() |