Windows NT 4.0 source code leak
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.

178 lines
3.2 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. linklist.hxx
  5. Abstract:
  6. This file contains a linked list class definition.
  7. This base class for Link and Item just contains a set of
  8. two pointers. Derived classes are created with the
  9. macros LinkList or LinkListClass (used for nested inheritance).
  10. These derived classes take your member data items and add them
  11. to the base class.
  12. If you define a macro ASSERT_VCLASS/ASSERT_CLASS, then you must
  13. define a member method Assert for each class you derived which checks
  14. the runtime data consistance of the members you have added.
  15. Author:
  16. Steven Zeck (stevez) 07/01/90
  17. --*/
  18. #ifndef _LINKLIST_
  19. #define _LINKLIST_
  20. #ifndef ASSERT_VCLASS
  21. #define ASSERT_VCLASS {(void)(0);}
  22. #define ASSERT_CLASS
  23. #endif
  24. /*++
  25. Class Definition:
  26. LINK_ITEM
  27. Abstract:
  28. This the base class for a linked list item. It is inherited from
  29. to create a object which can be in a linked list.
  30. --*/
  31. class LINK_ITEM {
  32. private:
  33. // List items are doubly linked to allow easily removal.
  34. LINK_ITEM *pLINext; // Next and Previous Nodes
  35. LINK_ITEM *pLIPrev;
  36. public:
  37. friend class LINK_LIST;
  38. ASSERT_VCLASS;
  39. // Return the Next element on the list.
  40. LINK_ITEM
  41. *Next(
  42. )
  43. {
  44. return ((this)? pLINext: NIL);
  45. }
  46. // Delete a linked list object from a LinkList
  47. void
  48. Remove(
  49. IN OUT LINK_LIST& pLLHead
  50. );
  51. };
  52. /*++
  53. Class Definition:
  54. LINK_LIST
  55. Abstract:
  56. This class contains linked list root. It maintains pointers to the
  57. first and last item in the linked list.
  58. --*/
  59. class LINK_LIST {
  60. friend class LINK_ITEM;
  61. private:
  62. LINK_ITEM *pLIHead; // Head of list
  63. LINK_ITEM *pLITail; // Tail of list
  64. public:
  65. ASSERT_CLASS;
  66. LINK_LIST(
  67. )
  68. {
  69. pLIHead = pLITail = NIL;
  70. }
  71. void
  72. Add(
  73. IN LINK_ITEM *pLInew
  74. );
  75. void
  76. Append(
  77. IN LINK_ITEM *pLInew
  78. );
  79. // Return the First element on the list
  80. LINK_ITEM *
  81. First(
  82. )
  83. {
  84. this->Assert();
  85. return (pLIHead);
  86. }
  87. };
  88. //** This macro defines template which a instance of a linklist can be make **//
  89. #define NEW_LINK_LIST(CLASS_PREFIX, MEMBERS) NEW_LINK_LIST_CLASS(CLASS_PREFIX, LINK, MEMBERS)
  90. #define NEW_LINK_LIST_CLASS(CLASS_PREFIX, BASE, MEMBERS) \
  91. \
  92. class CLASS_PREFIX##_LIST; \
  93. \
  94. class CLASS_PREFIX##_ITEM:public BASE##_ITEM { \
  95. \
  96. public: \
  97. ASSERT_VCLASS; \
  98. \
  99. CLASS_PREFIX##_ITEM *Next( \
  100. ) { \
  101. this->Assert(); \
  102. return ((CLASS_PREFIX##_ITEM *)(this->LINK_ITEM::Next())); \
  103. } \
  104. \
  105. MEMBERS \
  106. \
  107. }; \
  108. \
  109. class CLASS_PREFIX##_LIST:public BASE##_LIST { \
  110. \
  111. public: \
  112. CLASS_PREFIX##_ITEM *Append(CLASS_PREFIX##_ITEM *pLLI) { \
  113. \
  114. LINK_LIST::Append(pLLI); \
  115. return (pLLI); \
  116. } \
  117. \
  118. CLASS_PREFIX##_ITEM *Add(CLASS_PREFIX##_ITEM *pLLI) { \
  119. \
  120. LINK_LIST::Add(pLLI); \
  121. return (pLLI); \
  122. } \
  123. \
  124. CLASS_PREFIX##_ITEM *First( \
  125. ) { \
  126. return ((CLASS_PREFIX##_ITEM *)LINK_LIST::First()); \
  127. } \
  128. };
  129. #endif // _LINKLIST_