X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Flib%2Fdlist.h;h=32933ad608518254b7205dc94949e0dc3736be86;hb=3f8a3a045ea058657030f588a10f786449d00e0d;hp=90200f541342865f46ef609f01c10b76bb506859;hpb=4c9d5e05d85b2567788335730f326f9081df87cd;p=bacula%2Fbacula diff --git a/bacula/src/lib/dlist.h b/bacula/src/lib/dlist.h index 90200f5413..32933ad608 100644 --- a/bacula/src/lib/dlist.h +++ b/bacula/src/lib/dlist.h @@ -1,61 +1,57 @@ /* * Version $Id$ */ - /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2004-2005 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. This program 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 - General Public License for more details. - - You should have received a copy of the GNU General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ + /* ======================================================================== - * + * * Doubly linked list -- dlist * + * Kern Sibbald, MMIV + * */ #define M_ABORT 1 -#undef New -#define New(type) new type /* In case you want to specifically specify the offset to the link */ -#define OFFSET(item, link) ((char *)(link) - (char *)(item)) -/* +#define OFFSET(item, link) (int)((char *)(link) - (char *)(item)) +/* * There is a lot of extra casting here to work around the fact * that some compilers (Sun and Visual C++) do not accept * (void *) as an lvalue on the left side of an equal. * * Loop var through each member of list */ +#ifdef HAVE_GCC #define foreach_dlist(var, list) \ - for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); ) - -#ifdef the_old_way + for((var)=NULL; ((var)=(typeof(var))(list)->next(var)); ) +#else #define foreach_dlist(var, list) \ - for((var)=NULL; (((void *)(var))=(list)->next(var)); ) + for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); ) #endif + struct dlink { void *next; void *prev; }; -class dlist { +class dlist : public SMARTALLOC { void *head; void *tail; int16_t loffset; @@ -69,8 +65,9 @@ public: void append(void *item); void insert_before(void *item, void *where); void insert_after(void *item, void *where); - void *unique_binary_insert(void *item, int compare(void *item1, void *item2)); - void binary_insert(void *item, int compare(void *item1, void *item2)); + void *binary_insert(void *item, int compare(void *item1, void *item2)); + void *binary_search(void *item, int compare(void *item1, void *item2)); + void binary_insert_multiple(void *item, int compare(void *item1, void *item2)); void remove(void *item); bool empty() const; int size() const; @@ -79,35 +76,30 @@ public: void destroy(); void *first() const; void *last() const; - void * operator new(size_t); - void operator delete(void *); }; -dlist *new_dlist(); -dlist *new_dlist(void *item, dlink *link); - -/* +/* * This allows us to do explicit initialization, * allowing us to mix C++ classes inside malloc'ed * C structures. Define before called in constructor. */ -inline void dlist::init(void *item, dlink *link) +inline void dlist::init(void *item, dlink *link) { head = tail = NULL; - loffset = (char *)link - (char *)item; + loffset = (int)((char *)link - (char *)item); if (loffset < 0 || loffset > 5000) { Emsg0(M_ABORT, 0, "Improper dlist initialization.\n"); } num_items = 0; } -/* - * Constructor called with the address of a +/* + * Constructor called with the address of a * member of the list (not the list head), and * the address of the link within that member. * If the link is at the beginning of the list member, - * then there is no need to specify the link address + * then there is no need to specify the link address * since the offset is zero. */ inline dlist::dlist(void *item, dlink *link) @@ -130,18 +122,7 @@ inline int dlist::size() const return num_items; } - -inline void * dlist::operator new(size_t) -{ - return malloc(sizeof(dlist)); -} -inline void dlist::operator delete(void *item) -{ - ((dlist *)item)->destroy(); - free(item); -} - inline void * dlist::first() const {