Planeshift
|
00001 /* xdelta 3 - delta compression tools and library 00002 * Copyright (C) 2002, 2006, 2007. Joshua P. MacDonald 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 #ifndef __XDELTA3_LIST__ 00020 #define __XDELTA3_LIST__ 00021 00022 #define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \ 00023 \ 00024 static inline ETYPE* \ 00025 LTYPE ## _entry (LTYPE* l) \ 00026 { \ 00027 return (ETYPE*) ((char*) l - (ptrdiff_t) &((ETYPE*) 0)->LNAME); \ 00028 } \ 00029 \ 00030 static inline void \ 00031 LTYPE ## _init (LTYPE *l) \ 00032 { \ 00033 l->next = l; \ 00034 l->prev = l; \ 00035 } \ 00036 \ 00037 static inline void \ 00038 LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \ 00039 { \ 00040 next->prev = ins; \ 00041 prev->next = ins; \ 00042 ins->next = next; \ 00043 ins->prev = prev; \ 00044 } \ 00045 \ 00046 static inline void \ 00047 LTYPE ## _push_back (LTYPE *l, ETYPE *i) \ 00048 { \ 00049 LTYPE ## _add (l->prev, l, & i->LNAME); \ 00050 } \ 00051 \ 00052 static inline void \ 00053 LTYPE ## _del (LTYPE *next, \ 00054 LTYPE *prev) \ 00055 { \ 00056 next->prev = prev; \ 00057 prev->next = next; \ 00058 } \ 00059 \ 00060 static inline ETYPE* \ 00061 LTYPE ## _remove (ETYPE *f) \ 00062 { \ 00063 LTYPE *i = f->LNAME.next; \ 00064 LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \ 00065 return LTYPE ## _entry (i); \ 00066 } \ 00067 \ 00068 static inline ETYPE* \ 00069 LTYPE ## _pop_back (LTYPE *l) \ 00070 { \ 00071 LTYPE *i = l->prev; \ 00072 LTYPE ## _del (i->next, i->prev); \ 00073 return LTYPE ## _entry (i); \ 00074 } \ 00075 \ 00076 static inline ETYPE* \ 00077 LTYPE ## _pop_front (LTYPE *l) \ 00078 { \ 00079 LTYPE *i = l->next; \ 00080 LTYPE ## _del (i->next, i->prev); \ 00081 return LTYPE ## _entry (i); \ 00082 } \ 00083 \ 00084 static inline int \ 00085 LTYPE ## _empty (LTYPE *l) \ 00086 { \ 00087 return l == l->next; \ 00088 } \ 00089 \ 00090 static inline ETYPE* \ 00091 LTYPE ## _front (LTYPE *f) \ 00092 { \ 00093 return LTYPE ## _entry (f->next); \ 00094 } \ 00095 \ 00096 static inline ETYPE* \ 00097 LTYPE ## _back (LTYPE *f) \ 00098 { \ 00099 return LTYPE ## _entry (f->prev); \ 00100 } \ 00101 \ 00102 static inline int \ 00103 LTYPE ## _end (LTYPE *f, ETYPE *i) \ 00104 { \ 00105 return f == & i->LNAME; \ 00106 } \ 00107 \ 00108 static inline ETYPE* \ 00109 LTYPE ## _next (ETYPE *f) \ 00110 { \ 00111 return LTYPE ## _entry (f->LNAME.next); \ 00112 } \ 00113 \ 00114 static inline usize_t \ 00115 LTYPE ## _length (LTYPE *l) \ 00116 { \ 00117 LTYPE *p; \ 00118 int c = 0; \ 00119 \ 00120 for (p = l->next; p != l; p = p->next) \ 00121 { \ 00122 c += 1; \ 00123 } \ 00124 \ 00125 return c; \ 00126 } \ 00127 \ 00128 typedef int unused_ ## LTYPE 00129 00130 #endif