source: nikanabo/current/xdelta/diy/xdelta3-list.h@ 407

Last change on this file since 407 was 185, checked in by geyser, 18 years ago
File size: 10.4 KB
RevLine 
[185]1/* xdelta 3 - delta compression tools and library
2 * Copyright (C) 2002, 2006, 2007. Joshua P. MacDonald
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#ifndef __XDELTA3_LIST__
20#define __XDELTA3_LIST__
21
22#define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \
23 \
24static inline ETYPE* \
25LTYPE ## _entry (LTYPE* l) \
26{ \
27 return (ETYPE*) ((char*) l - (unsigned long) &((ETYPE*) 0)->LNAME); \
28} \
29 \
30static inline void \
31LTYPE ## _init (LTYPE *l) \
32{ \
33 l->next = l; \
34 l->prev = l; \
35} \
36 \
37static inline void \
38LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \
39{ \
40 next->prev = ins; \
41 prev->next = ins; \
42 ins->next = next; \
43 ins->prev = prev; \
44} \
45 \
46static inline void \
47LTYPE ## _push_back (LTYPE *l, ETYPE *i) \
48{ \
49 LTYPE ## _add (l->prev, l, & i->LNAME); \
50} \
51 \
52static inline void \
53LTYPE ## _del (LTYPE *next, \
54 LTYPE *prev) \
55{ \
56 next->prev = prev; \
57 prev->next = next; \
58} \
59 \
60static inline ETYPE* \
61LTYPE ## _remove (ETYPE *f) \
62{ \
63 LTYPE *i = f->LNAME.next; \
64 LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \
65 return LTYPE ## _entry (i); \
66} \
67 \
68static inline ETYPE* \
69LTYPE ## _pop_back (LTYPE *l) \
70{ \
71 LTYPE *i = l->prev; \
72 LTYPE ## _del (i->next, i->prev); \
73 return LTYPE ## _entry (i); \
74} \
75 \
76static inline ETYPE* \
77LTYPE ## _pop_front (LTYPE *l) \
78{ \
79 LTYPE *i = l->next; \
80 LTYPE ## _del (i->next, i->prev); \
81 return LTYPE ## _entry (i); \
82} \
83 \
84static inline int \
85LTYPE ## _empty (LTYPE *l) \
86{ \
87 return l == l->next; \
88} \
89 \
90static inline ETYPE* \
91LTYPE ## _front (LTYPE *f) \
92{ \
93 return LTYPE ## _entry (f->next); \
94} \
95 \
96static inline ETYPE* \
97LTYPE ## _back (LTYPE *f) \
98{ \
99 return LTYPE ## _entry (f->prev); \
100} \
101 \
102static inline int \
103LTYPE ## _end (LTYPE *f, ETYPE *i) \
104{ \
105 return f == & i->LNAME; \
106} \
107 \
108static inline ETYPE* \
109LTYPE ## _next (ETYPE *f) \
110{ \
111 return LTYPE ## _entry (f->LNAME.next); \
112} \
113 \
114static inline int \
115LTYPE ## _length (LTYPE *l) \
116{ \
117 LTYPE *p; \
118 int c = 0; \
119 \
120 for (p = l->next; p != l; p = p->next) \
121 { \
122 c += 1; \
123 } \
124 \
125 return c; \
126} \
127 \
128typedef int unused_ ## LTYPE
129
130#endif
Note: See TracBrowser for help on using the repository browser.