WvStreams
wvlink.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * WvLink is one element of a linked list.
00006  * Used by wvlinklist.h.
00007  */
00008 #ifndef __WVLINK_H
00009 #define __WVLINK_H
00010 
00011 #include <stdlib.h>  // for 'NULL'
00012 
00023 class WvLink
00024 {
00025 public:
00026     void *data;
00027     WvLink *next;
00028     const char *id;
00029 
00030 private:
00031     bool autofree : 1;
00032 
00033 public:
00034     WvLink(void *_data, bool _autofree, const char *_id = NULL):
00035         data(_data), next(NULL), id(_id), autofree(_autofree)
00036     {}
00037 
00038     WvLink(void *_data, WvLink *prev, WvLink *&tail, bool _autofree,
00039            const char *_id = NULL);
00040 
00041     bool get_autofree()
00042     {
00043         return autofree;
00044     }
00045 
00046     void set_autofree(bool _autofree)
00047     {
00048         autofree = _autofree;
00049     }
00050 
00051     void unlink(WvLink *prev)
00052     {
00053         prev->next = next;
00054         delete this;
00055     }
00056 };
00057 
00058 #define WvIterStuff(_type_) \
00059  \
00060     _type_ &operator () () const \
00061         { return *ptr(); } \
00062  \
00063     _type_ *operator -> () const \
00064         { return ptr(); } \
00065  \
00066     _type_ &operator* () const \
00067         { return *ptr(); }
00068 
00069 #endif // __WVLINK_H