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.

205 lines
5.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995.
  5. //
  6. // File: DisBmk.hxx
  7. //
  8. // Contents: Inline wrapper for distributed bookmark.
  9. //
  10. // Classes: CDistributedBookmark
  11. //
  12. // History: 05-Jun-95 KyleP Created
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. //+---------------------------------------------------------------------------
  17. //
  18. // Class: CDistributedBookmark
  19. //
  20. // Purpose: Inline wrapper for distributed bookmark.
  21. //
  22. // History: 05-Jun-95 KyleP Created.
  23. //
  24. // Notes: A distributed bookmark is organized as follows:
  25. // Offset 0: Index of 'primary' cursor (length sizeof(ULONG))
  26. // Offset 4: Bookmark for child cursor 0 (length n)
  27. // Offset 4 + (i*n): Bookmark for child cursor i (length n)
  28. //
  29. // Each child bookmark must be fixed length, and the same length.
  30. //
  31. //----------------------------------------------------------------------------
  32. class CDistributedBookmark
  33. {
  34. public:
  35. inline CDistributedBookmark( DBBKMARK cbBookmark,
  36. BYTE const * pbBookmark,
  37. DBBKMARK cbTotal,
  38. unsigned cCursor );
  39. inline unsigned Index() const;
  40. inline BYTE const * Get() const;
  41. inline BYTE const * Get( unsigned iChild ) const;
  42. inline DBBKMARK GetSize() const;
  43. inline BOOL IsValid( unsigned iChild ) const;
  44. private:
  45. DBBKMARK _cbChild;
  46. DBBKMARK _cbBookmark;
  47. BYTE const * _pbBookmark;
  48. };
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Member: CDistributedBookmark::CDistributedBookmark, public
  52. //
  53. // Synopsis: Initializes and validates bookmark.
  54. //
  55. // Arguments: [cbBookmark] -- Size of [pbBookmark].
  56. // [pbBookmark] -- Pointer to bookmark.
  57. // [cbTotal] -- Size of fully formed bookmark.
  58. // [cCursor] -- Number of child cursors.
  59. //
  60. // History: 05-Jun-95 KyleP Created.
  61. // 24-Jan-97 KrishnaN Modified to conform with 1.0 spec
  62. //
  63. //----------------------------------------------------------------------------
  64. inline CDistributedBookmark::CDistributedBookmark( DBBKMARK cbBookmark,
  65. BYTE const * pbBookmark,
  66. DBBKMARK cbTotal,
  67. unsigned cCursor )
  68. : _cbChild( (cbTotal - sizeof(ULONG)) / cCursor ),
  69. _cbBookmark( cbBookmark ),
  70. _pbBookmark( pbBookmark )
  71. {
  72. //
  73. // We only support fixed length bookmarks with equal size components and
  74. // the special bookmarks (beginning, end, and null).
  75. //
  76. if ( 0 == _cbBookmark)
  77. {
  78. // Legal, though weird...
  79. _cbChild = 0;
  80. return; // no need to check further.
  81. }
  82. if ( _cbBookmark != cbTotal )
  83. {
  84. if ( _cbBookmark == 1 )
  85. {
  86. if (*_pbBookmark != DBBMK_FIRST && *_pbBookmark != DBBMK_LAST )
  87. THROW( CException( DB_E_BADBOOKMARK ) );
  88. _cbChild = 1;
  89. }
  90. else
  91. THROW( CException( DB_E_BADBOOKMARK ) );
  92. }
  93. }
  94. //+---------------------------------------------------------------------------
  95. //
  96. // Member: CDistributedBookmark::Index, public
  97. //
  98. // Returns: Index of primary cursor.
  99. //
  100. // History: 05-Jun-95 KyleP Created.
  101. //
  102. //----------------------------------------------------------------------------
  103. inline unsigned CDistributedBookmark::Index() const
  104. {
  105. Win4Assert( _cbBookmark > 1 );
  106. return *(ULONG UNALIGNED *)_pbBookmark;
  107. }
  108. //+---------------------------------------------------------------------------
  109. //
  110. // Member: CDistributedBookmark::Get, public
  111. //
  112. // Returns: Bookmark of primary cursor.
  113. //
  114. // History: 05-Jun-95 KyleP Created.
  115. //
  116. //----------------------------------------------------------------------------
  117. inline BYTE const * CDistributedBookmark::Get() const
  118. {
  119. if ( _cbBookmark <= 1 )
  120. return _pbBookmark;
  121. else
  122. return _pbBookmark + sizeof(ULONG) + Index() * _cbChild;
  123. }
  124. //+---------------------------------------------------------------------------
  125. //
  126. // Member: CDistributedBookmark::Get, public
  127. //
  128. // Arguments: [iChild] -- Bookmark fetched for this child.
  129. //
  130. // Returns: Bookmark of cursor [iChild].
  131. //
  132. // History: 05-Jun-95 KyleP Created.
  133. //
  134. //----------------------------------------------------------------------------
  135. inline BYTE const * CDistributedBookmark::Get( unsigned iChild ) const
  136. {
  137. if ( _cbBookmark <= 1 )
  138. return _pbBookmark;
  139. else
  140. return _pbBookmark + sizeof(ULONG) + iChild * _cbChild;
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Member: CDistributedBookmark::GetSize, public
  145. //
  146. // Returns: Size of child bookmark.
  147. //
  148. // History: 05-Jun-95 KyleP Created.
  149. //
  150. //----------------------------------------------------------------------------
  151. inline DBBKMARK CDistributedBookmark::GetSize() const
  152. {
  153. return _cbChild;
  154. }
  155. //+---------------------------------------------------------------------------
  156. //
  157. // Member: CDistributedBookmark::IsValid, public
  158. //
  159. // Arguments: [iChild] -- Bookmark fetched for this child.
  160. //
  161. // Returns: TRUE if bookmark for [iChild] is valid (not all 0xFF).
  162. //
  163. // History: 05-Jun-95 KyleP Created.
  164. //
  165. //----------------------------------------------------------------------------
  166. inline BOOL CDistributedBookmark::IsValid( unsigned iChild ) const
  167. {
  168. if ( _cbBookmark <= 1 )
  169. return TRUE;
  170. BYTE const * pb = Get( iChild );
  171. for ( unsigned i = 0; i < _cbChild; i++ )
  172. if ( pb[i] != 0xFF )
  173. break;
  174. return i != _cbChild;
  175. }