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.

154 lines
4.3 KiB

  1. //-----------------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: caccess.cxx
  7. //
  8. // Contents: Microsoft OleDB/OleDS Data Source Object for ADSI
  9. //
  10. // Implementation of the Extended Buffer Object used for storing
  11. // accessor handles.
  12. //
  13. // History: 10-01-96 shanksh Created.
  14. //----------------------------------------------------------------------------
  15. #ifndef __CEXTBUFF_HXX
  16. #define __CEXTBUFF_HXX
  17. //---------------------------------- C L A S S E S ----------------------------------
  18. //-----------------------------------------------------------------------------------
  19. //
  20. // @class CExtBuff | Implementation class for the Extensible Buffer Object.
  21. //
  22. //-----------------------------------------------------------------------------------
  23. class CExtBuff {
  24. private:
  25. ULONG _cbItem; //@cmember size of item stored, in bytes
  26. ULONG _cItem; //@cmember current count of items
  27. ULONG _cItemMax; //@cmember max capacity without reallocation
  28. BYTE *_rgItem; //@cmember ptr to the beginning of space
  29. public:
  30. CExtBuff ( void );
  31. ~CExtBuff( void );
  32. //@cmember Initialize the Extended Buffer and store
  33. //the default item.
  34. BOOL FInit(
  35. ULONG cbItem,
  36. VOID *pvItemDefault
  37. );
  38. //@cmember Store an item in the Extended Buffer.
  39. STDMETHODIMP InsertIntoExtBuffer(
  40. VOID *pvItem,
  41. ULONG_PTR &hItem
  42. );
  43. //@cmember Retrieve an item from the Extended Buffer.
  44. inline STDMETHODIMP_(void) GetItemOfExtBuffer(
  45. ULONG_PTR hItem,
  46. VOID *pvItem
  47. )
  48. {
  49. // Is handle valid?
  50. if ( hItem >= _cItem )
  51. hItem = 0;
  52. // Copy the item.
  53. memcpy( (BYTE *)pvItem, (_rgItem + hItem*_cbItem), _cbItem );
  54. }
  55. //@cmember Faster version of GetItemOfExtBuffer for DWORD items.
  56. inline STDMETHODIMP_(ULONG) GetDWORDOfExtBuffer(
  57. ULONG_PTR hItem
  58. )
  59. {
  60. // Is handle valid?
  61. if ( hItem >= _cItem )
  62. hItem = 0;
  63. // Copy the item.
  64. return *(ULONG *)((ULONG *)_rgItem + hItem);
  65. }
  66. //@cmember Get Pointer to buffer
  67. inline STDMETHODIMP_(VOID *) GetPtrOfExtBuffer(
  68. ULONG_PTR hItem
  69. )
  70. {
  71. // Copy the item.
  72. return (VOID *)((BYTE *)_rgItem + (hItem * _cbItem));
  73. }
  74. //@cmember Remove an item from the Extended Buffer.
  75. inline STDMETHODIMP_(void) DeleteFromExtBuffer(
  76. ULONG_PTR hItem
  77. )
  78. {
  79. // Is handle valid?
  80. if ( hItem >= _cItem )
  81. return;
  82. // Copy NULL value into the item.
  83. memcpy( (_rgItem + hItem*_cbItem), _rgItem, _cbItem );
  84. }
  85. //@cmember Get handles of the first and last items
  86. // in the Extended Buffer.
  87. inline STDMETHODIMP_(void) GetLastItemHandle(
  88. ULONG_PTR &hItemLast
  89. )
  90. {
  91. hItemLast = _cItem ? _cItem-1 : 0;
  92. }
  93. //@cmember Get count of items
  94. // in the Extended Buffer.
  95. inline STDMETHODIMP_(ULONG) GetLastHandleCount(
  96. void
  97. )
  98. {
  99. return (_cItem ? _cItem-1 : 0);
  100. }
  101. //@cmember Compacts the end of the extended buffer.
  102. inline STDMETHODIMP_(void) CompactExtBuffer(
  103. void
  104. )
  105. {
  106. ULONG_PTR hItem;
  107. // Backup _cItem to last used entry
  108. GetLastItemHandle(hItem);
  109. while ( hItem ) {
  110. if ( memcmp((_rgItem + hItem*_cbItem), _rgItem,
  111. _cbItem) == 0 ) {
  112. _cItem--;
  113. hItem--;
  114. }
  115. else
  116. break;
  117. }
  118. }
  119. //@cmember Removes an item from the Extended Buffer and compacts
  120. //if possible
  121. inline STDMETHODIMP_(void) DeleteWithCompactFromExtBuffer(
  122. ULONG_PTR hItem
  123. )
  124. {
  125. // Delete the item, and then
  126. DeleteFromExtBuffer(hItem);
  127. // compact the end of the extended buffer.
  128. CompactExtBuffer();
  129. }
  130. };
  131. // quantum of buffer realloc
  132. const DWORD CEXTBUFFER_DITEM = 10;
  133. typedef CExtBuff *LPEXTBUFF;
  134. #endif // __CEXTBUFF_HXX