/* 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
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();
this->init(item, link);
}
+inline dlist::dlist(void)
+{
+ memset(this, 0, sizeof(dlist));
+}
+
inline bool dlist::empty()
{
return head == NULL;