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.

163 lines
3.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: alias.hxx
  7. //
  8. // Classes: CAliasBlock
  9. // CAliases
  10. //
  11. // History: 26-May-94 DrewB Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #ifndef __ALIAS_HXX__
  15. #define __ALIAS_HXX__
  16. // Number of alias slots to allocate in a chunk
  17. #define ALIAS_BLOCK_SIZE 64
  18. typedef WORD ALIAS;
  19. #define INVALID_ALIAS ((ALIAS)0xffff)
  20. // Aliases should not be zero because this causes error detection problems
  21. #define INITIAL_ALIAS ((ALIAS)1)
  22. // Values cannot be zero, this allows us to detect free slots in the
  23. // value array
  24. #define INVALID_VALUE ((DWORD)0)
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Class: CAliasBlock (ab)
  28. //
  29. // Purpose: A block of values indexed by alias
  30. //
  31. // History: 26-May-94 DrewB Created
  32. //
  33. //----------------------------------------------------------------------------
  34. class CAliasBlock
  35. {
  36. public:
  37. CAliasBlock(ALIAS aliasBase,
  38. CAliasBlock *pabNext);
  39. BOOL ContainsAlias(ALIAS alias)
  40. {
  41. return alias >= _aliasBase && alias < _aliasBase+ALIAS_BLOCK_SIZE;
  42. }
  43. DWORD AliasValue(ALIAS alias)
  44. {
  45. thkAssert(!IsFree(alias));
  46. return _dwValues[AliasIndex(alias)];
  47. }
  48. void RemoveAlias(ALIAS alias)
  49. {
  50. thkAssert(!IsFree(alias));
  51. #if DBG == 1
  52. CheckFree();
  53. #endif
  54. thkAssert(_iFilled > 0);
  55. _iFilled--;
  56. _dwValues[AliasIndex(alias)] = INVALID_VALUE;
  57. }
  58. void SetValue(ALIAS alias, DWORD dwValue)
  59. {
  60. thkAssert(!IsFree(alias));
  61. thkAssert(dwValue != INVALID_VALUE);
  62. _dwValues[AliasIndex(alias)] = dwValue;
  63. }
  64. ALIAS ValueAlias(DWORD dwValue);
  65. ALIAS AddValue(DWORD dwValue);
  66. CAliasBlock *GetNext(void)
  67. {
  68. return _pabNext;
  69. }
  70. void SetNext(CAliasBlock *pab)
  71. {
  72. _pabNext = pab;
  73. }
  74. int AliasesFilled(void)
  75. {
  76. return _iFilled;
  77. }
  78. #if DBG == 1
  79. BOOL IsFree(ALIAS alias)
  80. {
  81. return _dwValues[AliasIndex(alias)] == INVALID_VALUE;
  82. }
  83. #endif
  84. private:
  85. int AliasIndex(ALIAS alias)
  86. {
  87. thkAssert(ContainsAlias(alias));
  88. return (int)(alias-_aliasBase);
  89. }
  90. ALIAS IndexAlias(int iIndex)
  91. {
  92. thkAssert(iIndex >= 0 && iIndex < ALIAS_BLOCK_SIZE);
  93. return (ALIAS)(iIndex+_aliasBase);
  94. }
  95. #if DBG == 1
  96. void CheckFree(void);
  97. #endif
  98. ALIAS _aliasBase;
  99. int _iFilled;
  100. DWORD _dwValues[ALIAS_BLOCK_SIZE];
  101. CAliasBlock *_pabNext;
  102. };
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Class: CAliases (aliases)
  106. //
  107. // Purpose: Maintains a set of aliases for values
  108. //
  109. // History: 26-May-94 DrewB Created
  110. //
  111. // Notes: Values must be unique
  112. //
  113. //----------------------------------------------------------------------------
  114. class CAliases
  115. {
  116. public:
  117. CAliases(void)
  118. : _abStatic(INITIAL_ALIAS, NULL)
  119. {
  120. // Start alias list with the static block
  121. _pabAliases = &_abStatic;
  122. // The static block takes the first block of aliases
  123. _aliasBase = INITIAL_ALIAS+ALIAS_BLOCK_SIZE;
  124. }
  125. ~CAliases(void);
  126. DWORD AliasValue(ALIAS alias);
  127. ALIAS ValueAlias(DWORD dwValue);
  128. ALIAS AddValue(DWORD dwValue);
  129. void RemoveAlias(ALIAS alias);
  130. void SetValue(ALIAS alias, DWORD dwValue);
  131. private:
  132. void DeleteBlock(CAliasBlock *pab, CAliasBlock *pabPrev);
  133. CAliasBlock _abStatic;
  134. CAliasBlock *_pabAliases;
  135. ALIAS _aliasBase;
  136. };
  137. #endif // #ifndef __ALIAS_HXX__