const.h
Go to the documentation of this file.
00001 // File: $Id$
00002 // Author: John Wu <John.Wu at acm.org>
00003 //      Lawrence Berkeley National Laboratory
00004 // Copyright 2000-2012 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 
00278 #if defined(_WIN32) && (defined(_MSC_VER) || defined(__MINGW32__))
00279 #  if defined(_USRDLL) || defined(CXX_USE_DLL)
00280 #    if defined(DLL_EXPORT)
00281 #      define FASTBIT_CXX_DLLSPEC __declspec(dllexport)
00282 #    else
00283 #      define FASTBIT_CXX_DLLSPEC __declspec(dllimport)
00284 #    endif
00285 #  else
00286 #    define FASTBIT_CXX_DLLSPEC
00287 #  endif
00288 #else
00289 #  define FASTBIT_CXX_DLLSPEC
00290 #endif
00291 
00292 /* causes problems on solaris 2.8
00293 #ifdef PTHREAD_RWLOCK_INITIALIZER
00294 #if xPTHREAD_RWLOCK_INITIALIZER == x
00295 #undef PTHREAD_RWLOCK_INITIALIZER
00296 #endif
00297 #endif
00298 */
00299 #if defined(__APPLE__) && !defined(PTHREAD_RWLOCK_INITIALIZER)
00300 #define PTHREAD_RWLOCK_INITIALIZER
00301 #endif
00302 // still don't have correct RWLOCK, then use mutex lock instead
00303 #ifndef PTHREAD_RWLOCK_INITIALIZER
00304 #define IBIS_REPLACEMENT_RWLOCK
00305 #define THREAD_RWLOCK_INITIALIZER \
00306                 {PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, \
00307                 PTHREAD_COND_INITIALIZER, 0, 0}
00308 typedef struct _rwlock {
00309     pthread_mutex_t lock;     // lock for structure          
00310     pthread_cond_t  readers;  // waiting readers             
00311     pthread_cond_t  writers;  // waiting writers            
00312     int             state;    // -1:writer,0:free,>0:readers 
00313     int             waiters;  // number of waiting writers  
00314 } pthread_rwlock_t;
00315 int pthread_rwlock_init(pthread_rwlock_t *rwlock, void*);
00316 int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
00317 int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
00318 int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
00319 int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
00320 int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
00321 int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
00322 #endif
00323 
00324 //
00325 // functions for case-insensitive string comparisons
00326 //
00327 #ifdef _WIN32
00328 #  if _MSC_VER >= 1500
00329 #    define strnicmp _strnicmp
00330 #    define stricmp _stricmp
00331 #  endif
00332 #else
00333 #  include <strings.h>  // strcasecmp, strncasecmp
00334 #  define MessageBox(x1,x2,x3,x4); {} // fake message box
00335 #  define strnicmp strncasecmp
00336 #  define stricmp strcasecmp
00337 #endif
00338 
00339 // #ifndef REASON
00340 // #  define REASON " " << strerror(errno) << std::endl;
00341 // #endif // ifndef REASON
00342 
00343 // namespace of ibis contains most of the useful classes of the implementation
00344 namespace ibis { // forward definition of all the classes in IBIS
00347     class part;         
00348     class query;        
00349     class qExpr;        
00350 
00351 
00352     template<class T> class array_t;
00354     typedef FASTBIT_CXX_DLLSPEC std::vector< part* > partList;
00356     typedef FASTBIT_CXX_DLLSPEC std::vector< const part* > constPartList;
00357 
00359     union FASTBIT_CXX_DLLSPEC rid_t {
00360         uint64_t value; 
00361 
00362         struct name {
00363             uint32_t run;       
00364             uint32_t event;     
00365         } num;
00366 
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 {
00377             return((num.run > r.num.run) |
00378                    (num.run == r.num.run && num.event >= r.num.event));}
00379         bool operator==(const rid_t& r) const {return(value == r.value);}
00380         bool operator!=(const rid_t& r) const {return(value != r.value);}
00381     };
00382 
00385     struct lessi :
00386         public std::binary_function< const char*, const char*, bool > {
00387         bool operator()(const char* x, const char* y) const {
00388             return (x && y ? stricmp(x, y) < 0 : false);
00389         }
00390     };
00391 
00394     extern FASTBIT_CXX_DLLSPEC int gVerbose;
00395 } // namespace ibis
00396 #endif // ifndef IBIS_CONST_H

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive