home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 May / Game.EXE_05_2002.iso / Alawar / Lib / SimpleList.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-27  |  839 b   |  50 lines

  1. #ifndef __SIMPLELIST_H__
  2. #define __SIMPLELIST_H__
  3.  
  4. class SimpleListNodeBase
  5. {
  6. protected:
  7.     SimpleListNodeBase * next;
  8.     SimpleListNodeBase * prev;
  9.  
  10.     void link( SimpleListNodeBase * start )
  11.     {
  12.         SimpleListNodeBase * nn = start->next;
  13.         next = nn;
  14.         if( nn )
  15.             nn->prev = this;
  16.         prev = start;
  17.         start->next = this;
  18.     }
  19. public:
  20.     SimpleListNodeBase()
  21.         :    prev( 0 ),
  22.             next( 0 )
  23.     {}
  24.     void unlink()
  25.     {
  26.         SimpleListNodeBase * pp = prev;
  27.         SimpleListNodeBase * nn = next;
  28.  
  29.         pp->next = nn;
  30.         if( nn )
  31.             nn->prev = pp;
  32.         prev = next = 0;
  33.     }
  34. };
  35.  
  36. template<typename T>
  37. class SimpleListNode : public SimpleListNodeBase
  38. {
  39. public:
  40.     void link( SimpleListNode<T> * start )
  41.     {
  42.         SimpleListNodeBase::link( start );
  43.     }
  44.     T * get_next()const
  45.     {
  46.         return static_cast<T*>( next );
  47.     }
  48. };
  49.  
  50. #endif //__SIMPLELIST_H__