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.

231 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: pidtable.hxx
  7. //
  8. // Contents: Property to PROPID mapping table for downlevel content
  9. // index. Stored persistently in the files CiPT0000.00?.
  10. //
  11. // Classes: CPidLookupEntry
  12. // CPidLookupTable
  13. // SPidLookupTableHeader
  14. //
  15. // History: 02 Jan 1996 AlanW Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include <prcstob.hxx>
  20. class CFullPropSpec;
  21. class CiStorage;
  22. const unsigned MAX_PROPERTY_NAME_LEN = MAX_PATH;
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Class: CPidLookupEntry
  26. //
  27. // Purpose: CPidLookup table entries.
  28. //
  29. // History: 02 Jan 1996 AlanW Created
  30. //
  31. // Notes:
  32. //
  33. //----------------------------------------------------------------------------
  34. #include <pshpack8.h> // pack(8), and round size to 32 bytes
  35. class CPidLookupEntry
  36. {
  37. public:
  38. BOOL IsEqual( const CFullPropSpec & rProp,
  39. const WCHAR * pchStringBase = 0) const;
  40. BOOL IsFree() { return _pid == 0; }
  41. //
  42. // Member variable access
  43. //
  44. void SetPropSet( GUID const & guidPropSet ) { _guid = guidPropSet; }
  45. GUID const & GetPropSet() const { return _guid; }
  46. void SetPropertyNameOffset( ULONG iString ) {
  47. _eType = 0;
  48. _iString = iString; }
  49. void SetPropertyPropid( PROPID pidProperty ) {
  50. _eType = 1;
  51. _propid = pidProperty; }
  52. ULONG GetPropertyNameOffset() const { return _iString; }
  53. PROPID GetPropertyPropid() const { return _propid; }
  54. BOOL IsPropertyName() const { return _eType == 0; }
  55. BOOL IsPropertyPropid() const { return _eType == 1; }
  56. void SetPid(PROPID Pid) { _pid = Pid; }
  57. PROPID Pid() const { return _pid; }
  58. private:
  59. GUID _guid;
  60. ULONG _eType;
  61. union {
  62. ULONG _propid;
  63. ULONG _iString;
  64. };
  65. PROPID _pid;
  66. };
  67. #include <poppack.h>
  68. class PSaveProgressTracker;
  69. //+---------------------------------------------------------------------------
  70. //
  71. // Class: CPidLookupTable
  72. //
  73. // Purpose: Persistent property spec. to PROPID mapping table for
  74. // downlevel content index.
  75. //
  76. // History: 02 Jan 1996 AlanW Created
  77. //
  78. // Notes:
  79. //
  80. //----------------------------------------------------------------------------
  81. class CPidLookupTable
  82. {
  83. public:
  84. CPidLookupTable ( );
  85. ~CPidLookupTable ();
  86. void Init( ULONG cEntries );
  87. BOOL Init( PRcovStorageObj * pObj );
  88. void MakeBackupCopy( PRcovStorageObj & dstObj, PSaveProgressTracker & tracker );
  89. void Empty();
  90. BOOL FindPropid( const CFullPropSpec & rProp,
  91. PROPID & rPid,
  92. BOOL fAddToTable = TRUE );
  93. BOOL EnumerateProperty( CFullPropSpec & ps, unsigned & iBmk );
  94. struct SPidLookupTableHeader {
  95. CHAR Signature[8]; // "PIDTABLE"
  96. ULONG cbRecord; // size of file records
  97. ULONG cHash; // number of hash table entries
  98. ULONG cEntries; // nunber of hash entries in use
  99. PROPID NextPropid; // next PROPID to be allocated
  100. };
  101. ULONG Size() const { return _Header.cHash; }
  102. ULONG Entries() const { return _Header.cEntries; }
  103. private:
  104. ULONG Hash( const CPidLookupEntry & rProp );
  105. ULONG Hash( const CFullPropSpec & rProp );
  106. ULONG HashString( const WCHAR * pwszStr );
  107. BOOL LookUp( const CFullPropSpec & Prop, ULONG &riTable );
  108. void StoreInTable( const CPidLookupEntry & Prop );
  109. ULONG AddEntry( const CFullPropSpec & Prop );
  110. void GrowAndRehash( ULONG Count );
  111. void GrowStringSpace( ULONG cbNewString );
  112. BOOL IsFull( ) const { return ! (Entries() < Size()); }
  113. PROPID NextPropid() const { return _Header.NextPropid; }
  114. ULONG GrowSize() const;
  115. SPidLookupTableHeader _Header;
  116. CPidLookupEntry * _pTable; // the hash table
  117. WCHAR * _pchStringBase; // pointer to string memory
  118. ULONG _cbStrings; // size of string memory
  119. ULONG _cbStringUsed; // size of used string memory
  120. CMutexSem _mutex;
  121. #if ! defined(UNIT_TEST)
  122. XPtr<PRcovStorageObj> _xrsoPidTable; // The persistent storage itself
  123. #else // defined(UNIT_TEST)
  124. public:
  125. void SetFillFactor(ULONG iFill) {
  126. _iFillFactor = iFill;
  127. _maxEntries = (Size() * iFill) / 100; }
  128. void SetNextPropid(PROPID Next) { _Header.NextPropid = Next; }
  129. void Print( void );
  130. #endif // defined(UNIT_TEST)
  131. #if (DBG == 1)
  132. ULONG _cMaxChainLen;
  133. ULONG _cTotalSearches;
  134. ULONG _cTotalLength;
  135. ULONG _iFillFactor;
  136. #endif // (DBG == 1)
  137. ULONG _maxEntries; // max # of hash table entries
  138. };
  139. //+-------------------------------------------------------------------------
  140. //
  141. // Method: CPidLookupEntry::IsEqual, public
  142. //
  143. // Synopsis: Compare a hash table entry with a propspec
  144. //
  145. // Arguments: [rProp] - the property to be compared
  146. // [pchStringBase] - the base address for string-named properties
  147. // in the CPidLookupEntry
  148. //
  149. // Returns: BOOL - TRUE if the entry is equivalent to the property
  150. //
  151. // Notes: For string named properties, the input strings are assumed
  152. // to be mapped to lower case.
  153. //
  154. //--------------------------------------------------------------------------
  155. inline BOOL CPidLookupEntry::IsEqual(
  156. const CFullPropSpec & rProp,
  157. const WCHAR * pchStringBase) const
  158. {
  159. if (rProp.IsPropertyPropid())
  160. {
  161. return IsPropertyPropid() &&
  162. rProp.GetPropertyPropid() == _propid &&
  163. rProp.GetPropSet() == _guid;
  164. }
  165. else
  166. {
  167. if (! IsPropertyName() || rProp.GetPropSet() != _guid)
  168. return FALSE;
  169. const WCHAR * pwszProp = rProp.GetPropertyName();
  170. unsigned cbPropName = (wcslen(pwszProp) + 1) * sizeof (WCHAR);
  171. return RtlEqualMemory( pwszProp, _iString + pchStringBase, cbPropName );
  172. }
  173. }