Leptonica 1.68
C Image Processing Library

list.h

Go to the documentation of this file.
00001 
00002 /*====================================================================*
00003  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00004  -  This software is distributed in the hope that it will be
00005  -  useful, but with NO WARRANTY OF ANY KIND.
00006  -  No author or distributor accepts responsibility to anyone for the
00007  -  consequences of using this software, or for whether it serves any
00008  -  particular purpose or works at all, unless he or she says so in
00009  -  writing.  Everyone is granted permission to copy, modify and
00010  -  redistribute this source code, for commercial or non-commercial
00011  -  purposes, with the following restrictions: (1) the origin of this
00012  -  source code must not be misrepresented; (2) modified versions must
00013  -  be plainly marked as such; and (3) this notice may not be removed
00014  -  or altered from any source or modified source distribution.
00015  *====================================================================*/
00016 
00017 #ifndef  LEPTONICA_LIST_H
00018 #define  LEPTONICA_LIST_H
00019 
00020 /*
00021  *   list.h
00022  *
00023  *       Cell for double-linked lists
00024  *
00025  *       This allows composition of a list of cells with 
00026  *           prev, next and data pointers.  Generic data
00027  *           structures hang on the list cell data pointers.
00028  *
00029  *       The list is not circular because that would add much
00030  *           complexity in traversing the list under general
00031  *           conditions where list cells can be added and removed.
00032  *           The only disadvantage of not having the head point to
00033  *           the last cell is that the list must be traversed to
00034  *           find its tail.  However, this traversal is fast, and
00035  *           the listRemoveFromTail() function updates the tail
00036  *           so there is no searching overhead with repeated use.
00037  *
00038  *       The list macros are used to run through a list, and their
00039  *       use is encouraged.  They are invoked, e.g., as
00040  *
00041  *             DLLIST  *head, *elem;
00042  *             ...
00043  *             L_BEGIN_LIST_FORWARD(head, elem)
00044  *                 <do something with elem and/or elem->data >
00045  *             L_END_LIST
00046  *
00047  */
00048 
00049 struct DoubleLinkedList
00050 {
00051     struct DoubleLinkedList    *prev;
00052     struct DoubleLinkedList    *next;
00053     void                       *data;
00054 };
00055 typedef struct DoubleLinkedList    DLLIST;
00056 
00057 
00058     /*  Simple list traverse macros */
00059 #define L_BEGIN_LIST_FORWARD(head, element) \
00060         { \
00061         DLLIST   *_leptvar_nextelem_; \
00062         for ((element) = (head); (element); (element) = _leptvar_nextelem_) { \
00063             _leptvar_nextelem_ = (element)->next;
00064 
00065 
00066 #define L_BEGIN_LIST_REVERSE(tail, element) \
00067         { \
00068         DLLIST   *_leptvar_prevelem_; \
00069         for ((element) = (tail); (element); (element) = _leptvar_prevelem_) { \
00070             _leptvar_prevelem_ = (element)->prev;
00071 
00072 
00073 #define L_END_LIST    }}
00074 
00075 
00076 #endif  /* LEPTONICA_LIST_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines