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