home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / DSSHOW3D / DBLIST.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  2KB  |  79 lines

  1. #ifndef __DBLIST_H__
  2. #define __DBLIST_H__
  3.  
  4. #include "debug.h"
  5.  
  6. #ifndef __cplusplus
  7. #error DBList.h included from a C file!
  8. #endif
  9.  
  10. template<class A>
  11. class DblNode
  12. {
  13. friend class DbLinkedList<A>;
  14.  
  15. private:
  16.     class DblNode<A>    *pNext;
  17.     class DblNode<A>    *pPrev;
  18.  
  19.     A       value;
  20. };
  21.  
  22. template <class T>
  23. class DbLinkedList
  24. {
  25. private:
  26.  
  27. public:
  28.     DbLinkedList();
  29.     DbLinkedList( T emptyElt );
  30.     ~DbLinkedList();
  31.  
  32.     inline void SetEmpty( T emptyElt ) { m_emptyT = emptyElt; }
  33.  
  34.     inline BOOL IsAtTail()  { ASSERT( NULL != m_pCurrent );
  35.                     return (m_pCurrent->pNext == NULL); }
  36.  
  37.     void Clear( void );
  38.     void RemoveCurrent();
  39.     void Remove( T );
  40.     BOOL InsertAfterCurrent( T val );
  41.     BOOL InsertBeforeCurrent( T val );
  42.     T GetCurrent();
  43.     void Append( T );
  44.  
  45.     inline void SetAtHead()     { m_pCurrent = m_pHead; }
  46.     inline void SetAtTail()     { m_pCurrent = m_pTail; }
  47.  
  48.     void AssertValid();
  49.  
  50.     inline int GetElementCount( void )  { return m_nElementCount; }
  51.  
  52.     DbLinkedList<T> &operator++()
  53.         { if( m_pCurrent && m_pCurrent->pNext ) m_pCurrent = m_pCurrent->pNext; return *this; }
  54.     DbLinkedList<T> &operator++( int )
  55.         { if( m_pCurrent && m_pCurrent->pNext ) m_pCurrent = m_pCurrent->pNext; return *this; }
  56.     DbLinkedList<T> &operator--()
  57.         { if( m_pCurrent && m_pCurrent->pPrev ) m_pCurrent = m_pCurrent->pPrev; return *this; }
  58.     DbLinkedList<T> &operator--( int )
  59.         { if( m_pCurrent && m_pCurrent->pPrev ) m_pCurrent = m_pCurrent->pPrev; return *this; }
  60.  
  61.  
  62. protected:
  63.     DblNode<T>  *m_pHead;
  64.     DblNode<T>  *m_pTail;
  65.     DblNode<T>  *m_pCurrent;
  66.  
  67.     int m_nElementCount;
  68.     T   m_emptyT;
  69. };
  70.  
  71.  
  72. // Because of the way templates work, we must include the code from the
  73. // header file.
  74. #include "DbList.cpp"
  75.  
  76.  
  77. #endif
  78.  
  79.