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.

126 lines
2.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) 1998-1998 Microsoft Corporation
  6. //
  7. // File: alist.cpp
  8. // Copyright (c) 1998-1999 Microsoft Corporation
  9. //
  10. // alist.cpp
  11. //
  12. #include "alist.h"
  13. LONG AListItem::GetCount(void) const
  14. {
  15. LONG l;
  16. const AListItem *li;
  17. for(l=0,li=this; li!=NULL ; li=li->m_pNext,++l);
  18. return l;
  19. }
  20. AListItem* AListItem::Cat(AListItem *pItem)
  21. {
  22. AListItem *li;
  23. if(this==NULL)
  24. return pItem;
  25. for(li=this ; li->m_pNext!=NULL ; li=li->m_pNext);
  26. li->m_pNext=pItem;
  27. return this;
  28. }
  29. AListItem* AListItem::Remove(AListItem *pItem)
  30. {
  31. AListItem *li,*prev;
  32. //treat remove(NULL) same as item not found in list
  33. if (pItem==NULL)
  34. return this;
  35. if(pItem==this)
  36. {
  37. li = m_pNext;
  38. m_pNext = NULL;
  39. return li;
  40. }
  41. prev=NULL;
  42. for(li=this; li!=NULL && li!=pItem ; li=li->m_pNext)
  43. prev=li;
  44. if(li==NULL) // item not found in list
  45. return this;
  46. // here it is guaranteed that prev is non-NULL since we checked for
  47. // that condition at the very beginning
  48. prev->SetNext(li->m_pNext);
  49. li->SetNext(NULL);
  50. // SetNext on pItem to NULL
  51. pItem->SetNext(NULL);
  52. return this;
  53. }
  54. AListItem* AListItem::GetPrev(AListItem *pItem) const
  55. {
  56. const AListItem *li,*prev;
  57. prev=NULL;
  58. for(li=this ; li!=NULL && li!=pItem ; li=li->m_pNext)
  59. prev=li;
  60. return (AListItem*)prev;
  61. }
  62. AListItem * AListItem::GetItem(LONG index)
  63. {
  64. AListItem *scan;
  65. for (scan = this; scan!=NULL && index; scan = scan->m_pNext)
  66. {
  67. index--;
  68. }
  69. return (scan);
  70. }
  71. void AList::InsertBefore(AListItem *pItem,AListItem *pInsert)
  72. {
  73. AListItem *prev = GetPrev(pItem);
  74. pInsert->SetNext(pItem);
  75. if (prev) prev->SetNext(pInsert);
  76. else m_pHead = pInsert;
  77. }
  78. void AList::AddTail(AListItem *pItem)
  79. {
  80. if (m_pHead == NULL)
  81. {
  82. AddHead(pItem);
  83. }
  84. else
  85. {
  86. m_pHead = m_pHead->AddTail(pItem);
  87. }
  88. }
  89. void AList::Reverse()
  90. {
  91. AList Temp;
  92. AListItem *pItem;
  93. while (pItem = RemoveHead())
  94. {
  95. Temp.AddHead(pItem);
  96. }
  97. m_pHead = Temp.GetHead();
  98. }
  99. BOOL AList::IsMember(AListItem *pItem)
  100. {
  101. AListItem *pScan = GetHead();
  102. for (;pScan;pScan = pScan->GetNext())
  103. {
  104. if (pItem == pScan) return TRUE;
  105. }
  106. return FALSE;
  107. }