6 Copyright (C) 2000-2003 Kern Sibbald and John Walker
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public
19 License along with this program; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 /* ========================================================================
27 * Doubly linked list -- dlist
31 /* In case you want to specifically specify the offset to the link */
32 #define OFFSET(item, link) ((char *)(link) - (char *)(item))
34 * There is a lot of extra casting here to work around the fact
35 * that some compilers (Sun and Visual C++) do not accept
36 * (void *) as an lvalue on the left side of an equal.
38 * Loop var through each member of list
40 #define foreach_dlist(var, list) \
41 for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); )
44 #define foreach_dlist(var, list) \
45 for((var)=NULL; (((void *)(var))=(list)->next(var)); )
60 dlist(void *item, void *link);
61 void init(void *item, void *link);
62 void prepend(void *item);
63 void append(void *item);
64 void insert_before(void *item, void *where);
65 void insert_after(void *item, void *where);
66 void *dlist::binary_insert(void *item, int compare(void *item1, void *item2));
67 void remove(void *item);
70 void *next(void *item);
71 void *prev(void *item);
75 void * operator new(size_t);
76 void operator delete(void *);
80 * This allows us to do explicit initialization,
81 * allowing us to mix C++ classes inside malloc'ed
82 * C structures. Define before called in constructor.
84 inline void dlist::init(void *item, void *link)
87 loffset = (char *)link - (char *)item;
92 inline dlist::dlist(void *item, void *link)
94 this->init(item, link);
97 inline bool dlist::empty()
102 inline int dlist::size()
108 inline void * dlist::operator new(size_t)
110 return malloc(sizeof(dlist));
113 inline void dlist::operator delete(void *item)
115 ((dlist *)item)->destroy();
120 inline void * dlist::first()
125 inline void * dlist::last()