// This may look like C code, but it is really -*- C++ -*- /* Copyright (C) 1988 Free Software Foundation written by Doug Lea (dl@rocky.oswego.edu) This file is part of GNU CC. GNU CC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the GNU CC General Public License for full details. Everyone is granted permission to copy, modify and redistribute GNU CC, but only under the conditions described in the GNU CC General Public License. A copy of this license is supposed to have been given to you along with GNU CC so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. */ #ifndef _DLList_h #pragma once #define _DLList_h 1 #include #include ".defs.h" #ifndef _DLListNode_h #define _DLListNode_h 1 struct DLListNode { DLListNode* bk; DLListNode* fd; hd; DLListNode(); DLListNode( h, DLListNode* p = 0, DLListNode* n = 0); ~DLListNode(); }; inline DLListNode::DLListNode() {} inline DLListNode::DLListNode( h, DLListNode* p = 0, DLListNode* n = 0) { hd = h; bk = p; fd = n; } inline DLListNode::~DLListNode() {} typedef DLListNode* DLListNodePtr; #endif class DLList { friend class DLListTrav; DLListNode* h; public: DLList(); DLList(DLList& a); ~DLList(); DLList& operator = (DLList& a); int empty(); int length(); void clear(); Pix prepend( item); Pix append( item); void join(DLList&); & front(); remove_front(); void del_front(); & rear(); remove_rear(); void del_rear(); & operator () (Pix p); Pix first(); Pix last(); void next(Pix& p); void prev(Pix& p); int owns(Pix p); Pix ins_after(Pix p, item); Pix ins_before(Pix p, item); void del(Pix& p, int dir = 1); void error(const char* msg); int OK(); }; inline DLList::~DLList() { clear(); } inline DLList::DLList() { h = 0; } inline int DLList::empty() { return h == 0; } inline int DLList::length() { int l = 0; DLListNode* t = h; if (t != 0) do { ++l; t = t->fd; } while (t != h); return l; } inline void DLList::next(Pix& p) { p = (p == 0 || p == h->bk)? 0 : Pix(((DLListNode*)p)->fd); } inline void DLList::prev(Pix& p) { p = (p == 0 || p == h)? 0 : Pix(((DLListNode*)p)->bk); } inline Pix DLList::first() { return Pix(h); } inline Pix DLList::last() { return (h == 0)? 0 : Pix(h->bk); } inline & DLList::operator () (Pix p) { if (p == 0) error("null Pix"); return ((DLListNode*)p)->hd; } inline & DLList::front() { if (h == 0) error("front: empty list"); return h->hd; } inline & DLList::rear() { if (h == 0) error("rear: empty list"); return h->bk->hd; } #endif