home *** CD-ROM | disk | FTP | other *** search
/ Beginning Direct3D Game Programming / Direct3D.iso / directx / dxf / samples / multimedia / directshow / dmo / gargledmo / medparambase / alist.cpp next >
Encoding:
C/C++ Source or Header  |  2000-10-02  |  2.4 KB  |  120 lines

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