home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / CFGED1B.ZIP / CFGEDSRC.ZIP / STRDLL.H < prev   
C/C++ Source or Header  |  1992-07-18  |  4KB  |  157 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 _StrDLList_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _StrDLList_h 1
  25.  
  26. #include <Pix.h>
  27. #include "Strdefs.h"
  28.  
  29. #ifndef _StrDLListNode_h
  30. #define _StrDLListNode_h 1
  31.  
  32. struct StrDLListNode
  33. {
  34.   StrDLListNode*         bk;
  35.   StrDLListNode*         fd;
  36.   Str                    hd;
  37.                          StrDLListNode();
  38.                          StrDLListNode(Str& h, 
  39.                                        StrDLListNode* p = 0,
  40.                                        StrDLListNode* n = 0);
  41.                          ~StrDLListNode();
  42. };
  43.  
  44. inline StrDLListNode::StrDLListNode() {}
  45.  
  46. inline StrDLListNode::StrDLListNode(Str& h, StrDLListNode* p,
  47.                                     StrDLListNode* n)
  48.   :hd(h), bk(p), fd(n) {}
  49.  
  50. inline StrDLListNode::~StrDLListNode() {}
  51.  
  52. typedef StrDLListNode* StrDLListNodePtr;
  53.  
  54. #endif
  55.  
  56. class StrDLList
  57. {
  58.   friend class          StrDLListTrav;
  59.  
  60.   StrDLListNode*        h;
  61.  
  62. public:
  63.                         StrDLList();
  64.                         StrDLList(StrDLList& a);
  65.                         ~StrDLList();
  66.  
  67.   StrDLList&            operator = (StrDLList& a);
  68.  
  69.   int                   empty();
  70.   int                   length();
  71.  
  72.   void                  clear();
  73.  
  74.   Pix                   prepend(Str& item);
  75.   Pix                   append(Str& item);
  76.   void                  join(StrDLList&);
  77.  
  78.   Str&                  front();
  79.   Str                   remove_front();
  80.   void                  del_front();
  81.  
  82.   Str&                  rear();
  83.   Str                   remove_rear();
  84.   void                  del_rear();
  85.  
  86.   Str&                  operator () (Pix p);
  87.   Pix                   first();
  88.   Pix                   last();
  89.   void                  next(Pix& p);
  90.   void                  prev(Pix& p);
  91.   int                   owns(Pix p);
  92.   Pix                   ins_after(Pix p, Str& item);
  93.   Pix                   ins_before(Pix p, Str& item);
  94.   void                  del(Pix& p, int dir = 1);
  95.   void                  del_after(Pix& p);
  96.  
  97.   void                  error(const char* msg);
  98.   int                   OK();
  99. };
  100.  
  101.  
  102. inline StrDLList::~StrDLList()
  103. {
  104.   clear();
  105. }
  106.  
  107. inline StrDLList::StrDLList()
  108. {
  109.   h = 0;
  110. }
  111.  
  112. inline int StrDLList::empty()
  113. {
  114.   return h == 0;
  115. }
  116.  
  117.  
  118. inline void StrDLList::next(Pix& p)
  119. {
  120.   p = (p == 0 || p == h->bk)? 0 : Pix(((StrDLListNode*)p)->fd);
  121. }
  122.  
  123. inline void StrDLList::prev(Pix& p)
  124. {
  125.   p = (p == 0 || p == h)? 0 : Pix(((StrDLListNode*)p)->bk);
  126. }
  127.  
  128. inline Pix StrDLList::first()
  129. {
  130.   return Pix(h);
  131. }
  132.  
  133. inline Pix StrDLList::last()
  134. {
  135.   return (h == 0)? 0 : Pix(h->bk);
  136. }
  137.  
  138. inline Str& StrDLList::operator () (Pix p)
  139. {
  140.   if (p == 0) error("null Pix");
  141.   return ((StrDLListNode*)p)->hd;
  142. }
  143.  
  144. inline Str& StrDLList::front()
  145. {
  146.   if (h == 0) error("front: empty list");
  147.   return h->hd;
  148. }
  149.  
  150. inline Str& StrDLList::rear()
  151. {
  152.   if (h == 0) error("rear: empty list");
  153.   return h->bk->hd;
  154. }
  155.  
  156. #endif
  157.