home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / libg++-2.5.3-bin.lha / lib / g++-include / gen / DLList.hP < prev    next >
Text File  |  1994-02-21  |  4KB  |  158 lines

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