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.

206 lines
4.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: tbrowkey.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes: CTableRowKey
  11. //
  12. // Functions:
  13. //
  14. // History: 2-15-95 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #pragma once
  18. #include <tblvarnt.hxx> // for CTableVariant
  19. #include <compare.hxx>
  20. #include <coldesc.hxx>
  21. class CRetriever;
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Class: CInlineVariant
  25. //
  26. // Purpose: To have a dummy field at the end of a PROPVARIANT. This will
  27. // help us get the correct offset for variable data in an inline
  28. // variant.
  29. //
  30. // History: 2-15-95 srikants Created
  31. //
  32. //----------------------------------------------------------------------------
  33. #pragma warning( disable : 4200 )
  34. class CInlineVariant : public CTableVariant
  35. {
  36. public:
  37. BYTE * GetVarBuffer()
  38. {
  39. return &_abVarData[0];
  40. }
  41. private:
  42. BYTE _abVarData[];
  43. };
  44. #pragma warning( default : 4200 )
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Class: CTableRowKey
  48. //
  49. // Purpose: A Bucket row consists of a columns that are part of the
  50. // sort key. Each field is stored as a fully expanded in-line
  51. // variant to avoid frequent memory allocations and frees.
  52. //
  53. // History: 2-15-95 srikants Created
  54. //
  55. // Notes:
  56. //
  57. //----------------------------------------------------------------------------
  58. class CTableRowKey
  59. {
  60. enum { cThreshold = 20 };
  61. public:
  62. CTableRowKey( CSortSet const & sortSet );
  63. ~CTableRowKey();
  64. //
  65. // The assignment operator can be used only when the RHS has the same
  66. // ordinality as the LHS.
  67. //
  68. CTableRowKey & operator = ( CTableRowKey & src );
  69. //
  70. // Initialize the specified column with given variant.
  71. //
  72. void Init( unsigned i, CTableVariant & src, BYTE * pbSrcBias = 0 );
  73. CTableVariant * Get( unsigned i, ULONG & size )
  74. {
  75. Win4Assert( i < _cCols );
  76. size = _acbVariants[i];
  77. return _apVariants[i];
  78. }
  79. //
  80. // Reallocates the specified variant to be atlease as big as cbData.
  81. //
  82. void ReAlloc( unsigned i, VARTYPE vt, unsigned cbData );
  83. //
  84. // Pointer to an array of variants that constitute the row.
  85. //
  86. PROPVARIANT ** GetVariants()
  87. {
  88. return (PROPVARIANT **) _apVariants.GetPointer();
  89. }
  90. //
  91. // Test if the spcified "vt" is for an ascii string.
  92. //
  93. static BOOL IsSTR( VARTYPE vt )
  94. {
  95. Win4Assert( (VT_BYREF | VT_LPSTR) != vt );
  96. return VT_LPSTR == vt;
  97. }
  98. //
  99. // Test if the specified "vt" is for a WIDE string.
  100. //
  101. static BOOL IsWSTR( VARTYPE vt )
  102. {
  103. Win4Assert( (VT_BYREF | VT_LPWSTR) != vt );
  104. return VT_LPWSTR == vt;
  105. }
  106. void PreSet( CRetriever * obj, XArray<VARTYPE> * pSortInfo );
  107. void MakeReady();
  108. const CSortSet & GetSortSet() const { return _sortSet; }
  109. BOOL IsInitialized()
  110. {
  111. return 0 == _cCols || _apVariants[0] != 0;
  112. }
  113. private:
  114. void Set( CRetriever & obj, XArray<VARTYPE> & vtInfoSortKey );
  115. // Number of columns in the row.
  116. unsigned _cCols;
  117. const CSortSet & _sortSet;
  118. // Array of lengths of variants.
  119. XArray<unsigned> _acbVariants;
  120. // Array of variants, one for each column in the row.
  121. XArray<CInlineVariant *> _apVariants;
  122. CRetriever * _pObj;
  123. XArray<VARTYPE> * _pVarType;
  124. };
  125. //+---------------------------------------------------------------------------
  126. //
  127. // Class: CTableKeyCompare
  128. //
  129. // Purpose: A comparator for two rows in a bucket.
  130. //
  131. // History: 2-15-95 srikants Created
  132. //
  133. // Notes:
  134. //
  135. //----------------------------------------------------------------------------
  136. class CTableKeyCompare
  137. {
  138. public:
  139. CTableKeyCompare( const CSortSet & sortOrder ) :
  140. _cProps( sortOrder.Count() )
  141. {
  142. if ( _cProps > 0 )
  143. {
  144. _ComparePS.Init( _cProps, &sortOrder, 0 );
  145. }
  146. }
  147. ~CTableKeyCompare() {}
  148. int Compare( CTableRowKey & row1, CTableRowKey & row2 )
  149. {
  150. return _ComparePS.Compare( row1.GetVariants(), row2.GetVariants() );
  151. }
  152. private:
  153. // Number of properties that need to be compared.
  154. unsigned _cProps;
  155. // Comparator for propety sets.
  156. CComparePropSets _ComparePS;
  157. };