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.

220 lines
4.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: cdlink.hxx
  7. //
  8. // Contents:
  9. //
  10. // Classes: CDlink
  11. //
  12. // History: 18-Mar-96 RaviR Created.
  13. //
  14. //--------------------------------------------------------------------------
  15. #ifndef _CDLINKLIST_HXX_
  16. #define _CDLINKLIST_HXX_
  17. #include "cdlink.hxx"
  18. class CDLinkList;
  19. typedef CDLinkList *PDLINKLIST;
  20. typedef CDLink *PDLINK;
  21. //+----------------------------------------------------------------------
  22. //
  23. // Class: CDLinkList, dl
  24. //
  25. // Purpose: A double linked list class
  26. //
  27. //----------------------------------------------------------------------
  28. class CDLinkList
  29. {
  30. public:
  31. CDLinkList():
  32. _pdlFirst(NULL),
  33. _pdlLast(NULL) {;}
  34. virtual ~CDLinkList() {
  35. this->FreeList();
  36. }
  37. virtual void Add(PDLINK pdl, BOOL fAsHead);
  38. virtual void Remove(PDLINK pdl);
  39. void FreeList();
  40. UINT Count();
  41. protected:
  42. PDLINK First() const;
  43. PDLINK Last() const;
  44. private:
  45. PDLINK _pdlFirst;
  46. PDLINK _pdlLast;
  47. };
  48. //+----------------------------------------------------------------------
  49. //
  50. // Member: CDLinkList::First const
  51. //
  52. // Purpose: Member variable access function
  53. //
  54. // Returns: _pdlFirst
  55. //
  56. //-----------------------------------------------------------------------
  57. inline PDLINK CDLinkList::First() const
  58. {
  59. return _pdlFirst;
  60. }
  61. //+----------------------------------------------------------------------
  62. //
  63. // Member: CDLinkList::First const
  64. //
  65. // Purpose: Member variable access function
  66. //
  67. // Returns: _pdlLast
  68. //
  69. //-----------------------------------------------------------------------
  70. inline PDLINK CDLinkList::Last() const
  71. {
  72. return _pdlLast;
  73. }
  74. //+----------------------------------------------------------------------
  75. //
  76. // Member: CDLinkList::FreeList
  77. //
  78. // Purpose: Frees the list.
  79. //
  80. //-----------------------------------------------------------------------
  81. inline void CDLinkList::FreeList()
  82. {
  83. PDLINK pdlCurr;
  84. while (_pdlFirst != NULL)
  85. {
  86. pdlCurr = _pdlFirst;
  87. _pdlFirst = _pdlFirst->Next();
  88. delete pdlCurr;
  89. }
  90. _pdlLast = NULL;
  91. }
  92. //+----------------------------------------------------------------------
  93. //
  94. // Member: CDLinkList::Add
  95. //
  96. // Purpose: Adds a CSlink to the end of the list.
  97. //
  98. // Returns: void
  99. //
  100. //-----------------------------------------------------------------------
  101. inline void CDLinkList::Add(PDLINK pdl, BOOL fAsHead)
  102. {
  103. if (_pdlFirst == NULL)
  104. {
  105. _pdlLast = _pdlFirst = pdl;
  106. }
  107. else if (fAsHead == TRUE)
  108. {
  109. pdl->LinkBefore(_pdlFirst);
  110. _pdlFirst = pdl;
  111. }
  112. else // as tail
  113. {
  114. pdl->LinkAfter(_pdlLast);
  115. _pdlLast = pdl;
  116. }
  117. }
  118. //+----------------------------------------------------------------------
  119. //
  120. // Member: CDLinkList::Remove
  121. //
  122. // Purpose: Removes a CSLink from the list.
  123. //
  124. // Returns: void
  125. //
  126. //-----------------------------------------------------------------------
  127. inline void CDLinkList::Remove(PDLINK pdl)
  128. {
  129. if (pdl == _pdlFirst)
  130. {
  131. _pdlFirst = _pdlFirst->Next();
  132. }
  133. if (pdl == _pdlLast)
  134. {
  135. _pdlLast = _pdlLast->Prev();
  136. }
  137. pdl->UnLink();
  138. }
  139. //+----------------------------------------------------------------------
  140. //
  141. // Member: CDLinkList::Count
  142. //
  143. // Purpose: To compute the number of nodes
  144. //
  145. // Returns: The count of nodes
  146. //
  147. //-----------------------------------------------------------------------
  148. inline UINT CDLinkList::Count()
  149. {
  150. UINT uiCount = 0;
  151. for (PDLINK pdl = _pdlFirst; pdl != NULL; pdl = pdl->Next())
  152. {
  153. ++uiCount;
  154. }
  155. return uiCount;
  156. }
  157. //+---------------------------------------------------------------------------
  158. //
  159. // macro: DECLARE_SINGLE_LINK_LIST_CLASS(cls)
  160. //
  161. // Synopsis: Declares a single link list class.
  162. //
  163. // Arguments: [cls] The element's class name
  164. //
  165. //----------------------------------------------------------------------------
  166. #define DECLARE_DOUBLE_LINK_LIST_CLASS(cls) \
  167. class cls##List : public CDLinkList \
  168. { \
  169. public: \
  170. cls##List() {;} \
  171. virtual ~cls##List() {;} \
  172. \
  173. inline virtual void Add(cls *pcls, BOOL fAsHead) { CDLinkList::Add((PDLINK)pcls, fAsHead); } \
  174. inline virtual void Remove(cls *pcls) { CDLinkList::Remove((PDLINK)pcls); } \
  175. inline void Add(cls *pcls) { CDLinkList::Add((PDLINK)pcls, FALSE); } \
  176. inline cls * First() const { return((cls *) CDLinkList::First()); } \
  177. };
  178. #endif // _CDLINKLIST_HXX_