Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
7.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 1998.
  5. //
  6. // File: LANG.HXX
  7. //
  8. // Contents: Language support
  9. //
  10. // Classes: CLanguage, CLangList
  11. //
  12. // History: 02-May-91 BartoszM Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <ciintf.h>
  17. #include <regacc.hxx>
  18. #include <twidhash.hxx>
  19. const MAX_REG_STR_LEN = 150;
  20. const INIT_PID_HASH_TABLE_SIZE = 257;
  21. const INIT_LANGUAGES_COUNT = 7;
  22. const USE_WB_DEFAULT_PID = 0x0001;
  23. const USE_STEMMER_DEFAULT_PID = 0x0002;
  24. const USE_NWL_DEFAULT_PID = 0x0004;
  25. const USE_DEFAULT_PID = USE_WB_DEFAULT_PID | USE_STEMMER_DEFAULT_PID | USE_NWL_DEFAULT_PID;
  26. const LANG_LOAD_WORDBREAKER = 0x1;
  27. const LANG_LOAD_STEMMER = 0x2;
  28. const LANG_LOAD_NOISE = 0x4;
  29. const LANG_LOAD_NO_STEMMER = 0x5;
  30. const LANG_LOAD_ALL = 0x7;
  31. inline BOOL LoadWB( ULONG r ) { return ( 0 != ( r & LANG_LOAD_WORDBREAKER ) ); }
  32. inline BOOL LoadST( ULONG r ) { return ( 0 != ( r & LANG_LOAD_STEMMER ) ); }
  33. inline BOOL LoadNO( ULONG r ) { return ( 0 != ( r & LANG_LOAD_NOISE ) ); }
  34. class CKeyMaker;
  35. class CStringTable;
  36. class PKeyRepository;
  37. class CLanguage;
  38. class CStringTable;
  39. //+---------------------------------------------------------------------------
  40. //
  41. // Class: CLanguage
  42. //
  43. // Purpose: Language specific object
  44. //
  45. // History: 16-Jul-91 BartoszM Created.
  46. // 25-Apr-94 KyleP Multi-language support
  47. //
  48. //----------------------------------------------------------------------------
  49. class CLanguage : public CDoubleLink
  50. {
  51. public:
  52. CLanguage( LCID locale,
  53. PROPID pid,
  54. XInterface<IWordBreaker> & xWBreak,
  55. XInterface<IStemmer> & xStemmer,
  56. XInterface<IStream> & xIStrmNoiseFile );
  57. virtual ~CLanguage();
  58. CStringTable * GetNoiseTable() { return _xNoiseTable.GetPointer(); }
  59. IWordBreaker * GetWordBreaker() { return _xWBreak.GetPointer(); }
  60. IStemmer * GetStemmer() { return _xStemmer.GetPointer(); }
  61. LCID Locale() const { return _locale; }
  62. BOOL IsLocale( LCID locale ) const { return( _locale == locale ); }
  63. BOOL IsPid( PROPID pid ) const { return( _pid == pid ); }
  64. BOOL IsZombie() const { return _zombie; }
  65. void Zombify() { _zombie = TRUE; }
  66. ULONG LastUsed() const { return _ulLastUsed; }
  67. void SetLastUsed( ULONG dwTick ) { _ulLastUsed = dwTick; }
  68. private:
  69. XPtr<CStringTable> _xNoiseTable;
  70. XInterface<IWordBreaker> _xWBreak;
  71. XInterface<IStemmer> _xStemmer;
  72. XInterface<IStream> _xIStrmNoiseFile;
  73. ULONG _ulLastUsed;
  74. LCID _locale;
  75. PROPID _pid;
  76. BOOL _zombie;
  77. };
  78. //+---------------------------------------------------------------------------
  79. //
  80. // Class: CLangDoubleList
  81. //
  82. // Purpose: Doubly linked list of language objects
  83. //
  84. // History: 14-Sep-91 SitaramR Created.
  85. //
  86. //----------------------------------------------------------------------------
  87. class CLangDoubleList : public CDoubleList
  88. {
  89. public:
  90. CLanguage *Pop() { return (CLanguage *) _Pop(); }
  91. void Push (CLanguage * pLang) { _Push( pLang ); }
  92. void Queue (CLanguage * pLang) { _Queue( pLang ); }
  93. };
  94. //+---------------------------------------------------------------------------
  95. //
  96. // Class: CLangIter
  97. //
  98. // Purpose: Iterator over language objects
  99. //
  100. // History: 14-Sep-91 SitaramR Created.
  101. //
  102. //----------------------------------------------------------------------------
  103. class CLangIter : public CForwardIter
  104. {
  105. public:
  106. CLangIter ( CLangDoubleList& list ) : CForwardIter( list ) {}
  107. CLanguage * operator->() { return (CLanguage *) _pLinkCur; }
  108. CLanguage * GetLang() { return (CLanguage *) _pLinkCur; }
  109. };
  110. //+---------------------------------------------------------------------------
  111. //
  112. // Class: CLangPidStateInfo
  113. //
  114. // Purpose: Maintains state specific information for CLangList::BorrowLang
  115. //
  116. // History: 2-27-97 MohamedN Created
  117. //
  118. //----------------------------------------------------------------------------
  119. class CLangPidStateInfo
  120. {
  121. public:
  122. CLangPidStateInfo() : _pidToUse(0), _langIndex(0)
  123. {
  124. // trivial consturctor.
  125. }
  126. void SetPidFlags(unsigned pidFlag) { _pidToUse |= pidFlag; }
  127. unsigned GetPidFlags() { return _pidToUse; }
  128. BOOL IsPidFlagSet( unsigned pidToUse ) { return pidToUse & _pidToUse; }
  129. void SetLangIndex(unsigned langIndex) { _langIndex = langIndex; }
  130. unsigned GetLangIndex() { return _langIndex; }
  131. private:
  132. unsigned _pidToUse;
  133. unsigned _langIndex;
  134. };
  135. //+---------------------------------------------------------------------------
  136. //
  137. // Class: CDefaultPidHash
  138. //
  139. // Purpose: Maintains a cache of default pids per langid
  140. //
  141. // History: 2-28-97 MohamedN Created
  142. //
  143. //----------------------------------------------------------------------------
  144. class CDefaultPidHash
  145. {
  146. public:
  147. CDefaultPidHash() : _aHashPidTables(INIT_LANGUAGES_COUNT), _aLangId(INIT_LANGUAGES_COUNT), _langIdCount(0)
  148. {
  149. // trivial constructor
  150. }
  151. BOOL LokLookupOrAddLang( LANGID langid, CLangPidStateInfo & stateInfo );
  152. BOOL LokIsUseDefaultPid( PROPID pid, unsigned index );
  153. void LokAddDefaultPid( PROPID pid, unsigned index );
  154. private:
  155. typedef TWidHashTable<CWidHashEntry> CPidHash;
  156. CDynArray<CPidHash> _aHashPidTables;
  157. CDynArrayInPlace<LANGID> _aLangId;
  158. unsigned _langIdCount;
  159. };
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Class: CLangList
  163. //
  164. // Purpose: List of language objects
  165. //
  166. // History: 02-May-91 BartoszM Created.
  167. // 05-June-91 t-WadeR changed to use CKeyMaker
  168. //
  169. //----------------------------------------------------------------------------
  170. class CLangList
  171. {
  172. public:
  173. CLangList( ICiCLangRes * pICiCLangRes, ULONG ulMaxIdle = 300 );
  174. ~CLangList();
  175. CLanguage* BorrowLang ( LCID locale, PROPID pid = 0, ULONG resources = LANG_LOAD_ALL );
  176. void ReturnLang( CLanguage *lang );
  177. void InvalidateLangResources();
  178. void Shutdown();
  179. BOOL Supports( CLanguage const * pLang, PROPID pid, LCID lcid );
  180. private:
  181. CLanguage *FindLangAndActivate( LCID locale, PROPID pid );
  182. CLanguage * CreateLang ( LANGID langId, PROPID pid, CLangPidStateInfo & stateInfo, CLanguage const * pDup = 0, ULONG resources = LANG_LOAD_ALL );
  183. IWordBreaker * GetWordBreaker ( LANGID langid, PROPID pid, CLangPidStateInfo & stateInfo, BOOL fCreateDefault );
  184. IStemmer * GetStemmer ( LANGID langid, PROPID pid, CLangPidStateInfo & stateInfo );
  185. IStream * GetNoiseWordList ( LANGID langid, PROPID pid, CLangPidStateInfo & stateInfo );
  186. CMutexSem _mtxList; // serialization for list manipulation
  187. CMutexSem _mtxCreate; // serialization for language creation
  188. CLangDoubleList _langsInUse; // Linked list of languages in use
  189. CLangDoubleList _langsAvailable; // Linked list of languages available
  190. XInterface<ICiCLangRes> _xICiCLangRes;
  191. CDefaultPidHash _pidHash;
  192. ULONG _ulMaxIdle; // Time (in ms Ticks) a language object can sit idle before deletion
  193. };