Subversion Repositories Scribus

Rev

Rev 14952 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14952 fschmid 1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2009 Chris Wilson
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it either under the terms of the GNU Lesser General Public
7
 * License version 2.1 as published by the Free Software Foundation
8
 * (the "LGPL") or, at your option, under the terms of the Mozilla
9
 * Public License Version 1.1 (the "MPL"). If you do not alter this
10
 * notice, a recipient may use your version of this file under either
11
 * the MPL or the LGPL.
12
 *
13
 * You should have received a copy of the LGPL along with this library
14
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18122 mrdocs 15
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14952 fschmid 16
 * You should have received a copy of the MPL along with this library
17
 * in the file COPYING-MPL-1.1
18
 *
19
 * The contents of this file are subject to the Mozilla Public License
20
 * Version 1.1 (the "License"); you may not use this file except in
21
 * compliance with the License. You may obtain a copy of the License at
22
 * http://www.mozilla.org/MPL/
23
 *
24
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26
 * the specific language governing rights and limitations.
27
 *
28
 * The Original Code is the cairo graphics library.
29
 *
30
 * The Initial Developer of the Original Code is Chris Wilson.
31
 *
32
 * Contributor(s):
33
 *      Chris Wilson <chris@chris-wilson.co.uk>
34
 *
35
 */
36
 
37
#ifndef CAIRO_LIST_PRIVATE_H
38
#define CAIRO_LIST_PRIVATE_H
39
 
40
#include "cairo-compiler-private.h"
41
 
42
/* Basic circular, doubly linked list implementation */
43
 
44
typedef struct _cairo_list {
45
    struct _cairo_list *next, *prev;
46
} cairo_list_t;
47
 
48
#define cairo_list_entry(ptr, type, member) \
49
        cairo_container_of(ptr, type, member)
50
 
51
#define cairo_list_first_entry(ptr, type, member) \
52
        cairo_list_entry((ptr)->next, type, member)
53
 
54
#define cairo_list_last_entry(ptr, type, member) \
55
        cairo_list_entry((ptr)->prev, type, member)
56
 
57
#define cairo_list_foreach(pos, head)                   \
58
        for (pos = (head)->next; pos != (head); pos = pos->next)
59
 
60
#define cairo_list_foreach_entry(pos, type, head, member)               \
61
        for (pos = cairo_list_entry((head)->next, type, member);\
62
             &pos->member != (head);                                    \
63
             pos = cairo_list_entry(pos->member.next, type, member))
64
 
65
#define cairo_list_foreach_entry_safe(pos, n, type, head, member)       \
66
        for (pos = cairo_list_entry ((head)->next, type, member),\
67
             n = cairo_list_entry (pos->member.next, type, member);\
68
             &pos->member != (head);                                    \
69
             pos = n, n = cairo_list_entry (n->member.next, type, member))
70
 
71
#define cairo_list_foreach_entry_reverse(pos, type, head, member)       \
72
        for (pos = cairo_list_entry((head)->prev, type, member);\
73
             &pos->member != (head);                                    \
74
             pos = cairo_list_entry(pos->member.prev, type, member))
75
 
76
#ifdef CAIRO_LIST_DEBUG
77
static inline void
78
cairo_list_validate (const cairo_list_t *head)
79
{
80
    cairo_list_t *link;
81
 
82
    cairo_list_foreach (link, head) {
83
        assert (link->next->prev == link);
84
        assert (link->prev->next == link);
85
    }
86
}
87
#else
88
#define cairo_list_validate(head)
89
#endif
90
 
91
static inline void
92
cairo_list_init (cairo_list_t *entry)
93
{
94
    entry->next = entry;
95
    entry->prev = entry;
96
}
97
 
98
static inline void
99
__cairo_list_add (cairo_list_t *entry,
100
                  cairo_list_t *prev,
101
                  cairo_list_t *next)
102
{
103
    next->prev = entry;
104
    entry->next = next;
105
    entry->prev = prev;
106
    prev->next = entry;
107
}
108
 
109
static inline void
110
cairo_list_add (cairo_list_t *entry, cairo_list_t *head)
111
{
112
    cairo_list_validate (head);
113
    __cairo_list_add (entry, head, head->next);
114
    cairo_list_validate (head);
115
}
116
 
117
static inline void
118
cairo_list_add_tail (cairo_list_t *entry, cairo_list_t *head)
119
{
120
    cairo_list_validate (head);
121
    __cairo_list_add (entry, head->prev, head);
122
    cairo_list_validate (head);
123
}
124
 
125
static inline void
126
__cairo_list_del (cairo_list_t *prev, cairo_list_t *next)
127
{
128
    next->prev = prev;
129
    prev->next = next;
130
}
131
 
132
static inline void
133
cairo_list_del (cairo_list_t *entry)
134
{
135
    __cairo_list_del (entry->prev, entry->next);
136
    cairo_list_init (entry);
137
}
138
 
139
static inline void
140
cairo_list_move (cairo_list_t *entry, cairo_list_t *head)
141
{
142
    cairo_list_validate (head);
143
    __cairo_list_del (entry->prev, entry->next);
144
    __cairo_list_add (entry, head, head->next);
145
    cairo_list_validate (head);
146
}
147
 
148
static inline void
149
cairo_list_move_tail (cairo_list_t *entry, cairo_list_t *head)
150
{
151
    cairo_list_validate (head);
152
    __cairo_list_del (entry->prev, entry->next);
153
    __cairo_list_add (entry, head->prev, head);
154
    cairo_list_validate (head);
155
}
156
 
157
static inline void
158
cairo_list_swap (cairo_list_t *entry, cairo_list_t *other)
159
{
160
    cairo_list_validate (head);
161
    __cairo_list_add (entry, other->prev, other->next);
162
    cairo_list_init (other);
163
    cairo_list_validate (head);
164
}
165
 
166
static inline cairo_bool_t
167
cairo_list_is_first (const cairo_list_t *entry,
168
                     const cairo_list_t *head)
169
{
170
    cairo_list_validate (head);
171
    return entry->prev == head;
172
}
173
 
174
static inline cairo_bool_t
175
cairo_list_is_last (const cairo_list_t *entry,
176
                    const cairo_list_t *head)
177
{
178
    cairo_list_validate (head);
179
    return entry->next == head;
180
}
181
 
182
static inline cairo_bool_t
183
cairo_list_is_empty (const cairo_list_t *head)
184
{
185
    cairo_list_validate (head);
186
    return head->next == head;
187
}
188
 
189
#endif /* CAIRO_LIST_PRIVATE_H */