Source code of Windows XP (NT5)
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.

282 lines
7.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998.
  5. //
  6. // File: cdoc.hxx
  7. //
  8. // Contents: a radically stripped down version of the document class
  9. // that gets rid of the notion of paragragph and maintains only
  10. // information relative to the stream
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. #include <ci64.hxx>
  15. const ULONG DISPLAY_SCRIPT_NONE = 0;
  16. const ULONG DISPLAY_SCRIPT_KNOWN_FILTER = 1;
  17. const ULONG DISPLAY_SCRIPT_ALL = 2;
  18. const WCHAR UNICODE_PARAGRAPH_SEPARATOR=0x2029;
  19. const unsigned cTab = 8;
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: ChunkOffset
  23. //
  24. // Purpose: marker that stores the position of a chunk within a buffer or
  25. // stream. Used to map the memory-mapped file into which the
  26. // document file is read
  27. //
  28. //--------------------------------------------------------------------------
  29. class ChunkOffset
  30. {
  31. public:
  32. void SetChunkId (ULONG id) { _idChunk = id; }
  33. void SetOffset (ULONG off) { _offset = off; }
  34. ULONG ChunkId () const { return _idChunk; }
  35. ULONG Offset () const { return _offset; }
  36. private:
  37. ULONG _idChunk;
  38. ULONG _offset;
  39. };
  40. //+-------------------------------------------------------------------------
  41. //
  42. // Class: Position
  43. //
  44. // Purpose: marker for a single "word" inside the stream or buffer. Stores
  45. // the beginning offset in the buffer and the number of
  46. // characters that follow
  47. //
  48. //--------------------------------------------------------------------------
  49. class Position
  50. {
  51. public:
  52. Position():_length(0),_start(0) {}
  53. Position( ULONG start, ULONG length):_start(start),_length(length) {}
  54. ULONG GetBegOffset () const { return _start; }
  55. ULONG GetEndOffset () const { return _start+_length; }
  56. ULONG GetLength () const { return _length; }
  57. void SetLen (ULONG length) { _length=length; }
  58. void SetStart(ULONG start ) { _start = start; }
  59. BOOL IsNullPosition() const { return (_start == 0) && (_length == 0); }
  60. private:
  61. ULONG _start;
  62. ULONG _length;
  63. };
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Class: Hit
  67. //
  68. // Purpose: Stores a set of positions which determine a query "hit".
  69. //--------------------------------------------------------------------------
  70. class Hit
  71. {
  72. friend class CExtractedHit;
  73. public:
  74. Hit( const Position * aPos, unsigned cPos );
  75. ~Hit();
  76. unsigned GetPositionCount() const { return _cPos; }
  77. const Position& GetPos (int i) const
  78. {
  79. Win4Assert ( i < int(_cPos) );
  80. return _aPos[i];
  81. }
  82. void Sort();
  83. BOOL IsNullHit();
  84. private:
  85. Position * _aPos;
  86. unsigned _cPos;
  87. };
  88. //+-------------------------------------------------------------------------
  89. //
  90. // Member: Hit::IsNullHit, public inline
  91. //
  92. // Synopsis: returns TRUE if the hit consists solely of null positions, or has
  93. // 0 positions. Returns FALSE otherwise
  94. //--------------------------------------------------------------------------
  95. inline BOOL Hit::IsNullHit()
  96. {
  97. for (int i=0;i < (int) _cPos;i++)
  98. {
  99. if (!_aPos[i].IsNullPosition())
  100. return FALSE;
  101. }
  102. return TRUE;
  103. }
  104. //+-------------------------------------------------------------------------
  105. //
  106. // Class: CDocument
  107. //
  108. // Purpose: Used to obtain and store information about query hits in
  109. // the document.
  110. //
  111. //--------------------------------------------------------------------------
  112. class CDocument
  113. {
  114. friend class HitIter;
  115. public:
  116. enum DocConst { BUF_SIZE = 4096 };
  117. CDocument( WCHAR * filename,
  118. ULONG rank,
  119. ISearchQueryHits & rSearch,
  120. DWORD cmsReadTimeout,
  121. CReleasableLock & lockSingleThreadedFilter,
  122. CEmptyPropertyList & propertyList,
  123. ULONG ulDisplayScript );
  124. ~CDocument();
  125. WCHAR* GetInternalBuffer () const
  126. { return _xBuffer.GetPointer(); }
  127. WCHAR* GetInternalBufferEnd () const { return _bufEnd; }
  128. const WCHAR* GetPointerToOffset(long offset);
  129. WCHAR* GetWritablePointerToOffset(long offset);
  130. ULONG GetEOFOffset()
  131. { return CiPtrToUlong( _bufEnd - GetInternalBuffer() ); }
  132. const WCHAR* GetFilename() const { return _filename;}
  133. unsigned GetHitCount() const { return _cHit; }
  134. ULONG GetRank () const { return _rank; }
  135. private:
  136. void AllocBuffer();
  137. BOOL BindToFilter();
  138. void ReadFile();
  139. void FreeHits();
  140. Position RegionToPos( FILTERREGION& region );
  141. DWORD _cmsReadTimeout;
  142. CReleasableLock & _lockSingleThreadedFilter;
  143. //
  144. // used when converting region to position - saves a re-scan of the entire array
  145. //
  146. int _iChunkHint;
  147. WCHAR* _filename;
  148. ULONG _rank;
  149. CDynArrayInPlace<Hit *> _aHit;
  150. unsigned _cHit;
  151. XInterface<IFilter> _xFilter;
  152. ISearchQueryHits& _rSearch;
  153. XArray<WCHAR> _xBuffer;
  154. WCHAR * _bufEnd;
  155. int _chunkCount;
  156. CDynArrayInPlace<ChunkOffset> _chunk;
  157. };
  158. //+-------------------------------------------------------------------------
  159. //
  160. // Class: HitIter
  161. //
  162. // Purpose: Hit Iterator
  163. //
  164. //--------------------------------------------------------------------------
  165. class HitIter
  166. {
  167. public:
  168. HitIter () : _pDoc (0) {}
  169. void Init (const CDocument* pDoc)
  170. {
  171. _pDoc = pDoc;
  172. _cHit = pDoc->GetHitCount();
  173. _iHit = 0;
  174. _iRestoreHit = 0;
  175. }
  176. BOOL FirstHit();
  177. BOOL PrevHit();
  178. BOOL NextHit();
  179. void SaveHit() { _iRestoreHit = _iHit; }
  180. void RestoreHit() { _iHit = _iRestoreHit; }
  181. BOOL isLastHit() { return(_cHit == 0 || _iHit == _cHit - 1); }
  182. BOOL isFirstHit() { return(_iHit == 0); }
  183. int GetPositionCount () const;
  184. Position GetPosition ( int i ) const;
  185. Hit& GetHit() { return *_pDoc->_aHit[_iHit]; }
  186. private:
  187. const CDocument* _pDoc;
  188. unsigned _cHit;
  189. unsigned _iHit;
  190. unsigned _iRestoreHit;
  191. };
  192. inline BOOL HitIter::PrevHit()
  193. {
  194. if ( _cHit!= 0 && _iHit > 0 )
  195. {
  196. _iHit--;
  197. return TRUE;
  198. }
  199. return FALSE;
  200. }
  201. inline BOOL HitIter::FirstHit()
  202. {
  203. if ( _cHit != 0 )
  204. {
  205. _iHit = 0;
  206. return TRUE;
  207. }
  208. return FALSE;
  209. }
  210. inline BOOL HitIter::NextHit()
  211. {
  212. if ( _cHit != 0 && _iHit + 1 < _cHit)
  213. {
  214. _iHit++;
  215. return TRUE;
  216. }
  217. return FALSE;
  218. }