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.

414 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: Xpr.hxx
  7. //
  8. // Contents: Internal expression classes
  9. //
  10. // Classes: CNodeXpr
  11. // CXprPropertyValue
  12. // CXprPropertyRelation
  13. //
  14. // History: 10-Sep-91 KyleP Created
  15. //
  16. // Notes: Implementation for classes defined in this file will be
  17. // found with either the content index or the query engine.
  18. //
  19. //----------------------------------------------------------------------------
  20. #pragma once
  21. #include <strategy.hxx>
  22. // ..\Inc includes:
  23. #include <pvalxpr.hxx>
  24. class CNodeXpr;
  25. class CCI;
  26. //+---------------------------------------------------------------------------
  27. //
  28. // Class: CXpr (xp)
  29. //
  30. // Purpose: Base (internal) expression class.
  31. //
  32. // Interface:
  33. //
  34. // History: 11-Sep-91 KyleP Created.
  35. // 23-Jun-92 MikeHew Added Weighting
  36. // 05-Sep-92 MikeHew Added Serialization
  37. //
  38. // Notes: Restrictions are converted to expressions during
  39. // normalization. Expressions are aware of issues such as
  40. // what indexes can optimize their evaluation and can
  41. // be evaluated with respect to a particular object.
  42. //
  43. // In contrast, restrictions are just a description of an
  44. // expression.
  45. //
  46. // This class is shared with the content index. Some methods
  47. // only make sense for expressions which are capable of being
  48. // evaluated by the content index. Other methods only apply
  49. // to evaluation in the Query engine.
  50. //
  51. //----------------------------------------------------------------------------
  52. class CXpr : public CValueXpr
  53. {
  54. public:
  55. enum NodeType
  56. {
  57. NTAnd,
  58. NTOr,
  59. NTNot,
  60. NTAndNot,
  61. NTVector,
  62. NTScope,
  63. NTProperty,
  64. NTRegex,
  65. NTPropertyValue,
  66. NTNull
  67. };
  68. //
  69. // Construction-related methods
  70. //
  71. inline CXpr( NodeType type, ULONG ulWeight = MAX_QUERY_RANK );
  72. virtual ~CXpr();
  73. virtual CXpr * Clone();
  74. //
  75. // Index-related methods
  76. //
  77. virtual void SelectIndexing( CIndexStrategy & strategy );
  78. virtual BOOL IsMatch( CRetriever & obj );
  79. //
  80. // Match quality methods
  81. //
  82. virtual ULONG HitCount( CRetriever & );
  83. virtual LONG Rank( CRetriever & );
  84. //
  85. // Value-related methods
  86. //
  87. virtual GetValueResult GetValue( CRetriever & obj,
  88. PROPVARIANT * p,
  89. ULONG * pcb );
  90. virtual ULONG ValueType() const;
  91. //
  92. // Node-related methods
  93. //
  94. NodeType NType() const;
  95. virtual BOOL IsLeaf() const;
  96. inline CNodeXpr* CastToNode();
  97. ULONG GetWeight() { return _weight; }
  98. void SetWeight(ULONG wt) { _weight = wt; }
  99. protected:
  100. NodeType _type;
  101. ULONG _weight;
  102. };
  103. DECLARE_SMARTP( Xpr );
  104. //+---------------------------------------------------------------------------
  105. //
  106. // Member: CXpr::NType, public
  107. //
  108. // Returns: Type of expression node
  109. //
  110. // History: 27-Sep-91 BartoszM Created.
  111. //
  112. //----------------------------------------------------------------------------
  113. inline CXpr::NodeType CXpr::NType() const
  114. {
  115. return _type;
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Member: CXpr::CastToNode, public
  120. //
  121. // Synopsis: "Safe" cast down to CNodeXpr
  122. //
  123. // Requires: Type to be one of CNodeXpr types
  124. //
  125. // History: 27-Sep-91 BartoszM Created.
  126. //
  127. //----------------------------------------------------------------------------
  128. inline CNodeXpr* CXpr::CastToNode()
  129. {
  130. Assert ( _type == NTAnd ||
  131. _type == NTOr ||
  132. _type == NTAndNot ||
  133. _type == NTVector );
  134. return (CNodeXpr*) this;
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Member: CXpr::~CXpr, public
  139. //
  140. // Synopsis: Destroys an expression.
  141. //
  142. // History: 23-Sep-91 KyleP Created.
  143. //
  144. //----------------------------------------------------------------------------
  145. inline CXpr::~CXpr()
  146. {}
  147. inline void CXpr::SelectIndexing( CIndexStrategy & strategy )
  148. {
  149. strategy.SetUnknownBounds();
  150. }
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Class: CNodeXpr
  154. //
  155. // Purpose: Node with child expressions (Boolean, Phrase, etc...)
  156. //
  157. // Interface:
  158. //
  159. // History: 11-Sep-91 BartoszM Created.
  160. // 05-Sep-92 MikeHew Added Serialization
  161. //
  162. // Notes: CNodeXpr does not guarantee the position of nodes across
  163. // calls to RemoveChild.
  164. //
  165. //----------------------------------------------------------------------------
  166. class CNodeXpr : public CXpr
  167. {
  168. public:
  169. CNodeXpr( CXpr::NodeType type, unsigned cInit = 2 );
  170. CNodeXpr( CNodeXpr & nxpr );
  171. virtual ~CNodeXpr();
  172. virtual CXpr * Clone();
  173. //
  174. // Index-related methods
  175. //
  176. virtual void SelectIndexing( CIndexStrategy & strategy );
  177. virtual BOOL IsMatch( CRetriever & obj );
  178. //
  179. // Match quality methods
  180. //
  181. virtual ULONG HitCount( CRetriever & );
  182. virtual LONG Rank( CRetriever & );
  183. //
  184. // Node-specific methods
  185. //
  186. BOOL IsLeaf() const;
  187. void AddChild ( CXpr* child );
  188. inline void SetChild ( CXpr* child, unsigned iPos );
  189. inline CXpr* GetChild ( unsigned iPos );
  190. CXpr* RemoveChild ( unsigned iPos );
  191. unsigned Count() { return _cXpr; }
  192. private:
  193. unsigned _size;
  194. unsigned _cXpr;
  195. CXpr * * _aXpr;
  196. };
  197. //+---------------------------------------------------------------------------
  198. //
  199. // Class: CVectorXpr
  200. //
  201. // Purpose: Extended from node expression to support weighted vectors.
  202. //
  203. // History: 24-Jul-92 KyleP Created.
  204. // 05-Sep-92 MikeHew Added Serialization
  205. //
  206. //----------------------------------------------------------------------------
  207. class CVectorXpr : public CNodeXpr
  208. {
  209. public:
  210. CVectorXpr( unsigned cInit, ULONG RankMethod );
  211. inline ULONG GetRankMethod() { return( _ulRankMethod ); }
  212. private:
  213. ULONG _ulRankMethod;
  214. };
  215. //+-------------------------------------------------------------------------
  216. //
  217. // Class: CXprPropertyRelation (pv)
  218. //
  219. // Purpose: Performs relational operations on properties
  220. //
  221. // Interface:
  222. //
  223. // History: 11-Oct-91 KyleP Created
  224. //
  225. //--------------------------------------------------------------------------
  226. class CXprPropertyRelation : public CXpr
  227. {
  228. public:
  229. CXprPropertyRelation( PROPID pid,
  230. ULONG relop,
  231. CStorageVariant const & prval,
  232. CRestriction * prstContentHelper );
  233. CXprPropertyRelation( CXprPropertyRelation & propxpr );
  234. virtual ~CXprPropertyRelation();
  235. virtual CXpr * Clone();
  236. virtual void SelectIndexing( CIndexStrategy & strategy );
  237. virtual BOOL IsMatch( CRetriever & obj );
  238. private:
  239. CXprPropertyValue _xpval; // Gets value from filesystem
  240. BOOL (* _relop) (PROPVARIANT const &,
  241. PROPVARIANT const &); // Relational operator
  242. CStorageVariant _cval; // Constant value
  243. ULONG _rel; // Relation (used if type
  244. // mismatch)
  245. XPtr<CRestriction> _xrstContentHelper; // Content helper.
  246. };
  247. //+---------------------------------------------------------------------------
  248. //
  249. // Member: CXpr::CXpr, public
  250. //
  251. // Synopsis:
  252. //
  253. // Arguments: [type] -- type of expression
  254. //
  255. // History: 27-Sep-91 BartoszM Created.
  256. // 23-Jun-92 MikeHew Added Weighting.
  257. //
  258. //----------------------------------------------------------------------------
  259. CXpr::CXpr(NodeType type, ULONG ulWeight ) :
  260. _type(type), _weight(ulWeight)
  261. {
  262. END_CONSTRUCTION( CXpr );
  263. }
  264. //+---------------------------------------------------------------------------
  265. //
  266. // Member: CNodeXpr::SetChild, public
  267. //
  268. // Synopsis: Set the child expression at a specific position.
  269. //
  270. // Arguments: [child] -- New child node.
  271. // [iPos] -- Position of node.
  272. //
  273. // Requires: [iPos] is a valid index.
  274. //
  275. // History: 12-Dec-91 KyleP Created.
  276. //
  277. // Notes: The position of an expression within the node is not
  278. // guaranteed to be constant over all operations on the node.
  279. // The only safe way to use this function is after a call to
  280. // GetChild.
  281. //
  282. //----------------------------------------------------------------------------
  283. inline void CNodeXpr::SetChild ( CXpr* child, unsigned iPos )
  284. {
  285. Win4Assert ( iPos <= _cXpr );
  286. _aXpr[iPos] = child;
  287. }
  288. //+---------------------------------------------------------------------------
  289. //
  290. // Member: CNodeXpr::GetChild, public
  291. //
  292. // Synopsis: Retrieves a child expression without removing it from the node.
  293. //
  294. // Arguments: [iPos] -- Position of expression to retrieve.
  295. //
  296. // Requires: [iPos] is a valid index.
  297. //
  298. // Returns: A pointer the the expression at [iPos].
  299. //
  300. // History: 12-Dec-91 KyleP Created.
  301. //
  302. // Notes: You are just 'borrowing' a node when retrieving it with
  303. // this method. Do not delete the borrowed node!
  304. //
  305. //----------------------------------------------------------------------------
  306. inline CXpr* CNodeXpr::GetChild ( unsigned iPos )
  307. {
  308. Win4Assert ( iPos <= _cXpr );
  309. return _aXpr[iPos];
  310. }
  311. #ifdef DOCGEN
  312. //+---------------------------------------------------------------------------
  313. //
  314. // Member: CXpr::NType, public
  315. //
  316. // Returns: Type type of this particular node (AND, CONTENT, etc.)
  317. //
  318. // History: 23-Sep-91 KyleP Created.
  319. //
  320. //----------------------------------------------------------------------------
  321. NodeType CXpr::NType() const
  322. {}
  323. #endif /* DOCGEN */