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.

127 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. BList.hxx
  5. Abstract:
  6. Generic list of pointers class.
  7. List elements are treated as four byte values.
  8. Note:
  9. It is acceptable to insert the same pointer into the list
  10. several times. Some usage depends on this.
  11. Author:
  12. Mario Goertzel [MarioGo]
  13. Revision History:
  14. MarioGo 95-03-02 Bits 'n pieces
  15. MarioGo 95-09-07 Changed from a template to a generic class for PPC.
  16. --*/
  17. #ifndef __BLIST_HXX
  18. #define __BLIST_HXX
  19. class CBListIterator;
  20. class CBList
  21. {
  22. friend class CBListIterator;
  23. private:
  24. ULONG Hash(PVOID p);
  25. protected:
  26. ULONG _ulmaxData;
  27. ULONG _ulcElements;
  28. PVOID *_data;
  29. public:
  30. CBList(USHORT cElement = 8)
  31. {
  32. // It's going to grow next time.
  33. ASSERT(cElement > 1);
  34. _ulmaxData = cElement/2;
  35. _ulcElements = 0;
  36. _data = 0;
  37. }
  38. ~CBList()
  39. {
  40. delete _data;
  41. }
  42. ORSTATUS
  43. Insert(IN PVOID p);
  44. PVOID
  45. Remove(IN PVOID p);
  46. BOOL
  47. Member(IN PVOID p);
  48. ULONG
  49. Size()
  50. {
  51. return(_ulcElements);
  52. }
  53. };
  54. class CBListIterator
  55. {
  56. private:
  57. CBList *_pblist;
  58. LONG _next;
  59. public:
  60. CBListIterator(CBList *head) :
  61. _pblist(head),
  62. _next(-1)
  63. { }
  64. PVOID
  65. Next()
  66. {
  67. if (_pblist->_data)
  68. {
  69. do
  70. {
  71. _next++;
  72. }
  73. while(_next < (LONG)_pblist->_ulmaxData && 0 == _pblist->_data[_next]);
  74. if (_next < (LONG)_pblist->_ulmaxData)
  75. {
  76. ASSERT(_pblist->_data[_next] != 0);
  77. return(_pblist->_data[_next]);
  78. }
  79. }
  80. return(0);
  81. }
  82. void
  83. Reset(CBList *head)
  84. {
  85. // Could just assign the new head if there is a use for that.
  86. ASSERT(head == _pblist);
  87. _next = -1;
  88. }
  89. };
  90. #endif / __BLIST_HXX