Source code of Windows XP (NT5)
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.

150 lines
3.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1990 - 1999
  6. //
  7. // File: linklist.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. /* --------------------------------------------------------------------
  11. Microsoft OS/2 LAN Manager
  12. Copyright(c) Microsoft Corp., 1990
  13. RPC Runtime - Written by Steven Zeck
  14. This file contains the class implementation of linked list.
  15. -------------------------------------------------------------------- */
  16. #include <precomp.hxx>
  17. #include <linklist.hxx>
  18. // ** LinkItem class implementations ** //
  19. void LinkItem::Remove ( // delete an LinkList from a list *^
  20. LinkList& pLLHead // pointer to Head to Remove
  21. // Removal of a Linked List item is easy with doubly linked lists.
  22. )/*-----------------------------------------------------------------------*/
  23. {
  24. ASSERT(this && (void *)&pLLHead);
  25. if (!pLIPrev)
  26. pLLHead.pLIHead = pLINext; // LI at head of list
  27. else
  28. pLIPrev->pLINext = pLINext;
  29. if (!pLINext)
  30. pLLHead.pLITail = pLIPrev; // LI at tail of list
  31. else
  32. pLINext->pLIPrev = pLIPrev;
  33. pLLHead.Assert();
  34. }
  35. // ** LinkList class implementations ** //
  36. void LinkList::Add ( // Add a new node at the head of a list
  37. LinkItem *pLInew // allocated Item to Add
  38. // Add the newly allocated item to the front of the linked list.
  39. )/*-----------------------------------------------------------------------*/
  40. {
  41. if ( this == 0 )
  42. {
  43. return;
  44. }
  45. this->Assert();
  46. pLInew->pLINext = pLIHead; // old head is now Next
  47. pLInew->pLIPrev = Nil;
  48. pLIHead = pLInew; // new is now Head
  49. if (!pLITail) // handle empty list
  50. pLITail = pLInew;
  51. else {
  52. ASSERT(pLInew->pLINext);
  53. pLInew->pLINext->pLIPrev = pLInew; // old head points back to new
  54. }
  55. }
  56. void LinkList::Append ( // Append a new node at the end of a list
  57. LinkItem *pLInew // allocated Item to Add
  58. )/*-----------------------------------------------------------------------*/
  59. {
  60. if ( this == 0 )
  61. {
  62. return;
  63. }
  64. this->Assert();
  65. // empty lists are just like Add
  66. if (!pLITail) {
  67. this->Add(pLInew);
  68. return;
  69. }
  70. pLInew->pLINext = Nil; // new points back to old tail
  71. pLInew->pLIPrev = pLITail;
  72. pLITail->pLINext = pLInew; // old tail points forward to new
  73. pLITail = pLInew; // tail is now new
  74. }
  75. #ifdef LDEBUG
  76. void LinkList::Assert( // check consistency of the class
  77. // First check the boundary conditions for the linked list root,
  78. // then walk the list checking the backward/forward pointers. Finial
  79. // invoke the virtural function to check the contents of each item.
  80. )/*-----------------------------------------------------------------------*/
  81. {
  82. if (!pLIHead) // empty list
  83. ASSERT(!pLITail);
  84. if (!pLITail)
  85. ASSERT(!pLIHead);
  86. for (LinkItem *pLI = pLIHead; pLI; pLI = pLI->pLINext) {
  87. // tail should point to end of list
  88. if (pLI->pLINext == Nil)
  89. ASSERT(pLITail == pLI);
  90. // first in chain, should have NIL back pointer
  91. if (pLI->pLIPrev == Nil)
  92. ASSERT(pLIHead == pLI);
  93. // check back pointer of next Item points here
  94. if (pLI->pLINext)
  95. ASSERT(pLI->pLINext->pLIPrev == pLI);
  96. pLI->Assert(); // check any derived data
  97. }
  98. }
  99. void LinkItem::Assert(
  100. )/*-----------------------------------------------------------------------*/
  101. {
  102. return; // base class has no additional members, so return
  103. }
  104. #endif