home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNU_1OF3.ZIP / HEADERS.ZIP / g++-include / gen / SLList.hP < prev    next >
Encoding:
Text File  |  1992-03-06  |  3.1 KB  |  136 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18.  
  19.  
  20. #ifndef _<T>SLList_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _<T>SLList_h 1
  25.  
  26. #include <Pix.h>
  27. #include "<T>.defs.h"
  28.  
  29. #ifndef _<T>SLListNode_h
  30. #define _<T>SLListNode_h 1
  31.  
  32. struct <T>SLListNode
  33. {
  34.   <T>SLListNode*         tl;
  35.   <T>                    hd;
  36.                          <T>SLListNode() { }
  37.                          <T>SLListNode(<T&> h, <T>SLListNode* t = 0);
  38.                          ~<T>SLListNode() { }
  39. };
  40.  
  41.  
  42. inline <T>SLListNode::<T>SLListNode(<T&> h, <T>SLListNode* t) :hd(h), tl(t) {}
  43.  
  44. typedef <T>SLListNode* <T>SLListNodePtr;
  45.  
  46. #endif
  47.  
  48.  
  49. class <T>SLList
  50. {
  51. protected:
  52.   <T>SLListNode*        last;
  53.  
  54. public:
  55.                         <T>SLList();
  56.                         <T>SLList(<T>SLList& a);
  57.                         ~<T>SLList();
  58.  
  59.   <T>SLList&            operator = (<T>SLList& a);
  60.  
  61.   int                   empty();
  62.   int                   length();
  63.  
  64.   void                  clear();
  65.  
  66.   Pix                   prepend(<T&> item);
  67.   Pix                   append(<T&> item);
  68.  
  69.   void                  join(<T>SLList&);
  70.  
  71.   Pix                   prepend(<T>SLListNode*);
  72.   Pix                   append(<T>SLListNode*);
  73.  
  74.   <T>&                  operator () (Pix p);
  75.   Pix                   first();
  76.   void                  next(Pix& p);
  77.   int                   owns(Pix p);
  78.   Pix                   ins_after(Pix p, <T&> item);
  79.   void                  del_after(Pix p);
  80.  
  81.   <T>&                  front();
  82.   <T>&                  rear();
  83.   <T>                   remove_front();
  84.   int                   remove_front(<T>& x);
  85.   void                  del_front();
  86.  
  87.   void                  error(const char* msg);
  88.   int                   OK();
  89. };
  90.  
  91. inline <T>SLList::~<T>SLList()
  92. {
  93.   clear();
  94. }
  95.  
  96. inline <T>SLList::<T>SLList()
  97. {
  98.   last = 0;
  99. }
  100.  
  101. inline int <T>SLList::empty()
  102. {
  103.   return last == 0;
  104. }
  105.  
  106.  
  107. inline Pix <T>SLList::first()
  108. {
  109.   return (last == 0)? 0 : Pix(last->tl);
  110. }
  111.  
  112. inline void <T>SLList::next(Pix& p)
  113. {
  114.   p = (p == 0 || p == last)? 0 : Pix(((<T>SLListNode*)(p))->tl);
  115. }
  116.  
  117. inline <T>& <T>SLList::operator () (Pix p)
  118. {
  119.   if (p == 0) error("null Pix");
  120.   return ((<T>SLListNode*)(p))->hd;
  121. }
  122.  
  123. inline <T>& <T>SLList::front()
  124. {
  125.   if (last == 0) error("front: empty list");
  126.   return last->tl->hd;
  127. }
  128.  
  129. inline <T>& <T>SLList::rear()
  130. {
  131.   if (last == 0) error("rear: empty list");
  132.   return last->hd;
  133. }
  134.  
  135. #endif
  136.