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.

125 lines
3.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994.
  5. //
  6. // File: KVec.hxx
  7. //
  8. // Contents: CKeyVector
  9. //
  10. // Classes: CEntryBuffer, CEntryBufferHandler
  11. //
  12. // History: 18-Mar-93 AmyA Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include <entry.hxx>
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Class: CKeyVector
  20. //
  21. // Purpose: A vector of pointers to entries stored in the entry buffer
  22. // The vector grows backwards from the end of the buffer
  23. //
  24. // Notes: Instead of storing pointers we store byte offsets
  25. // from the beginning of buffer. FixPointers converts
  26. // them to actual pointers by adding the address
  27. // of the base pointer.
  28. //
  29. // History: 12-Jun-91 BartoszM Created
  30. // 18-Mar-93 AmyA Moved from sort.hxx
  31. //
  32. //----------------------------------------------------------------------------
  33. class CKeyVector
  34. {
  35. public:
  36. inline void Init ( BYTE * buf, unsigned cb );
  37. inline void Add ( CEntry* pEntry );
  38. inline void Sentinel( CEntry* sentinel );
  39. inline BYTE* GetCurPos() const;
  40. inline CEntry** GetVector() const;
  41. inline void CalculateOffsets( unsigned count );
  42. private:
  43. CEntry** _ppEntry;
  44. BYTE * _pbFirstEntry;
  45. };
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Member: CKeyVector::Init, public
  49. //
  50. // Synopsis: Initialize cursor to point to the end of buffer
  51. //
  52. // Arguments: [buf] -- buffer
  53. // [cb] -- size of buffer
  54. //
  55. // History: 07-Jun-91 BartoszM Created
  56. //
  57. //----------------------------------------------------------------------------
  58. inline void CKeyVector::Init ( BYTE * buf, unsigned cb )
  59. {
  60. //
  61. // point it at the end of buffer.
  62. // it will grow up
  63. //
  64. _ppEntry = (CEntry **) & buf[cb];
  65. _pbFirstEntry = buf;
  66. }
  67. inline void CKeyVector::Add ( CEntry* pEntry )
  68. {
  69. --_ppEntry;
  70. // store pointer to entry
  71. *_ppEntry = pEntry;
  72. }
  73. inline void CKeyVector::Sentinel( CEntry* sentinel )
  74. {
  75. Add ( sentinel );
  76. }
  77. inline BYTE * CKeyVector::GetCurPos() const
  78. {
  79. return (BYTE*)_ppEntry;
  80. }
  81. inline CEntry** CKeyVector::GetVector() const
  82. {
  83. return _ppEntry;
  84. }
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Member: CKeyVector::CalculateOffsets, public
  88. //
  89. // Synopsis: Calculate relative pointers by subtracting the base pointer
  90. //
  91. // Arguments: [count] -- number of offsets to calculate
  92. //
  93. // History: 30-Jun-93 AmyA Created
  94. //
  95. //----------------------------------------------------------------------------
  96. inline void CKeyVector::CalculateOffsets ( unsigned count )
  97. {
  98. // _ppEntry stores an array of pointers to entries. We subtract the base
  99. // pointer from all of them in order to create an array of relative
  100. // pointers to entries.
  101. for ( unsigned i = 0; i < count; i++ )
  102. *((INT_PTR *)(_ppEntry+i)) = (BYTE *)(_ppEntry[i]) - _pbFirstEntry;
  103. }