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.

91 lines
1.8 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. //
  3. // clist.cpp
  4. //
  5. //
  6. #ifdef DMSYNTH_MINIPORT
  7. #include "common.h"
  8. #else
  9. #include "simple.h"
  10. #include "clist.h"
  11. #endif
  12. LONG CListItem::GetCount(void) const
  13. {
  14. LONG l;
  15. const CListItem *li;
  16. for(l=0,li=this; li!=NULL ; li=li->m_pNext,++l);
  17. return l;
  18. }
  19. BOOL CListItem::IsMember(CListItem *pItem)
  20. {
  21. CListItem *li = this;
  22. for (;li != NULL; li=li->m_pNext)
  23. {
  24. if (li == pItem) return (TRUE);
  25. }
  26. return (FALSE);
  27. }
  28. CListItem* CListItem::Cat(CListItem *pItem)
  29. {
  30. CListItem *li;
  31. if(this==NULL)
  32. return pItem;
  33. for(li=this ; li->m_pNext!=NULL ; li=li->m_pNext);
  34. li->m_pNext=pItem;
  35. return this;
  36. }
  37. CListItem* CListItem::Remove(CListItem *pItem)
  38. {
  39. CListItem *li,*prev;
  40. if(pItem==this)
  41. return m_pNext;
  42. prev=NULL;
  43. for(li=this; li!=NULL && li!=pItem ; li=li->m_pNext)
  44. prev=li;
  45. if(li==NULL) // item not found in list
  46. return this;
  47. // here it is guaranteed that prev is non-NULL since we checked for
  48. // that condition at the very beginning
  49. prev->SetNext(li->m_pNext);
  50. li->SetNext(NULL);
  51. return this;
  52. }
  53. CListItem* CListItem::GetPrev(CListItem *pItem) const
  54. {
  55. const CListItem *li,*prev;
  56. prev=NULL;
  57. for(li=this ; li!=NULL && li!=pItem ; li=li->m_pNext)
  58. prev=li;
  59. return (CListItem*)prev;
  60. }
  61. CListItem * CListItem::GetItem(LONG index)
  62. {
  63. CListItem *scan;
  64. for (scan = this; scan!=NULL && index; scan = scan->m_pNext) index--;
  65. return (scan);
  66. }
  67. void CList::InsertBefore(CListItem *pItem,CListItem *pInsert)
  68. {
  69. CListItem *prev = GetPrev(pItem);
  70. pInsert->SetNext(pItem);
  71. if (prev) prev->SetNext(pInsert);
  72. else m_pHead = pInsert;
  73. }