]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/dlist.h
Pool + label cleanups from bug reports
[bacula/bacula] / bacula / src / lib / dlist.h
index e607b776cb115f780f5034d0cc25254e76f025db..49403d966ca8dcddea7e9b5f1ecc8944c9dfe1d0 100644 (file)
 
 /* In case you want to specifically specify the offset to the link */
 #define OFFSET(item, link) ((char *)(link) - (char *)(item))
-#ifdef HAVE_WIN32
-/* Extra ***& workaround for VisualC Studio */
-#define foreach_dlist(var, list) \
-    for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); )
-#else
-/*
+/* 
+ * 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
  */
+#define foreach_dlist(var, list) \
+    for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); )
+
+#ifdef the_old_way
 #define foreach_dlist(var, list) \
         for((var)=NULL; (((void *)(var))=(list)->next(var)); )
 #endif
@@ -51,15 +54,19 @@ struct dlink {
 class dlist {
    void *head;
    void *tail;
-   int loffset;
-   int num_items;
+   uint16_t loffset;
+   uint32_t num_items;
 public:
    dlist(void *item, void *link);
+   dlist(void);
+   ~dlist() { destroy(); }
    void init(void *item, void *link);
    void prepend(void *item);
    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 remove(void *item);
    bool empty();
    int  size();
@@ -90,6 +97,11 @@ inline dlist::dlist(void *item, void *link)
    this->init(item, link);
 }
 
+inline dlist::dlist(void)
+{
+   memset(this, 0, sizeof(dlist));
+}
+
 inline bool dlist::empty()
 {
    return head == NULL;