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.

740 lines
16 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1991 - 2000.
  5. //
  6. // File: IRest.hxx
  7. //
  8. // Contents: Internal query restrictions
  9. //
  10. // Classes: CInternalPropertyRestriction
  11. // COccRestriction
  12. // CWordRestriction
  13. // CSynRestriction
  14. // CRangeRestriction
  15. // CUnfilteredRestriction
  16. // CScopeRestriction
  17. // CPhraseRestriction
  18. //
  19. // History: 19-Sep-91 BartoszM Implemented.
  20. // 30-Nov-92 KyleP Removed CPhraseXpr
  21. //
  22. //----------------------------------------------------------------------------
  23. #pragma once
  24. DECLARE_SMARTP( Restriction )
  25. DECLARE_SMARTP( NodeRestriction )
  26. DECLARE_SMARTP( NotRestriction )
  27. #define INIT_PHRASE_WORDS 4
  28. #if CIDBG == 1
  29. void Display( CRestriction * pxp, int indent, ULONG infolevel );
  30. #endif // DBG == 1
  31. //
  32. // Internal node types
  33. //
  34. int const RTWord = 0xffffffff;
  35. int const RTSynonym = 0xfffffffe;
  36. int const RTPhrase = 0xfffffffd;
  37. int const RTRange = 0xfffffffc;
  38. int const RTIndexedProp = 0xfffffffb;
  39. int const RTInternalProp = 0xfffffffa;
  40. const ULONG RTScope = 9; // moved from querys.idl
  41. // This is a helper function for unmarshalling a wide string from a stream.
  42. // This can't be in memdeser since it calls CoTaskMemAlloc, which isn't
  43. // available in ntdll.dll
  44. WCHAR * UnMarshallWideString( PDeSerStream & stm );
  45. WCHAR * UnMarshallWideStringNew( PDeSerStream & stm );
  46. BOOL ValidateScopeRestriction( CRestriction * prestScope );
  47. //+-------------------------------------------------------------------------
  48. //
  49. // Class: CInternalPropertyRestriction
  50. //
  51. // Purpose: Property <relop> constant restriction
  52. //
  53. // History: 21-Jan-92 KyleP Created
  54. //
  55. // Notes: Identical to CPropertyRestriction except the Property
  56. // name string is replaced with a pid.
  57. //
  58. //--------------------------------------------------------------------------
  59. class CInternalPropertyRestriction : public CRestriction
  60. {
  61. public:
  62. //
  63. // Constructors
  64. //
  65. inline CInternalPropertyRestriction();
  66. CInternalPropertyRestriction( ULONG relop,
  67. PROPID pid,
  68. CStorageVariant const & prval,
  69. CRestriction * pcrstHelper = 0 );
  70. CInternalPropertyRestriction( CInternalPropertyRestriction const & intPropRst );
  71. CInternalPropertyRestriction *Clone() const;
  72. //
  73. // Destructor
  74. //
  75. ~CInternalPropertyRestriction();
  76. //
  77. // Validity check
  78. //
  79. inline BOOL IsValid() const;
  80. //
  81. // Serialization
  82. //
  83. void Marshall( PSerStream & stm ) const;
  84. CInternalPropertyRestriction( ULONG ulWeight, PDeSerStream & stm );
  85. //
  86. // Member variable access
  87. //
  88. inline void SetRelation( ULONG relop );
  89. inline ULONG Relation() const;
  90. inline void SetPid( PROPID pid );
  91. inline PROPID Pid() const;
  92. inline void SetValue( double dValue );
  93. inline void SetValue( ULONG ulValue );
  94. inline void SetValue( LONG lValue );
  95. inline void SetValue( BOOL fValue );
  96. inline void SetValue( FILETIME ftValue );
  97. void SetValue( BLOB & bValue );
  98. void SetValue( GUID & guidValue );
  99. void SetValue( WCHAR * pwcsValue );
  100. inline CStorageVariant const & Value() const;
  101. //
  102. // A content helper is a content index restriction that
  103. // may help to resolve the property restriction.
  104. //
  105. inline CRestriction * GetContentHelper() const;
  106. inline CRestriction * AcquireContentHelper();
  107. inline void SetContentHelper( CRestriction * pcrst );
  108. private:
  109. ULONG _relop; // Relation
  110. PROPID _pid; // Property
  111. CStorageVariant _prval; // Constant value
  112. CRestriction * _pcrst; // Expanded content restriction (for strings)
  113. };
  114. //+---------------------------------------------------------------------------
  115. //
  116. // Class: COccRestriction
  117. //
  118. // Purpose: Occurrence restriction
  119. //
  120. // History: 29-Nov-94 SitaramR Created
  121. //
  122. //----------------------------------------------------------------------------
  123. class COccRestriction : public CRestriction
  124. {
  125. public:
  126. COccRestriction( ULONG ulType, ULONG ulWeight, OCCURRENCE occ,
  127. ULONG cPrevNoiseWords, ULONG cPostNoiseWords );
  128. ~COccRestriction();
  129. //
  130. // Validity check
  131. //
  132. BOOL IsValid() const;
  133. //
  134. // serialization
  135. //
  136. void Marshall( PSerStream& stm) const;
  137. COccRestriction( ULONG ulType, ULONG ulWeight, PDeSerStream& stm);
  138. COccRestriction *Clone() const;
  139. OCCURRENCE Occurrence() const { return _occ; }
  140. void SetOccurrence( OCCURRENCE occ) { _occ = occ; }
  141. ULONG CountPrevNoiseWords() const { return _cPrevNoiseWords; }
  142. ULONG CountPostNoiseWords() const { return _cPostNoiseWords; }
  143. void AddCountPostNoiseWords( ULONG cWords ) { _cPostNoiseWords += cWords; }
  144. protected:
  145. OCCURRENCE _occ;
  146. ULONG _cPrevNoiseWords;
  147. ULONG _cPostNoiseWords;
  148. };
  149. //+---------------------------------------------------------------------------
  150. //
  151. // Class: CWordRestriction
  152. //
  153. // Purpose: Word expression
  154. //
  155. // Interface:
  156. //
  157. // History: 19-Sep-91 BartoszM Created
  158. // 05-Sep-92 MikeHew Added Serialization
  159. // 14-Jan-93 KyleP Converted to restriction
  160. //
  161. //----------------------------------------------------------------------------
  162. class CWordRestriction : public COccRestriction
  163. {
  164. public:
  165. //
  166. // Constructors
  167. //
  168. CWordRestriction ( const CKeyBuf& keybuf,
  169. OCCURRENCE occ,
  170. ULONG cPrevNoiseWords,
  171. ULONG cPostNoiseWords,
  172. BOOL isRange );
  173. CWordRestriction ( const CWordRestriction& wordRst );
  174. //
  175. // Destructor
  176. //
  177. ~CWordRestriction();
  178. //
  179. // Validity check
  180. //
  181. inline BOOL IsValid() const;
  182. //
  183. // Serialization
  184. //
  185. void Marshall( PSerStream & stm ) const;
  186. CWordRestriction( ULONG ulWeight, PDeSerStream & stm );
  187. CWordRestriction *Clone() const;
  188. //
  189. // Member variable access
  190. //
  191. BOOL IsRange() const { return _isRange; }
  192. const CKey* GetKey() const { return &_key; }
  193. PROPID Pid() const { return _key.Pid(); }
  194. void SetPid( PROPID pid ) { _key.SetPid( pid ); }
  195. private:
  196. CKey _key;
  197. BOOL _isRange;
  198. };
  199. //+---------------------------------------------------------------------------
  200. //
  201. // Class: CSynRestriction
  202. //
  203. // Purpose: Synonym expression
  204. //
  205. // History: 07-Feb-92 BartoszM Created
  206. // 05-Sep-92 MikeHew Added Serialization
  207. // 14-Jan-93 KyleP Converted to restriction
  208. //
  209. //----------------------------------------------------------------------------
  210. class CSynRestriction : public COccRestriction
  211. {
  212. public:
  213. //
  214. // Constructors
  215. //
  216. CSynRestriction ( const CKey& key, OCCURRENCE occ,
  217. ULONG cPrevNoiseWords, ULONG cPostNoiseWords, BOOL isRange );
  218. CSynRestriction( CSynRestriction& synRst );
  219. //
  220. // Destructor
  221. //
  222. ~CSynRestriction();
  223. //
  224. // Validity check
  225. //
  226. inline BOOL IsValid() const;
  227. //
  228. // Serialization
  229. //
  230. void Marshall( PSerStream & stm ) const;
  231. CSynRestriction( ULONG ulWeight, PDeSerStream & stm );
  232. CSynRestriction *Clone() const;
  233. //
  234. // Member variable access
  235. //
  236. void AddKey ( const CKeyBuf& Key );
  237. CKeyArray& GetKeys() { return _keyArray; }
  238. BOOL IsRange() { return _isRange; }
  239. private:
  240. CKeyArray _keyArray;
  241. BOOL _isRange;
  242. };
  243. //+---------------------------------------------------------------------------
  244. //
  245. // Class: CRangeRestriction
  246. //
  247. // Purpose: Range expression
  248. //
  249. // History: 24-Sep-91 BartoszM Created
  250. // 14-Jan-93 KyleP Converted to restriction
  251. //
  252. //----------------------------------------------------------------------------
  253. class CRangeRestriction : public CRestriction
  254. {
  255. public:
  256. //
  257. // Constructors
  258. //
  259. CRangeRestriction ();
  260. CRangeRestriction( const CRangeRestriction& rangeRst );
  261. CRangeRestriction *Clone() const;
  262. //
  263. // Destructor
  264. //
  265. ~CRangeRestriction();
  266. //
  267. // Validity check
  268. //
  269. inline BOOL IsValid() const;
  270. //
  271. // Serialization
  272. //
  273. void Marshall( PSerStream & stm ) const;
  274. CRangeRestriction( ULONG ulWeight, PDeSerStream & stm );
  275. //
  276. // Member variable access
  277. //
  278. void SetStartKey ( const CKeyBuf& keyStart );
  279. void SetEndKey ( const CKeyBuf& keyEnd );
  280. PROPID Pid() const
  281. {
  282. Win4Assert(_keyStart.Pid() == _keyEnd.Pid() );
  283. return _keyStart.Pid();
  284. }
  285. const CKey* GetStartKey() const { return &_keyStart; }
  286. const CKey* GetEndKey() const { return &_keyEnd; }
  287. private:
  288. CKey _keyStart;
  289. CKey _keyEnd;
  290. };
  291. class CUnfilteredRestriction : public CRangeRestriction
  292. {
  293. public:
  294. CUnfilteredRestriction();
  295. };
  296. //+-------------------------------------------------------------------------
  297. //
  298. // Class: CScopeRestriction
  299. //
  300. // Purpose: Scope restriction
  301. //
  302. // History: 07-Jan-93 KyleP Created
  303. //
  304. //--------------------------------------------------------------------------
  305. class CScopeRestriction : public CRestriction
  306. {
  307. public:
  308. //
  309. // Constructors
  310. //
  311. inline CScopeRestriction();
  312. CScopeRestriction( WCHAR const * pwcsPath, BOOL fRecursive, BOOL fVirtual );
  313. //
  314. // Copy constructors/assignment/clone
  315. //
  316. CScopeRestriction & operator =( CScopeRestriction const & source );
  317. CScopeRestriction * Clone() const;
  318. //
  319. // Destructor
  320. //
  321. ~CScopeRestriction();
  322. //
  323. // Validity check
  324. //
  325. inline BOOL IsValid() const;
  326. //
  327. // Serialization
  328. //
  329. void Marshall( PSerStream & stm ) const;
  330. CScopeRestriction( ULONG ulWeight, PDeSerStream & stm );
  331. //
  332. // Member variable access
  333. //
  334. void SetPath( WCHAR const * pwcsPath );
  335. inline WCHAR const * GetPath() const;
  336. inline ULONG PathLength() const;
  337. inline const CLowerFunnyPath & GetFunnyPath() const;
  338. //
  339. // Query depth
  340. //
  341. inline void MakeDeep();
  342. inline void MakeShallow();
  343. inline BOOL IsDeep() const;
  344. inline BOOL IsShallow() const;
  345. //
  346. // Virtual/Physical scoping.
  347. //
  348. inline void MakePhysical();
  349. inline void MakeVirtual();
  350. inline BOOL IsPhysical() const;
  351. inline BOOL IsVirtual() const;
  352. # ifdef CIEXTMODE
  353. void CiExtDump(void *ciExtSelf);
  354. # endif
  355. private:
  356. BOOL _fValid;
  357. CLowerFunnyPath _lowerFunnyPath;
  358. ULONG _fRecursive; // Should be BOOL, but MIDL dislikes
  359. ULONG _fVirtual; // Should be BOOL, but MIDL dislikes
  360. };
  361. //+-------------------------------------------------------------------------
  362. //
  363. // Class: CPhraseRestriction
  364. //
  365. // Purpose: Phrase restriction whose children are occurrence restrictions
  366. //
  367. // History: 29-Nov-94 SitaramR Created
  368. //
  369. //--------------------------------------------------------------------------
  370. class CPhraseRestriction : public CNodeRestriction
  371. {
  372. public:
  373. CPhraseRestriction( unsigned cInitAllocated = 2 )
  374. : CNodeRestriction( RTPhrase, cInitAllocated ) { }
  375. ~CPhraseRestriction();
  376. //
  377. // De-serialization (serialization is done by CNodeRestriction only, because
  378. // there are no data members in CPhraseRestriction)
  379. //
  380. CPhraseRestriction( ULONG ulWeight, PDeSerStream & stm );
  381. //
  382. // Node manipulation
  383. //
  384. void AddChild( CRestriction * presChild, unsigned & pos )
  385. {
  386. Win4Assert( presChild->Type() == RTWord || presChild->Type() == RTSynonym );
  387. CNodeRestriction::AddChild( presChild, pos );
  388. }
  389. void AddChild( CRestriction * presChild )
  390. {
  391. Win4Assert( presChild->Type() == RTWord || presChild->Type() == RTSynonym );
  392. CNodeRestriction::AddChild( presChild );
  393. }
  394. COccRestriction * RemoveChild( unsigned pos )
  395. {
  396. CRestriction *pRst = CNodeRestriction::RemoveChild( pos );
  397. #if CIDBG == 1
  398. if ( pRst )
  399. Win4Assert( pRst->Type() == RTWord || pRst->Type() == RTSynonym );
  400. #endif
  401. return (COccRestriction *)pRst;
  402. }
  403. //
  404. // Member variable access
  405. //
  406. void SetChild( CRestriction * presChild, unsigned pos )
  407. {
  408. Win4Assert( presChild->Type() == RTWord || presChild->Type() == RTSynonym );
  409. CNodeRestriction::SetChild( presChild, pos );
  410. }
  411. COccRestriction * GetChild( unsigned pos ) const
  412. {
  413. CRestriction *pRst = CNodeRestriction::GetChild( pos );
  414. #if CIDBG == 1
  415. if ( pRst )
  416. Win4Assert( pRst->Type() == RTWord || pRst->Type() == RTSynonym );
  417. #endif
  418. return (COccRestriction *)pRst;
  419. }
  420. };
  421. DECLARE_SMARTP( ScopeRestriction )
  422. inline CInternalPropertyRestriction::CInternalPropertyRestriction()
  423. : CRestriction( RTInternalProp, MAX_QUERY_RANK )
  424. {
  425. }
  426. inline BOOL CInternalPropertyRestriction::IsValid() const
  427. {
  428. return ( _pid != pidInvalid &&
  429. _prval.IsValid() &&
  430. ( 0 == _pcrst || _pcrst->IsValid() ) );
  431. }
  432. inline void CInternalPropertyRestriction::SetRelation( ULONG relop )
  433. {
  434. _relop = relop;
  435. }
  436. inline ULONG CInternalPropertyRestriction::Relation() const
  437. {
  438. return _relop;
  439. }
  440. inline void CInternalPropertyRestriction::SetPid( PROPID pid )
  441. {
  442. _pid = pid;
  443. }
  444. inline PROPID CInternalPropertyRestriction::Pid() const
  445. {
  446. return _pid;
  447. }
  448. inline void CInternalPropertyRestriction::SetValue( double dValue )
  449. {
  450. _prval = dValue;
  451. }
  452. inline void CInternalPropertyRestriction::SetValue( ULONG ulValue )
  453. {
  454. _prval.SetUI4( ulValue );
  455. }
  456. inline void CInternalPropertyRestriction::SetValue( LONG lValue )
  457. {
  458. _prval = lValue;
  459. }
  460. inline void CInternalPropertyRestriction::SetValue( BOOL fValue )
  461. {
  462. _prval.SetBOOL( fValue ? VARIANT_TRUE : VARIANT_FALSE );
  463. }
  464. inline void CInternalPropertyRestriction::SetValue( FILETIME ftValue )
  465. {
  466. _prval = ftValue;
  467. }
  468. inline CStorageVariant const & CInternalPropertyRestriction::Value() const
  469. {
  470. return( _prval );
  471. }
  472. inline CRestriction * CInternalPropertyRestriction::GetContentHelper() const
  473. {
  474. return( _pcrst );
  475. }
  476. inline CRestriction * CInternalPropertyRestriction::AcquireContentHelper()
  477. {
  478. CRestriction * pTemp = _pcrst;
  479. _pcrst = 0;
  480. return( pTemp );
  481. }
  482. inline void CInternalPropertyRestriction::SetContentHelper( CRestriction * pcrst )
  483. {
  484. Win4Assert( _pcrst == 0 );
  485. _pcrst = pcrst;
  486. }
  487. //
  488. // CWordRestriction inline
  489. //
  490. inline BOOL CWordRestriction::IsValid() const
  491. {
  492. return ( 0 != _key.GetBuf() );
  493. }
  494. //
  495. // CSynRestriction inline
  496. //
  497. inline BOOL CSynRestriction::IsValid() const
  498. {
  499. for ( int i = 0; i < _keyArray.Count(); i++ )
  500. {
  501. if ( 0 == _keyArray.Get(i).GetBuf() )
  502. return FALSE;
  503. }
  504. return TRUE;
  505. }
  506. //
  507. // CRangeRestriction inline
  508. //
  509. inline BOOL CRangeRestriction::IsValid() const
  510. {
  511. return ( 0 != _keyStart.GetBuf() && 0 != _keyEnd.GetBuf() );
  512. }
  513. //
  514. // CScopeRestriction inline
  515. //
  516. inline CScopeRestriction::CScopeRestriction()
  517. : CRestriction( RTScope, MAX_QUERY_RANK ),
  518. _fValid(FALSE)
  519. {
  520. }
  521. inline BOOL CScopeRestriction::IsValid() const
  522. {
  523. return ( _fValid );
  524. }
  525. // returns the Actual Path
  526. inline WCHAR const * CScopeRestriction::GetPath() const
  527. {
  528. return _fValid ? _lowerFunnyPath.GetActualPath() : NULL;
  529. }
  530. // returns the actual path length
  531. inline ULONG CScopeRestriction::PathLength() const
  532. {
  533. return _lowerFunnyPath.GetActualLength();
  534. }
  535. // Returns funny path
  536. inline const CLowerFunnyPath & CScopeRestriction::GetFunnyPath() const
  537. {
  538. return _lowerFunnyPath;
  539. }
  540. inline void CScopeRestriction::MakeDeep()
  541. {
  542. _fRecursive = TRUE;
  543. }
  544. inline void CScopeRestriction::MakeShallow()
  545. {
  546. _fRecursive = FALSE;
  547. }
  548. inline BOOL CScopeRestriction::IsDeep() const
  549. {
  550. return ( _fRecursive == TRUE );
  551. }
  552. inline BOOL CScopeRestriction::IsShallow() const
  553. {
  554. return ( _fRecursive == FALSE );
  555. }
  556. inline void CScopeRestriction::MakePhysical()
  557. {
  558. _fVirtual = FALSE;
  559. }
  560. inline void CScopeRestriction::MakeVirtual()
  561. {
  562. _fVirtual = TRUE;
  563. }
  564. inline BOOL CScopeRestriction::IsPhysical() const
  565. {
  566. return ( _fVirtual == FALSE );
  567. }
  568. inline BOOL CScopeRestriction::IsVirtual() const
  569. {
  570. return ( _fVirtual == TRUE );
  571. }