home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctdemo.zip / classes / @CLSLIB1.ZIP / cls / icclc / tinylist.cpp < prev   
C/C++ Source or Header  |  1994-06-17  |  2KB  |  149 lines

  1. #ifndef INCL_TINYLIST
  2. #define INCL_TINYLIST
  3.  
  4. #ifndef __FIRST__
  5. #define __FIRST__
  6. #define __IMPL__TINYLIST
  7. #endif
  8.  
  9. /////V TinyList PCM f:\cls_ibm\cls\icclc 0 PM 20.10.94 19:37:13
  10.  
  11. /*
  12. /////H 
  13. 20.10.94 19:37 PM 0 copied from: TinyList TOS f:\cls_ibm\cls\icclc 0 PM 19.10.94 00:26:01
  14. 30.03.95 10:34 PM 0 archived: TinyList PCM f:\cls_ibm\cls\icclc 0 PM 20.10.94 19:37:13
  15. /////
  16. */
  17.  
  18. /////1
  19. #undef inline
  20.  
  21. #include <bsa.h>
  22.  
  23.  
  24. #ifndef __INLINE__
  25. #define inline
  26. #endif
  27.  
  28. /////C TinyList @ <class t> @ template iccl 
  29. template <class t>
  30. class TinyList
  31.  
  32. {
  33. /////T Aux inside 
  34. struct Node {
  35.     t*        pData;
  36.     Node*    pNext;
  37.  
  38.     Node ( t* d )
  39.         { pData = d; pNext = 0; }
  40. };
  41. /////
  42.  
  43.  
  44. protected:
  45. /////D Current @  @ instance protected 
  46.     TinyList<t>::Node*     Current;
  47.  
  48. /////D First @  @ instance protected 
  49.     TinyList<t>::Node*     First;
  50.  
  51.  
  52. public:
  53.     int    add (t*);
  54.     t*    first ();
  55.     t*    next ();
  56.     TinyList ();
  57.     ~TinyList ();
  58. };
  59.  
  60.  
  61. /////2
  62. #undef inline
  63.  
  64.  
  65. #if (defined __INLINE__) || (defined __IMPL__TINYLIST)
  66.  
  67. #ifndef __INLINE__
  68. #define inline
  69. #endif
  70.  
  71. /////
  72. #endif
  73.  
  74. /////3
  75. #undef inline
  76.  
  77. #ifdef __IMPL__TINYLIST
  78. /////F add @ @ instance public 
  79. template <class t> 
  80. int TinyList<t>:: add ( t* pData )
  81. {
  82.     TinyList<t>::Node * newNode = new TinyList<t>::Node( pData );
  83.  
  84.     if ( ! First ){
  85.         First = newNode;
  86.         return 1;
  87.     }
  88.  
  89.     for ( Current = First; Current->pNext; Current = Current->pNext );
  90.     Current->pNext = newNode;
  91.  
  92.     return 1;
  93. }
  94.  
  95. /////F first @ @ instance public 
  96. template <class t> 
  97. t* TinyList<t>:: first ()
  98. {
  99.     if ( !First ){
  100.         Current = 0;
  101.         return 0;
  102.     }
  103.     else {
  104.         Current = First;
  105.         return First->pData;
  106.     }
  107. }
  108.  
  109. /////F next @ @ instance public 
  110. template <class t> 
  111. t* TinyList<t>:: next ()
  112. {
  113.     if ( !Current ){
  114.         return 0;
  115.     }
  116.     else {
  117.         Current = Current->pNext;
  118.         if ( Current )
  119.             return Current->pData;
  120.         else
  121.             return 0;
  122.     }
  123. }
  124.  
  125. /////F TinyList @ @ instance public 
  126. template <class t> 
  127. TinyList<t>:: TinyList ()
  128. {
  129.     First = 0;
  130.     Current = 0;
  131. }
  132.  
  133. /////F ~TinyList @ @ instance public 
  134. template <class t> 
  135. TinyList<t>:: ~TinyList ()
  136. {
  137.     TinyList<t>::Node *pNode;
  138.  
  139.     for ( Current = First; Current; Current = pNode ){
  140.         pNode = Current->pNext;
  141.         delete Current;
  142.     }
  143. }
  144.  
  145. /////
  146. #endif
  147.  
  148. #endif
  149.