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.

207 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1998
  5. //
  6. // File: PCache.hxx
  7. //
  8. // Contents: Protocol for HROW cache
  9. //
  10. // Classes: PMiniRowCache
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: PMiniRowCache
  19. //
  20. // Purpose: Protocol for HROW cache
  21. //
  22. // History: 05-Jun-95 KyleP Created.
  23. //
  24. // Notes: PMiniRowCache is responsible for caching behaviour.
  25. // Derived classes control movement within the rowset.
  26. // Unlike IRowset*, there is a notion of 'current position'
  27. // in PMiniRowCache.
  28. //
  29. // In addition to caching HROWs, a single binding can be
  30. // cached for the top row. This is used to assist in
  31. // sorting.
  32. //
  33. //----------------------------------------------------------------------------
  34. class PMiniRowCache
  35. {
  36. public:
  37. PMiniRowCache( int Index,
  38. IRowset * pRowset,
  39. unsigned cBindings,
  40. DBBINDING * pBindings,
  41. unsigned cbMaxLen );
  42. virtual ~PMiniRowCache();
  43. //
  44. // Iteration
  45. //
  46. enum ENext
  47. {
  48. Ok,
  49. NotNow,
  50. EndOfRows
  51. };
  52. virtual ENext Next( int iDir = 1 ) = 0;
  53. inline BOOL IsAtEnd() const;
  54. virtual void FlushCache();
  55. //
  56. // Member data access
  57. //
  58. inline HROW GetHROW();
  59. inline int Index() const;
  60. inline BYTE * GetData() const;
  61. inline ULONG DataLength() const;
  62. //
  63. // Cache control
  64. //
  65. inline ULONG CacheSize() const;
  66. void SetCacheSize( DBCOUNTITEM cNewRows );
  67. protected:
  68. void LoadData();
  69. //
  70. // Bookeeping.
  71. //
  72. int const _Index;
  73. IRowset * _pRowset;
  74. HACCESSOR _hacc;
  75. //
  76. // Cached rows
  77. //
  78. XArray<HROW> _ahrow;
  79. DBCOUNTITEM _chrow;
  80. DBCOUNTITEM _ihrow;
  81. //
  82. // Cached data for top row.
  83. //
  84. ULONG _cbRow;
  85. BYTE * _pbRow;
  86. };
  87. //+---------------------------------------------------------------------------
  88. //
  89. // Member: PMiniRowCache::IsAtEnd, public
  90. //
  91. // Returns: TRUE if there are no more rows in cache.
  92. //
  93. // History: 05-Jun-95 KyleP Created.
  94. //
  95. //----------------------------------------------------------------------------
  96. inline BOOL PMiniRowCache::IsAtEnd() const
  97. {
  98. return( _ihrow >= _chrow );
  99. }
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Member: PMiniRowCache::CacheSize, public
  103. //
  104. // Returns: Size of cache.
  105. //
  106. // History: 05-Jun-95 KyleP Created.
  107. //
  108. //----------------------------------------------------------------------------
  109. inline ULONG PMiniRowCache::CacheSize() const
  110. {
  111. return _ahrow.Count();
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // Member: PMiniRowCache::GetHROW, public
  116. //
  117. // Returns: HROW of top row.
  118. //
  119. // History: 05-Jun-95 KyleP Created.
  120. //
  121. //----------------------------------------------------------------------------
  122. inline HROW PMiniRowCache::GetHROW()
  123. {
  124. Win4Assert( !IsAtEnd() );
  125. return _ahrow[(unsigned) _ihrow];
  126. }
  127. //+---------------------------------------------------------------------------
  128. //
  129. // Member: PMiniRowCache::Index, public
  130. //
  131. // Returns: Index of this cache (usually position in array of rowsets).
  132. //
  133. // History: 05-Jun-95 KyleP Created.
  134. //
  135. //----------------------------------------------------------------------------
  136. inline int PMiniRowCache::Index() const
  137. {
  138. return _Index;
  139. }
  140. //+---------------------------------------------------------------------------
  141. //
  142. // Member: PMiniRowCache::GetData, public
  143. //
  144. // Returns: Prefetched data for top row.
  145. //
  146. // History: 05-Jun-95 KyleP Created.
  147. //
  148. //----------------------------------------------------------------------------
  149. inline BYTE * PMiniRowCache::GetData() const
  150. {
  151. Win4Assert( !IsAtEnd() );
  152. return _pbRow;
  153. }
  154. //+---------------------------------------------------------------------------
  155. //
  156. // Member: PMiniRowCache::DataLength, public
  157. // k
  158. // Returns: Size of prefetched data.
  159. //
  160. // History: 05-Jun-95 KyleP Created.
  161. //
  162. //----------------------------------------------------------------------------
  163. inline ULONG PMiniRowCache::DataLength() const
  164. {
  165. return _cbRow;
  166. }