Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. IdTable.hxx
  5. Abstract:
  6. Generic tables indexed by 1, 2 or 2.5 64bit IDs.
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 12-13-95 Bits 'n pieces
  11. --*/
  12. #ifndef __ID_TABLE_HXX
  13. #define __ID_TABLE_HXX
  14. class CIdTableElement;
  15. class CId2TableElement;
  16. class CId3TableElement;
  17. class CIdKey : public CTableKey
  18. {
  19. friend CIdTableElement;
  20. public:
  21. CIdKey(const ID id) : _id(id) { }
  22. virtual DWORD
  23. Hash() {
  24. return((DWORD)_id ^ (*((DWORD *)&_id + 1)));
  25. }
  26. virtual BOOL
  27. Compare(CTableKey &tk) {
  28. CIdKey &idk = (CIdKey &)tk;
  29. return(idk._id == _id);
  30. }
  31. protected:
  32. ID _id;
  33. };
  34. class CId2Key : public CIdKey
  35. {
  36. friend CId2TableElement;
  37. public:
  38. CId2Key(const ID id, const ID id2) : CIdKey(id), _id2(id2) { }
  39. virtual DWORD
  40. Hash() {
  41. return( (DWORD)_id2 ^ (*((DWORD *)&_id2 + 1))
  42. ^ (DWORD)_id ^ (*((DWORD *)&_id + 1)) );
  43. }
  44. virtual BOOL
  45. Compare(CTableKey &tk) {
  46. CId2Key &idk = (CId2Key &)tk;
  47. return(idk._id2 == _id2
  48. && this->CIdKey::Compare(tk));
  49. }
  50. protected:
  51. ID _id2;
  52. };
  53. class CId3Key : public CId2Key
  54. {
  55. friend CId3TableElement;
  56. public:
  57. CId3Key(const ID id, const ID id2, const PVOID id3) : CId2Key(id,id2), _id3(id3) { }
  58. virtual DWORD
  59. Hash() {
  60. return( PtrToUlong(_id3)
  61. ^ (DWORD)_id2 ^ (*((DWORD *)&_id2 + 1))
  62. ^ (DWORD)_id ^ (*((DWORD *)&_id + 1)) );
  63. }
  64. virtual BOOL
  65. Compare(CTableKey &tk) {
  66. CId3Key &idk = (CId3Key &)tk;
  67. return(idk._id3 == _id3
  68. && this->CId2Key::Compare(tk));
  69. }
  70. protected:
  71. PVOID _id3;
  72. };
  73. class CIdTableElement : public CTableElement
  74. {
  75. public:
  76. CIdTableElement(ID id) : _id(id) {}
  77. ID
  78. Id() {
  79. return(_id);
  80. }
  81. virtual DWORD
  82. Hash() {
  83. return(((DWORD)_id) ^ (*((DWORD *)&_id + 1)));
  84. }
  85. virtual BOOL
  86. Compare(CTableKey &tk) {
  87. CIdKey &idk = (CIdKey &)tk;
  88. return( _id == idk._id );
  89. }
  90. virtual BOOL
  91. Compare(CONST CTableElement *pElement) {
  92. CIdTableElement *pidte = (CIdTableElement *)pElement;
  93. return(_id == pidte->_id);
  94. }
  95. private:
  96. ID _id;
  97. };
  98. class CId2TableElement : public CIdTableElement
  99. {
  100. public:
  101. CId2TableElement(ID id, ID id2) : CIdTableElement(id), _id2(id2) {}
  102. ID
  103. Id2() {
  104. return(_id2);
  105. }
  106. virtual DWORD
  107. Hash() {
  108. return( this->CIdTableElement::Hash()
  109. ^ ((DWORD)_id2) ^ (*((DWORD *)&_id2 + 1)) );
  110. }
  111. virtual BOOL
  112. Compare(CTableKey &tk) {
  113. CId2Key &idk = (CId2Key &)tk;
  114. return( _id2 == idk._id2
  115. && this->CIdTableElement::Compare(tk));
  116. }
  117. virtual BOOL
  118. Compare(CONST CTableElement *pElement) {
  119. CId2TableElement *pidte = (CId2TableElement *)pElement;
  120. return(_id2 == pidte->_id2
  121. && this->CIdTableElement::Compare(pElement));
  122. }
  123. private:
  124. ID _id2;
  125. };
  126. class CId3TableElement : public CId2TableElement
  127. {
  128. public:
  129. CId3TableElement(ID id, ID id2, PVOID id3) : CId2TableElement(id, id2), _id3(id3) {}
  130. PVOID
  131. Id3() {
  132. return(_id3);
  133. }
  134. virtual DWORD
  135. Hash() {
  136. return( this->CId2TableElement::Hash()
  137. ^ PtrToUlong(_id3) );
  138. }
  139. virtual BOOL
  140. Compare(CTableKey &tk) {
  141. CId3Key &idk = (CId3Key &)tk;
  142. return( _id3 == idk._id3
  143. && this->CId2TableElement::Compare(tk));
  144. }
  145. virtual BOOL
  146. Compare(CONST CTableElement *pElement) {
  147. CId3TableElement *pidte = (CId3TableElement *)pElement;
  148. return(_id3 == pidte->_id3
  149. && this->CId2TableElement::Compare(pElement));
  150. }
  151. private:
  152. PVOID _id3;
  153. };
  154. #endif