137#define BU_LIST_NULL ((struct bu_list *)0)
142#define BU_LIST_MAGIC_SET(_l, _magic) {(_l)->magic = (_magic);}
148#define BU_LIST_MAGIC_EQUAL(_l, _magic) ((_l)->magic == (_magic))
155#define BU_CK_LIST_HEAD(_p) BU_CKMAG((_p), BU_LIST_HEAD_MAGIC, "bu_list")
161#define BU_LIST_INIT(_headp) { \
162 BU_ASSERT((void *)(_headp) != (void *)NULL); \
163 (_headp)->forw = (_headp)->back = (_headp); \
164 (_headp)->magic = BU_LIST_HEAD_MAGIC; }
170#define BU_LIST_INIT_MAGIC(_headp, _magic) { \
171 BU_LIST_INIT((_headp)); \
172 BU_LIST_MAGIC_SET((_headp), (_magic)); \
181#define BU_LIST_INIT_ZERO { 0, BU_LIST_NULL, BU_LIST_NULL }
189#define BU_LIST_IS_INITIALIZED(_headp) (((struct bu_list *)(_headp) != BU_LIST_NULL) && LIKELY((_headp)->forw != BU_LIST_NULL))
197#define BU_LIST_INSERT(old, new) { \
198 BU_ASSERT((void *)(old) != (void *)NULL); \
199 BU_ASSERT((void *)(new) != (void *)NULL); \
200 (new)->back = (old)->back; \
201 (old)->back = (new); \
202 (new)->forw = (old); \
203 BU_ASSERT((void *)((new)->back) != (void *)NULL); \
204 (new)->back->forw = (new); }
211#define BU_LIST_APPEND(old, new) { \
212 BU_ASSERT((void *)(old) != (void *)NULL); \
213 BU_ASSERT((void *)(new) != (void *)NULL); \
214 (new)->forw = (old)->forw; \
215 (new)->back = (old); \
216 (old)->forw = (new); \
217 BU_ASSERT((void *)((new)->forw) != (void *)NULL); \
218 (new)->forw->back = (new); }
223#define BU_LIST_DEQUEUE(cur) { \
224 BU_ASSERT((void *)(cur) != (void *)NULL); \
225 if (LIKELY((cur)->forw != NULL)) (cur)->forw->back = (cur)->back; \
226 if (LIKELY((cur)->back != NULL)) (cur)->back->forw = (cur)->forw; \
227 (cur)->forw = (cur)->back = BU_LIST_NULL; }
232#define BU_LIST_DQ(cur) {\
233 BU_ASSERT((void *)(cur) != (void *)NULL); \
234 if (LIKELY((cur)->forw != NULL)) (cur)->forw->back = (cur)->back; \
235 if (LIKELY((cur)->back != NULL)) (cur)->back->forw = (cur)->forw; }
237#define BU_LIST_DQ_T(cur, type) (\
238 (cur)->forw->back = (cur)->back, \
239 (cur)->back->forw = (cur)->forw, \
246#define BU_LIST_DEQUEUE_T(cur, type) (\
247 (cur)->forw->back = (cur)->back, \
248 (cur)->back->forw = (cur)->forw, \
249 (cur)->forw = (cur)->back = BU_LIST_NULL, \
260#define BU_LIST_PUSH(headp, p) \
261 BU_LIST_APPEND(headp, (struct bu_list *)(p))
263#define BU_LIST_POP(structure, headp, p) \
265 if (BU_LIST_NON_EMPTY(headp)) { \
266 (p) = ((struct structure *)((headp)->forw)); \
267 BU_LIST_DEQUEUE((struct bu_list *)(p)); \
269 (p) = (struct structure *) 0; \
273#define BU_LIST_POP_T(headp, type) \
274 (type *)bu_list_pop(headp)
284#define BU_LIST_INSERT_LIST(dest_headp, src_headp) \
285 if (LIKELY(BU_LIST_NON_EMPTY(src_headp))) { \
286 struct bu_list *_first = (src_headp)->forw; \
287 struct bu_list *_last = (src_headp)->back; \
288 (dest_headp)->forw->back = _last; \
289 _last->forw = (dest_headp)->forw; \
290 (dest_headp)->forw = _first; \
291 _first->back = (dest_headp); \
292 (src_headp)->forw = (src_headp)->back = (src_headp); \
295#define BU_LIST_APPEND_LIST(dest_headp, src_headp) \
296 if (LIKELY(BU_LIST_NON_EMPTY(src_headp))) {\
297 struct bu_list *_first = (src_headp)->forw; \
298 struct bu_list *_last = (src_headp)->back; \
299 _first->back = (dest_headp)->back; \
300 (dest_headp)->back->forw = _first; \
301 (dest_headp)->back = _last; \
302 _last->forw = (dest_headp); \
303 (src_headp)->forw = (src_headp)->back = (src_headp); \
309#define BU_LIST_IS_EMPTY(headp) ((headp)->forw == (headp))
310#define BU_LIST_NON_EMPTY(headp) ((headp)->forw != (headp))
311#define BU_LIST_NON_EMPTY_P(p, structure, headp) \
312 (((p)=(struct structure *)((headp)->forw)) != (struct structure *)(headp))
313#define BU_LIST_IS_CLEAR(headp) ((headp)->magic == 0 && \
314 (headp)->forw == BU_LIST_NULL && \
315 (headp)->back == BU_LIST_NULL)
320#define BU_LIST_LAST(structure, headp) \
321 ((struct structure *)((headp)->back))
322#define BU_LIST_BACK(structure, headp) \
323 ((struct structure *)((headp)->back))
324#define BU_LIST_PREV(structure, headp) \
325 ((struct structure *)((headp)->back))
326#define BU_LIST_FIRST(structure, headp) \
327 ((struct structure *)((headp)->forw))
328#define BU_LIST_FORW(structure, headp) \
329 ((struct structure *)((headp)->forw))
330#define BU_LIST_NEXT(structure, headp) \
331 ((struct structure *)((headp)->forw))
336#define BU_LIST_IS_HEAD(p, headp) \
337 (((struct bu_list *)(p)) == (struct bu_list *)(headp))
338#define BU_LIST_NOT_HEAD(p, headp) \
339 (!BU_LIST_IS_HEAD(p, headp))
344#define BU_LIST_PREV_IS_HEAD(p, headp)\
345 (((struct bu_list *)(p))->back == (struct bu_list *)(headp))
346#define BU_LIST_PREV_NOT_HEAD(p, headp)\
347 (!BU_LIST_PREV_IS_HEAD(p, headp))
352#define BU_LIST_NEXT_IS_HEAD(p, headp) \
353 (((struct bu_list *)(p))->forw == (struct bu_list *)(headp))
354#define BU_LIST_NEXT_NOT_HEAD(p, headp) \
355 (!BU_LIST_NEXT_IS_HEAD(p, headp))
357#define BU_LIST_EACH(headp, p, type) \
358 for ((p)=(type *)BU_LIST_FIRST(bu_list, headp); \
359 (p) && BU_LIST_NOT_HEAD(p, headp); \
360 (p)=(type *)BU_LIST_PNEXT(bu_list, p)) \
362#define BU_LIST_REVEACH(headp, p, type) \
363 for ((p)=(type *)BU_LIST_LAST(bu_list, headp); \
364 (p) && BU_LIST_NOT_HEAD(p, headp); \
365 (p)=(type *)BU_LIST_PREV(bu_list, ((struct bu_list *)(p)))) \
367#define BU_LIST_TAIL(headp, start, p, type) \
368 for ((p)=(type *)start; \
369 (p) && BU_LIST_NOT_HEAD(p, headp); \
370 (p)=(type *)BU_LIST_PNEXT(bu_list, (p)))
379#define BU_LIST_FOR(p, structure, headp) \
380 (p)=BU_LIST_FIRST(structure, headp); \
381 (p) && BU_LIST_NOT_HEAD(p, headp); \
382 (p)=BU_LIST_PNEXT(structure, p)
384#define BU_LIST_FOR_BACKWARDS(p, structure, headp) \
385 (p)=BU_LIST_LAST(structure, headp); \
386 (p) && BU_LIST_NOT_HEAD(p, headp); \
387 (p)=BU_LIST_PLAST(structure, p)
393#define BU_LIST_FOR_CIRC(p, structure, headp) \
394 (p)=BU_LIST_PNEXT_CIRC(structure, headp); \
395 (p) && BU_LIST_NOT_HEAD(p, headp); \
396 (p)=BU_LIST_PNEXT_CIRC(structure, p)
406#define BU_LIST_FOR2(p1, p2, structure, headp1, headp2) \
407 (p1)=BU_LIST_FIRST(structure, headp1), \
408 (p2)=BU_LIST_FIRST(structure, headp2); \
409 (p1) && BU_LIST_NOT_HEAD((struct bu_list *)(p1), (headp1)) && \
410 (p2) && BU_LIST_NOT_HEAD((struct bu_list *)(p2), (headp2)); \
411 (p1)=BU_LIST_NEXT(structure, (struct bu_list *)(p1)), \
412 (p2)=BU_LIST_NEXT(structure, (struct bu_list *)(p2))
424#define BU_LIST_WHILE(p, structure, headp) \
425 (((p)=(struct structure *)((headp)->forw)) != (struct structure *)(headp))
430#define BU_LIST_FIRST_MAGIC(headp) ((headp)->forw->magic)
431#define BU_LIST_LAST_MAGIC(headp) ((headp)->back->magic)
436#define BU_LIST_PNEXT(structure, p) \
437 ((struct structure *)(((struct bu_list *)(p))->forw))
438#define BU_LIST_PLAST(structure, p) \
439 ((struct structure *)(((struct bu_list *)(p))->back))
444#define BU_LIST_PNEXT_PNEXT(structure, p) \
445 ((struct structure *)(((struct bu_list *)(p))->forw->forw))
446#define BU_LIST_PNEXT_PLAST(structure, p) \
447 ((struct structure *)(((struct bu_list *)(p))->forw->back))
448#define BU_LIST_PLAST_PNEXT(structure, p) \
449 ((struct structure *)(((struct bu_list *)(p))->back->forw))
450#define BU_LIST_PLAST_PLAST(structure, p) \
451 ((struct structure *)(((struct bu_list *)(p))->back->back))
456#define BU_LIST_PNEXT_CIRC(structure, p) \
457 ((BU_LIST_FIRST_MAGIC((struct bu_list *)(p)) == BU_LIST_HEAD_MAGIC) ? \
458 BU_LIST_PNEXT_PNEXT(structure, (struct bu_list *)(p)) : \
459 BU_LIST_PNEXT(structure, p))
464#define BU_LIST_PPREV_CIRC(structure, p) \
465 ((BU_LIST_LAST_MAGIC((struct bu_list *)(p)) == BU_LIST_HEAD_MAGIC) ? \
466 BU_LIST_PLAST_PLAST(structure, (struct bu_list *)(p)) : \
467 BU_LIST_PLAST(structure, p))
484#define BU_LIST_MAIN_PTR(_type, _ptr2, _name2) \
485 ((struct _type *)(((char *)(_ptr2)) - (bu_offsetof(struct _type, _name2) + bu_offsetof(struct bu_list, magic))))
550 const uint32_t
magic);
Header file for the BRL-CAD common definitions.
void bu_ck_list(const struct bu_list *headp, const char *str)
void bu_ck_list_magic(const struct bu_list *headp, const char *str, const uint32_t magic)
void bu_list_reverse(struct bu_list *headp)
int bu_list_len(const struct bu_list *headp)
struct bu_list * bu_list_parallel_dequeue(struct bu_list *headp)
struct bu_list * bu_list_pop(struct bu_list *headp)
void bu_list_free(struct bu_list *headp)
void bu_list_parallel_append(struct bu_list *headp, struct bu_list *itemp)
struct bu_list * bu_list_new(void)
Global registry of recognized magic numbers.
uint32_t magic
Magic # for mem id/check.
struct bu_list * forw
"forward", "next"
struct bu_list * back
"back", "last"