CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef lucene_stdheader_h 00008 #define lucene_stdheader_h 00009 00010 #if defined(OVERRIDE_DEFAULT_CLCONFIG) 00011 #include "AltCLConfig.h" 00012 #else 00013 #include "CLucene/CLConfig.h" 00014 #endif 00015 00016 //first inclusion of compiler.h (it will be called again later) 00017 #include "CLucene/config/compiler.h" 00018 00019 extern void _lucene_shutdown(); 00020 extern int _lucene_counter_break; //can set a watch on this 00021 #if defined(LUCENE_ENABLE_MEMLEAKTRACKING) 00022 extern bool _lucene_disable_debuglogging; //if LUCENE_ENABLE_CONSTRUCTOR_LOG is on, dont do log if this is true 00023 #endif 00024 00026 // default includes 00028 #ifndef LUCENE_DISABLE_INCLUDES 00029 00030 #include <stdio.h> 00031 00032 #if defined(_CL_STDC_HEADERS) 00033 #include <stdlib.h> 00034 #include <stddef.h> 00035 #else 00036 #if defined(_CL_HAVE_STDLIB_H) 00037 #include <stdlib.h> 00038 #endif 00039 #endif 00040 00041 #if defined(_CL_HAVE_STRING_H) 00042 #if !defined(_CL_STDC_HEADERS) && defined(_CL_HAVE_MEMORY_H) 00043 #include <memory.h> 00044 #endif 00045 #include <string.h> 00046 #elif defined(_CL_HAVE_STRINGS_H) 00047 //note: as a side note, strtok is not thread-safe.. so be careful where you use it! 00048 #error "strtok replacement for BSD has not been implemented" 00049 #include <strings.h> 00050 #if !defined(_CL_HAVE_STRCHR) 00051 #define strchr index 00052 #define strrchr rindex 00053 #endif 00054 #endif 00055 00056 #if defined(_CL_HAVE_UNISTD_H) 00057 #include <unistd.h> 00058 #elif defined(_CL_HAVE_IO_H) && defined(_CL_HAVE_DIRECT_H) 00059 #include <io.h> 00060 #include <direct.h> 00061 #else 00062 #error "Neither unistd.h or (io.h & direct.h) were available" 00063 #endif 00064 00065 #ifndef _CL_DISABLE_NATIVE_EXCEPTIONS 00066 #ifdef _CL_HAVE_STDEXCEPT 00067 #include <stdexcept> 00068 #else 00069 #error "CLucene can't compile with exception handling on because <stdexcept> header is not available" 00070 #endif 00071 #endif 00072 00073 #if defined(_CL_STAT_MACROS_BROKEN) 00074 #error "Haven't implemented STAT_MACROS_BROKEN fix yet" 00075 #elif defined(_CL_HAVE_SYS_STAT_H) 00076 #include <sys/stat.h> 00077 #else 00078 #error "Haven't implemented platforms with no sys/stat.h" 00079 #endif 00080 00081 #if defined(_CL_HAVE_STDARG_H) 00082 #include <stdarg.h> 00083 #else 00084 #error "CLucene can compile, but some extras may not work" 00085 #endif 00086 00087 #if defined(_CL_HAVE_MATH_H) 00088 #include <math.h> 00089 #else 00090 #error "CLucene can't compile without <math.h>" 00091 #endif 00092 00093 #if defined(_CL_HAVE_MAP) 00094 #include <map> 00095 #else 00096 #error "CLucene can't compile without the map header" 00097 #endif 00098 00099 #if defined(_CL_HAVE_LIST) 00100 #include <list> 00101 #else 00102 #error "CLucene can't compile without the list header" 00103 #endif 00104 00105 #if defined(_CL_HAVE_SET) 00106 #include <set> 00107 #else 00108 #error "CLucene can't compile without the set header" 00109 #endif 00110 00111 #if defined(_CL_HAVE_VECTOR) 00112 #include <vector> 00113 #else 00114 #error "CLucene can't compile without the vector header" 00115 #endif 00116 00117 #if !defined(LUCENE_DISABLE_HASHING) && defined(_CL_HAVE_HASH_MAP) && defined(_CL_HAVE_HASH_SET) 00118 //hashing is all or nothing! 00119 #include <hash_map> 00120 #include <hash_set> 00121 #elif !defined(LUCENE_DISABLE_HASHING) && defined(_CL_HAVE_EXT_HASH_MAP) && defined(_CL_HAVE_EXT_HASH_SET) 00122 #include <ext/hash_map> 00123 #include <ext/hash_set> 00124 #elif !defined(LUCENE_DISABLE_HASHING) 00125 #define LUCENE_DISABLE_HASHING 00126 #endif 00127 #if !defined(LUCENE_DISABLE_HASHING) && !defined(CL_NS_HASHING) 00128 #define CL_NS_HASHING(func) std::func 00129 #endif 00130 00131 #if defined(_CL_HAVE_ALGORITHM) 00132 # include <algorithm> 00133 #else 00134 # error "Can't compile clucene without <algorithm>" 00135 #endif 00136 00137 #if defined(_CL_HAVE_FUNCTIONAL) 00138 # include <functional> 00139 #else 00140 # error "Can't compile clucene without <functional>" 00141 #endif 00142 00143 #if !defined(_CL_HAVE_PRINTF) 00144 #error "CLucene can't compile without printf, replacements have not been implemented" 00145 #endif 00146 00147 #if !defined(_CL_HAVE_SNPRINTF) && !defined(_CL_HAVE__SNPRINTF) 00148 #error "CLucene can't compile without snprintf, replacements have not been implemented" 00149 #elif !defined(_CL_HAVE__SNPRINTF)&& defined(_CL_HAVE_SVNPRINTF) 00150 #define _snprintf snprintf 00151 #endif 00152 00153 #if defined(_UCS2) 00154 #if defined(_CL_HAVE_WCHAR_H) 00155 #include <wchar.h> 00156 #else 00157 //actually the repl_wchar.h replacements header will 00158 //always be included. It replaces some functions 00159 //that are missing in some wchar.h headers. 00160 #endif 00161 #endif 00162 00163 #if defined(_UCS2) && defined(_CL_HAVE_WCTYPE_H) 00164 #include <wctype.h> 00165 #elif defined(_ASCII) && defined(_CL_HAVE_CTYPE_H) 00166 #include <ctype.h> 00167 #undef LUCENE_USE_INTERNAL_CHAR_FUNCTIONS 00168 #elif defined(_UCS2) 00169 //must be in _UCS2 to use internal char functions 00170 #undef LUCENE_USE_INTERNAL_CHAR_FUNCTIONS 00171 #define LUCENE_USE_INTERNAL_CHAR_FUNCTIONS 00172 #else 00173 #error "Cannot compile in _ASCII without ctype.h" 00174 #endif 00175 00176 //always include replacement, some missing tchar defines 00177 #include "CLucene/config/repl_tchar.h" 00178 00179 #if defined(_CL_HAVE_ERRNO_H) 00180 #include <errno.h> 00181 #else 00182 #error "Haven't implemented platforms with no errno.h" 00183 #endif 00184 00185 #if defined(_CL_HAVE_FCNTL_H) 00186 #include <fcntl.h> 00187 #else 00188 #error "Haven't implemented platforms with no fcntl.h" 00189 #endif 00190 00191 #if defined(_CL_HAVE_WINDOWS_H) 00192 #include <windows.h> 00193 #endif 00194 00195 #endif //LUCENE_DISABLE_INCLUDES 00196 // 00198 00199 //second inclusion of compiler.h 00200 //this gives CompilerXXX.h a chance to include other headers 00201 #include "CLucene/config/compiler.h" 00202 // 00204 00205 00207 // Character functions. 00208 // Here we decide whose character functions to use 00210 #if defined(LUCENE_USE_INTERNAL_CHAR_FUNCTIONS) 00211 #define stringCaseFold cl_tcscasefold 00212 #define stringCaseFoldCmp cl_tcscasefoldcmp 00213 00214 #undef _istspace 00215 #undef _istdigit 00216 #undef _istalnum 00217 #undef _istalpha 00218 #undef _totlower 00219 #undef _totupper 00220 #define _istalnum cl_isalnum 00221 #define _istalpha cl_isletter 00222 #define _istspace cl_isspace 00223 #define _istdigit cl_isdigit 00224 #define _totlower cl_tolower 00225 #define _totupper cl_toupper 00226 00227 //here are some functions to help deal with utf8/ucs2 conversions 00228 //lets let the user decide what mb functions to use... we provide pure utf8 ones no matter what. 00229 /*#undef _mbtowc 00230 #undef _mbstowcs 00231 #undef _wctomb 00232 #undef _wcstombs 00233 #define _mbtowc lucene_mbstowc 00234 #define _mbsstowcs lucene_mbstowcs 00235 #define _wctomb lucene_wcto_mb 00236 #define _wcstombs lucene_wcstombs*/ 00237 #else 00238 //we are using native functions 00239 //here are some functions to help deal with utf8/ucs2 conversions 00240 /*#define _mbtowc mbtowc 00241 #define _wctomb wctomb 00242 #define _mbstowcs mbstowcs 00243 #define _wcstombs wcstombs*/ 00244 00245 //we are using native character functions 00246 #if defined(_ASCII) 00247 #undef _istspace 00248 #undef _istdigit 00249 #undef _istalnum 00250 #undef _istalpha 00251 #undef _totlower 00252 #undef _totupper 00253 #define _istspace(x) isspace((unsigned char)x) 00254 #define _istdigit(x) isdigit((unsigned char)x) 00255 #define _istalnum(x) isalnum((unsigned char)x) 00256 #define _istalpha(x) isalpha((unsigned char)x) 00257 #define _totlower(x) tolower((unsigned char)x) 00258 #define _totupper(x) toupper((unsigned char)x) 00259 #endif 00260 #endif 00261 00262 //the methods contained in gunichartables.h 00263 typedef unsigned long clunichar; 00264 bool cl_isletter(clunichar c); 00265 bool cl_isalnum(clunichar c); 00266 bool cl_isdigit(clunichar c); 00267 bool cl_isspace (clunichar c); 00268 TCHAR cl_tolower (TCHAR c); 00269 TCHAR cl_toupper (TCHAR c); 00270 00271 int cl_tcscasefoldcmp(const TCHAR * dst, const TCHAR * src); 00272 TCHAR* cl_tcscasefold( TCHAR * str, int len=-1 ); 00273 00274 //we provide utf8 conversion functions 00275 size_t lucene_utf8towc (wchar_t *ret, const char *s, size_t n); 00276 size_t lucene_utf8towcs(wchar_t *, const char *, size_t maxslen); 00277 size_t lucene_wctoutf8 (char * ret, const wchar_t str); 00278 size_t lucene_wcstoutf8 (char *, const wchar_t *, size_t maxslen); 00279 size_t lucene_utf8charlen(const char *p); 00280 00282 extern TCHAR* _LUCENE_BLANK_STRING; 00283 #define LUCENE_BLANK_STRING _LUCENE_BLANK_STRING 00284 extern char* _LUCENE_BLANK_ASTRING; 00285 #define LUCENE_BLANK_ASTRING _LUCENE_BLANK_ASTRING 00286 00287 /* Converts a string into a form that is independent of case. The 00288 * result will not correspond to any particular case, but can be 00289 * compared for equality or ordered with the results of calling 00290 * stringCaseFold() on other strings. 00291 * 00292 * If we did not define this elsewhere, then just convert to lower case 00293 */ 00294 #ifndef stringCaseFold 00295 #define stringCaseFold _tcslwr 00296 #endif 00297 /* Compares 2 strings using case folding (if available) 00298 * If we did not define this elsewhere, then just compare 00299 * using normal method 00300 */ 00301 #ifndef stringCaseFoldCmp 00302 #define stringCaseFoldCmp _tcsicmp 00303 #endif 00304 00305 //now that all the character routines are completed, include the 00306 //wchar.h replacements. 00307 #include "CLucene/config/repl_wchar.h" //always include replacements 00308 00309 //a replacement for _tcsdup. This uses new TCHAR[] instead of malloc, so that we can use delete[] to free 00310 #if defined(LUCENE_ENABLE_FILELINEINFO) 00311 #define CL_FILELINE ,__FILE__,__LINE__ 00312 #define CL_FILELINEREF ,file,line 00313 #define CL_FILELINEREF2 ,file,line 00314 #define CL_FILELINEPARAM ,char* file,int line 00315 #else 00316 #define CL_FILELINE 00317 #define CL_FILELINEREF 00318 #define CL_FILELINEREF2 ,NULL,-1 00319 #define CL_FILELINEPARAM 00320 #endif 00321 00322 char* lucenestrdup(const char* v CL_FILELINEPARAM); 00323 #if defined(_UCS2) 00324 wchar_t* lucenewcsdup(const wchar_t* v CL_FILELINEPARAM); 00325 #define stringDuplicate(x) lucenewcsdup(x CL_FILELINE) //don't change this... uses [] instead of malloc 00326 #else 00327 #define stringDuplicate(x) lucenestrdup(x CL_FILELINE) //don't change this... uses [] instead of malloc 00328 #endif 00329 00330 #define STRCPY_AtoA(target,src,len) strncpy(target,src,len) 00331 #define STRDUP_AtoA(x) lucenestrdup(x CL_FILELINE) 00332 00333 #if defined(_UCS2) 00334 #define STRDUP_WtoW(x) lucenewcsdup(x CL_FILELINE) 00335 #define STRDUP_TtoT STRDUP_WtoW 00336 #define STRDUP_WtoT STRDUP_WtoW 00337 #define STRDUP_TtoW STRDUP_WtoW 00338 00339 #define STRDUP_AtoW(x) CL_NS(util)::Misc::_charToWide(x CL_FILELINE) 00340 #define STRDUP_AtoT STRDUP_AtoW 00341 00342 #define STRDUP_WtoA(x) CL_NS(util)::Misc::_wideToChar(x CL_FILELINE) 00343 #define STRDUP_TtoA STRDUP_WtoA 00344 00345 #define STRCPY_WtoW(target,src,len) _tcsncpy(target,src,len) 00346 #define STRCPY_TtoW STRCPY_WtoW 00347 #define STRCPY_WtoT STRCPY_WtoW 00348 #define STRCPY_TtoT STRCPY_WtoW 00349 00350 #define STRCPY_AtoW(target,src,len) CL_NS(util)::Misc::_cpycharToWide(src,target,len) 00351 #define STRCPY_AtoT STRCPY_AtoW 00352 00353 #define STRCPY_WtoA(target,src,len) CL_NS(util)::Misc::_cpywideToChar(src,target,len) 00354 #define STRCPY_TtoA STRCPY_WtoA 00355 #else 00356 #define STRDUP_AtoT STRDUP_AtoA 00357 #define STRDUP_TtoA STRDUP_AtoA 00358 #define STRDUP_TtoT STRDUP_AtoA 00359 00360 #define STRDUP_WtoT(x) xxxxxxxxxxxxxxx //not possible 00361 #define STRCPY_WtoT(target,src,len) xxxxxxxxxxxxxxx //not possible 00362 00363 #define STRCPY_AtoT STRCPY_AtoA 00364 #define STRCPY_TtoA STRCPY_AtoA 00365 #define STRCPY_TtoT STRCPY_AtoA 00366 #endif 00367 00368 // 00370 00372 //namespace helper 00374 #if defined(_LUCENE_DONTIMPLEMENT_NS_MACROS) 00375 00376 #elif !defined(DISABLE_NAMESPACE) 00377 #define CL_NS_DEF(sub) namespace lucene{ namespace sub{ 00378 #define CL_NS_DEF2(sub,sub2) namespace lucene{ namespace sub{ namespace sub2 { 00379 00380 #define CL_NS_END }} 00381 #define CL_NS_END2 }}} 00382 00383 #define CL_NS_USE(sub) using namespace lucene::sub; 00384 #define CL_NS_USE2(sub,sub2) using namespace lucene::sub::sub2; 00385 00386 #define CL_NS(sub) lucene::sub 00387 #define CL_NS2(sub,sub2) lucene::sub::sub2 00388 #else 00389 #define CL_NS_DEF(sub) 00390 #define CL_NS_DEF2(sub, sub2) 00391 #define CL_NS_END 00392 #define CL_NS_END2 00393 #define CL_NS_USE(sub) 00394 #define CL_NS_USE2(sub,sub2) 00395 #define CL_NS(sub) 00396 #define CL_NS2(sub,sub2) 00397 #endif 00398 00399 #if defined(LUCENE_NO_STDC_NAMESPACE) 00400 //todo: haven't actually tested this on a non-stdc compliant compiler 00401 #define CL_NS_STD(func) ::func 00402 #else 00403 #define CL_NS_STD(func) std::func 00404 #endif 00405 // 00407 00408 // 00409 void CLDebugBreak(); //define a debugbreak function 00410 00411 00413 // These are defines and functions used throughout clucene 00415 #undef _T //remove any previously defined _T - required for ppc os 00416 #if defined(_UCS2) 00417 #define _T(x) L ## x 00418 #else 00419 #define _T(x) x 00420 #endif 00421 00422 //third inclusion of compiler.h 00423 //this gives CompilerXXX.h a chance to fix any of the 00424 //default settings 00425 #include "CLucene/config/compiler.h" 00426 00427 //use std namespace 00428 #ifndef LUCENE_NO_STDC_NAMESPACE 00429 using namespace std; 00430 #endif 00431 00432 00434 //misc shortcut defines 00436 00437 //include the headers that we need practically everywhere 00438 #include "CLucene/debug/error.h" //all delete/creation/mem debugging code 00439 #include "CLucene/debug/condition.h" //conditional debugging (like assert) 00440 #include "CLucene/debug/mem.h" //all delete/creation/mem debugging code 00441 #include "LuceneThreads.h" //lucene threading support 00442 00443 #include "CLucene/util/Misc.h" 00444 #include "CLucene/util/Equators.h" 00445 #include "CLucene/util/VoidList.h" 00446 #include "CLucene/util/VoidMap.h" 00447 00448 00449 CL_NS_DEF(util) 00450 typedef CL_NS(util)::CLVector<TCHAR*> StringArray; 00451 typedef CL_NS(util)::CLVector<TCHAR*, CL_NS(util)::Deletor::tcArray > StringArrayWithDeletor; 00452 typedef CL_NS(util)::CLVector<const TCHAR*> StringArrayConst; 00453 typedef CL_NS(util)::CLVector<const TCHAR*, CL_NS(util)::Deletor::tcArray > StringArrayConstWithDeletor; 00454 00455 typedef CL_NS(util)::CLVector<char*> AStringArray; 00456 typedef CL_NS(util)::CLVector<char*, CL_NS(util)::Deletor::acArray > AStringArrayWithDeletor; 00457 typedef CL_NS(util)::CLVector<const char*> AStringArrayConst; 00458 typedef CL_NS(util)::CLVector<const char*, CL_NS(util)::Deletor::acArray > AStringArrayConstWithDeletor; 00459 CL_NS_END 00460 00461 // 00463 00464 #endif // STDHEADER_H