00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MLIST_H
00021 #define MLIST_H
00022
00023 #include <assert.h>
00024
00025 template <typename T>
00026 struct mlist_elem {
00027 T *prev;
00028 T *next;
00029
00030 mlist_elem() : prev(0), next(0) {}
00031 };
00032
00033 #define MLIST_RM(root, p, m) mlist_rm(((p)->m.prev ? &(p)->m.prev->m : 0), \
00034 &(p)->m, \
00035 ((p)->m.next ? &(p)->m.next->m : 0), \
00036 p,\
00037 root)
00038 #define MLIST_INSERT(root, p, m) \
00039 { \
00040 if (root) root->m.prev = p; \
00041 p->m.next = root; \
00042 root = p; \
00043 }
00044
00045 template<typename T>
00046 void mlist_rm(mlist_elem<T> *prev, mlist_elem<T> *e, mlist_elem<T> *next, const T *p, T **root_ptr)
00047 {
00048 if (prev==0 && root_ptr) {
00049 assert(p==*root_ptr);
00050 }
00051 if (root_ptr && (p == *root_ptr)) *root_ptr = e->next;
00052 if (prev) prev->next = e->next;
00053 if (next) next->prev = e->prev;
00054 e->next = e->prev = 0;
00055 }
00056
00057 template<typename T>
00058 void mlist_rm(mlist_elem<T> *prev, mlist_elem<T> *e, mlist_elem<T> *next, const T *p, int )
00059 {
00060 mlist_rm<T>(prev,e,next,p,(T **) 0);
00061 }
00062
00063 #define RLIST_RM(root, p, m) rlist_rm(((p)->m.prev ? &(p)->m.prev->m : 0), \
00064 &(p)->m, \
00065 ((p)->m.next ? &(p)->m.next->m : 0), \
00066 p,\
00067 root)
00068 #define RLIST_INSERT(root, p, m) \
00069 { \
00070 if (root) root->m.next = p; \
00071 p->m.prev = root; \
00072 root = p; \
00073 }
00074
00075 template<typename T>
00076 void rlist_rm(mlist_elem<T> *prev, mlist_elem<T> *e, mlist_elem<T> *next, const T *p, T **root_ptr)
00077 {
00078 if (next==0 && root_ptr) {
00079 assert(p==*root_ptr);
00080 }
00081 if (root_ptr && (p == *root_ptr)) *root_ptr = e->prev;
00082 if (prev) prev->next = e->next;
00083 if (next) next->prev = e->prev;
00084 e->next = e->prev = 0;
00085 }
00086
00087 template<typename T>
00088 void rlist_rm(mlist_elem<T> *prev, mlist_elem<T> *e, mlist_elem<T> *next, const T *p, int )
00089 {
00090 rlist_rm<T>(prev,e,next,p,(T **) 0);
00091 }
00092
00093
00094 #endif