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.

275 lines
7.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: Compare.hxx
  7. //
  8. // Contents: Comparator class for property sets.
  9. //
  10. // Classes: CComparePropSets
  11. //
  12. // History: 07-Jun-92 KyleP Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #pragma once
  16. typedef BOOL (* FRel)(PROPVARIANT const &, PROPVARIANT const &);
  17. typedef BOOL (* FPRel)(BYTE const *, BYTE const *);
  18. typedef int (* FCmp)(PROPVARIANT const &, PROPVARIANT const &);
  19. typedef int (* FPCmp)(BYTE const *, BYTE const *);
  20. typedef int (* FDBCmp)(BYTE const *, ULONG, BYTE const *, ULONG);
  21. class CComparators
  22. {
  23. public:
  24. static FCmp GetComparator( VARENUM vt );
  25. static FRel GetRelop( VARENUM vt, ULONG rel );
  26. static FPCmp GetPointerComparator( PROPVARIANT const & v1,
  27. PROPVARIANT const & v2 );
  28. static FPRel GetPointerRelop( PROPVARIANT const & v1,
  29. PROPVARIANT const & v2,
  30. ULONG rel );
  31. static FDBCmp GetDBComparator( DBTYPEENUM vt );
  32. private:
  33. //
  34. // There is one SComparators structure for each base variant type.
  35. // They are accessed off aVariantComarators by VT_xxx. Within
  36. // the SComparators structure relops are accessed by PRxxx.
  37. //
  38. struct SComparators
  39. {
  40. FCmp comparator;
  41. FPCmp pointercomparator;
  42. FRel relops[9];
  43. FPRel pointerrelops[9];
  44. };
  45. struct SDBComparators
  46. {
  47. FDBCmp dbcomparator;
  48. FDBCmp dbvectorcomparator;
  49. };
  50. static ULONG const _iDBStart;
  51. static SDBComparators const _aDBComparators[];
  52. static ULONG const _cDBComparators;
  53. static ULONG const _iDBStart2;
  54. static SDBComparators const _aDBComparators2[];
  55. static ULONG const _cDBComparators2;
  56. static ULONG const _iDBStart3;
  57. static SDBComparators const _aDBComparators3[];
  58. static ULONG const _cDBComparators3;
  59. static DBTYPEENUM _RationalizeDBByRef( DBTYPEENUM vt );
  60. static ULONG const _iStart;
  61. static SComparators const _aVariantComparators[];
  62. static ULONG const _cVariantComparators;
  63. static ULONG const _iStart2;
  64. static SComparators const _aVariantComparators2[];
  65. static ULONG const _cVariantComparators2;
  66. static ULONG const _iStart3;
  67. static SComparators const _aVariantComparators3[];
  68. static ULONG const _cVariantComparators3;
  69. static FRel const _aVectorComparators[];
  70. static ULONG const _cVectorComparators;
  71. static FRel const _aVectorComparatorsAll[];
  72. static ULONG const _cVectorComparatorsAll;
  73. static FRel const _aVectorComparatorsAny[];
  74. static ULONG const _cVectorComparatorsAny;
  75. };
  76. extern CComparators VariantCompare;
  77. //+-------------------------------------------------------------------------
  78. //
  79. // Class: CComparePropSets
  80. //
  81. // Purpose: Compares two property sets for purposes of sorting.
  82. //
  83. // Interface:
  84. //
  85. // History: 07-Jun-92 KyleP Created
  86. //
  87. //--------------------------------------------------------------------------
  88. class CSortSet;
  89. class CColumnSet;
  90. class CComparePropSets : INHERIT_UNWIND
  91. {
  92. INLINE_UNWIND( CComparePropSets )
  93. public:
  94. inline CComparePropSets();
  95. inline ~CComparePropSets();
  96. void Init( int cCols, CSortSet const * psort, int aColIndex[] );
  97. void Init( CColumnSet const & cols );
  98. inline BOOL IsEmpty();
  99. int Compare( PROPVARIANT ** row1, PROPVARIANT ** row2 );
  100. BOOL IsLT( PROPVARIANT ** row1, PROPVARIANT ** row2 );
  101. BOOL IsGT( PROPVARIANT ** row1, PROPVARIANT ** row2 );
  102. BOOL IsEQ( PROPVARIANT ** row1, PROPVARIANT ** row2 );
  103. private:
  104. void _UpdateCompare( UINT iCol, VARENUM vt );
  105. struct SColCompare
  106. {
  107. int _iCol; // Index of column into row.
  108. ULONG _dir; // Direction
  109. ULONG _pt; // Property type (matches fns below)
  110. //
  111. // LE/GE are a bit of a misnomer. If the sort order for a column
  112. // is reversed ( large to small ) then LE is really GE and
  113. // vice-versa.
  114. //
  115. FCmp _comp;
  116. int _DirMult; // -1 if directions reversed.
  117. };
  118. UINT _cColComp;
  119. SColCompare * _aColComp;
  120. };
  121. //+-------------------------------------------------------------------------
  122. //
  123. // Member: CComparePropSets::CComparePropSets, public
  124. //
  125. // Synopsis: Construct a property set comparator.
  126. //
  127. // History: 16-Jun-92 KyleP Created
  128. //
  129. //--------------------------------------------------------------------------
  130. inline CComparePropSets::CComparePropSets()
  131. : _aColComp( 0 ),
  132. _cColComp( 0 )
  133. {
  134. }
  135. //+-------------------------------------------------------------------------
  136. //
  137. // Member: CComparePropSets::~CComparePropSets, public
  138. //
  139. // Synopsis: Destroy a property set comparator.
  140. //
  141. // History: 16-Jun-92 KyleP Created
  142. //
  143. //--------------------------------------------------------------------------
  144. inline CComparePropSets::~CComparePropSets()
  145. {
  146. delete _aColComp;
  147. }
  148. //+-------------------------------------------------------------------------
  149. //
  150. // Member: CComparePropSets::IsEmpty, public
  151. //
  152. // Returns: TRUE if there is no property set to compare.
  153. //
  154. // History: 16-Jun-92 Author Comment
  155. //
  156. //--------------------------------------------------------------------------
  157. inline BOOL CComparePropSets::IsEmpty()
  158. {
  159. return( _aColComp == 0 );
  160. }
  161. inline BOOL isVector(VARTYPE vt)
  162. {
  163. return 0 != ( vt & VT_VECTOR );
  164. }
  165. inline BOOL isVector(PROPVARIANT const & v)
  166. {
  167. return isVector( v.vt );
  168. }
  169. inline BOOL isArray(VARTYPE vt)
  170. {
  171. return 0 != ( vt & VT_ARRAY );
  172. }
  173. inline BOOL isArray(PROPVARIANT const & v)
  174. {
  175. return isArray( v.vt );
  176. }
  177. inline BOOL isVectorOrArray(VARTYPE vt)
  178. {
  179. return 0 != ( vt & (VT_ARRAY|VT_VECTOR) );
  180. }
  181. inline BOOL isVectorOrArray(PROPVARIANT const & v)
  182. {
  183. return isVectorOrArray( v.vt );
  184. }
  185. inline BOOL isVectorRelop(ULONG relop)
  186. {
  187. return relop & (PRAny | PRAll);
  188. }
  189. inline BOOL isRelopAny(ULONG relop)
  190. {
  191. return relop & PRAny;
  192. }
  193. inline BOOL isRelopAll(ULONG relop)
  194. {
  195. return relop & PRAll;
  196. }
  197. inline VARENUM getBaseType(PROPVARIANT const &v)
  198. {
  199. return (VARENUM) (VT_TYPEMASK & v.vt);
  200. }
  201. inline ULONG getBaseRelop(ULONG relop)
  202. {
  203. return relop & ~(PRAny | PRAll);
  204. }
  205. BOOL VT_VARIANT_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  206. BOOL VT_VARIANT_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  207. BOOL VT_VARIANT_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  208. BOOL VT_VARIANT_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  209. BOOL VT_VARIANT_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  210. BOOL VT_VARIANT_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  211. #if 0
  212. BOOL VT_VECTOR_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  213. BOOL VT_VECTOR_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  214. BOOL VT_VECTOR_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  215. BOOL VT_VECTOR_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  216. BOOL VT_VECTOR_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  217. BOOL VT_VECTOR_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 );
  218. #endif