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.

3616 lines
85 KiB

  1. //
  2. // varcomp.cpp
  3. //
  4. // Issue: string comparisons ignore sort spec lcid.
  5. // Issue -- unsupported types:
  6. // VT_RECORD
  7. //
  8. // Notes: The following comparisons are suppored
  9. //
  10. // Variant Equality Relational Bitwise
  11. // ----------- ----------- ---------- -------
  12. //
  13. // VT_EMPTY X
  14. // VT_NULL X
  15. // VT_I2 X X X
  16. // VT_I4 X X X
  17. // VT_R4 X X
  18. // VT_R8 X X
  19. // VT_CY X X
  20. // VT_DATE X X
  21. // VT_BSTR X X
  22. // VT_DISPATCH -
  23. // VT_ERROR X X X
  24. // VT_BOOL X
  25. // VT_VARIANT X X
  26. // VT_UNKNOWN -
  27. // VT_DECIMAL X X
  28. // VT_I1 X X X
  29. // VT_UI1 X X X
  30. // VT_UI2 X X X
  31. // VT_UI4 X X X
  32. // VT_I8 X X X
  33. // VT_UI8 X X X
  34. // VT_INT X X X
  35. // VT_UINT X X X
  36. // VT_VOID -
  37. // VT_HRESULT X X X
  38. // VT_PTR -
  39. // VT_SAFEARRAY -
  40. // VT_CARRAY -
  41. // VT_USERDEFINED -
  42. // VT_LPSTR X X
  43. // VT_LPWSTR X X
  44. // VT_FILETIME X X
  45. // VT_BLOB X X
  46. // VT_STREAM
  47. // VT_STORAGE
  48. // VT_STREAMED_OBJECT
  49. // VT_STORED_OBJECT
  50. // VT_BLOB_OBJECT X X
  51. // VT_CF X X
  52. // VT_CLSID X
  53. //
  54. #include "private.h"
  55. #include "varcomp.h"
  56. CComparators VariantCompare;
  57. //
  58. // DEFAULT. Used for optimization in looped comparisons. If we can't
  59. // determine the way to compare, then use this default.
  60. //
  61. int VT_DEFAULT_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  62. {
  63. return( 0 );
  64. }
  65. //
  66. // VT_EMPTY
  67. //
  68. int VT_EMPTY_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  69. {
  70. return( 0 );
  71. }
  72. BOOL VT_EMPTY_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  73. {
  74. return( TRUE );
  75. }
  76. BOOL VT_EMPTY_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  77. {
  78. return( FALSE );
  79. }
  80. //
  81. // VT_NULL
  82. //
  83. int VT_NULL_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  84. {
  85. return( 0 );
  86. }
  87. BOOL VT_NULL_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  88. {
  89. return( TRUE );
  90. }
  91. BOOL VT_NULL_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  92. {
  93. return( FALSE );
  94. }
  95. //
  96. // VT_I2
  97. //
  98. int VT_I2_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  99. {
  100. return( v1.iVal - v2.iVal );
  101. }
  102. BOOL VT_I2_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  103. {
  104. return( v1.iVal < v2.iVal );
  105. }
  106. BOOL VT_I2_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  107. {
  108. return( v1.iVal <= v2.iVal );
  109. }
  110. BOOL VT_I2_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  111. {
  112. return( v1.iVal >= v2.iVal );
  113. }
  114. BOOL VT_I2_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  115. {
  116. return( v1.iVal > v2.iVal );
  117. }
  118. BOOL VT_I2_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  119. {
  120. return( v1.iVal == v2.iVal );
  121. }
  122. BOOL VT_I2_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  123. {
  124. return( v1.iVal != v2.iVal );
  125. }
  126. BOOL VT_I2_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  127. {
  128. return( (v1.iVal & v2.iVal) == v2.iVal );
  129. }
  130. BOOL VT_I2_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  131. {
  132. return( (v1.iVal & v2.iVal) != 0 );
  133. }
  134. //
  135. // VT_I4
  136. //
  137. int VT_I4_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  138. {
  139. return ( v1.lVal > v2.lVal ) ? 1 : ( v1.lVal < v2.lVal ) ? -1 : 0;
  140. }
  141. BOOL VT_I4_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  142. {
  143. return( v1.lVal < v2.lVal );
  144. }
  145. BOOL VT_I4_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  146. {
  147. return( v1.lVal <= v2.lVal );
  148. }
  149. BOOL VT_I4_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  150. {
  151. return( v1.lVal >= v2.lVal );
  152. }
  153. BOOL VT_I4_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  154. {
  155. return( v1.lVal > v2.lVal );
  156. }
  157. BOOL VT_I4_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  158. {
  159. return( v1.lVal == v2.lVal );
  160. }
  161. BOOL VT_I4_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  162. {
  163. return( v1.lVal != v2.lVal );
  164. }
  165. BOOL VT_I4_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  166. {
  167. return( (v1.lVal & v2.lVal) == v2.lVal );
  168. }
  169. BOOL VT_I4_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  170. {
  171. return( (v1.lVal & v2.lVal) != 0 );
  172. }
  173. //
  174. // VT_R4
  175. //
  176. //
  177. // We can't use floating point in the kernel. Luckily, it's easy to
  178. // fake comparisons on floating point. The format of an IEEE floating
  179. // point number is:
  180. //
  181. // <sign bit> <biased exponent> <normalized mantissa>
  182. //
  183. // Because the exponent is biased, after flipping the sign bit we can
  184. // make all comparisons as if the numbers were unsigned long.
  185. //
  186. ULONG const R4_SignBit = 0x80000000;
  187. int VT_R4_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  188. {
  189. // axp (not x86) generates exceptions when floating point numbers
  190. // don't look like ieee floating point numbers. This can happen
  191. // with bogus queries or bogus values stored in properties or the
  192. // property store.
  193. #if (_X86_ == 1)
  194. return ( v1.fltVal > v2.fltVal ) ? 1 :
  195. ( v1.fltVal < v2.fltVal ) ? -1 : 0;
  196. #else
  197. ULONG u1 = v1.ulVal ^ R4_SignBit;
  198. ULONG u2 = v2.ulVal ^ R4_SignBit;
  199. if ( (v1.ulVal & v2.ulVal & R4_SignBit) != 0 )
  200. return ( ( u1 > u2 ) ? -1 : ( u1 < u2 ) ? 1 : 0 );
  201. else
  202. return ( ( u1 > u2 ) ? 1 : ( u1 < u2 ) ? -1 : 0 );
  203. #endif
  204. }
  205. BOOL VT_R4_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  206. {
  207. return VT_R4_Compare( v1, v2 ) < 0;
  208. }
  209. BOOL VT_R4_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  210. {
  211. return VT_R4_Compare( v1, v2 ) <= 0;
  212. }
  213. BOOL VT_R4_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  214. {
  215. return VT_R4_Compare( v1, v2 ) >= 0;
  216. }
  217. BOOL VT_R4_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  218. {
  219. return VT_R4_Compare( v1, v2 ) > 0;
  220. }
  221. BOOL VT_R4_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  222. {
  223. return( v1.ulVal == v2.ulVal );
  224. }
  225. BOOL VT_R4_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  226. {
  227. return( v1.ulVal != v2.ulVal );
  228. }
  229. //
  230. // VT_R8
  231. //
  232. LONGLONG const R8_SignBit = 0x8000000000000000;
  233. int VT_R8_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  234. {
  235. // axp (not x86) generates exceptions when floating point numbers
  236. // don't look like ieee floating point numbers. This can happen
  237. // with bogus queries or bogus values stored in properties or the
  238. // property store.
  239. #if (_X86_ == 1)
  240. return ( v1.dblVal > v2.dblVal ) ? 1 :
  241. ( v1.dblVal < v2.dblVal ) ? -1 : 0;
  242. #else
  243. if ( (v1.uhVal.QuadPart & v2.uhVal.QuadPart & R8_SignBit) != 0 )
  244. return( (v1.uhVal.QuadPart ^ R8_SignBit) < (v2.uhVal.QuadPart ^ R8_SignBit) ? 1 :
  245. (v1.uhVal.QuadPart ^ R8_SignBit) == (v2.uhVal.QuadPart ^ R8_SignBit) ? 0 :
  246. -1 );
  247. else
  248. return( (v1.uhVal.QuadPart ^ R8_SignBit) > (v2.uhVal.QuadPart ^ R8_SignBit) ? 1 :
  249. (v1.uhVal.QuadPart ^ R8_SignBit) == (v2.uhVal.QuadPart ^ R8_SignBit) ? 0 :
  250. -1 );
  251. #endif // 0
  252. }
  253. BOOL VT_R8_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  254. {
  255. return VT_R8_Compare( v1, v2 ) < 0;
  256. }
  257. BOOL VT_R8_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  258. {
  259. return VT_R8_Compare( v1, v2 ) <= 0;
  260. }
  261. BOOL VT_R8_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  262. {
  263. return VT_R8_Compare( v1, v2 ) >= 0;
  264. }
  265. BOOL VT_R8_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  266. {
  267. return VT_R8_Compare( v1, v2 ) > 0;
  268. }
  269. BOOL VT_R8_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  270. {
  271. return( v1.uhVal.QuadPart == v2.uhVal.QuadPart );
  272. }
  273. BOOL VT_R8_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  274. {
  275. return( v1.uhVal.QuadPart != v2.uhVal.QuadPart );
  276. }
  277. //
  278. // VT_BSTR
  279. //
  280. int VT_BSTR_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  281. {
  282. BSTR const pxv1 = v1.bstrVal;
  283. BSTR const pxv2 = v2.bstrVal;
  284. return wcscmp( pxv1, pxv2);
  285. }
  286. BOOL VT_BSTR_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  287. {
  288. return( VT_BSTR_Compare( v1, v2 ) < 0 );
  289. }
  290. BOOL VT_BSTR_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  291. {
  292. return( VT_BSTR_Compare( v1, v2 ) <= 0 );
  293. }
  294. BOOL VT_BSTR_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  295. {
  296. return( VT_BSTR_Compare( v1, v2 ) >= 0 );
  297. }
  298. BOOL VT_BSTR_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  299. {
  300. return( VT_BSTR_Compare( v1, v2 ) > 0 );
  301. }
  302. BOOL VT_BSTR_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  303. {
  304. BSTR const pxv1 = v1.bstrVal;
  305. BSTR const pxv2 = v2.bstrVal;
  306. return( wcscmp( pxv1, pxv2) == 0 );
  307. }
  308. BOOL VT_BSTR_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  309. {
  310. BSTR const pxv1 = v1.bstrVal;
  311. BSTR const pxv2 = v2.bstrVal;
  312. return( wcscmp( pxv1, pxv2) != 0 );
  313. }
  314. //
  315. // VT_BOOL
  316. //
  317. int VT_BOOL_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  318. {
  319. if (v1.boolVal == 0)
  320. if (v2.boolVal == 0)
  321. return( 0 );
  322. else
  323. return( -1 );
  324. else
  325. if (v2.boolVal == 0)
  326. return( 1 );
  327. else
  328. return( 0 );
  329. }
  330. BOOL VT_BOOL_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  331. {
  332. return( ((v1.boolVal==0) && (v2.boolVal==0)) ||
  333. ((v1.boolVal!=0) && (v2.boolVal!=0)) );
  334. }
  335. BOOL VT_BOOL_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  336. {
  337. return( !VT_BOOL_EQ( v1, v2 ) );
  338. }
  339. //
  340. // VT_VARIANT
  341. //
  342. int VT_VARIANT_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  343. {
  344. if ( v1.vt != v2.vt )
  345. return v1.vt - v2.vt;
  346. FCmp comp = VariantCompare.GetComparator( (VARENUM) v1.vt );
  347. if (0 == comp)
  348. return 0;
  349. else
  350. return comp( v1, v2 );
  351. }
  352. BOOL VT_VARIANT_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  353. {
  354. return VT_VARIANT_Compare( v1, v2 ) < 0;
  355. }
  356. BOOL VT_VARIANT_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  357. {
  358. return VT_VARIANT_Compare( v1, v2 ) <= 0;
  359. }
  360. BOOL VT_VARIANT_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  361. {
  362. return VT_VARIANT_Compare( v1, v2 ) >= 0;
  363. }
  364. BOOL VT_VARIANT_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  365. {
  366. return VT_VARIANT_Compare( v1, v2 ) > 0;
  367. }
  368. BOOL VT_VARIANT_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  369. {
  370. return VT_VARIANT_Compare( v1, v2 ) == 0;
  371. }
  372. BOOL VT_VARIANT_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  373. {
  374. return VT_VARIANT_Compare( v1, v2 ) != 0;
  375. }
  376. //
  377. // VT_DECIMAL
  378. //
  379. int VT_DEC_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  380. {
  381. if ( v1.decVal.sign == v2.decVal.sign &&
  382. v1.decVal.scale == v2.decVal.scale &&
  383. v1.decVal.Hi32 == v2.decVal.Hi32 &&
  384. v1.decVal.Lo64 == v2.decVal.Lo64)
  385. return 0;
  386. int iSign = v1.decVal.sign == DECIMAL_NEG ? -1 : 1;
  387. if ( v1.decVal.sign != v2.decVal.sign )
  388. return iSign;
  389. if ( v1.decVal.scale == v2.decVal.scale )
  390. {
  391. int iRet = 0;
  392. if (v1.decVal.Hi32 != v2.decVal.Hi32)
  393. iRet = (v1.decVal.Hi32 < v2.decVal.Hi32) ? -1 : 1;
  394. else if (v1.decVal.Lo64 != v2.decVal.Lo64)
  395. iRet = (v1.decVal.Lo64 < v2.decVal.Lo64) ? -1 : 1;
  396. return iRet * iSign;
  397. }
  398. double d1;
  399. VarR8FromDec( (DECIMAL*)&v1.decVal, &d1 );
  400. double d2;
  401. VarR8FromDec( (DECIMAL*)&v2.decVal, &d2 );
  402. return (( d1 > d2 ) ? 1 : ( d1 < d2 ) ? -1 : 0);
  403. }
  404. BOOL VT_DEC_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  405. {
  406. return VT_VARIANT_Compare( v1, v2 ) < 0;
  407. }
  408. BOOL VT_DEC_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  409. {
  410. return VT_DEC_Compare( v1, v2 ) <= 0;
  411. }
  412. BOOL VT_DEC_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  413. {
  414. return VT_DEC_Compare( v1, v2 ) >= 0;
  415. }
  416. BOOL VT_DEC_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  417. {
  418. return VT_DEC_Compare( v1, v2 ) > 0;
  419. }
  420. BOOL VT_DEC_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  421. {
  422. return VT_DEC_Compare( v1, v2 ) == 0;
  423. }
  424. BOOL VT_DEC_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  425. {
  426. return VT_DEC_Compare( v1, v2 ) != 0;
  427. }
  428. //
  429. // VT_I1
  430. //
  431. int VT_I1_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  432. {
  433. return( v1.cVal - v2.cVal );
  434. }
  435. BOOL VT_I1_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  436. {
  437. return( v1.cVal < v2.cVal );
  438. }
  439. BOOL VT_I1_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  440. {
  441. return( v1.cVal <= v2.cVal );
  442. }
  443. BOOL VT_I1_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  444. {
  445. return( v1.cVal >= v2.cVal );
  446. }
  447. BOOL VT_I1_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  448. {
  449. return( v1.cVal > v2.cVal );
  450. }
  451. BOOL VT_I1_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  452. {
  453. return( v1.cVal == v2.cVal );
  454. }
  455. BOOL VT_I1_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  456. {
  457. return( v1.cVal != v2.cVal );
  458. }
  459. BOOL VT_I1_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  460. {
  461. return( (v1.cVal & v2.cVal) == v2.cVal );
  462. }
  463. BOOL VT_I1_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  464. {
  465. return( (v1.cVal & v2.cVal) != 0 );
  466. }
  467. //
  468. // VT_UI1
  469. //
  470. int VT_UI1_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  471. {
  472. return( v1.bVal - v2.bVal );
  473. }
  474. BOOL VT_UI1_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  475. {
  476. return( v1.bVal < v2.bVal );
  477. }
  478. BOOL VT_UI1_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  479. {
  480. return( v1.bVal <= v2.bVal );
  481. }
  482. BOOL VT_UI1_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  483. {
  484. return( v1.bVal >= v2.bVal );
  485. }
  486. BOOL VT_UI1_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  487. {
  488. return( v1.bVal > v2.bVal );
  489. }
  490. BOOL VT_UI1_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  491. {
  492. return( v1.bVal == v2.bVal );
  493. }
  494. BOOL VT_UI1_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  495. {
  496. return( v1.bVal != v2.bVal );
  497. }
  498. BOOL VT_UI1_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  499. {
  500. return( (v1.bVal & v2.bVal) == v2.bVal );
  501. }
  502. BOOL VT_UI1_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  503. {
  504. return( (v1.bVal & v2.bVal) != 0 );
  505. }
  506. //
  507. // VT_UI2
  508. //
  509. int VT_UI2_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  510. {
  511. return( v1.uiVal - v2.uiVal );
  512. }
  513. BOOL VT_UI2_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  514. {
  515. return( v1.uiVal < v2.uiVal );
  516. }
  517. BOOL VT_UI2_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  518. {
  519. return( v1.uiVal <= v2.uiVal );
  520. }
  521. BOOL VT_UI2_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  522. {
  523. return( v1.uiVal >= v2.uiVal );
  524. }
  525. BOOL VT_UI2_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  526. {
  527. return( v1.uiVal > v2.uiVal );
  528. }
  529. BOOL VT_UI2_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  530. {
  531. return( v1.uiVal == v2.uiVal );
  532. }
  533. BOOL VT_UI2_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  534. {
  535. return( v1.uiVal != v2.uiVal );
  536. }
  537. BOOL VT_UI2_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  538. {
  539. return( (v1.uiVal & v2.uiVal) == v2.uiVal );
  540. }
  541. BOOL VT_UI2_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  542. {
  543. return( (v1.uiVal & v2.uiVal) != 0 );
  544. }
  545. //
  546. // VT_UI4
  547. //
  548. int VT_UI4_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  549. {
  550. return ( v1.ulVal > v2.ulVal ) ? 1 : ( v1.ulVal < v2.ulVal ) ? -1 : 0;
  551. }
  552. BOOL VT_UI4_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  553. {
  554. return( v1.ulVal < v2.ulVal );
  555. }
  556. BOOL VT_UI4_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  557. {
  558. return( v1.ulVal <= v2.ulVal );
  559. }
  560. BOOL VT_UI4_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  561. {
  562. return( v1.ulVal >= v2.ulVal );
  563. }
  564. BOOL VT_UI4_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  565. {
  566. return( v1.ulVal > v2.ulVal );
  567. }
  568. BOOL VT_UI4_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  569. {
  570. return( v1.ulVal == v2.ulVal );
  571. }
  572. BOOL VT_UI4_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  573. {
  574. return( v1.ulVal != v2.ulVal );
  575. }
  576. BOOL VT_UI4_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  577. {
  578. return( (v1.ulVal & v2.ulVal) == v2.ulVal );
  579. }
  580. BOOL VT_UI4_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  581. {
  582. return( (v1.ulVal & v2.ulVal) != 0 );
  583. }
  584. //
  585. // VT_I8
  586. //
  587. int VT_I8_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  588. {
  589. return( v1.hVal.QuadPart > v2.hVal.QuadPart ? 1 :
  590. v1.hVal.QuadPart == v2.hVal.QuadPart ? 0 :
  591. -1 );
  592. }
  593. BOOL VT_I8_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  594. {
  595. return( v1.hVal.QuadPart < v2.hVal.QuadPart );
  596. }
  597. BOOL VT_I8_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  598. {
  599. return( v1.hVal.QuadPart <= v2.hVal.QuadPart );
  600. }
  601. BOOL VT_I8_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  602. {
  603. return( v1.hVal.QuadPart >= v2.hVal.QuadPart );
  604. }
  605. BOOL VT_I8_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  606. {
  607. return( v1.hVal.QuadPart > v2.hVal.QuadPart );
  608. }
  609. BOOL VT_I8_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  610. {
  611. return( v1.hVal.QuadPart == v2.hVal.QuadPart );
  612. }
  613. BOOL VT_I8_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  614. {
  615. return( v1.hVal.QuadPart != v2.hVal.QuadPart );
  616. }
  617. BOOL VT_I8_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  618. {
  619. return( (v1.hVal.QuadPart & v2.hVal.QuadPart) == v2.hVal.QuadPart );
  620. }
  621. BOOL VT_I8_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  622. {
  623. return( (v1.hVal.QuadPart & v2.hVal.QuadPart) != 0 );
  624. }
  625. //
  626. // VT_UI8
  627. //
  628. int VT_UI8_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  629. {
  630. return( v1.uhVal.QuadPart > v2.uhVal.QuadPart ? 1 :
  631. v1.uhVal.QuadPart == v2.uhVal.QuadPart ? 0 :
  632. -1 );
  633. }
  634. BOOL VT_UI8_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  635. {
  636. return( v1.uhVal.QuadPart < v2.uhVal.QuadPart );
  637. }
  638. BOOL VT_UI8_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  639. {
  640. return( v1.uhVal.QuadPart <= v2.uhVal.QuadPart );
  641. }
  642. BOOL VT_UI8_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  643. {
  644. return( v1.uhVal.QuadPart >= v2.uhVal.QuadPart );
  645. }
  646. BOOL VT_UI8_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  647. {
  648. return( v1.uhVal.QuadPart > v2.uhVal.QuadPart );
  649. }
  650. BOOL VT_UI8_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  651. {
  652. return( v1.uhVal.QuadPart == v2.uhVal.QuadPart );
  653. }
  654. BOOL VT_UI8_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  655. {
  656. return( v1.uhVal.QuadPart != v2.uhVal.QuadPart );
  657. }
  658. BOOL VT_UI8_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  659. {
  660. return( (v1.uhVal.QuadPart & v2.uhVal.QuadPart) == v2.uhVal.QuadPart );
  661. }
  662. BOOL VT_UI8_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  663. {
  664. return( (v1.uhVal.QuadPart & v2.uhVal.QuadPart) != 0 );
  665. }
  666. //
  667. // VT_LPSTR
  668. //
  669. int VT_LPSTR_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  670. {
  671. return ( lstrcmpiA( v1.pszVal, v2.pszVal ) );
  672. }
  673. BOOL VT_LPSTR_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  674. {
  675. int rc = lstrcmpiA( v1.pszVal, v2.pszVal );
  676. return( rc < 0 );
  677. }
  678. BOOL VT_LPSTR_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  679. {
  680. int rc = lstrcmpiA( v1.pszVal, v2.pszVal );
  681. return( rc <= 0 );
  682. }
  683. BOOL VT_LPSTR_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  684. {
  685. int rc = lstrcmpiA( v1.pszVal, v2.pszVal );
  686. return( rc >= 0 );
  687. }
  688. BOOL VT_LPSTR_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  689. {
  690. int rc = lstrcmpiA( v1.pszVal, v2.pszVal );
  691. return( rc > 0 );
  692. }
  693. BOOL VT_LPSTR_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  694. {
  695. return( lstrcmpiA( v1.pszVal, v2.pszVal ) == 0 );
  696. }
  697. BOOL VT_LPSTR_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  698. {
  699. return( lstrcmpiA( v1.pszVal, v2.pszVal ) != 0 );
  700. }
  701. //
  702. // VT_LPWSTR
  703. //
  704. int VT_LPWSTR_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  705. {
  706. int rc = CompareStringW( LOCALE_SYSTEM_DEFAULT,
  707. NORM_IGNORECASE,
  708. v1.pwszVal,
  709. -1,
  710. v2.pwszVal,
  711. -1 );
  712. //
  713. // rc == 1, means less than
  714. // rc == 2, means equal
  715. // rc == 3, means greater than
  716. //
  717. return rc - 2;
  718. }
  719. BOOL VT_LPWSTR_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  720. {
  721. return ( VT_LPWSTR_Compare( v1, v2 ) < 0 );
  722. }
  723. BOOL VT_LPWSTR_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  724. {
  725. return ( VT_LPWSTR_Compare( v1, v2 ) <= 0 );
  726. }
  727. BOOL VT_LPWSTR_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  728. {
  729. return ( VT_LPWSTR_Compare( v1, v2 ) >= 0 );
  730. }
  731. BOOL VT_LPWSTR_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  732. {
  733. return ( VT_LPWSTR_Compare( v1, v2 ) > 0 );
  734. }
  735. BOOL VT_LPWSTR_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  736. {
  737. return ( VT_LPWSTR_Compare( v1, v2 ) == 0 );
  738. }
  739. BOOL VT_LPWSTR_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  740. {
  741. return ( VT_LPWSTR_Compare( v1, v2 ) != 0 );
  742. }
  743. //
  744. // VT_BLOB
  745. //
  746. int VT_BLOB_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  747. {
  748. ULONG len = v1.blob.cbSize;
  749. if ( v2.blob.cbSize < len )
  750. len = v2.blob.cbSize;
  751. int iCmp = memcmp( v1.blob.pBlobData,
  752. v2.blob.pBlobData,
  753. len );
  754. if ( iCmp != 0 || v1.blob.cbSize == v2.blob.cbSize )
  755. return( iCmp );
  756. if ( v1.blob.cbSize > v2.blob.cbSize )
  757. return( 1 );
  758. else
  759. return( -1 );
  760. }
  761. BOOL VT_BLOB_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  762. {
  763. return( VT_BLOB_Compare( v1, v2 ) < 0 );
  764. }
  765. BOOL VT_BLOB_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  766. {
  767. return( VT_BLOB_Compare( v1, v2 ) <= 0 );
  768. }
  769. BOOL VT_BLOB_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  770. {
  771. return( VT_BLOB_Compare( v1, v2 ) >= 0 );
  772. }
  773. BOOL VT_BLOB_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  774. {
  775. return( VT_BLOB_Compare( v1, v2 ) > 0 );
  776. }
  777. BOOL VT_BLOB_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  778. {
  779. return( v1.blob.cbSize == v2.blob.cbSize &&
  780. memcmp( v1.blob.pBlobData,
  781. v2.blob.pBlobData,
  782. v1.blob.cbSize ) == 0 );
  783. }
  784. BOOL VT_BLOB_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  785. {
  786. return( v1.blob.cbSize != v2.blob.cbSize ||
  787. memcmp( v1.blob.pBlobData,
  788. v2.blob.pBlobData,
  789. v1.blob.cbSize ) != 0 );
  790. }
  791. //
  792. // VT_CF
  793. //
  794. int VT_CF_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  795. {
  796. if ( v1.pclipdata->ulClipFmt != v2.pclipdata->ulClipFmt )
  797. {
  798. return( v1.pclipdata->ulClipFmt - v2.pclipdata->ulClipFmt );
  799. }
  800. ULONG len = CBPCLIPDATA(*v1.pclipdata);
  801. if ( CBPCLIPDATA(*v2.pclipdata) < len )
  802. len = CBPCLIPDATA(*v2.pclipdata);
  803. int iCmp = memcmp( v1.pclipdata->pClipData,
  804. v2.pclipdata->pClipData,
  805. len );
  806. if ( iCmp != 0 || v1.pclipdata->cbSize == v2.pclipdata->cbSize )
  807. return( iCmp );
  808. if ( v1.pclipdata->cbSize > v2.pclipdata->cbSize )
  809. return( 1 );
  810. else
  811. return( -1 );
  812. }
  813. BOOL VT_CF_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  814. {
  815. return( VT_CF_Compare( v1, v2 ) < 0 );
  816. }
  817. BOOL VT_CF_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  818. {
  819. return( VT_CF_Compare( v1, v2 ) <= 0 );
  820. }
  821. BOOL VT_CF_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  822. {
  823. return( VT_CF_Compare( v1, v2 ) >= 0 );
  824. }
  825. BOOL VT_CF_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  826. {
  827. return( VT_CF_Compare( v1, v2 ) > 0 );
  828. }
  829. BOOL VT_CF_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  830. {
  831. return( v1.pclipdata->ulClipFmt == v2.pclipdata->ulClipFmt &&
  832. v1.pclipdata->cbSize == v2.pclipdata->cbSize &&
  833. memcmp( v1.pclipdata->pClipData,
  834. v2.pclipdata->pClipData,
  835. CBPCLIPDATA(*v1.pclipdata) ) == 0 );
  836. }
  837. BOOL VT_CF_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  838. {
  839. return( v1.pclipdata->ulClipFmt != v2.pclipdata->ulClipFmt ||
  840. v1.pclipdata->cbSize != v2.pclipdata->cbSize ||
  841. memcmp( v1.pclipdata->pClipData,
  842. v2.pclipdata->pClipData,
  843. CBPCLIPDATA(*v1.pclipdata) ) != 0 );
  844. }
  845. //
  846. // VT_CLSID
  847. //
  848. int VT_CLSID_Compare( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  849. {
  850. return( memcmp( v1.puuid, v2.puuid, sizeof(GUID) ) );
  851. }
  852. BOOL VT_CLSID_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  853. {
  854. return( memcmp( v1.puuid, v2.puuid, sizeof(GUID) ) == 0 );
  855. }
  856. BOOL VT_CLSID_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  857. {
  858. return( memcmp( v1.puuid, v2.puuid, sizeof(GUID) ) != 0 );
  859. }
  860. /////////////////////////////////////////////////////////////////////////
  861. /////////////////////////////////////////////////////////////////////////
  862. /////////////////////////////////////////////////////////////////////////
  863. /////////////////////////////////////////////////////////////////////////
  864. /////////////////////////////////////////////////////////////////////////
  865. /////////////////////////////////////////////////////////////////////////
  866. //
  867. // VTP_EMPTY
  868. //
  869. int VTP_EMPTY_Compare( BYTE const *pv1, BYTE const *pv2 )
  870. {
  871. return( TRUE );
  872. }
  873. BOOL VTP_EMPTY_EQ( BYTE const *pv1, BYTE const *pv2 )
  874. {
  875. return( TRUE );
  876. }
  877. BOOL VTP_EMPTY_NE( BYTE const *pv1, BYTE const *pv2 )
  878. {
  879. return( FALSE );
  880. }
  881. //
  882. // VTP_NULL
  883. //
  884. int VTP_NULL_Compare( BYTE const *pv1, BYTE const *pv2 )
  885. {
  886. return( TRUE );
  887. }
  888. BOOL VTP_NULL_EQ( BYTE const *pv1, BYTE const *pv2 )
  889. {
  890. return( TRUE );
  891. }
  892. BOOL VTP_NULL_NE( BYTE const *pv1, BYTE const *pv2 )
  893. {
  894. return( FALSE );
  895. }
  896. //
  897. // VTP_I2
  898. //
  899. int VTP_I2_Compare( BYTE const *pv1, BYTE const *pv2 )
  900. {
  901. return( (* (short *) pv1) - (* (short *) pv2) );
  902. }
  903. BOOL VTP_I2_LT( BYTE const *pv1, BYTE const *pv2 )
  904. {
  905. return( (* (short *) pv1) < (* (short *) pv2) );
  906. }
  907. BOOL VTP_I2_LE( BYTE const *pv1, BYTE const *pv2 )
  908. {
  909. return( (* (short *) pv1) <= (* (short *) pv2) );
  910. }
  911. BOOL VTP_I2_GE( BYTE const *pv1, BYTE const *pv2 )
  912. {
  913. return( (* (short *) pv1) >= (* (short *) pv2) );
  914. }
  915. BOOL VTP_I2_GT( BYTE const *pv1, BYTE const *pv2 )
  916. {
  917. return( (* (short *) pv1) > (* (short *) pv2) );
  918. }
  919. BOOL VTP_I2_EQ( BYTE const *pv1, BYTE const *pv2 )
  920. {
  921. return( (* (short *) pv1) == (* (short *) pv2) );
  922. }
  923. BOOL VTP_I2_NE( BYTE const *pv1, BYTE const *pv2 )
  924. {
  925. return( (* (short *) pv1) != (* (short *) pv2) );
  926. }
  927. BOOL VTP_I2_AllBits( BYTE const *pv1, BYTE const *pv2 )
  928. {
  929. return( ((* (short *) pv1) & (* (short *) pv2)) == (* (short *) pv2) );
  930. }
  931. BOOL VTP_I2_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  932. {
  933. return( ((* (short *) pv1) & (* (short *) pv2)) != 0 );
  934. }
  935. //
  936. // VTP_I4
  937. //
  938. int VTP_I4_Compare( BYTE const *pv1, BYTE const *pv2 )
  939. {
  940. long l1 = * (long *) pv1;
  941. long l2 = * (long *) pv2;
  942. return ( l1 > l2 ) ? 1 : ( l1 < l2 ) ? -1 : 0;
  943. }
  944. BOOL VTP_I4_LT( BYTE const *pv1, BYTE const *pv2 )
  945. {
  946. return( (* (long *) pv1) < (* (long *) pv2) );
  947. }
  948. BOOL VTP_I4_LE( BYTE const *pv1, BYTE const *pv2 )
  949. {
  950. return( (* (long *) pv1) <= (* (long *) pv2) );
  951. }
  952. BOOL VTP_I4_GE( BYTE const *pv1, BYTE const *pv2 )
  953. {
  954. return( (* (long *) pv1) >= (* (long *) pv2) );
  955. }
  956. BOOL VTP_I4_GT( BYTE const *pv1, BYTE const *pv2 )
  957. {
  958. return( (* (long *) pv1) > (* (long *) pv2) );
  959. }
  960. BOOL VTP_I4_EQ( BYTE const *pv1, BYTE const *pv2 )
  961. {
  962. return( (* (long *) pv1) == (* (long *) pv2) );
  963. }
  964. BOOL VTP_I4_NE( BYTE const *pv1, BYTE const *pv2 )
  965. {
  966. return( (* (long *) pv1) != (* (long *) pv2) );
  967. }
  968. BOOL VTP_I4_AllBits( BYTE const *pv1, BYTE const *pv2 )
  969. {
  970. return( ((* (long *) pv1) & (* (long *) pv2)) == (* (long *) pv2) );
  971. }
  972. BOOL VTP_I4_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  973. {
  974. return( ((* (long *) pv1) & (* (long *) pv2)) != 0 );
  975. }
  976. //
  977. // VTP_R4
  978. //
  979. //
  980. // We can't use floating point in the kernel. Luckily, it's easy to
  981. // fake comparisons on floating point. The format of an IEEE floating
  982. // point number is:
  983. //
  984. // <sign bit> <biased exponent> <normalized mantissa>
  985. //
  986. // Because the exponent is biased, after flipping the sign bit we can
  987. // make all comparisons as if the numbers were unsigned long.
  988. //
  989. int VTP_R4_Compare( BYTE const *pv1, BYTE const *pv2 )
  990. {
  991. #if 0
  992. ULONG ul1 = * (ULONG *) pv1;
  993. ULONG ul2 = * (ULONG *) pv2;
  994. ULONG u1 = ul1 ^ R4_SignBit;
  995. ULONG u2 = ul2 ^ R4_SignBit;
  996. if ( (ul1 & ul2 & R4_SignBit) != 0 )
  997. return ( ( u1 > u2 ) ? -1 : ( u1 < u2 ) ? 1 : 0 );
  998. else
  999. return ( ( u1 > u2 ) ? 1 : ( u1 < u2 ) ? -1 : 0 );
  1000. #else // 0
  1001. float f1 = * (float *) pv1;
  1002. float f2 = * (float *) pv2;
  1003. return ( f1 > f2 ) ? 1 : ( f1 < f2 ) ? -1 : 0;
  1004. #endif // 0
  1005. }
  1006. BOOL VTP_R4_LT( BYTE const *pv1, BYTE const *pv2 )
  1007. {
  1008. return VTP_R4_Compare( pv1, pv2 ) < 0;
  1009. }
  1010. BOOL VTP_R4_LE( BYTE const *pv1, BYTE const *pv2 )
  1011. {
  1012. return VTP_R4_Compare( pv1, pv2 ) <= 0;
  1013. }
  1014. BOOL VTP_R4_GE( BYTE const *pv1, BYTE const *pv2 )
  1015. {
  1016. return VTP_R4_Compare( pv1, pv2 ) >= 0;
  1017. }
  1018. BOOL VTP_R4_GT( BYTE const *pv1, BYTE const *pv2 )
  1019. {
  1020. return VTP_R4_Compare( pv1, pv2 ) > 0;
  1021. }
  1022. BOOL VTP_R4_EQ( BYTE const *pv1, BYTE const *pv2 )
  1023. {
  1024. return VTP_R4_Compare( pv1, pv2 ) == 0;
  1025. }
  1026. BOOL VTP_R4_NE( BYTE const *pv1, BYTE const *pv2 )
  1027. {
  1028. return VTP_R4_Compare( pv1, pv2 ) != 0;
  1029. }
  1030. //
  1031. // VTP_R8
  1032. //
  1033. int VTP_R8_Compare( BYTE const *pv1, BYTE const *pv2 )
  1034. {
  1035. #if 0
  1036. ULONGLONG uh1 = * (ULONGLONG *) pv1;
  1037. ULONGLONG uh2 = * (ULONGLONG *) pv2;
  1038. if ( (uh1 & uh2 & R8_SignBit) != 0 )
  1039. return( (uh1 ^ R8_SignBit) < (uh2 ^ R8_SignBit) ? 1 :
  1040. (uh1 ^ R8_SignBit) == (uh2 ^ R8_SignBit) ? 0 :
  1041. -1 );
  1042. else
  1043. return( (uh1 ^ R8_SignBit) > (uh2 ^ R8_SignBit) ? 1 :
  1044. (uh1 ^ R8_SignBit) == (uh2 ^ R8_SignBit) ? 0 :
  1045. -1 );
  1046. #else // 0
  1047. double d1 = * (double *) pv1;
  1048. double d2 = * (double *) pv2;
  1049. return ( d1 > d2 ) ? 1 : ( d1 < d2 ) ? -1 : 0;
  1050. #endif // 0
  1051. }
  1052. BOOL VTP_R8_LT( BYTE const *pv1, BYTE const *pv2 )
  1053. {
  1054. return VTP_R8_Compare( pv1, pv2 ) < 0;
  1055. }
  1056. BOOL VTP_R8_LE( BYTE const *pv1, BYTE const *pv2 )
  1057. {
  1058. return VTP_R8_Compare( pv1, pv2 ) <= 0;
  1059. }
  1060. BOOL VTP_R8_GE( BYTE const *pv1, BYTE const *pv2 )
  1061. {
  1062. return VTP_R8_Compare( pv1, pv2 ) >= 0;
  1063. }
  1064. BOOL VTP_R8_GT( BYTE const *pv1, BYTE const *pv2 )
  1065. {
  1066. return VTP_R8_Compare( pv1, pv2 ) > 0;
  1067. }
  1068. BOOL VTP_R8_EQ( BYTE const *pv1, BYTE const *pv2 )
  1069. {
  1070. return VTP_R8_Compare( pv1, pv2 ) == 0;
  1071. }
  1072. BOOL VTP_R8_NE( BYTE const *pv1, BYTE const *pv2 )
  1073. {
  1074. return VTP_R8_Compare( pv1, pv2 ) != 0;
  1075. }
  1076. //
  1077. // VTP_BSTR
  1078. //
  1079. int VTP_BSTR_Compare( BYTE const *pv1, BYTE const *pv2 )
  1080. {
  1081. BSTR const pxv1 = *(BSTR*)pv1;
  1082. BSTR const pxv2 = *(BSTR*)pv2;
  1083. return wcscmp( pxv1, pxv2 );
  1084. }
  1085. BOOL VTP_BSTR_LT( BYTE const *pv1, BYTE const *pv2 )
  1086. {
  1087. return( VTP_BSTR_Compare( pv1, pv2 ) < 0 );
  1088. }
  1089. BOOL VTP_BSTR_LE( BYTE const *pv1, BYTE const *pv2 )
  1090. {
  1091. return( VTP_BSTR_Compare( pv1, pv2 ) <= 0 );
  1092. }
  1093. BOOL VTP_BSTR_GE( BYTE const *pv1, BYTE const *pv2 )
  1094. {
  1095. return( VTP_BSTR_Compare( pv1, pv2 ) >= 0 );
  1096. }
  1097. BOOL VTP_BSTR_GT( BYTE const *pv1, BYTE const *pv2 )
  1098. {
  1099. return( VTP_BSTR_Compare( pv1, pv2 ) > 0 );
  1100. }
  1101. BOOL VTP_BSTR_EQ( BYTE const *pv1, BYTE const *pv2 )
  1102. {
  1103. BSTR const pxv1 = *(BSTR*)pv1;
  1104. BSTR const pxv2 = *(BSTR*)pv2;
  1105. return( wcscmp( pxv1, pxv2 ) == 0 );
  1106. }
  1107. BOOL VTP_BSTR_NE( BYTE const *pv1, BYTE const *pv2 )
  1108. {
  1109. BSTR const pxv1 = *(BSTR*)pv1;
  1110. BSTR const pxv2 = *(BSTR*)pv2;
  1111. return( wcscmp( pxv1, pxv2 ) != 0 );
  1112. }
  1113. //
  1114. // VTP_BOOL
  1115. //
  1116. int VTP_BOOL_Compare( BYTE const *pv1, BYTE const *pv2 )
  1117. {
  1118. if ((*(VARIANT_BOOL *) pv1) == 0)
  1119. if ((*(VARIANT_BOOL *) pv2) == 0)
  1120. return( 0 );
  1121. else
  1122. return( -1 );
  1123. else
  1124. if ((*(VARIANT_BOOL *) pv2) == 0)
  1125. return( 1 );
  1126. else
  1127. return( 0 );
  1128. }
  1129. BOOL VTP_BOOL_EQ( BYTE const *pv1, BYTE const *pv2 )
  1130. {
  1131. return( ( ((*(VARIANT_BOOL *) pv1)==0) && ((*(VARIANT_BOOL *) pv2)==0) ) ||
  1132. ( ((*(VARIANT_BOOL *) pv1)!=0) && ((*(VARIANT_BOOL *) pv2)!=0) ) );
  1133. }
  1134. BOOL VTP_BOOL_NE( BYTE const *pv1, BYTE const *pv2 )
  1135. {
  1136. return( !VTP_BOOL_EQ( pv1, pv2 ) );
  1137. }
  1138. //
  1139. // VTP_VARIANT
  1140. //
  1141. int VTP_VARIANT_Compare( BYTE const *pv1, BYTE const *pv2 )
  1142. {
  1143. return VT_VARIANT_Compare( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1144. }
  1145. BOOL VTP_VARIANT_LT( BYTE const *pv1, BYTE const *pv2 )
  1146. {
  1147. return VT_VARIANT_LT( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1148. }
  1149. BOOL VTP_VARIANT_LE( BYTE const *pv1, BYTE const *pv2 )
  1150. {
  1151. return VT_VARIANT_LE( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1152. }
  1153. BOOL VTP_VARIANT_GE( BYTE const *pv1, BYTE const *pv2 )
  1154. {
  1155. return VT_VARIANT_GE( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1156. }
  1157. BOOL VTP_VARIANT_GT( BYTE const *pv1, BYTE const *pv2 )
  1158. {
  1159. return VT_VARIANT_GT( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1160. }
  1161. BOOL VTP_VARIANT_EQ( BYTE const *pv1, BYTE const *pv2 )
  1162. {
  1163. return VT_VARIANT_EQ( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1164. }
  1165. BOOL VTP_VARIANT_NE( BYTE const *pv1, BYTE const *pv2 )
  1166. {
  1167. return VT_VARIANT_NE( * (PROPVARIANT *) pv1, * (PROPVARIANT *) pv2 );
  1168. }
  1169. //
  1170. // VTP_DECIMAL
  1171. //
  1172. int VTP_DEC_Compare( BYTE const *pv1, BYTE const *pv2 )
  1173. {
  1174. PROPVARIANT v1;
  1175. RtlCopyMemory( &v1, pv1, sizeof DECIMAL );
  1176. v1.vt = VT_DECIMAL;
  1177. PROPVARIANT v2;
  1178. RtlCopyMemory( &v2, pv2, sizeof DECIMAL );
  1179. v2.vt = VT_DECIMAL;
  1180. return VT_DEC_Compare( v1, v2 );
  1181. }
  1182. BOOL VTP_DEC_LT( BYTE const *pv1, BYTE const *pv2 )
  1183. {
  1184. return ( VTP_DEC_Compare( pv1, pv2 ) < 0 );
  1185. }
  1186. BOOL VTP_DEC_LE( BYTE const *pv1, BYTE const *pv2 )
  1187. {
  1188. return ( VTP_DEC_Compare( pv1, pv2 ) <= 0 );
  1189. }
  1190. BOOL VTP_DEC_GE( BYTE const *pv1, BYTE const *pv2 )
  1191. {
  1192. return ( VTP_DEC_Compare( pv1, pv2 ) >= 0 );
  1193. }
  1194. BOOL VTP_DEC_GT( BYTE const *pv1, BYTE const *pv2 )
  1195. {
  1196. return ( VTP_DEC_Compare( pv1, pv2 ) > 0 );
  1197. }
  1198. BOOL VTP_DEC_EQ( BYTE const *pv1, BYTE const *pv2 )
  1199. {
  1200. return ( VTP_DEC_Compare( pv1, pv2 ) == 0 );
  1201. }
  1202. BOOL VTP_DEC_NE( BYTE const *pv1, BYTE const *pv2 )
  1203. {
  1204. return ( VTP_DEC_Compare( pv1, pv2 ) != 0 );
  1205. }
  1206. //
  1207. // VTP_I1
  1208. //
  1209. int VTP_I1_Compare( BYTE const *pv1, BYTE const *pv2 )
  1210. {
  1211. return( (*(signed char *) pv1) - (*(signed char *) pv2) );
  1212. }
  1213. BOOL VTP_I1_LT( BYTE const *pv1, BYTE const *pv2 )
  1214. {
  1215. return( (*(signed char *) pv1) < (*(signed char *) pv2) );
  1216. }
  1217. BOOL VTP_I1_LE( BYTE const *pv1, BYTE const *pv2 )
  1218. {
  1219. return( (*(signed char *) pv1) <= (*(signed char *) pv2) );
  1220. }
  1221. BOOL VTP_I1_GE( BYTE const *pv1, BYTE const *pv2 )
  1222. {
  1223. return( (*(signed char *) pv1) >= (*(signed char *) pv2) );
  1224. }
  1225. BOOL VTP_I1_GT( BYTE const *pv1, BYTE const *pv2 )
  1226. {
  1227. return( (*(signed char *) pv1) > (*(signed char *) pv2) );
  1228. }
  1229. BOOL VTP_I1_EQ( BYTE const *pv1, BYTE const *pv2 )
  1230. {
  1231. return( (*(signed char *) pv1) == (*(signed char *) pv2) );
  1232. }
  1233. BOOL VTP_I1_NE( BYTE const *pv1, BYTE const *pv2 )
  1234. {
  1235. return( (*(signed char *) pv1) != (*(signed char *) pv2) );
  1236. }
  1237. BOOL VTP_I1_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1238. {
  1239. return( ((*(signed char *) pv1) & (*(signed char *) pv2)) == (*(signed char *) pv2) );
  1240. }
  1241. BOOL VTP_I1_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1242. {
  1243. return( ((*(signed char *) pv1) & (*(signed char *) pv2)) != 0 );
  1244. }
  1245. //
  1246. // VTP_UI1
  1247. //
  1248. int VTP_UI1_Compare( BYTE const *pv1, BYTE const *pv2 )
  1249. {
  1250. return( (*(unsigned char *) pv1) - (*(unsigned char *) pv2) );
  1251. }
  1252. BOOL VTP_UI1_LT( BYTE const *pv1, BYTE const *pv2 )
  1253. {
  1254. return( (*(unsigned char *) pv1) < (*(unsigned char *) pv2) );
  1255. }
  1256. BOOL VTP_UI1_LE( BYTE const *pv1, BYTE const *pv2 )
  1257. {
  1258. return( (*(unsigned char *) pv1) <= (*(unsigned char *) pv2) );
  1259. }
  1260. BOOL VTP_UI1_GE( BYTE const *pv1, BYTE const *pv2 )
  1261. {
  1262. return( (*(unsigned char *) pv1) >= (*(unsigned char *) pv2) );
  1263. }
  1264. BOOL VTP_UI1_GT( BYTE const *pv1, BYTE const *pv2 )
  1265. {
  1266. return( (*(unsigned char *) pv1) > (*(unsigned char *) pv2) );
  1267. }
  1268. BOOL VTP_UI1_EQ( BYTE const *pv1, BYTE const *pv2 )
  1269. {
  1270. return( (*(unsigned char *) pv1) == (*(unsigned char *) pv2) );
  1271. }
  1272. BOOL VTP_UI1_NE( BYTE const *pv1, BYTE const *pv2 )
  1273. {
  1274. return( (*(unsigned char *) pv1) != (*(unsigned char *) pv2) );
  1275. }
  1276. BOOL VTP_UI1_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1277. {
  1278. return( ((*(unsigned char *) pv1) & (*(unsigned char *) pv2)) == (*(unsigned char *) pv2) );
  1279. }
  1280. BOOL VTP_UI1_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1281. {
  1282. return( ((*(unsigned char *) pv1) & (*(unsigned char *) pv2)) != 0 );
  1283. }
  1284. //
  1285. // VTP_UI2
  1286. //
  1287. int VTP_UI2_Compare( BYTE const *pv1, BYTE const *pv2 )
  1288. {
  1289. return( (*(USHORT *) pv1) - (*(USHORT *) pv2) );
  1290. }
  1291. BOOL VTP_UI2_LT( BYTE const *pv1, BYTE const *pv2 )
  1292. {
  1293. return( (*(USHORT *) pv1) < (*(USHORT *) pv2) );
  1294. }
  1295. BOOL VTP_UI2_LE( BYTE const *pv1, BYTE const *pv2 )
  1296. {
  1297. return( (*(USHORT *) pv1) <= (*(USHORT *) pv2) );
  1298. }
  1299. BOOL VTP_UI2_GE( BYTE const *pv1, BYTE const *pv2 )
  1300. {
  1301. return( (*(USHORT *) pv1) >= (*(USHORT *) pv2) );
  1302. }
  1303. BOOL VTP_UI2_GT( BYTE const *pv1, BYTE const *pv2 )
  1304. {
  1305. return( (*(USHORT *) pv1) > (*(USHORT *) pv2) );
  1306. }
  1307. BOOL VTP_UI2_EQ( BYTE const *pv1, BYTE const *pv2 )
  1308. {
  1309. return( (*(USHORT *) pv1) == (*(USHORT *) pv2) );
  1310. }
  1311. BOOL VTP_UI2_NE( BYTE const *pv1, BYTE const *pv2 )
  1312. {
  1313. return( (*(USHORT *) pv1) != (*(USHORT *) pv2) );
  1314. }
  1315. BOOL VTP_UI2_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1316. {
  1317. return( ((*(USHORT *) pv1) & (*(USHORT *) pv2)) == (*(USHORT *) pv2) );
  1318. }
  1319. BOOL VTP_UI2_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1320. {
  1321. return( ((*(USHORT *) pv1) & (*(USHORT *) pv2)) != 0 );
  1322. }
  1323. //
  1324. // VTP_UI4
  1325. //
  1326. int VTP_UI4_Compare( BYTE const *pv1, BYTE const *pv2 )
  1327. {
  1328. ULONG ul1 = * (ULONG *) pv1;
  1329. ULONG ul2 = * (ULONG *) pv2;
  1330. return ( ul1 > ul2 ) ? 1 : ( ul1 < ul2 ) ? -1 : 0;
  1331. }
  1332. BOOL VTP_UI4_LT( BYTE const *pv1, BYTE const *pv2 )
  1333. {
  1334. return( (*(ULONG *) pv1) < (*(ULONG *) pv2) );
  1335. }
  1336. BOOL VTP_UI4_LE( BYTE const *pv1, BYTE const *pv2 )
  1337. {
  1338. return( (*(ULONG *) pv1) <= (*(ULONG *) pv2) );
  1339. }
  1340. BOOL VTP_UI4_GE( BYTE const *pv1, BYTE const *pv2 )
  1341. {
  1342. return( (*(ULONG *) pv1) >= (*(ULONG *) pv2) );
  1343. }
  1344. BOOL VTP_UI4_GT( BYTE const *pv1, BYTE const *pv2 )
  1345. {
  1346. return( (*(ULONG *) pv1) > (*(ULONG *) pv2) );
  1347. }
  1348. BOOL VTP_UI4_EQ( BYTE const *pv1, BYTE const *pv2 )
  1349. {
  1350. return( (*(ULONG *) pv1) == (*(ULONG *) pv2) );
  1351. }
  1352. BOOL VTP_UI4_NE( BYTE const *pv1, BYTE const *pv2 )
  1353. {
  1354. return( (*(ULONG *) pv1) != (*(ULONG *) pv2) );
  1355. }
  1356. BOOL VTP_UI4_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1357. {
  1358. return( ((*(ULONG *) pv1) & (*(ULONG *) pv2)) == (*(ULONG *) pv2) );
  1359. }
  1360. BOOL VTP_UI4_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1361. {
  1362. return( ((*(ULONG *) pv1) & (*(ULONG *) pv2)) != 0 );
  1363. }
  1364. //
  1365. // VTP_I8
  1366. //
  1367. int VTP_I8_Compare( BYTE const *pv1, BYTE const *pv2 )
  1368. {
  1369. return( (*(LONGLONG *) pv1) > (*(LONGLONG *) pv2) ? 1 :
  1370. (*(LONGLONG *) pv1) == (*(LONGLONG *) pv2) ? 0 :
  1371. -1 );
  1372. }
  1373. BOOL VTP_I8_LT( BYTE const *pv1, BYTE const *pv2 )
  1374. {
  1375. return( (*(LONGLONG *) pv1) < (*(LONGLONG *) pv2) );
  1376. }
  1377. BOOL VTP_I8_LE( BYTE const *pv1, BYTE const *pv2 )
  1378. {
  1379. return( (*(LONGLONG *) pv1) <= (*(LONGLONG *) pv2) );
  1380. }
  1381. BOOL VTP_I8_GE( BYTE const *pv1, BYTE const *pv2 )
  1382. {
  1383. return( (*(LONGLONG *) pv1) >= (*(LONGLONG *) pv2) );
  1384. }
  1385. BOOL VTP_I8_GT( BYTE const *pv1, BYTE const *pv2 )
  1386. {
  1387. return( (*(LONGLONG *) pv1) > (*(LONGLONG *) pv2) );
  1388. }
  1389. BOOL VTP_I8_EQ( BYTE const *pv1, BYTE const *pv2 )
  1390. {
  1391. return( (*(LONGLONG *) pv1) == (*(LONGLONG *) pv2) );
  1392. }
  1393. BOOL VTP_I8_NE( BYTE const *pv1, BYTE const *pv2 )
  1394. {
  1395. return( (*(LONGLONG *) pv1) != (*(LONGLONG *) pv2) );
  1396. }
  1397. BOOL VTP_I8_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1398. {
  1399. return( ((*(LONGLONG *) pv1) & (*(LONGLONG *) pv2)) == (*(LONGLONG *) pv2) );
  1400. }
  1401. BOOL VTP_I8_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1402. {
  1403. return( ((*(LONGLONG *) pv1) & (*(LONGLONG *) pv2)) != 0 );
  1404. }
  1405. //
  1406. // VTP_UI8
  1407. //
  1408. int VTP_UI8_Compare( BYTE const *pv1, BYTE const *pv2 )
  1409. {
  1410. return( (*(ULONGLONG *) pv1) > (*(ULONGLONG *) pv2) ? 1 :
  1411. (*(ULONGLONG *) pv1) == (*(ULONGLONG *) pv2) ? 0 :
  1412. -1 );
  1413. }
  1414. BOOL VTP_UI8_LT( BYTE const *pv1, BYTE const *pv2 )
  1415. {
  1416. return( (*(ULONGLONG *) pv1) < (*(ULONGLONG *) pv2) );
  1417. }
  1418. BOOL VTP_UI8_LE( BYTE const *pv1, BYTE const *pv2 )
  1419. {
  1420. return( (*(ULONGLONG *) pv1) <= (*(ULONGLONG *) pv2) );
  1421. }
  1422. BOOL VTP_UI8_GE( BYTE const *pv1, BYTE const *pv2 )
  1423. {
  1424. return( (*(ULONGLONG *) pv1) >= (*(ULONGLONG *) pv2) );
  1425. }
  1426. BOOL VTP_UI8_GT( BYTE const *pv1, BYTE const *pv2 )
  1427. {
  1428. return( (*(ULONGLONG *) pv1) > (*(ULONGLONG *) pv2) );
  1429. }
  1430. BOOL VTP_UI8_EQ( BYTE const *pv1, BYTE const *pv2 )
  1431. {
  1432. return( (*(ULONGLONG *) pv1) == (*(ULONGLONG *) pv2) );
  1433. }
  1434. BOOL VTP_UI8_NE( BYTE const *pv1, BYTE const *pv2 )
  1435. {
  1436. return( (*(ULONGLONG *) pv1) != (*(ULONGLONG *) pv2) );
  1437. }
  1438. BOOL VTP_UI8_AllBits( BYTE const *pv1, BYTE const *pv2 )
  1439. {
  1440. return( ((*(ULONGLONG *) pv1) & (*(ULONGLONG *) pv2)) == (*(ULONGLONG *) pv2) );
  1441. }
  1442. BOOL VTP_UI8_SomeBits( BYTE const *pv1, BYTE const *pv2 )
  1443. {
  1444. return( ((*(ULONGLONG *) pv1) & (*(ULONGLONG *) pv2)) != 0 );
  1445. }
  1446. //
  1447. // VTP_LPSTR
  1448. //
  1449. int VTP_LPSTR_Compare( BYTE const *pv1, BYTE const *pv2 )
  1450. {
  1451. return ( lstrcmpiA( (*(char **) pv1), (*(char **) pv2) ) );
  1452. }
  1453. BOOL VTP_LPSTR_LT( BYTE const *pv1, BYTE const *pv2 )
  1454. {
  1455. int rc = lstrcmpiA( (*(char **) pv1), (*(char **) pv2) );
  1456. return( rc < 0 );
  1457. }
  1458. BOOL VTP_LPSTR_LE( BYTE const *pv1, BYTE const *pv2 )
  1459. {
  1460. int rc = lstrcmpiA( (*(char **) pv1), (*(char **) pv2) );
  1461. return( rc <= 0 );
  1462. }
  1463. BOOL VTP_LPSTR_GE( BYTE const *pv1, BYTE const *pv2 )
  1464. {
  1465. int rc = lstrcmpiA( (*(char **) pv1), (*(char **) pv2) );
  1466. return( rc >= 0 );
  1467. }
  1468. BOOL VTP_LPSTR_GT( BYTE const *pv1, BYTE const *pv2 )
  1469. {
  1470. int rc = lstrcmpiA( (*(char **) pv1), (*(char **) pv2) );
  1471. return( rc > 0 );
  1472. }
  1473. BOOL VTP_LPSTR_EQ( BYTE const *pv1, BYTE const *pv2 )
  1474. {
  1475. return( lstrcmpiA( (*(char **) pv1), (*(char **) pv2) ) == 0 );
  1476. }
  1477. BOOL VTP_LPSTR_NE( BYTE const *pv1, BYTE const *pv2 )
  1478. {
  1479. return( lstrcmpiA( (*(char **) pv1), (*(char **) pv2) ) != 0 );
  1480. }
  1481. //
  1482. // VTP_LPWSTR
  1483. //
  1484. int VTP_LPWSTR_Compare( BYTE const *pv1, BYTE const *pv2 )
  1485. {
  1486. int rc = CompareStringW( LOCALE_SYSTEM_DEFAULT,
  1487. NORM_IGNORECASE,
  1488. (*(WCHAR **) pv1),
  1489. -1,
  1490. (*(WCHAR **) pv2),
  1491. -1 );
  1492. //
  1493. // rc == 1, means less than
  1494. // rc == 2, means equal
  1495. // rc == 3, means greater than
  1496. //
  1497. return rc - 2;
  1498. }
  1499. BOOL VTP_LPWSTR_LT( BYTE const *pv1, BYTE const *pv2 )
  1500. {
  1501. return ( VTP_LPWSTR_Compare( pv1, pv2 ) < 0 );
  1502. }
  1503. BOOL VTP_LPWSTR_LE( BYTE const *pv1, BYTE const *pv2 )
  1504. {
  1505. return ( VTP_LPWSTR_Compare( pv1, pv2 ) <= 0 );
  1506. }
  1507. BOOL VTP_LPWSTR_GE( BYTE const *pv1, BYTE const *pv2 )
  1508. {
  1509. return ( VTP_LPWSTR_Compare( pv1, pv2 ) >= 0 );
  1510. }
  1511. BOOL VTP_LPWSTR_GT( BYTE const *pv1, BYTE const *pv2 )
  1512. {
  1513. return ( VTP_LPWSTR_Compare( pv1, pv2 ) > 0 );
  1514. }
  1515. BOOL VTP_LPWSTR_EQ( BYTE const *pv1, BYTE const *pv2 )
  1516. {
  1517. return ( VTP_LPWSTR_Compare( pv1, pv2 ) == 0 );
  1518. }
  1519. BOOL VTP_LPWSTR_NE( BYTE const *pv1, BYTE const *pv2 )
  1520. {
  1521. return ( VTP_LPWSTR_Compare( pv1, pv2 ) != 0 );
  1522. }
  1523. //
  1524. // VTP_BLOB
  1525. //
  1526. int VTP_BLOB_Compare( BYTE const *pv1, BYTE const *pv2 )
  1527. {
  1528. ULONG len = (*(BLOB **) pv1)->cbSize;
  1529. if ( (*(BLOB **) pv2)->cbSize < len )
  1530. len = (*(BLOB **) pv2)->cbSize;
  1531. int iCmp = memcmp( (*(BLOB **) pv1)->pBlobData,
  1532. (*(BLOB **) pv2)->pBlobData,
  1533. len );
  1534. if ( iCmp != 0 || (*(BLOB **) pv1)->cbSize == (*(BLOB **) pv2)->cbSize )
  1535. return( iCmp );
  1536. if ( (*(BLOB **) pv1)->cbSize > (*(BLOB **) pv2)->cbSize )
  1537. return( 1 );
  1538. else
  1539. return( -1 );
  1540. }
  1541. BOOL VTP_BLOB_LT( BYTE const *pv1, BYTE const *pv2 )
  1542. {
  1543. return( VTP_BLOB_Compare( pv1, pv2 ) < 0 );
  1544. }
  1545. BOOL VTP_BLOB_LE( BYTE const *pv1, BYTE const *pv2 )
  1546. {
  1547. return( VTP_BLOB_Compare( pv1, pv2 ) <= 0 );
  1548. }
  1549. BOOL VTP_BLOB_GE( BYTE const *pv1, BYTE const *pv2 )
  1550. {
  1551. return( VTP_BLOB_Compare( pv1, pv2 ) >= 0 );
  1552. }
  1553. BOOL VTP_BLOB_GT( BYTE const *pv1, BYTE const *pv2 )
  1554. {
  1555. return( VTP_BLOB_Compare( pv1, pv2 ) > 0 );
  1556. }
  1557. BOOL VTP_BLOB_EQ( BYTE const *pv1, BYTE const *pv2 )
  1558. {
  1559. return( (*(BLOB **) pv1)->cbSize == (*(BLOB **) pv2)->cbSize &&
  1560. memcmp( (*(BLOB **) pv1)->pBlobData,
  1561. (*(BLOB **) pv2)->pBlobData,
  1562. (*(BLOB **) pv1)->cbSize ) == 0 );
  1563. }
  1564. BOOL VTP_BLOB_NE( BYTE const *pv1, BYTE const *pv2 )
  1565. {
  1566. return( (*(BLOB **) pv1)->cbSize != (*(BLOB **) pv2)->cbSize ||
  1567. memcmp( (*(BLOB **) pv1)->pBlobData,
  1568. (*(BLOB **) pv2)->pBlobData,
  1569. (*(BLOB **) pv1)->cbSize ) != 0 );
  1570. }
  1571. //
  1572. // VTP_CF
  1573. //
  1574. int VTP_CF_Compare( BYTE const *pv1, BYTE const *pv2 )
  1575. {
  1576. if ( (* (CLIPDATA **) pv1)->ulClipFmt != (* (CLIPDATA **) pv2)->ulClipFmt )
  1577. {
  1578. return( (* (CLIPDATA **) pv1)->ulClipFmt - (* (CLIPDATA **) pv2)->ulClipFmt );
  1579. }
  1580. ULONG len = CBPCLIPDATA( **(CLIPDATA **) pv1 );
  1581. if ( CBPCLIPDATA( **(CLIPDATA **) pv2 ) < len )
  1582. len = CBPCLIPDATA( **(CLIPDATA **) pv2 );
  1583. int iCmp = memcmp( (* (CLIPDATA **) pv1)->pClipData,
  1584. (* (CLIPDATA **) pv2)->pClipData,
  1585. len );
  1586. if ( iCmp != 0 || (* (CLIPDATA **) pv1)->cbSize == (* (CLIPDATA **) pv2)->cbSize)
  1587. return( iCmp );
  1588. if ( (* (CLIPDATA **) pv1)->cbSize > (* (CLIPDATA **) pv2)->cbSize )
  1589. return( 1 );
  1590. else
  1591. return( -1 );
  1592. }
  1593. BOOL VTP_CF_LT( BYTE const *pv1, BYTE const *pv2 )
  1594. {
  1595. return( VTP_CF_Compare( pv1, pv2 ) < 0 );
  1596. }
  1597. BOOL VTP_CF_LE( BYTE const *pv1, BYTE const *pv2 )
  1598. {
  1599. return( VTP_CF_Compare( pv1, pv2 ) <= 0 );
  1600. }
  1601. BOOL VTP_CF_GE( BYTE const *pv1, BYTE const *pv2 )
  1602. {
  1603. return( VTP_CF_Compare( pv1, pv2 ) >= 0 );
  1604. }
  1605. BOOL VTP_CF_GT( BYTE const *pv1, BYTE const *pv2 )
  1606. {
  1607. return( VTP_CF_Compare( pv1, pv2 ) > 0 );
  1608. }
  1609. BOOL VTP_CF_EQ( BYTE const *pv1, BYTE const *pv2 )
  1610. {
  1611. return( (* (CLIPDATA **) pv1)->ulClipFmt == (* (CLIPDATA **) pv2)->ulClipFmt &&
  1612. (* (CLIPDATA **) pv1)->cbSize == (* (CLIPDATA **) pv2)->cbSize &&
  1613. memcmp( (* (CLIPDATA **) pv1)->pClipData,
  1614. (* (CLIPDATA **) pv2)->pClipData,
  1615. CBPCLIPDATA( **(CLIPDATA **) pv1 )) == 0 );
  1616. }
  1617. BOOL VTP_CF_NE( BYTE const *pv1, BYTE const *pv2 )
  1618. {
  1619. return( (* (CLIPDATA **) pv1)->ulClipFmt != (* (CLIPDATA **) pv2)->ulClipFmt &&
  1620. (* (CLIPDATA **) pv1)->cbSize != (* (CLIPDATA **) pv2)->cbSize ||
  1621. memcmp( (* (CLIPDATA **) pv1)->pClipData,
  1622. (* (CLIPDATA **) pv2)->pClipData,
  1623. CBPCLIPDATA( **(CLIPDATA **) pv1 )) != 0 );
  1624. }
  1625. //
  1626. // VTP_CLSID. V means vector ( a pointer to a guid )
  1627. // S meand singleton ( a pointer to a pointer to a guid )
  1628. //
  1629. int VTP_VV_CLSID_Compare( BYTE const *pv1, BYTE const *pv2 )
  1630. {
  1631. return( memcmp( pv1, pv2, sizeof GUID ) );
  1632. }
  1633. int VTP_VS_CLSID_Compare( BYTE const *pv1, BYTE const *pv2 )
  1634. {
  1635. return( memcmp( pv1, (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) );
  1636. }
  1637. int VTP_SV_CLSID_Compare( BYTE const *pv1, BYTE const *pv2 )
  1638. {
  1639. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), pv2, sizeof GUID ) );
  1640. }
  1641. int VTP_SS_CLSID_Compare( BYTE const *pv1, BYTE const *pv2 )
  1642. {
  1643. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) );
  1644. }
  1645. BOOL VTP_SS_CLSID_EQ( BYTE const *pv1, BYTE const *pv2 )
  1646. {
  1647. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) == 0 );
  1648. }
  1649. BOOL VTP_SS_CLSID_NE( BYTE const *pv1, BYTE const *pv2 )
  1650. {
  1651. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) != 0 );
  1652. }
  1653. BOOL VTP_VV_CLSID_EQ( BYTE const *pv1, BYTE const *pv2 )
  1654. {
  1655. return( memcmp( pv1, pv2, sizeof GUID ) == 0 );
  1656. }
  1657. BOOL VTP_VV_CLSID_NE( BYTE const *pv1, BYTE const *pv2 )
  1658. {
  1659. return( memcmp( pv1, pv2, sizeof GUID ) != 0 );
  1660. }
  1661. BOOL VTP_VS_CLSID_EQ( BYTE const *pv1, BYTE const *pv2 )
  1662. {
  1663. return( memcmp( pv1, (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) == 0 );
  1664. }
  1665. BOOL VTP_VS_CLSID_NE( BYTE const *pv1, BYTE const *pv2 )
  1666. {
  1667. return( memcmp( pv1, (* (CLSID __RPC_FAR * *) pv2), sizeof GUID ) != 0 );
  1668. }
  1669. BOOL VTP_SV_CLSID_EQ( BYTE const *pv1, BYTE const *pv2 )
  1670. {
  1671. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), pv2, sizeof GUID ) == 0 );
  1672. }
  1673. BOOL VTP_SV_CLSID_NE( BYTE const *pv1, BYTE const *pv2 )
  1674. {
  1675. return( memcmp( (* (CLSID __RPC_FAR * *) pv1), pv2, sizeof GUID ) != 0 );
  1676. }
  1677. /////////////////////////////////////////////////////////////////////////
  1678. /////////////////////////////////////////////////////////////////////////
  1679. /////////////////////////////////////////////////////////////////////////
  1680. /////////////////////////////////////////////////////////////////////////
  1681. /////////////////////////////////////////////////////////////////////////
  1682. /////////////////////////////////////////////////////////////////////////
  1683. ULONG const CComparators::_iStart = VT_EMPTY;
  1684. CComparators::SComparators const CComparators::_aVariantComparators[] = {
  1685. // VT_EMPTY
  1686. { VT_EMPTY_Compare, VTP_EMPTY_Compare,
  1687. { 0,
  1688. 0,
  1689. 0,
  1690. 0,
  1691. VT_EMPTY_EQ,
  1692. VT_EMPTY_NE,
  1693. 0,
  1694. 0,
  1695. 0 },
  1696. { 0,
  1697. 0,
  1698. 0,
  1699. 0,
  1700. VTP_EMPTY_EQ,
  1701. VTP_EMPTY_NE,
  1702. 0,
  1703. 0,
  1704. 0 },
  1705. },
  1706. // VT_NULL
  1707. { VT_NULL_Compare, VTP_NULL_Compare,
  1708. { 0,
  1709. 0,
  1710. 0,
  1711. 0,
  1712. VT_NULL_EQ,
  1713. VT_NULL_NE,
  1714. 0,
  1715. 0,
  1716. 0 },
  1717. { 0,
  1718. 0,
  1719. 0,
  1720. 0,
  1721. VTP_NULL_EQ,
  1722. VTP_NULL_NE,
  1723. 0,
  1724. 0,
  1725. 0 },
  1726. },
  1727. // VT_I2
  1728. { VT_I2_Compare, VTP_I2_Compare,
  1729. { VT_I2_LT,
  1730. VT_I2_LE,
  1731. VT_I2_GT,
  1732. VT_I2_GE,
  1733. VT_I2_EQ,
  1734. VT_I2_NE,
  1735. 0,
  1736. VT_I2_AllBits,
  1737. VT_I2_SomeBits
  1738. },
  1739. { VTP_I2_LT,
  1740. VTP_I2_LE,
  1741. VTP_I2_GT,
  1742. VTP_I2_GE,
  1743. VTP_I2_EQ,
  1744. VTP_I2_NE,
  1745. 0,
  1746. VTP_I2_AllBits,
  1747. VTP_I2_SomeBits
  1748. },
  1749. },
  1750. // VT_I4
  1751. { VT_I4_Compare, VTP_I4_Compare,
  1752. { VT_I4_LT,
  1753. VT_I4_LE,
  1754. VT_I4_GT,
  1755. VT_I4_GE,
  1756. VT_I4_EQ,
  1757. VT_I4_NE,
  1758. 0,
  1759. VT_I4_AllBits,
  1760. VT_I4_SomeBits
  1761. },
  1762. { VTP_I4_LT,
  1763. VTP_I4_LE,
  1764. VTP_I4_GT,
  1765. VTP_I4_GE,
  1766. VTP_I4_EQ,
  1767. VTP_I4_NE,
  1768. 0,
  1769. VTP_I4_AllBits,
  1770. VTP_I4_SomeBits
  1771. },
  1772. },
  1773. // VT_R4
  1774. { VT_R4_Compare, VTP_R4_Compare,
  1775. { VT_R4_LT,
  1776. VT_R4_LE,
  1777. VT_R4_GT,
  1778. VT_R4_GE,
  1779. VT_R4_EQ,
  1780. VT_R4_NE,
  1781. 0,
  1782. 0,
  1783. 0,
  1784. },
  1785. { VTP_R4_LT,
  1786. VTP_R4_LE,
  1787. VTP_R4_GT,
  1788. VTP_R4_GE,
  1789. VTP_R4_EQ,
  1790. VTP_R4_NE,
  1791. 0,
  1792. 0,
  1793. 0,
  1794. },
  1795. },
  1796. // VT_R8
  1797. { VT_R8_Compare, VTP_R8_Compare,
  1798. { VT_R8_LT,
  1799. VT_R8_LE,
  1800. VT_R8_GT,
  1801. VT_R8_GE,
  1802. VT_R8_EQ,
  1803. VT_R8_NE,
  1804. 0,
  1805. 0,
  1806. 0,
  1807. },
  1808. { VTP_R8_LT,
  1809. VTP_R8_LE,
  1810. VTP_R8_GT,
  1811. VTP_R8_GE,
  1812. VTP_R8_EQ,
  1813. VTP_R8_NE,
  1814. 0,
  1815. 0,
  1816. 0,
  1817. },
  1818. },
  1819. // VT_CY
  1820. { VT_I8_Compare, VTP_I8_Compare,
  1821. { VT_I8_LT,
  1822. VT_I8_LE,
  1823. VT_I8_GT,
  1824. VT_I8_GE,
  1825. VT_I8_EQ,
  1826. VT_I8_NE,
  1827. 0,
  1828. 0,
  1829. 0
  1830. },
  1831. { VTP_I8_LT,
  1832. VTP_I8_LE,
  1833. VTP_I8_GT,
  1834. VTP_I8_GE,
  1835. VTP_I8_EQ,
  1836. VTP_I8_NE,
  1837. 0,
  1838. 0,
  1839. 0
  1840. },
  1841. },
  1842. // VT_DATE
  1843. { VT_R8_Compare, VTP_R8_Compare,
  1844. { VT_R8_LT,
  1845. VT_R8_LE,
  1846. VT_R8_GT,
  1847. VT_R8_GE,
  1848. VT_R8_EQ,
  1849. VT_R8_NE,
  1850. 0,
  1851. 0,
  1852. 0,
  1853. },
  1854. { VTP_R8_LT,
  1855. VTP_R8_LE,
  1856. VTP_R8_GT,
  1857. VTP_R8_GE,
  1858. VTP_R8_EQ,
  1859. VTP_R8_NE,
  1860. 0,
  1861. 0,
  1862. 0,
  1863. },
  1864. },
  1865. // VT_BSTR
  1866. { VT_BSTR_Compare, VTP_BSTR_Compare,
  1867. { VT_BSTR_LT,
  1868. VT_BSTR_LE,
  1869. VT_BSTR_GT,
  1870. VT_BSTR_GE,
  1871. VT_BSTR_EQ,
  1872. VT_BSTR_NE,
  1873. 0,
  1874. 0,
  1875. 0
  1876. },
  1877. { VTP_BSTR_LT,
  1878. VTP_BSTR_LE,
  1879. VTP_BSTR_GT,
  1880. VTP_BSTR_GE,
  1881. VTP_BSTR_EQ,
  1882. VTP_BSTR_NE,
  1883. 0,
  1884. 0,
  1885. 0
  1886. },
  1887. },
  1888. // VT_DISPATCH
  1889. { 0, 0,
  1890. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1891. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1892. },
  1893. // VT_ERROR
  1894. { VT_I4_Compare, VTP_I4_Compare,
  1895. { VT_I4_LT,
  1896. VT_I4_LE,
  1897. VT_I4_GT,
  1898. VT_I4_GE,
  1899. VT_I4_EQ,
  1900. VT_I4_NE,
  1901. 0,
  1902. VT_I4_AllBits,
  1903. VT_I4_SomeBits
  1904. },
  1905. { VTP_I4_LT,
  1906. VTP_I4_LE,
  1907. VTP_I4_GT,
  1908. VTP_I4_GE,
  1909. VTP_I4_EQ,
  1910. VTP_I4_NE,
  1911. 0,
  1912. VTP_I4_AllBits,
  1913. VTP_I4_SomeBits
  1914. },
  1915. },
  1916. // VT_BOOL
  1917. { VT_BOOL_Compare, VTP_BOOL_Compare,
  1918. { 0,
  1919. 0,
  1920. 0,
  1921. 0,
  1922. VT_BOOL_EQ,
  1923. VT_BOOL_NE,
  1924. 0,
  1925. 0,
  1926. 0
  1927. },
  1928. { 0,
  1929. 0,
  1930. 0,
  1931. 0,
  1932. VTP_BOOL_EQ,
  1933. VTP_BOOL_NE,
  1934. 0,
  1935. 0,
  1936. 0
  1937. },
  1938. },
  1939. // VT_VARIANT
  1940. { VT_VARIANT_Compare, VTP_VARIANT_Compare,
  1941. { VT_VARIANT_LT,
  1942. VT_VARIANT_LE,
  1943. VT_VARIANT_GT,
  1944. VT_VARIANT_GE,
  1945. VT_VARIANT_EQ,
  1946. VT_VARIANT_NE,
  1947. 0,
  1948. 0,
  1949. 0,
  1950. },
  1951. { VTP_VARIANT_LT,
  1952. VTP_VARIANT_LE,
  1953. VTP_VARIANT_GT,
  1954. VTP_VARIANT_GE,
  1955. VTP_VARIANT_EQ,
  1956. VTP_VARIANT_NE,
  1957. 0,
  1958. 0,
  1959. 0,
  1960. },
  1961. },
  1962. // VT_UNKNOWN
  1963. { 0, 0,
  1964. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1965. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1966. },
  1967. // VT_DECIMAL
  1968. { VT_DEC_Compare, VTP_DEC_Compare,
  1969. { VT_DEC_LT,
  1970. VT_DEC_LE,
  1971. VT_DEC_GT,
  1972. VT_DEC_GE,
  1973. VT_DEC_EQ,
  1974. VT_DEC_NE,
  1975. 0,
  1976. 0,
  1977. 0
  1978. },
  1979. { VTP_DEC_LT,
  1980. VTP_DEC_LE,
  1981. VTP_DEC_GT,
  1982. VTP_DEC_GE,
  1983. VTP_DEC_EQ,
  1984. VTP_DEC_NE,
  1985. 0,
  1986. 0,
  1987. 0
  1988. },
  1989. },
  1990. // VARENUM value 15 unused
  1991. { 0, 0,
  1992. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1993. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  1994. },
  1995. // VT_I1
  1996. { VT_I1_Compare, VTP_I1_Compare,
  1997. { VT_I1_LT,
  1998. VT_I1_LE,
  1999. VT_I1_GT,
  2000. VT_I1_GE,
  2001. VT_I1_EQ,
  2002. VT_I1_NE,
  2003. 0,
  2004. VT_I1_AllBits,
  2005. VT_I1_SomeBits
  2006. },
  2007. { VTP_I1_LT,
  2008. VTP_I1_LE,
  2009. VTP_I1_GT,
  2010. VTP_I1_GE,
  2011. VTP_I1_EQ,
  2012. VTP_I1_NE,
  2013. 0,
  2014. VTP_I1_AllBits,
  2015. VTP_I1_SomeBits
  2016. },
  2017. },
  2018. // VT_UI1
  2019. { VT_UI1_Compare, VTP_UI1_Compare,
  2020. { VT_UI1_LT,
  2021. VT_UI1_LE,
  2022. VT_UI1_GT,
  2023. VT_UI1_GE,
  2024. VT_UI1_EQ,
  2025. VT_UI1_NE,
  2026. 0,
  2027. VT_UI1_AllBits,
  2028. VT_UI1_SomeBits
  2029. },
  2030. { VTP_UI1_LT,
  2031. VTP_UI1_LE,
  2032. VTP_UI1_GT,
  2033. VTP_UI1_GE,
  2034. VTP_UI1_EQ,
  2035. VTP_UI1_NE,
  2036. 0,
  2037. VTP_UI1_AllBits,
  2038. VTP_UI1_SomeBits
  2039. },
  2040. },
  2041. // VT_UI2
  2042. { VT_UI2_Compare, VTP_UI2_Compare,
  2043. { VT_UI2_LT,
  2044. VT_UI2_LE,
  2045. VT_UI2_GT,
  2046. VT_UI2_GE,
  2047. VT_UI2_EQ,
  2048. VT_UI2_NE,
  2049. 0,
  2050. VT_UI2_AllBits,
  2051. VT_UI2_SomeBits
  2052. },
  2053. { VTP_UI2_LT,
  2054. VTP_UI2_LE,
  2055. VTP_UI2_GT,
  2056. VTP_UI2_GE,
  2057. VTP_UI2_EQ,
  2058. VTP_UI2_NE,
  2059. 0,
  2060. VTP_UI2_AllBits,
  2061. VTP_UI2_SomeBits
  2062. },
  2063. },
  2064. // VT_UI4
  2065. { VT_UI4_Compare, VTP_UI4_Compare,
  2066. { VT_UI4_LT,
  2067. VT_UI4_LE,
  2068. VT_UI4_GT,
  2069. VT_UI4_GE,
  2070. VT_UI4_EQ,
  2071. VT_UI4_NE,
  2072. 0,
  2073. VT_UI4_AllBits,
  2074. VT_UI4_SomeBits
  2075. },
  2076. { VTP_UI4_LT,
  2077. VTP_UI4_LE,
  2078. VTP_UI4_GT,
  2079. VTP_UI4_GE,
  2080. VTP_UI4_EQ,
  2081. VTP_UI4_NE,
  2082. 0,
  2083. VTP_UI4_AllBits,
  2084. VTP_UI4_SomeBits
  2085. },
  2086. },
  2087. // VT_I8
  2088. { VT_I8_Compare, VTP_I8_Compare,
  2089. { VT_I8_LT,
  2090. VT_I8_LE,
  2091. VT_I8_GT,
  2092. VT_I8_GE,
  2093. VT_I8_EQ,
  2094. VT_I8_NE,
  2095. 0,
  2096. VT_I8_AllBits,
  2097. VT_I8_SomeBits
  2098. },
  2099. { VTP_I8_LT,
  2100. VTP_I8_LE,
  2101. VTP_I8_GT,
  2102. VTP_I8_GE,
  2103. VTP_I8_EQ,
  2104. VTP_I8_NE,
  2105. 0,
  2106. VTP_I8_AllBits,
  2107. VTP_I8_SomeBits
  2108. },
  2109. },
  2110. // VT_UI8
  2111. { VT_UI8_Compare, VTP_UI8_Compare,
  2112. { VT_UI8_LT,
  2113. VT_UI8_LE,
  2114. VT_UI8_GT,
  2115. VT_UI8_GE,
  2116. VT_UI8_EQ,
  2117. VT_UI8_NE,
  2118. 0,
  2119. VT_UI8_AllBits,
  2120. VT_UI8_SomeBits
  2121. },
  2122. { VTP_UI8_LT,
  2123. VTP_UI8_LE,
  2124. VTP_UI8_GT,
  2125. VTP_UI8_GE,
  2126. VTP_UI8_EQ,
  2127. VTP_UI8_NE,
  2128. 0,
  2129. VTP_UI8_AllBits,
  2130. VTP_UI8_SomeBits
  2131. },
  2132. },
  2133. // VT_INT
  2134. { VT_I4_Compare, VTP_I4_Compare,
  2135. { VT_I4_LT,
  2136. VT_I4_LE,
  2137. VT_I4_GT,
  2138. VT_I4_GE,
  2139. VT_I4_EQ,
  2140. VT_I4_NE,
  2141. 0,
  2142. VT_I4_AllBits,
  2143. VT_I4_SomeBits
  2144. },
  2145. { VTP_I4_LT,
  2146. VTP_I4_LE,
  2147. VTP_I4_GT,
  2148. VTP_I4_GE,
  2149. VTP_I4_EQ,
  2150. VTP_I4_NE,
  2151. 0,
  2152. VTP_I4_AllBits,
  2153. VTP_I4_SomeBits
  2154. },
  2155. },
  2156. // VT_UINT
  2157. { VT_UI4_Compare, VTP_UI4_Compare,
  2158. { VT_UI4_LT,
  2159. VT_UI4_LE,
  2160. VT_UI4_GT,
  2161. VT_UI4_GE,
  2162. VT_UI4_EQ,
  2163. VT_UI4_NE,
  2164. 0,
  2165. VT_UI4_AllBits,
  2166. VT_UI4_SomeBits
  2167. },
  2168. { VTP_UI4_LT,
  2169. VTP_UI4_LE,
  2170. VTP_UI4_GT,
  2171. VTP_UI4_GE,
  2172. VTP_UI4_EQ,
  2173. VTP_UI4_NE,
  2174. 0,
  2175. VTP_UI4_AllBits,
  2176. VTP_UI4_SomeBits
  2177. },
  2178. },
  2179. // VT_VOID
  2180. { 0, 0,
  2181. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2182. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2183. },
  2184. // VT_HRESULT
  2185. { VT_I4_Compare, VTP_I4_Compare,
  2186. { VT_I4_LT,
  2187. VT_I4_LE,
  2188. VT_I4_GT,
  2189. VT_I4_GE,
  2190. VT_I4_EQ,
  2191. VT_I4_NE,
  2192. 0,
  2193. VT_I4_AllBits,
  2194. VT_I4_SomeBits
  2195. },
  2196. { VTP_I4_LT,
  2197. VTP_I4_LE,
  2198. VTP_I4_GT,
  2199. VTP_I4_GE,
  2200. VTP_I4_EQ,
  2201. VTP_I4_NE,
  2202. 0,
  2203. VTP_I4_AllBits,
  2204. VTP_I4_SomeBits
  2205. },
  2206. },
  2207. // VT_PTR
  2208. { 0, 0,
  2209. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2210. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2211. },
  2212. // VT_SAFEARRAY
  2213. { 0, 0,
  2214. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2215. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2216. },
  2217. // VT_CARRAY
  2218. { 0, 0,
  2219. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2220. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2221. },
  2222. // VT_USERDEFINED
  2223. { 0, 0,
  2224. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2225. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2226. },
  2227. // VT_LPSTR
  2228. { VT_LPSTR_Compare, VTP_LPSTR_Compare,
  2229. { VT_LPSTR_LT,
  2230. VT_LPSTR_LE,
  2231. VT_LPSTR_GT,
  2232. VT_LPSTR_GE,
  2233. VT_LPSTR_EQ,
  2234. VT_LPSTR_NE,
  2235. 0,
  2236. 0,
  2237. 0
  2238. },
  2239. { VTP_LPSTR_LT,
  2240. VTP_LPSTR_LE,
  2241. VTP_LPSTR_GT,
  2242. VTP_LPSTR_GE,
  2243. VTP_LPSTR_EQ,
  2244. VTP_LPSTR_NE,
  2245. 0,
  2246. 0,
  2247. 0
  2248. },
  2249. },
  2250. // VT_LPWSTR
  2251. { VT_LPWSTR_Compare, VTP_LPWSTR_Compare,
  2252. { VT_LPWSTR_LT,
  2253. VT_LPWSTR_LE,
  2254. VT_LPWSTR_GT,
  2255. VT_LPWSTR_GE,
  2256. VT_LPWSTR_EQ,
  2257. VT_LPWSTR_NE,
  2258. 0,
  2259. 0,
  2260. 0
  2261. },
  2262. { VTP_LPWSTR_LT,
  2263. VTP_LPWSTR_LE,
  2264. VTP_LPWSTR_GT,
  2265. VTP_LPWSTR_GE,
  2266. VTP_LPWSTR_EQ,
  2267. VTP_LPWSTR_NE,
  2268. 0,
  2269. 0,
  2270. 0
  2271. },
  2272. }
  2273. };
  2274. ULONG const CComparators::_cVariantComparators =
  2275. sizeof(CComparators::_aVariantComparators) /
  2276. sizeof(CComparators::_aVariantComparators[0]);
  2277. ULONG const CComparators::_iStart2 = VT_FILETIME;
  2278. CComparators::SComparators const CComparators::_aVariantComparators2[] = {
  2279. // VT_FILETIME
  2280. { VT_UI8_Compare, VTP_UI8_Compare,
  2281. { VT_UI8_LT,
  2282. VT_UI8_LE,
  2283. VT_UI8_GT,
  2284. VT_UI8_GE,
  2285. VT_UI8_EQ,
  2286. VT_UI8_NE,
  2287. 0,
  2288. 0,
  2289. 0
  2290. },
  2291. { VTP_UI8_LT,
  2292. VTP_UI8_LE,
  2293. VTP_UI8_GT,
  2294. VTP_UI8_GE,
  2295. VTP_UI8_EQ,
  2296. VTP_UI8_NE,
  2297. 0,
  2298. 0,
  2299. 0
  2300. },
  2301. },
  2302. // VT_BLOB
  2303. { VT_BLOB_Compare, VTP_BLOB_Compare,
  2304. { VT_BLOB_LT,
  2305. VT_BLOB_LE,
  2306. VT_BLOB_GT,
  2307. VT_BLOB_GE,
  2308. VT_BLOB_EQ,
  2309. VT_BLOB_NE,
  2310. 0,
  2311. 0,
  2312. 0
  2313. },
  2314. { VTP_BLOB_LT,
  2315. VTP_BLOB_LE,
  2316. VTP_BLOB_GT,
  2317. VTP_BLOB_GE,
  2318. VTP_BLOB_EQ,
  2319. VTP_BLOB_NE,
  2320. 0,
  2321. 0,
  2322. 0
  2323. },
  2324. },
  2325. // VT_STREAM
  2326. { 0, 0,
  2327. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2328. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2329. },
  2330. // VT_STORAGE
  2331. { 0, 0,
  2332. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2333. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2334. },
  2335. // VT_STREAMED_OBJECT
  2336. { 0, 0,
  2337. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2338. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2339. },
  2340. // VT_STORED_OBJECT
  2341. { 0, 0,
  2342. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2343. { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  2344. },
  2345. // VT_BLOB_OBJECT
  2346. { VT_BLOB_Compare, VTP_BLOB_Compare,
  2347. { VT_BLOB_LT,
  2348. VT_BLOB_LE,
  2349. VT_BLOB_GT,
  2350. VT_BLOB_GE,
  2351. VT_BLOB_EQ,
  2352. VT_BLOB_NE,
  2353. 0,
  2354. 0,
  2355. 0
  2356. },
  2357. { VTP_BLOB_LT,
  2358. VTP_BLOB_LE,
  2359. VTP_BLOB_GT,
  2360. VTP_BLOB_GE,
  2361. VTP_BLOB_EQ,
  2362. VTP_BLOB_NE,
  2363. 0,
  2364. 0,
  2365. 0
  2366. },
  2367. },
  2368. // VT_CF
  2369. { VT_CF_Compare, VTP_CF_Compare,
  2370. { VT_CF_LT,
  2371. VT_CF_LE,
  2372. VT_CF_GT,
  2373. VT_CF_GE,
  2374. VT_CF_EQ,
  2375. VT_CF_NE,
  2376. 0,
  2377. 0,
  2378. 0
  2379. },
  2380. { VTP_CF_LT,
  2381. VTP_CF_LE,
  2382. VTP_CF_GT,
  2383. VTP_CF_GE,
  2384. VTP_CF_EQ,
  2385. VTP_CF_NE,
  2386. 0,
  2387. 0,
  2388. 0
  2389. },
  2390. },
  2391. // VT_CLSID
  2392. { VT_CLSID_Compare, 0, // Vector special-cased in GetPointerComparator
  2393. { 0,
  2394. 0,
  2395. 0,
  2396. 0,
  2397. VT_CLSID_EQ,
  2398. VT_CLSID_NE,
  2399. 0,
  2400. 0,
  2401. 0
  2402. },
  2403. { 0,
  2404. 0,
  2405. 0,
  2406. 0,
  2407. 0, // Special-cased in GetPointerRelop
  2408. 0, // Special-cased in GetPointerRelop
  2409. 0,
  2410. 0,
  2411. 0
  2412. },
  2413. }
  2414. };
  2415. ULONG const CComparators::_cVariantComparators2 =
  2416. sizeof(CComparators::_aVariantComparators2) /
  2417. sizeof(CComparators::_aVariantComparators2[0]);
  2418. ULONG const SortDescend = 1;
  2419. ULONG const SortNullFirst = 2;
  2420. inline void ConvertArrayToVector ( PROPVARIANT const & vIn, PROPVARIANT & vOut )
  2421. {
  2422. Assert( vIn.vt & VT_ARRAY );
  2423. SAFEARRAY * pSa = vIn.parray;
  2424. ULONG cDataElements = 1;
  2425. for ( unsigned i = 0; i < pSa->cDims; i++ )
  2426. {
  2427. cDataElements *= pSa->rgsabound[i].cElements;
  2428. }
  2429. vOut.vt = (vIn.vt & VT_TYPEMASK) | VT_VECTOR;
  2430. vOut.caub.cElems = cDataElements;
  2431. vOut.caub.pElems = (BYTE *)pSa->pvData;
  2432. }
  2433. BYTE * _GetNth( PROPVARIANT const & v, unsigned i )
  2434. {
  2435. Assert( isVector(v) );
  2436. switch ( getBaseType( v ) )
  2437. {
  2438. case VT_I1 : // Issue - no defined type for vector of VT_I1
  2439. return (BYTE *) & (v.caub.pElems[i]);
  2440. case VT_UI1 :
  2441. return (BYTE *) & (v.caub.pElems[i]);
  2442. case VT_I2 :
  2443. return (BYTE *) & (v.cai.pElems[i]);
  2444. case VT_UI2 :
  2445. return (BYTE *) & (v.caui.pElems[i]);
  2446. case VT_BOOL :
  2447. return (BYTE *) & (v.cabool.pElems[i]);
  2448. case VT_I4 :
  2449. case VT_INT :
  2450. return (BYTE *) & (v.cal.pElems[i]);
  2451. case VT_UI4 :
  2452. case VT_UINT :
  2453. return (BYTE *) & (v.caul.pElems[i]);
  2454. case VT_R4 :
  2455. return (BYTE *) & (v.caflt.pElems[i]);
  2456. case VT_ERROR :
  2457. return (BYTE *) & (v.cascode.pElems[i]);
  2458. case VT_I8 :
  2459. return (BYTE *) & (v.cah.pElems[i]);
  2460. case VT_UI8 :
  2461. return (BYTE *) & (v.cauh.pElems[i]);
  2462. case VT_R8 :
  2463. return (BYTE *) & (v.cadbl.pElems[i]);
  2464. case VT_CY :
  2465. return (BYTE *) & (v.cacy.pElems[i]);
  2466. case VT_DATE :
  2467. return (BYTE *) & (v.cadate.pElems[i]);
  2468. case VT_FILETIME :
  2469. return (BYTE *) & (v.cafiletime.pElems[i]);
  2470. case VT_CLSID :
  2471. return (BYTE *) & (v.cauuid.pElems[i]);
  2472. case VT_CF :
  2473. return (BYTE *) & (v.caclipdata.pElems[i]);
  2474. case VT_BSTR :
  2475. return (BYTE *) & (v.cabstr.pElems[i]);
  2476. case VT_LPSTR :
  2477. return (BYTE *) & (v.calpstr.pElems[i]);
  2478. case VT_LPWSTR :
  2479. return (BYTE *) & (v.calpwstr.pElems[i]);
  2480. case VT_VARIANT :
  2481. return (BYTE *) & (v.capropvar.pElems[i]);
  2482. case VT_DECIMAL :
  2483. // NOTE: not valid in a vector, but it could occur due to the
  2484. // simplistic conversion of arrays to vectors.
  2485. DECIMAL * paDec = (DECIMAL *) v.caub.pElems;
  2486. return (BYTE *) (paDec + i);
  2487. }
  2488. // illegal base variant type in vector compare.
  2489. Assert( 0 );
  2490. return 0;
  2491. } //_GetNth
  2492. //+-------------------------------------------------------------------------
  2493. //
  2494. // Member: VT_VECTOR_Compare, public
  2495. //
  2496. // Effects: Compares two property values, intended to be called when
  2497. // at least one of the arguments is a vector
  2498. //
  2499. // Arguments: [v1] -- 1st variant to compare
  2500. // [v2] -- 2nd variant to compare
  2501. //
  2502. // History: 1-May-95 dlee Created
  2503. //
  2504. //--------------------------------------------------------------------------
  2505. int VT_VECTOR_Compare( PROPVARIANT const & v1In, PROPVARIANT const & v2In )
  2506. {
  2507. // must be the same datatype, or just sort on type
  2508. if ( ( v1In.vt != v2In.vt ) )
  2509. return v1In.vt - v2In.vt;
  2510. PROPVARIANT v1 = v1In;
  2511. PROPVARIANT v2 = v2In;
  2512. if ( isArray(v1In) )
  2513. {
  2514. Assert( isArray(v2In) );
  2515. SAFEARRAY * pSa1 = v1In.parray;
  2516. SAFEARRAY * pSa2 = v2In.parray;
  2517. if (pSa1->cDims != pSa2->cDims)
  2518. return pSa1->cDims - pSa2->cDims;
  2519. ULONG cDataElements = 1;
  2520. for ( unsigned i = 0; i < pSa1->cDims; i++ )
  2521. {
  2522. if ( pSa1->rgsabound[i].lLbound != pSa2->rgsabound[i].lLbound )
  2523. return pSa1->rgsabound[i].lLbound - pSa2->rgsabound[i].lLbound;
  2524. if ( pSa1->rgsabound[i].cElements != pSa2->rgsabound[i].cElements )
  2525. return pSa1->rgsabound[i].cElements - pSa2->rgsabound[i].cElements;
  2526. cDataElements *= pSa1->rgsabound[i].cElements;
  2527. }
  2528. //
  2529. // arrays match in type, total size and dimensions. Compare as vectors.
  2530. //
  2531. v1.vt = v2.vt = (v1In.vt & VT_TYPEMASK) | VT_VECTOR;
  2532. v1.caub.cElems = v2.caub.cElems = cDataElements;
  2533. v1.caub.pElems = (BYTE *)pSa1->pvData;
  2534. v2.caub.pElems = (BYTE *)pSa2->pvData;
  2535. }
  2536. Assert( isVector(v1) );
  2537. FPCmp cmp = VariantCompare.GetPointerComparator( v1, v2 );
  2538. if (0 == cmp)
  2539. {
  2540. // Unknown property type or relation used in comparison.
  2541. Assert(0);
  2542. return 0;
  2543. }
  2544. unsigned cMin = __min( v1.cal.cElems, v2.cal.cElems );
  2545. for ( unsigned x = 0; x < cMin; x++ )
  2546. {
  2547. int r = cmp( _GetNth( v1, x), _GetNth( v2, x ) );
  2548. if (0 != r)
  2549. return r;
  2550. }
  2551. // All equal so far up to the minimum cardinality of the vectors.
  2552. // Any difference now would be due to the cardinality.
  2553. return v1.cal.cElems - v2.cal.cElems;
  2554. } //VT_VECTOR_Compare
  2555. int VTP_VECTOR_Compare( BYTE const *pv1, BYTE const *pv2 )
  2556. {
  2557. return VT_VECTOR_Compare( ** (PROPVARIANT **) pv1,
  2558. ** (PROPVARIANT **) pv2 );
  2559. } //VTP_VECTOR_Compare
  2560. BOOL VT_VECTOR_LT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2561. {
  2562. return VT_VECTOR_Compare( v1, v2 ) < 0;
  2563. } //VT_VECTOR_LT
  2564. BOOL VT_VECTOR_LE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2565. {
  2566. return VT_VECTOR_Compare( v1, v2 ) <= 0;
  2567. } //VT_VECTOR_LE
  2568. BOOL VT_VECTOR_GT( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2569. {
  2570. return ! VT_VECTOR_LE( v1, v2 );
  2571. } //VT_VECTOR_GT
  2572. BOOL VT_VECTOR_GE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2573. {
  2574. return ! VT_VECTOR_LT( v1, v2 );
  2575. } //VT_VECTOR_GE
  2576. BOOL VT_VECTOR_EQ( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2577. {
  2578. return VT_VECTOR_Compare( v1, v2 ) == 0;
  2579. } //VT_VECTOR_EQ
  2580. BOOL VT_VECTOR_NE( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2581. {
  2582. return !VT_VECTOR_EQ( v1, v2 );
  2583. } //VT_VECTOR_NE
  2584. BOOL VT_VECTOR_Common(
  2585. PROPVARIANT const & v1,
  2586. PROPVARIANT const & v2,
  2587. ULONG relop )
  2588. {
  2589. // must be the same datatype and a vector or it doesn't compare.
  2590. if ( ( v1.vt != v2.vt ) || ! isVector( v1 ) )
  2591. return FALSE;
  2592. // must be same cardinality, or it doesn't compare
  2593. if ( v1.cal.cElems != v2.cal.cElems )
  2594. return FALSE;
  2595. FPRel cmp = VariantCompare.GetPointerRelop( v1, v2, relop );
  2596. if ( 0 == cmp )
  2597. return FALSE;
  2598. unsigned cElems = v1.cal.cElems;
  2599. for ( unsigned x = 0; x < cElems; x++ )
  2600. {
  2601. if ( !cmp( _GetNth( v1, x), _GetNth( v2, x ) ) )
  2602. return FALSE;
  2603. }
  2604. return TRUE;
  2605. } //VT_VECTOR_Common
  2606. BOOL VT_VECTOR_AllBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2607. {
  2608. return VT_VECTOR_Common( v1, v2, PRAllBits );
  2609. } //VT_VECTOR_AllBits
  2610. BOOL VT_VECTOR_SomeBits( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2611. {
  2612. return VT_VECTOR_Common( v1, v2, PRSomeBits );
  2613. } //VT_VECTOR_SomeBits
  2614. ////////////////////////////////////
  2615. ////////////////////////////////////
  2616. ////////////////////////////////////
  2617. BOOL VT_VECTOR_Any(
  2618. PROPVARIANT const & v1In,
  2619. PROPVARIANT const & v2In,
  2620. ULONG relop )
  2621. {
  2622. //
  2623. // Note: first parameter (v1) is the object's property value
  2624. // second parameter (v2) is the query restriction
  2625. //
  2626. // return TRUE if any element in v1 holds the relation to any v2 element
  2627. //
  2628. // base type of variant must be the same
  2629. if ( getBaseType( v1In ) != getBaseType( v2In ) )
  2630. return FALSE;
  2631. //
  2632. // If either argument is a safearray, convert it to a vector
  2633. //
  2634. PROPVARIANT v1 = v1In;
  2635. if (isArray(v1))
  2636. ConvertArrayToVector( v1In, v1 );
  2637. PROPVARIANT v2 = v2In;
  2638. if (isArray(v2))
  2639. ConvertArrayToVector( v2In, v2 );
  2640. // first check for two singletons
  2641. if ( ! isVector( v1 ) && ! isVector( v2 ) )
  2642. {
  2643. FRel cmp = VariantCompare.GetRelop( (VARENUM) v1.vt, relop );
  2644. if ( 0 == cmp )
  2645. return FALSE;
  2646. else
  2647. return cmp( v1, v2 );
  2648. }
  2649. // two vectors or singleton+vector -- get a pointer comparator
  2650. FPRel cmp = VariantCompare.GetPointerRelop( v1, v2, relop );
  2651. if ( 0 == cmp )
  2652. return FALSE;
  2653. // check for two vectors
  2654. if ( isVector( v1 ) && isVector( v2 ) )
  2655. {
  2656. for ( unsigned x1 = 0; x1 < v1.cal.cElems; x1++ )
  2657. {
  2658. for ( unsigned x2 = 0; x2 < v2.cal.cElems; x2++ )
  2659. {
  2660. if ( cmp( _GetNth( v1, x1), _GetNth( v2, x2 ) ) )
  2661. return TRUE;
  2662. }
  2663. }
  2664. }
  2665. else
  2666. {
  2667. // must be a singleton and a vector
  2668. if ( isVector( v1 ) )
  2669. {
  2670. BYTE * pb2 = (BYTE *) &(v2.lVal);
  2671. if ( VT_DECIMAL == v2.vt )
  2672. pb2 = (BYTE *) &(v2.decVal);
  2673. for ( unsigned i = 0; i < v1.cal.cElems; i++ )
  2674. {
  2675. if ( cmp( _GetNth( v1, i ), pb2 ) )
  2676. return TRUE;
  2677. }
  2678. }
  2679. else
  2680. {
  2681. BYTE * pb1 = (BYTE *) &(v1.lVal);
  2682. if ( VT_DECIMAL == v1.vt )
  2683. pb1 = (BYTE *) &(v1.decVal);
  2684. for ( unsigned i = 0; i < v2.cal.cElems; i++ )
  2685. {
  2686. if ( cmp( pb1, _GetNth( v2, i ) ) )
  2687. return TRUE;
  2688. }
  2689. }
  2690. }
  2691. return FALSE;
  2692. } //VT_VECTOR_Any
  2693. BOOL VT_VECTOR_LT_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2694. {
  2695. return VT_VECTOR_Any( v1, v2, PRLT );
  2696. } //VT_VECTOR_LT_Any
  2697. BOOL VT_VECTOR_LE_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2698. {
  2699. return VT_VECTOR_Any( v1, v2, PRLE );
  2700. } //VT_VECTOR_LE_Any
  2701. BOOL VT_VECTOR_GT_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2702. {
  2703. return VT_VECTOR_Any( v1, v2, PRGT );
  2704. } //VT_VECTOR_GT_Any
  2705. BOOL VT_VECTOR_GE_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2706. {
  2707. return VT_VECTOR_Any( v1, v2, PRGE );
  2708. } //VT_VECTOR_GE_Any
  2709. BOOL VT_VECTOR_EQ_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2710. {
  2711. return VT_VECTOR_Any( v1, v2, PREQ );
  2712. } //VT_VECTOR_EQ_Any
  2713. BOOL VT_VECTOR_NE_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2714. {
  2715. return VT_VECTOR_Any( v1, v2, PRNE );
  2716. } //VT_VECTOR_NE_Any
  2717. BOOL VT_VECTOR_AllBits_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2718. {
  2719. return VT_VECTOR_Any( v1, v2, PRAllBits );
  2720. } //VT_VECTOR_AllBits_Any
  2721. BOOL VT_VECTOR_SomeBits_Any( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2722. {
  2723. return VT_VECTOR_Any( v1, v2, PRSomeBits );
  2724. } //VT_VECTOR_SomeBits_Any
  2725. ////////////////////////////////////
  2726. ////////////////////////////////////
  2727. ////////////////////////////////////
  2728. BOOL VT_VECTOR_All(
  2729. PROPVARIANT const & v1In,
  2730. PROPVARIANT const & v2In,
  2731. ULONG relop )
  2732. {
  2733. //
  2734. // Note: first parameter (v1) is the object's property value
  2735. // second parameter (v2) is the query restriction
  2736. //
  2737. // each element in v2 must hold the relation to each element v1
  2738. // (not necessarily vice-versa)
  2739. //
  2740. // base type of variant must be the same
  2741. if ( getBaseType( v1In ) != getBaseType( v2In ) )
  2742. return FALSE;
  2743. //
  2744. // If either argument is a safearray, convert it to a vector
  2745. //
  2746. PROPVARIANT v1 = v1In;
  2747. if (isArray(v1))
  2748. ConvertArrayToVector( v1In, v1 );
  2749. PROPVARIANT v2 = v2In;
  2750. if (isArray(v2))
  2751. ConvertArrayToVector( v2In, v2 );
  2752. // first check for two singletons
  2753. if ( ! isVector( v1 ) && ! isVector( v2 ) )
  2754. {
  2755. FRel cmp = VariantCompare.GetRelop( (VARENUM) v1.vt, relop );
  2756. if ( 0 == cmp )
  2757. return FALSE;
  2758. else
  2759. return cmp( v1, v2 );
  2760. }
  2761. // two vectors or singleton+vector -- get a pointer comparator
  2762. FPRel cmp = VariantCompare.GetPointerRelop( v1, v2, relop );
  2763. if ( 0 == cmp )
  2764. return FALSE;
  2765. // check for two vectors
  2766. if ( isVector( v1 ) && isVector( v2 ) )
  2767. {
  2768. for ( unsigned x2 = 0; x2 < v2.cal.cElems; x2++ )
  2769. {
  2770. for ( unsigned x1 = 0; x1 < v1.cal.cElems; x1++ )
  2771. {
  2772. if ( ! cmp( _GetNth( v1, x1), _GetNth( v2, x2 ) ) )
  2773. return FALSE;
  2774. }
  2775. }
  2776. }
  2777. else
  2778. {
  2779. // must be a singleton and a vector
  2780. if ( isVector( v1 ) )
  2781. {
  2782. BYTE * pb2 = (BYTE *) &(v2.lVal);
  2783. if ( VT_DECIMAL == v2.vt )
  2784. pb2 = (BYTE *) &(v2.decVal);
  2785. for ( unsigned i = 0; i < v1.cal.cElems; i++ )
  2786. {
  2787. if ( ! cmp( _GetNth( v1, i ), pb2 ) )
  2788. return FALSE;
  2789. }
  2790. }
  2791. else
  2792. {
  2793. BYTE * pb1 = (BYTE *) &(v1.lVal);
  2794. if ( VT_DECIMAL == v1.vt )
  2795. pb1 = (BYTE *) &(v1.decVal);
  2796. for ( unsigned i = 0; i < v2.cal.cElems; i++ )
  2797. {
  2798. if ( ! cmp( pb1, _GetNth( v2, i ) ) )
  2799. return FALSE;
  2800. }
  2801. }
  2802. }
  2803. return TRUE;
  2804. } //VT_VECTOR_All
  2805. BOOL VT_VECTOR_LT_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2806. {
  2807. return VT_VECTOR_All( v1, v2, PRLT );
  2808. } //VT_VECTOR_LT_All
  2809. BOOL VT_VECTOR_LE_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2810. {
  2811. return VT_VECTOR_All( v1, v2, PRLE );
  2812. } //VT_VECTOR_LE_All
  2813. BOOL VT_VECTOR_GT_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2814. {
  2815. return VT_VECTOR_All( v1, v2, PRGT );
  2816. } //VT_VECTOR_GT_All
  2817. BOOL VT_VECTOR_GE_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2818. {
  2819. return VT_VECTOR_All( v1, v2, PRGE );
  2820. } //VT_VECTOR_GE_All
  2821. BOOL VT_VECTOR_EQ_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2822. {
  2823. return VT_VECTOR_All( v1, v2, PREQ );
  2824. } //VT_VECTOR_EQ_All
  2825. BOOL VT_VECTOR_NE_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2826. {
  2827. return VT_VECTOR_All( v1, v2, PRNE );
  2828. } //VT_VECTOR_NE_All
  2829. BOOL VT_VECTOR_AllBits_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2830. {
  2831. return VT_VECTOR_All( v1, v2, PRAllBits );
  2832. } //VT_VECTOR_AllBits_All
  2833. BOOL VT_VECTOR_SomeBits_All( PROPVARIANT const & v1, PROPVARIANT const & v2 )
  2834. {
  2835. return VT_VECTOR_All( v1, v2, PRSomeBits );
  2836. } //VT_VECTOR_SomeBits_All
  2837. ////////////////////////////////////
  2838. ////////////////////////////////////
  2839. ////////////////////////////////////
  2840. FRel const CComparators::_aVectorComparators[] =
  2841. {
  2842. VT_VECTOR_LT,
  2843. VT_VECTOR_LE,
  2844. VT_VECTOR_GT,
  2845. VT_VECTOR_GE,
  2846. VT_VECTOR_EQ,
  2847. VT_VECTOR_NE,
  2848. 0,
  2849. VT_VECTOR_AllBits,
  2850. VT_VECTOR_SomeBits
  2851. };
  2852. ULONG const CComparators::_cVectorComparators =
  2853. sizeof CComparators::_aVectorComparators /
  2854. sizeof CComparators::_aVectorComparators[0];
  2855. FRel const CComparators::_aVectorComparatorsAll[] =
  2856. {
  2857. VT_VECTOR_LT_All,
  2858. VT_VECTOR_LE_All,
  2859. VT_VECTOR_GT_All,
  2860. VT_VECTOR_GE_All,
  2861. VT_VECTOR_EQ_All,
  2862. VT_VECTOR_NE_All,
  2863. 0,
  2864. VT_VECTOR_AllBits_All,
  2865. VT_VECTOR_SomeBits_All
  2866. };
  2867. ULONG const CComparators::_cVectorComparatorsAll =
  2868. sizeof CComparators::_aVectorComparatorsAll /
  2869. sizeof CComparators::_aVectorComparatorsAll[0];
  2870. FRel const CComparators::_aVectorComparatorsAny[] =
  2871. {
  2872. VT_VECTOR_LT_Any,
  2873. VT_VECTOR_LE_Any,
  2874. VT_VECTOR_GT_Any,
  2875. VT_VECTOR_GE_Any,
  2876. VT_VECTOR_EQ_Any,
  2877. VT_VECTOR_NE_Any,
  2878. 0,
  2879. VT_VECTOR_AllBits_Any,
  2880. VT_VECTOR_SomeBits_Any
  2881. };
  2882. ULONG const CComparators::_cVectorComparatorsAny =
  2883. sizeof CComparators::_aVectorComparatorsAny /
  2884. sizeof CComparators::_aVectorComparatorsAny[0];
  2885. ////////////////////////////////////
  2886. ////////////////////////////////////
  2887. ////////////////////////////////////
  2888. FCmp CComparators::GetComparator( VARENUM vt )
  2889. {
  2890. if ( isVectorOrArray( vt ) )
  2891. {
  2892. return VT_VECTOR_Compare;
  2893. }
  2894. else if ( vt >= _iStart && vt < _iStart + _cVariantComparators )
  2895. {
  2896. return( _aVariantComparators[vt].comparator );
  2897. }
  2898. else if ( vt >= _iStart2 && vt < _iStart2 + _cVariantComparators2 )
  2899. {
  2900. return( _aVariantComparators2[vt - _iStart2].comparator );
  2901. }
  2902. else
  2903. {
  2904. // Unknown property type or relation used in comparison.
  2905. Assert(0);
  2906. return( 0 );
  2907. }
  2908. } //GetComparator
  2909. FRel CComparators::GetRelop( VARENUM vt, ULONG relop )
  2910. {
  2911. if ( ( ( isVectorOrArray( vt ) ) ||
  2912. ( isVectorRelop( relop ) ) ) &&
  2913. ( getBaseRelop( relop ) < _cVectorComparators ) )
  2914. {
  2915. if ( isRelopAny( relop ) )
  2916. return _aVectorComparatorsAny[ getBaseRelop( relop ) ];
  2917. else if ( isRelopAll( relop ) )
  2918. return _aVectorComparatorsAll[ getBaseRelop( relop ) ];
  2919. else
  2920. return _aVectorComparators[ relop ];
  2921. }
  2922. else if ( vt >= _iStart && vt < _cVariantComparators &&
  2923. relop < sizeof(_aVariantComparators[0].relops)/
  2924. sizeof(_aVariantComparators[0].relops[0] ) )
  2925. {
  2926. return( _aVariantComparators[vt].relops[relop] );
  2927. }
  2928. else if ( vt >= _iStart2 && vt < _iStart2 + _cVariantComparators2 &&
  2929. relop < sizeof(_aVariantComparators2[0].relops)/
  2930. sizeof(_aVariantComparators2[0].relops[0] ) )
  2931. {
  2932. return( _aVariantComparators2[vt - _iStart2].relops[relop] );
  2933. }
  2934. else
  2935. {
  2936. // Unknown property type or relation used in comparison.
  2937. Assert( 0);
  2938. return( 0 );
  2939. }
  2940. } //GetRelop
  2941. FPCmp CComparators::GetPointerComparator(
  2942. PROPVARIANT const & v1,
  2943. PROPVARIANT const & v2 )
  2944. {
  2945. VARENUM vt = getBaseType( v1 );
  2946. if ( VT_CLSID == vt )
  2947. {
  2948. // GUIDs are the only case of variants where the data inside
  2949. // a singleton is different from an element in a vector.
  2950. // Data in a singleton is a pointer to a guid.
  2951. // Data in the element of a vector is the guid itself.
  2952. // The vector compare code assumes that the layout of singletons
  2953. // and vectors is the same, so we need special-case comparators
  2954. // for GUIDs.
  2955. if ( isVector( v1 ) && isVector( v2 ) )
  2956. return VTP_VV_CLSID_Compare;
  2957. else if ( isVector( v1 ) )
  2958. return VTP_VS_CLSID_Compare;
  2959. else if ( isVector( v2 ) )
  2960. return VTP_SV_CLSID_Compare;
  2961. else
  2962. return VTP_SS_CLSID_Compare;
  2963. Assert( !"unanticipated clsid / vector code path" );
  2964. }
  2965. if ( vt >= _iStart && vt < _iStart + _cVariantComparators )
  2966. return( _aVariantComparators[vt].pointercomparator );
  2967. else if ( vt >= _iStart2 && vt < _iStart2 + _cVariantComparators2 )
  2968. return( _aVariantComparators2[vt - _iStart2].pointercomparator );
  2969. else
  2970. {
  2971. // Unknown property type in comparison.
  2972. Assert( 0 );
  2973. return( 0 );
  2974. }
  2975. } //GetPointerComparator
  2976. FPRel CComparators::GetPointerRelop(
  2977. PROPVARIANT const & v1,
  2978. PROPVARIANT const & v2,
  2979. ULONG relop )
  2980. {
  2981. VARENUM vt = getBaseType( v1 );
  2982. if ( VT_CLSID == vt )
  2983. {
  2984. // GUIDs are the only case of variants where the data inside
  2985. // a singleton is different from an element in a vector.
  2986. // Data in a singleton is a pointer to a guid.
  2987. // Data in the element of a vector is the guid itself.
  2988. // The vector compare code assumes that the layout of singletons
  2989. // and vectors is the same, so we need special-case comparators
  2990. // for GUIDs.
  2991. if ( isVector( v1 ) && isVector( v2 ) )
  2992. {
  2993. if ( PREQ == relop )
  2994. return VTP_VV_CLSID_EQ;
  2995. else if ( PRNE == relop )
  2996. return VTP_VV_CLSID_NE;
  2997. else
  2998. return 0;
  2999. }
  3000. else if ( isVector( v1 ) )
  3001. {
  3002. if ( PREQ == relop )
  3003. return VTP_VS_CLSID_EQ;
  3004. else if ( PRNE == relop )
  3005. return VTP_VS_CLSID_NE;
  3006. else
  3007. return 0;
  3008. }
  3009. else if ( isVector( v2 ) )
  3010. {
  3011. if ( PREQ == relop )
  3012. return VTP_SV_CLSID_EQ;
  3013. else if ( PRNE == relop )
  3014. return VTP_SV_CLSID_NE;
  3015. else
  3016. return 0;
  3017. }
  3018. else
  3019. {
  3020. if ( PREQ == relop )
  3021. return VTP_SS_CLSID_EQ;
  3022. else if ( PRNE == relop )
  3023. return VTP_SS_CLSID_NE;
  3024. else
  3025. return 0;
  3026. }
  3027. }
  3028. if ( vt >= _iStart && vt < _cVariantComparators &&
  3029. relop < sizeof(_aVariantComparators[0].pointerrelops)/
  3030. sizeof(_aVariantComparators[0].pointerrelops[0] ) )
  3031. return( _aVariantComparators[vt].pointerrelops[relop] );
  3032. else if ( vt >= _iStart2 && vt < _iStart2 + _cVariantComparators2 &&
  3033. relop < sizeof(_aVariantComparators2[0].pointerrelops)/
  3034. sizeof(_aVariantComparators2[0].pointerrelops[0] ) )
  3035. return( _aVariantComparators2[vt - _iStart2].pointerrelops[relop] );
  3036. else
  3037. {
  3038. // Unknown type or relation used in comparison.
  3039. Assert( 0);
  3040. return( 0 );
  3041. }
  3042. } //GetPointerRelop