1/*------------------------------------------------------------------------------
2* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
3*
4* Distributable under the terms of either the Apache License (Version 2.0) or
5* the GNU Lesser General Public License, as specified in the COPYING file.
6*
7* Changes are Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
8------------------------------------------------------------------------------*/
9#ifndef lucene_stdheader_h
10#define lucene_stdheader_h
11
12#if defined(OVERRIDE_DEFAULT_CLCONFIG)
13 #include "AltCLConfig.h"
14#else
15 #include "CLucene/CLConfig.h"
16#endif
17
18//first inclusion of compiler.h (it will be called again later)
19#include "CLucene/config/compiler.h"
20
21extern void _lucene_shutdown();
22extern int _lucene_counter_break; //can set a watch on this
23#if defined(LUCENE_ENABLE_MEMLEAKTRACKING)
24 extern bool _lucene_disable_debuglogging; //if LUCENE_ENABLE_CONSTRUCTOR_LOG is on, dont do log if this is true
25#endif
26
27////////////////////////////////////////////////////////
28// default includes
29////////////////////////////////////////////////////////
30#ifndef LUCENE_DISABLE_INCLUDES
31
32#include <stdio.h>
33
34#if defined(_CL_STDC_HEADERS)
35 #include <stdlib.h>
36 #include <stddef.h>
37#else
38 #if defined(_CL_HAVE_STDLIB_H)
39 #include <stdlib.h>
40 #endif
41#endif
42
43#if defined(_CL_HAVE_STRING_H)
44 #if !defined(_CL_STDC_HEADERS) && defined(_CL_HAVE_MEMORY_H)
45 #include <memory.h>
46 #endif
47 #include <string.h>
48#elif defined(_CL_HAVE_STRINGS_H)
49 //note: as a side note, strtok is not thread-safe.. so be careful where you use it!
50 #error "strtok replacement for BSD has not been implemented"
51 #include <strings.h>
52 #if !defined(_CL_HAVE_STRCHR)
53 #define strchr index
54 #define strrchr rindex
55 #endif
56#endif
57
58#if defined(_CL_HAVE_UNISTD_H)
59 #include <unistd.h>
60#elif defined(_CL_HAVE_IO_H) && defined(_CL_HAVE_DIRECT_H)
61#ifndef UNDER_CE
62 #include <io.h>
63 #include <direct.h>
64#endif
65#else
66 #error "Neither unistd.h or (io.h & direct.h) were available"
67#endif
68
69#ifndef _CL_DISABLE_NATIVE_EXCEPTIONS
70 #ifdef _CL_HAVE_STDEXCEPT
71 #include <stdexcept>
72 #else
73 #error "CLucene can't compile with exception handling on because <stdexcept> header is not available"
74 #endif
75#endif
76
77#if defined(_CL_STAT_MACROS_BROKEN)
78 #error "Haven't implemented STAT_MACROS_BROKEN fix yet"
79#elif defined(_CL_HAVE_SYS_STAT_H)
80#ifdef UNDER_CE
81 #include <types.h>
82#else
83 #include <sys/stat.h>
84#endif
85#else
86 #error "Haven't implemented platforms with no sys/stat.h"
87#endif
88
89#if defined(_CL_HAVE_STDARG_H)
90 #include <stdarg.h>
91#else
92 #error "CLucene can compile, but some extras may not work"
93#endif
94
95#if defined(_CL_HAVE_MATH_H)
96 #include <math.h>
97#else
98 #error "CLucene can't compile without <math.h>"
99#endif
100
101#if defined(_CL_HAVE_MAP)
102 #include <map>
103#else
104 #error "CLucene can't compile without the map header"
105#endif
106
107#if defined(_CL_HAVE_LIST)
108 #include <list>
109#else
110 #error "CLucene can't compile without the list header"
111#endif
112
113#if defined(_CL_HAVE_SET)
114 #include <set>
115#else
116 #error "CLucene can't compile without the set header"
117#endif
118
119#if defined(_CL_HAVE_VECTOR)
120 #include <vector>
121#else
122 #error "CLucene can't compile without the vector header"
123#endif
124
125#if !defined(LUCENE_DISABLE_HASHING) && defined(_CL_HAVE_HASH_MAP) && defined(_CL_HAVE_HASH_SET)
126 //hashing is all or nothing!
127 #include <hash_map>
128 #include <hash_set>
129#elif !defined(LUCENE_DISABLE_HASHING) && defined(_CL_HAVE_EXT_HASH_MAP) && defined(_CL_HAVE_EXT_HASH_SET)
130 #include <ext/hash_map>
131 #include <ext/hash_set>
132#elif !defined(LUCENE_DISABLE_HASHING)
133 #define LUCENE_DISABLE_HASHING
134#endif
135#if !defined(LUCENE_DISABLE_HASHING) && !defined(CL_NS_HASHING)
136 #define CL_NS_HASHING(func) std::func
137#endif
138
139#if defined(_CL_HAVE_ALGORITHM)
140# include <algorithm>
141#else
142# error "Can't compile clucene without <algorithm>"
143#endif
144
145#if defined(_CL_HAVE_FUNCTIONAL)
146# include <functional>
147#else
148# error "Can't compile clucene without <functional>"
149#endif
150
151#if !defined(_CL_HAVE_PRINTF)
152 #error "CLucene can't compile without printf, replacements have not been implemented"
153#endif
154
155#if !defined(_CL_HAVE_SNPRINTF) && !defined(_CL_HAVE__SNPRINTF)
156 #error "CLucene can't compile without snprintf, replacements have not been implemented"
157#elif !defined(_CL_HAVE__SNPRINTF)&& defined(_CL_HAVE_SVNPRINTF)
158 #define _snprintf snprintf
159#endif
160
161#if defined(_UCS2)
162 #if defined(_CL_HAVE_WCHAR_H)
163 #include <wchar.h>
164 #else
165 //actually the repl_wchar.h replacements header will
166 //always be included. It replaces some functions
167 //that are missing in some wchar.h headers.
168 #endif
169#endif
170
171#if defined(_UCS2) && defined(_CL_HAVE_WCTYPE_H)
172 #include <wctype.h>
173#elif defined(_ASCII) && defined(_CL_HAVE_CTYPE_H)
174 #include <ctype.h>
175 #undef LUCENE_USE_INTERNAL_CHAR_FUNCTIONS
176#elif defined(_UCS2)
177 //must be in _UCS2 to use internal char functions
178 #undef LUCENE_USE_INTERNAL_CHAR_FUNCTIONS
179 #define LUCENE_USE_INTERNAL_CHAR_FUNCTIONS
180#else
181 #error "Cannot compile in _ASCII without ctype.h"
182#endif
183
184//always include replacement, some missing tchar defines
185#include "CLucene/config/repl_tchar.h"
186
187#if defined(_CL_HAVE_ERRNO_H)
188#ifndef UNDER_CE
189 #include <errno.h>
190#endif
191#else
192 #error "Haven't implemented platforms with no errno.h"
193#endif
194
195#if defined(_CL_HAVE_FCNTL_H)
196#ifndef UNDER_CE
197 #include <fcntl.h>
198#endif
199#else
200 #error "Haven't implemented platforms with no fcntl.h"
201#endif
202
203#if defined(_CL_HAVE_WINDOWS_H)
204 #include <windows.h>
205#endif
206
207#endif //LUCENE_DISABLE_INCLUDES
208//
209////////////////////////////////////////////////////////
210
211//second inclusion of compiler.h
212//this gives CompilerXXX.h a chance to include other headers
213#include "CLucene/config/compiler.h"
214//
215////////////////////////////////////////////////////////
216
217
218////////////////////////////////////////////////////////
219// Character functions.
220// Here we decide whose character functions to use
221////////////////////////////////////////////////////////
222#if defined(LUCENE_USE_INTERNAL_CHAR_FUNCTIONS)
223 #define stringCaseFold cl_tcscasefold
224 #define stringCaseFoldCmp cl_tcscasefoldcmp
225
226 #undef _istspace
227 #undef _istdigit
228 #undef _istalnum
229 #undef _istalpha
230 #undef _totlower
231 #undef _totupper
232 #define _istalnum cl_isalnum
233 #define _istalpha cl_isletter
234 #define _istspace cl_isspace
235 #define _istdigit cl_isdigit
236 #define _totlower cl_tolower
237 #define _totupper cl_toupper
238
239 //here are some functions to help deal with utf8/ucs2 conversions
240 //lets let the user decide what mb functions to use... we provide pure utf8 ones no matter what.
241 /*#undef _mbtowc
242 #undef _mbstowcs
243 #undef _wctomb
244 #undef _wcstombs
245 #define _mbtowc lucene_mbstowc
246 #define _mbsstowcs lucene_mbstowcs
247 #define _wctomb lucene_wcto_mb
248 #define _wcstombs lucene_wcstombs*/
249#else
250 //we are using native functions
251 //here are some functions to help deal with utf8/ucs2 conversions
252 /*#define _mbtowc mbtowc
253 #define _wctomb wctomb
254 #define _mbstowcs mbstowcs
255 #define _wcstombs wcstombs*/
256
257 //we are using native character functions
258 #if defined(_ASCII)
259 #undef _istspace
260 #undef _istdigit
261 #undef _istalnum
262 #undef _istalpha
263 #undef _totlower
264 #undef _totupper
265 #define _istspace(x) isspace((unsigned char)x)
266 #define _istdigit(x) isdigit((unsigned char)x)
267 #define _istalnum(x) isalnum((unsigned char)x)
268 #define _istalpha(x) isalpha((unsigned char)x)
269 #define _totlower(x) tolower((unsigned char)x)
270 #define _totupper(x) toupper((unsigned char)x)
271 #endif
272#endif
273
274//the methods contained in gunichartables.h
275typedef unsigned long clunichar;
276bool cl_isletter(clunichar c);
277bool cl_isalnum(clunichar c);
278bool cl_isdigit(clunichar c);
279bool cl_isspace (clunichar c);
280TCHAR cl_tolower (TCHAR c);
281TCHAR cl_toupper (TCHAR c);
282
283int cl_tcscasefoldcmp(const TCHAR * dst, const TCHAR * src);
284TCHAR* cl_tcscasefold( TCHAR * str, int len=-1 );
285
286//we provide utf8 conversion functions
287size_t lucene_utf8towc (wchar_t *ret, const char *s, size_t n);
288size_t lucene_utf8towcs(wchar_t *, const char *, size_t maxslen);
289size_t lucene_wctoutf8 (char * ret, const wchar_t str);
290size_t lucene_wcstoutf8 (char *, const wchar_t *, size_t maxslen);
291size_t lucene_utf8charlen(const char *p);
292
293///a blank string...
294extern TCHAR* _LUCENE_BLANK_STRING;
295#define LUCENE_BLANK_STRING _LUCENE_BLANK_STRING
296extern char* _LUCENE_BLANK_ASTRING;
297#define LUCENE_BLANK_ASTRING _LUCENE_BLANK_ASTRING
298
299/* Converts a string into a form that is independent of case. The
300 * result will not correspond to any particular case, but can be
301 * compared for equality or ordered with the results of calling
302 * stringCaseFold() on other strings.
303 *
304 * If we did not define this elsewhere, then just convert to lower case
305 */
306#ifndef stringCaseFold
307 #define stringCaseFold _tcslwr
308#endif
309/* Compares 2 strings using case folding (if available)
310 * If we did not define this elsewhere, then just compare
311 * using normal method
312 */
313#ifndef stringCaseFoldCmp
314 #define stringCaseFoldCmp _tcsicmp
315#endif
316
317//now that all the character routines are completed, include the
318//wchar.h replacements.
319#include "CLucene/config/repl_wchar.h" //always include replacements
320
321//a replacement for _tcsdup. This uses new TCHAR[] instead of malloc, so that we can use delete[] to free
322#if defined(LUCENE_ENABLE_FILELINEINFO)
323 #define CL_FILELINE ,__FILE__,__LINE__
324 #define CL_FILELINEREF ,file,line ///<for passing the reference along to another function
325 #define CL_FILELINEREF2 ,file,line ///<for passing the reference along to another function
326 #define CL_FILELINEPARAM ,char* file,int line
327#else
328 #define CL_FILELINE
329 #define CL_FILELINEREF
330 #define CL_FILELINEREF2 ,NULL,-1
331 #define CL_FILELINEPARAM
332#endif
333
334char* lucenestrdup(const char* v CL_FILELINEPARAM);
335#if defined(_UCS2)
336 wchar_t* lucenewcsdup(const wchar_t* v CL_FILELINEPARAM);
337 #define stringDuplicate(x) lucenewcsdup(x CL_FILELINE) //don't change this... uses [] instead of malloc
338#else
339 #define stringDuplicate(x) lucenestrdup(x CL_FILELINE) //don't change this... uses [] instead of malloc
340#endif
341
342#define STRCPY_AtoA(target,src,len) strncpy(target,src,len)
343#define STRDUP_AtoA(x) lucenestrdup(x CL_FILELINE)
344
345#if defined(_UCS2)
346 #define STRDUP_WtoW(x) lucenewcsdup(x CL_FILELINE)
347 #define STRDUP_TtoT STRDUP_WtoW
348 #define STRDUP_WtoT STRDUP_WtoW
349 #define STRDUP_TtoW STRDUP_WtoW
350
351 #define STRDUP_AtoW(x) CL_NS(util)::Misc::_charToWide(x CL_FILELINE)
352 #define STRDUP_AtoT STRDUP_AtoW
353
354 #define STRDUP_WtoA(x) CL_NS(util)::Misc::_wideToChar(x CL_FILELINE)
355 #define STRDUP_TtoA STRDUP_WtoA
356
357 #define STRCPY_WtoW(target,src,len) _tcsncpy(target,src,len)
358 #define STRCPY_TtoW STRCPY_WtoW
359 #define STRCPY_WtoT STRCPY_WtoW
360 #define STRCPY_TtoT STRCPY_WtoW
361
362 #define STRCPY_AtoW(target,src,len) CL_NS(util)::Misc::_cpycharToWide(src,target,len)
363 #define STRCPY_AtoT STRCPY_AtoW
364
365 #define STRCPY_WtoA(target,src,len) CL_NS(util)::Misc::_cpywideToChar(src,target,len)
366 #define STRCPY_TtoA STRCPY_WtoA
367#else
368 #define STRDUP_AtoT STRDUP_AtoA
369 #define STRDUP_TtoA STRDUP_AtoA
370 #define STRDUP_TtoT STRDUP_AtoA
371
372 #define STRDUP_WtoT(x) xxxxxxxxxxxxxxx //not possible
373 #define STRCPY_WtoT(target,src,len) xxxxxxxxxxxxxxx //not possible
374
375 #define STRCPY_AtoT STRCPY_AtoA
376 #define STRCPY_TtoA STRCPY_AtoA
377 #define STRCPY_TtoT STRCPY_AtoA
378#endif
379
380//
381////////////////////////////////////////////////////////
382
383////////////////////////////////////////////////////////
384//namespace helper
385////////////////////////////////////////////////////////
386#if defined(_LUCENE_DONTIMPLEMENT_NS_MACROS)
387
388#elif !defined(DISABLE_NAMESPACE)
389//
390// W A R N I N G
391// -------------
392//
393// adjustments here, need to be done in
394// QTDIR/src/tools/assistant/lib/fulltextsearch/qclucene_global.h as well
395//
396# ifdef QT_NAMESPACE
397# define CL_NS_DEF(sub) namespace QT_NAMESPACE { namespace lucene{ namespace sub{
398# define CL_NS_DEF2(sub,sub2) namespace QT_NAMESPACE { namespace lucene{ namespace sub{ namespace sub2 {
399
400# define CL_NS_END }}}
401# define CL_NS_END2 }}}}
402
403# define CL_NS_USE(sub) using namespace QT_NAMESPACE::lucene::sub;
404# define CL_NS_USE2(sub,sub2) using namespace QT_NAMESPACE::lucene::sub::sub2;
405
406# define CL_NS(sub) QT_NAMESPACE::lucene::sub
407# define CL_NS2(sub,sub2) QT_NAMESPACE::lucene::sub::sub2
408# else
409# define CL_NS_DEF(sub) namespace lucene{ namespace sub{
410# define CL_NS_DEF2(sub,sub2) namespace lucene{ namespace sub{ namespace sub2 {
411
412# define CL_NS_END }}
413# define CL_NS_END2 }}}
414
415# define CL_NS_USE(sub) using namespace lucene::sub;
416# define CL_NS_USE2(sub,sub2) using namespace lucene::sub::sub2;
417
418# define CL_NS(sub) lucene::sub
419# define CL_NS2(sub,sub2) lucene::sub::sub2
420# endif
421#else
422# define CL_NS_DEF(sub)
423# define CL_NS_DEF2(sub, sub2)
424# define CL_NS_END
425# define CL_NS_END2
426# define CL_NS_USE(sub)
427# define CL_NS_USE2(sub,sub2)
428# define CL_NS(sub)
429# define CL_NS2(sub,sub2)
430#endif
431
432#if defined(LUCENE_NO_STDC_NAMESPACE)
433 //todo: haven't actually tested this on a non-stdc compliant compiler
434 #define CL_NS_STD(func) ::func
435#else
436 #define CL_NS_STD(func) std::func
437#endif
438//
439////////////////////////////////////////////////////////
440
441//
442void CLDebugBreak(); //define a debugbreak function
443
444
445////////////////////////////////////////////////////////////////
446// These are defines and functions used throughout clucene
447////////////////////////////////////////////////////////////////
448#undef _T //remove any previously defined _T - required for ppc os
449#if defined(_UCS2)
450 #define _T(x) L ## x
451#else
452 #define _T(x) x
453#endif
454
455//third inclusion of compiler.h
456//this gives CompilerXXX.h a chance to fix any of the
457//default settings
458#include "CLucene/config/compiler.h"
459
460#if defined _MSC_VER && (_MSC_VER < 1300)
461# define LUCENE_NO_STDC_NAMESPACE
462#endif
463
464//use std namespace
465#ifndef LUCENE_NO_STDC_NAMESPACE
466#ifdef _LIBCPP_VERSION
467// clang's libc++ pulls in cwchar, clucene pulls in wchar.h and the entire std
468// namespace which causes ambiguity between ::wcschar() and std::wcschar(), but
469// clucene is only using std::min() and std::max()
470using std::min;
471using std::max;
472#else
473using namespace std;
474#endif
475#endif
476
477
478////////////////////////////////////////////////////////
479//misc shortcut defines
480////////////////////////////////////////////////////////
481
482//include the headers that we need practically everywhere
483#include "CLucene/debug/error.h" //all delete/creation/mem debugging code
484#include "CLucene/debug/condition.h" //conditional debugging (like assert)
485#include "CLucene/debug/mem.h" //all delete/creation/mem debugging code
486#include "LuceneThreads.h" //lucene threading support
487
488#include "CLucene/util/Misc.h"
489#include "CLucene/util/Equators.h"
490#include "CLucene/util/VoidList.h"
491#include "CLucene/util/VoidMap.h"
492
493
494CL_NS_DEF(util)
495typedef CL_NS(util)::CLVector<TCHAR*> StringArray;
496typedef CL_NS(util)::CLVector<TCHAR*, CL_NS(util)::Deletor::tcArray > StringArrayWithDeletor;
497typedef CL_NS(util)::CLVector<const TCHAR*> StringArrayConst;
498typedef CL_NS(util)::CLVector<const TCHAR*, CL_NS(util)::Deletor::tcArray > StringArrayConstWithDeletor;
499
500typedef CL_NS(util)::CLVector<char*> AStringArray;
501typedef CL_NS(util)::CLVector<char*, CL_NS(util)::Deletor::acArray > AStringArrayWithDeletor;
502typedef CL_NS(util)::CLVector<const char*> AStringArrayConst;
503typedef CL_NS(util)::CLVector<const char*, CL_NS(util)::Deletor::acArray > AStringArrayConstWithDeletor;
504CL_NS_END
505
506//
507////////////////////////////////////////////////////////
508
509#endif // STDHEADER_H
510