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#ifndef _lucene_util_StringIntern_H
8#define _lucene_util_StringIntern_H
9
10#if defined(_LUCENE_PRAGMA_ONCE)
11# pragma once
12#endif
13
14#include "VoidMap.h"
15CL_NS_DEF(util)
16typedef CL_NS(util)::CLHashMap<const TCHAR*,int,CL_NS(util)::Compare::TChar,CL_NS(util)::Equals::TChar,CL_NS(util)::Deletor::tcArray, CL_NS(util)::Deletor::DummyInt32 > __wcsintrntype;
17typedef CL_NS(util)::CLHashMap<const char*,int,CL_NS(util)::Compare::Char,CL_NS(util)::Equals::Char,CL_NS(util)::Deletor::acArray, CL_NS(util)::Deletor::DummyInt32 > __strintrntype;
18
19 /** Functions for intern'ing strings. This
20 * is a process of pooling strings thus using less memory,
21 * and furthermore allows intern'd strings to be directly
22 * compared:
23 * string1==string2, rather than _tcscmp(string1,string2)
24 */
25 class CLStringIntern{
26 static __wcsintrntype stringPool;
27 static __strintrntype stringaPool;
28 STATIC_DEFINE_MUTEX(THIS_LOCK)
29 public:
30 /**
31 * Internalise the specified string.
32 * \return Returns a pointer to the internalised string
33 */
34 static const char* internA(const char* str CL_FILELINEPARAM);
35 /**
36 * Uninternalise the specified string. Decreases
37 * the reference count and frees the string if
38 * reference count is zero
39 * \returns true if string was destroyed, otherwise false
40 */
41 static bool uninternA(const char* str);
42
43 /**
44 * Internalise the specified string.
45 * \return Returns a pointer to the internalised string
46 */
47 static const TCHAR* intern(const TCHAR* str CL_FILELINEPARAM);
48
49 /**
50 * Uninternalise the specified string. Decreases
51 * the reference count and frees the string if
52 * reference count is zero
53 * \returns true if string was destroyed, otherwise false
54 */
55 static bool unintern(const TCHAR* str);
56
57 static void shutdown();
58 };
59
60CL_NS_END
61#endif
62