// This may look like C code, but it is really -*- C++ -*-
// WARNING: This file is obsolete.  Use ../DLList.h, if you can.
/* 
Copyright (C) 1988 Free Software Foundation
    written by Doug Lea (dl@rocky.oswego.edu)

This file is part of the GNU C++ Library.  This library is free
software; you can redistribute it and/or modify it under the terms of
the GNU Library General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.  This library is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#ifndef _<T>DLList_h
#ifdef __GNUG__
#pragma interface
#endif
#define _<T>DLList_h 1

#include <Pix.h>
#include "<T>.defs.h"

#ifndef _<T>DLListNode_h
#define _<T>DLListNode_h 1

struct <T>DLListNode
{
  <T>DLListNode*         bk;
  <T>DLListNode*         fd;
  <T>                    hd;
                         <T>DLListNode();
                         <T>DLListNode(const <T&> h, 
                                       <T>DLListNode* p = 0,
                                       <T>DLListNode* n = 0);
                         ~<T>DLListNode();
};

inline <T>DLListNode::<T>DLListNode() {}

inline <T>DLListNode::<T>DLListNode(const <T&> h, <T>DLListNode* p,
                                    <T>DLListNode* n)
  :hd(h), bk(p), fd(n) {}

inline <T>DLListNode::~<T>DLListNode() {}

typedef <T>DLListNode* <T>DLListNodePtr;

#endif

class <T>DLList
{
  friend class          <T>DLListTrav;

  <T>DLListNode*        h;

public:
                        <T>DLList();
                        <T>DLList(const <T>DLList& a);
                        ~<T>DLList();

  <T>DLList&            operator = (const <T>DLList& a);

  int                   empty();
  int                   length();

  void                  clear();

  Pix                   prepend(<T&> item);
  Pix                   append(<T&> item);
  void                  join(<T>DLList&);

  <T>&                  front();
  <T>                   remove_front();
  void                  del_front();

  <T>&                  rear();
  <T>                   remove_rear();
  void                  del_rear();

  <T>&                  operator () (Pix p);
  Pix                   first();
  Pix                   last();
  void                  next(Pix& p);
  void                  prev(Pix& p);
  int                   owns(Pix p);
  Pix                   ins_after(Pix p, <T&> item);
  Pix                   ins_before(Pix p, <T&> item);
  void                  del(Pix& p, int dir = 1);
  void                  del_after(Pix& p);

  void                  error(const char* msg);
  int                   OK();
};


inline <T>DLList::~<T>DLList()
{
  clear();
}

inline <T>DLList::<T>DLList()
{
  h = 0;
}

inline int <T>DLList::empty()
{
  return h == 0;
}


inline void <T>DLList::next(Pix& p)
{
  p = (p == 0 || p == h->bk)? 0 : Pix(((<T>DLListNode*)p)->fd);
}

inline void <T>DLList::prev(Pix& p)
{
  p = (p == 0 || p == h)? 0 : Pix(((<T>DLListNode*)p)->bk);
}

inline Pix <T>DLList::first()
{
  return Pix(h);
}

inline Pix <T>DLList::last()
{
  return (h == 0)? 0 : Pix(h->bk);
}

inline <T>& <T>DLList::operator () (Pix p)
{
  if (p == 0) error("null Pix");
  return ((<T>DLListNode*)p)->hd;
}

inline <T>& <T>DLList::front()
{
  if (h == 0) error("front: empty list");
  return h->hd;
}

inline <T>& <T>DLList::rear()
{
  if (h == 0) error("rear: empty list");
  return h->bk->hd;
}

#endif
