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.

251 lines
6.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991-1992, Microsoft Corporation.
  4. //
  5. // File: RECOGNIZ.HXX
  6. //
  7. // Contents: Expression to cursor converter
  8. //
  9. // Classes: CScanRst
  10. //
  11. // History: 16-Sep-94 BartoszM Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #pragma once
  15. class CRestriction;
  16. class CNodeRestriction;
  17. enum DetectorType
  18. {
  19. DetSingleKey,
  20. DetRange,
  21. DetPrefix
  22. };
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Class: CDetector
  26. //
  27. // Purpose: The detector of keys
  28. //
  29. // History: 01-Oct-94 BartoszM Created
  30. //
  31. //----------------------------------------------------------------------------
  32. class CDetector
  33. {
  34. public:
  35. CDetector ( const CKey& key ) : _key(key) {}
  36. virtual ~CDetector() {}
  37. virtual BOOL Match ( const CKeyBuf& key ) const = 0;
  38. virtual DetectorType Type() const = 0;
  39. const CKey* GetKey () const { return &_key; }
  40. virtual const CKey* GetSecondKey () const { return 0; }
  41. BOOL PidMatch ( PROPID pid ) const
  42. {
  43. return _key.Pid() == pidAll || _key.Pid() == pid;
  44. }
  45. protected:
  46. const CKey& _key;
  47. };
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Class: CKeyDetector
  51. //
  52. // Purpose: Detects a single key
  53. //
  54. // History: 01-Oct-94 BartoszM Created
  55. //
  56. //----------------------------------------------------------------------------
  57. class CKeyDetector: public CDetector
  58. {
  59. public:
  60. CKeyDetector ( const CKey& key ) : CDetector (key) { }
  61. BOOL Match ( const CKeyBuf& key ) const;
  62. DetectorType Type () const;
  63. private:
  64. };
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Class: CKeyRangeDetector
  68. //
  69. // Purpose: Detects a range of keys
  70. //
  71. // History: 01-Oct-94 BartoszM Created
  72. //
  73. //----------------------------------------------------------------------------
  74. class CKeyRangeDetector: public CDetector
  75. {
  76. public:
  77. CKeyRangeDetector ( const CKey& keyStart, const CKey& keyEnd )
  78. : CDetector (keyStart), _keyEnd(keyEnd)
  79. { }
  80. BOOL Match ( const CKeyBuf& key ) const;
  81. DetectorType Type () const;
  82. const CKey* GetSecondKey () const { return &_keyEnd; }
  83. private:
  84. const CKey& _keyEnd;
  85. };
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Class: CKeyPrefixDetector
  89. //
  90. // Purpose: Detects a range of keys sharing the same prefix
  91. //
  92. // History: 01-Oct-94 BartoszM Created
  93. //
  94. //----------------------------------------------------------------------------
  95. class CKeyPrefixDetector: public CDetector
  96. {
  97. public:
  98. CKeyPrefixDetector ( const CKey& key )
  99. : CDetector (key)
  100. {
  101. _keyEnd.FillMax (key);
  102. }
  103. BOOL Match ( const CKeyBuf& key ) const;
  104. DetectorType Type () const;
  105. private:
  106. CKey _keyEnd;
  107. };
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Class: CRegionHit
  111. //
  112. // Purpose: Combine filter region with occurrence
  113. //
  114. // History: 06-Oct-94 BartoszM Created
  115. //
  116. //----------------------------------------------------------------------------
  117. class CRegionHit: public CDoubleLink
  118. {
  119. public:
  120. CRegionHit ( const FILTERREGION& region, OCCURRENCE occ )
  121. : _region(region), _occ(occ)
  122. {}
  123. const FILTERREGION& Region () const { return _region; }
  124. OCCURRENCE Occurrence () const { return _occ; }
  125. // int Compare ( const CRegionHit& reg ) const;
  126. private:
  127. FILTERREGION _region;
  128. OCCURRENCE _occ;
  129. };
  130. class CRegionList: public CDoubleList
  131. {
  132. public:
  133. ~CRegionList();
  134. void Insert ( CRegionHit* pHit );
  135. };
  136. // class CForFooIter : public CForwardIter
  137. // {
  138. // public:
  139. //
  140. // CForFooIter ( CFooList& list ) : CForwardIter(list) {}
  141. //
  142. // CFoo* operator->() { return (CFoo*) _pLinkCur; }
  143. // CFoo* GetFoo() { return (CFoo*) _pLinkCur; }
  144. // };
  145. class CRegionIter: public CForwardIter
  146. {
  147. public:
  148. CRegionIter (CRegionList& list): CForwardIter(list) {}
  149. CRegionHit* operator->() { return (CRegionHit*) _pLinkCur; }
  150. CRegionHit* GetRegionHit () { return (CRegionHit*) _pLinkCur; }
  151. };
  152. class CRegionBackIter: public CBackwardIter
  153. {
  154. public:
  155. CRegionBackIter (CRegionList& list): CBackwardIter(list) {}
  156. CRegionHit* operator->() { return (CRegionHit*) _pLinkCur; }
  157. CRegionHit* GetRegionHit () { return (CRegionHit*) _pLinkCur; }
  158. };
  159. //+-------------------------------------------------------------------------
  160. //
  161. // Function: Compare
  162. //
  163. // Synopsis: Compares filter regions
  164. //
  165. // History: 29-Sep-94 BartoszM Created.
  166. //
  167. //--------------------------------------------------------------------------
  168. inline BOOL Compare ( const FILTERREGION& reg1, const FILTERREGION& reg2 )
  169. {
  170. if (reg1.idChunk == reg2.idChunk)
  171. {
  172. return ( reg1.cwcStart - reg2.cwcStart );
  173. }
  174. else
  175. return reg1.idChunk - reg2.idChunk;
  176. }
  177. DECL_DYNSTACK(CDetectorArray, CDetector);
  178. //+---------------------------------------------------------------------------
  179. //
  180. // Class: CRecognizer
  181. //
  182. // Purpose: The recognizer of keys
  183. //
  184. // History: 30-Sep-94 BartoszM Created
  185. //
  186. //----------------------------------------------------------------------------
  187. class CRecognizer: INHERIT_UNWIND
  188. {
  189. DECLARE_UNWIND
  190. public:
  191. CRecognizer ();
  192. ~CRecognizer ();
  193. void MakeDetectors ( const CRestriction* pRst );
  194. int Count () const { return _aDetector.Count(); }
  195. BOOL Match ( const CKeyBuf& key );
  196. void Record ( const FILTERREGION& region, OCCURRENCE occ );
  197. CRegionList& GetRegionList ( int i ) const
  198. {
  199. Win4Assert ( i >= 0 );
  200. Win4Assert ( i < Count() );
  201. return _aRegionList [i];
  202. }
  203. int FindDet (DetectorType type, const CKey* pKey, const CKey* pKey2 = 0) const;
  204. private:
  205. void AddKey ( const CKey* pKey );
  206. void AddRange ( const CKey* pKeyStart, const CKey* pKeyEnd );
  207. void AddKeyArray ( const CKeyArray& keyArray, BOOL isRange );
  208. void AddPrefix ( const CKey* pKey );
  209. void ScanRst ( const CRestriction* pRst );
  210. void ScanNode ( const CNodeRestriction* pRst );
  211. void ScanLeaf ( const CRestriction* pRst );
  212. int _iDet;
  213. CDetectorArray _aDetector;
  214. // array of lists corresponding to detectors
  215. CRegionList* _aRegionList;
  216. };