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.

259 lines
6.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: pathstor.hxx
  7. //
  8. // Contents: Store for paths in the bigtable.
  9. //
  10. // Classes: CCompressedPath, CCompressedPathStore, XRefPath
  11. //
  12. // Functions:
  13. //
  14. // History: 5-02-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. #include "strhash.hxx"
  19. typedef ULONG STRINGID;
  20. const WCHAR wchPathSep = L'\\';
  21. //+---------------------------------------------------------------------------
  22. //
  23. // Class: CStringStore
  24. //
  25. // Purpose: A Store for strings allowing quick lookup.
  26. //
  27. // History: 5-23-95 srikants Created
  28. //
  29. // Notes: Right now it is just using the CCompressedColHashString to
  30. // actually store the strings. We should either make
  31. // CCompressedColHashString a dynamic hash table or come up with
  32. // a different scheme for storing paths in this class.
  33. //
  34. //----------------------------------------------------------------------------
  35. class CStringStore
  36. {
  37. public:
  38. CStringStore();
  39. ~CStringStore();
  40. STRINGID Add( const WCHAR * wszString );
  41. STRINGID AddCountedWStr( const WCHAR * wszString, ULONG cwcStr );
  42. STRINGID FindCountedWStr( const WCHAR * wszString, ULONG cwcStr );
  43. const WCHAR * GetCountedWStr( STRINGID strId, ULONG & cwcStr );
  44. GetValueResult GetString( STRINGID strId, WCHAR * pwszPath, ULONG & cwcStr );
  45. void GetData( PROPVARIANT * pVarnt, STRINGID strId )
  46. {
  47. _pStrHash->GetData( pVarnt, VT_LPWSTR, strId );
  48. }
  49. void FreeVariant( PROPVARIANT * pVarnt )
  50. {
  51. _pStrHash->FreeVariant( pVarnt );
  52. }
  53. WCHAR * GetStringBuffer( ULONG cwc )
  54. {
  55. return _pStrHash->_GetStringBuffer( cwc );
  56. }
  57. ULONG StrLen( STRINGID strId );
  58. ULONG MemUsed()
  59. {
  60. return _pStrHash->MemUsed();
  61. }
  62. private:
  63. CCompressedColHashString * _pStrHash;
  64. };
  65. //+---------------------------------------------------------------------------
  66. //
  67. // Class: CShortPath
  68. //
  69. // Purpose: A compact notation for storing a path name. A path name
  70. // is identifed by a "parent Id" and a "filename id".
  71. //
  72. // History: 5-02-95 srikants Created
  73. //
  74. // Notes:
  75. //
  76. //----------------------------------------------------------------------------
  77. class CShortPath
  78. {
  79. public:
  80. CShortPath( STRINGID idParent = stridInvalid, STRINGID idFileName = stridInvalid )
  81. :_idParent(idParent), _idFileName(idFileName)
  82. {
  83. }
  84. BOOL IsValid() const
  85. {
  86. return stridInvalid != _idParent && stridInvalid != _idFileName ;
  87. }
  88. void Set( STRINGID idParent, STRINGID idFileName )
  89. {
  90. _idParent = idParent;
  91. _idFileName = idFileName;
  92. }
  93. STRINGID GetParent() const { return _idParent; }
  94. void SetParent( STRINGID idParent ) { _idParent = idParent; }
  95. STRINGID GetFileName() const { return _idFileName; }
  96. void SetFileName( STRINGID idFileName ) { _idFileName = idFileName; }
  97. BOOL IsSame( CShortPath & other )
  98. { return _idParent == other._idParent &&
  99. _idFileName == other._idFileName; }
  100. private:
  101. STRINGID _idParent;
  102. STRINGID _idFileName;
  103. };
  104. class CSplitPath;
  105. DECL_DYNARRAY_INPLACE( CShortPathArray, CShortPath );
  106. //+---------------------------------------------------------------------------
  107. //
  108. // Class: CPathStore
  109. //
  110. // Purpose: A store for paths in the bigtable. It stores them in a compact
  111. // format. It also implements "Compare" methods which can compare
  112. // two paths by their PATHIDs or a full path and a PATHID. This
  113. // allows us to do comparisons quickly without having to construct
  114. // the variants.
  115. //
  116. // History: 5-02-95 srikants Created
  117. //
  118. // Notes:
  119. //
  120. //----------------------------------------------------------------------------
  121. typedef ULONG PATHID;
  122. class CPathStore : public CCompressedCol
  123. {
  124. //
  125. // CLEANCODE: this is somehow related to the expected number of rows in a
  126. // window - maybe 1/4 of the expected is a good start.
  127. //
  128. enum { INIT_PATHIDS = 128 };
  129. public:
  130. CPathStore() : _wchPathSep( wchPathSep ), _aShortPath(INIT_PATHIDS)
  131. {
  132. }
  133. ~CPathStore();
  134. //
  135. // Virtual methods of CCompressedCol.
  136. //
  137. void AddData( PROPVARIANT const * const pvarnt,
  138. ULONG * pKey,
  139. GetValueResult& reIndicator );
  140. BOOL FindData( PROPVARIANT const * const pvarnt,
  141. ULONG & rKey );
  142. GetValueResult GetData(PROPVARIANT * pvarnt,
  143. VARTYPE PreferredType,
  144. ULONG key = 0,
  145. PROPID prop = 0);
  146. void FreeVariant(PROPVARIANT * pvarnt);
  147. ULONG MemUsed(void)
  148. {
  149. return 0; // NEWFEATURE - to be written
  150. }
  151. CPathStore * GetPathStore() // virtual
  152. {
  153. return this;
  154. }
  155. PATHID AddPath( WCHAR * wszPath );
  156. //
  157. // Useful during window splits to copy a path from one window to another.
  158. //
  159. PATHID AddPath( CPathStore & srcStore, PATHID srcPathId );
  160. GetValueResult GetPath( CShortPath & path, WCHAR * pwszPath,
  161. ULONG & cwcPath );
  162. GetValueResult GetPath( PATHID pathId, PROPVARIANT & vtPath, ULONG & cbVarnt );
  163. WCHAR * Get( PATHID pathId, PROPID propId, PVarAllocator & dstPool );
  164. const CShortPath & GetShortPath( PATHID pathId )
  165. {
  166. Win4Assert( pathId > 0 && pathId <= _aShortPath.Count() );
  167. return _aShortPath.Get( pathId-1 );
  168. }
  169. ULONG PathLen( PATHID pathId );
  170. int Compare( PATHID pathid1, PATHID pathid2,
  171. PROPID propId = pidPath );
  172. int Compare( WCHAR const * wszPath1, PATHID pathid2,
  173. PROPID propId = pidPath );
  174. int Compare( PROPVARIANT & vtPath1, PATHID pathid2,
  175. PROPID propId = pidPath );
  176. CStringStore & GetStringStore() { return _strStore; }
  177. private:
  178. WCHAR _wchPathSep; // Path Separator
  179. CStringStore _strStore; // Storage for strings.
  180. CShortPathArray _aShortPath; // Array of short paths. Indexed
  181. // by pathid
  182. PATHID _AddPath( CSplitPath & splitPath );
  183. PATHID _AddEntry( STRINGID idParent, STRINGID idFileName );
  184. void _GetPath( PATHID pathId, WCHAR * pwszPath, ULONG cwcPath );
  185. BOOL _IsValid( PATHID pathid ) const
  186. {
  187. return pathid > 0 && pathid <= _aShortPath.Count();
  188. }
  189. WCHAR * _GetPathBuffer( ULONG cwc )
  190. {
  191. return _strStore.GetStringBuffer( cwc );
  192. }
  193. };