Leaked source code of windows server 2003
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.

173 lines
4.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: pathcomp.hxx
  7. //
  8. // Contents: Class definitions for doing "smart" path comparison in
  9. // bigtable.
  10. //
  11. // Classes: CSplitPath, CSplitPathCompare
  12. //
  13. // History: 5-09-95 srikants Created
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include "pathstor.hxx"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Class: CSplitPath
  21. //
  22. // Purpose: To hold a path as consisting of two components - a parent
  23. // component and a file component. This will be used
  24. // for doing path comparisons without having to construct a
  25. // full path but instead using the two components.
  26. //
  27. // History: 5-09-95 srikants Created
  28. //
  29. // Notes: It is possible to simplify the logic of comparison if we
  30. // were to construct a full path by concatening the parent
  31. // and file but that would require a big buffer. Allocating
  32. // from heap for each comparison is expensive and the buffer is
  33. // too big (MAX_PATH * sizeof(WCHAR)) to be allocated on stack.
  34. // If stack can be used, the logic can be simplified
  35. // significantly.
  36. //
  37. //----------------------------------------------------------------------------
  38. class CSplitPath
  39. {
  40. enum ECompareStep { eUseParent, eUsePathSep, eUseFile, eDone };
  41. friend class CPathStore;
  42. public:
  43. CSplitPath( CPathStore & pathStore, PATHID pathid );
  44. CSplitPath( const WCHAR * path );
  45. void Advance( ULONG cwc );
  46. BOOL IsDone() const { return eDone == _step; }
  47. int CompareCurr( CSplitPath & rhs )
  48. {
  49. ULONG cwcMin = min( _cwcCurr, rhs._cwcCurr );
  50. if ( 0 == cwcMin )
  51. return 0;
  52. return _wcsnicmp( _pCurr, rhs._pCurr, cwcMin );
  53. }
  54. ULONG GetCurrLen() const { return _cwcCurr; }
  55. unsigned GetStep() const { return _step; }
  56. void FormFullPath( WCHAR * pwszPath, ULONG cwcPath ) const ;
  57. void FormFileName( WCHAR * pwszFile, ULONG cwcFile ) const ;
  58. ULONG GetFullPathLen() const;
  59. ULONG GetFileNameLen() const
  60. {
  61. return _cwcFile+1;
  62. }
  63. void InitForPathCompare()
  64. {
  65. _pCurr = _pParent;
  66. _cwcCurr = _cwcParent;
  67. _step = eUseParent;
  68. }
  69. void InitForNameCompare()
  70. {
  71. if ( 0 != _pFile )
  72. _SetUseFile();
  73. else
  74. _SetDone();
  75. }
  76. private:
  77. //
  78. // Parent part of the path.
  79. //
  80. const WCHAR * _pParent;
  81. ULONG _cwcParent;
  82. //
  83. // File part of the path.
  84. //
  85. const WCHAR * _pFile;
  86. ULONG _cwcFile;
  87. //
  88. // Used for comparing two split paths.
  89. //
  90. const WCHAR * _pCurr;
  91. ULONG _cwcCurr;
  92. ECompareStep _step;
  93. static const WCHAR _awszPathSep[];
  94. void _SetUsePathSep()
  95. {
  96. _pCurr = _awszPathSep;
  97. _cwcCurr = 1;
  98. _step = eUsePathSep;
  99. }
  100. void _SetUseFile()
  101. {
  102. Win4Assert( 0 != _pFile );
  103. _pCurr = _pFile;
  104. _cwcCurr = _cwcFile;
  105. _step = eUseFile;
  106. }
  107. void _SetDone()
  108. {
  109. _pCurr = 0;
  110. _cwcCurr = 0;
  111. _step = eDone;
  112. }
  113. };
  114. //+---------------------------------------------------------------------------
  115. //
  116. // Class: CSplitPathCompare
  117. //
  118. // Purpose: To compare two paths which are "Split".
  119. //
  120. // History: 5-09-95 srikants Created
  121. //
  122. // Notes:
  123. //
  124. //----------------------------------------------------------------------------
  125. class CSplitPathCompare
  126. {
  127. public:
  128. CSplitPathCompare( CSplitPath & lhs, CSplitPath & rhs )
  129. : _lhs(lhs), _rhs(rhs) { }
  130. int ComparePaths();
  131. int CompareNames();
  132. private:
  133. CSplitPath & _lhs;
  134. CSplitPath & _rhs;
  135. BOOL _IsDone() const { return _lhs.IsDone() || _rhs.IsDone(); }
  136. int _Compare();
  137. };