PageRenderTime 27ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/ocr/ocrservice/jni/hydrogen/include/leptonica/list.h

http://eyes-free.googlecode.com/
C++ Header | 76 lines | 21 code | 12 blank | 43 comment | 2 complexity | 44124915f1c9737943be52924f8708f4 MD5 | raw file
 1
 2/*====================================================================*
 3 -  Copyright (C) 2001 Leptonica.  All rights reserved.
 4 -  This software is distributed in the hope that it will be
 5 -  useful, but with NO WARRANTY OF ANY KIND.
 6 -  No author or distributor accepts responsibility to anyone for the
 7 -  consequences of using this software, or for whether it serves any
 8 -  particular purpose or works at all, unless he or she says so in
 9 -  writing.  Everyone is granted permission to copy, modify and
10 -  redistribute this source code, for commercial or non-commercial
11 -  purposes, with the following restrictions: (1) the origin of this
12 -  source code must not be misrepresented; (2) modified versions must
13 -  be plainly marked as such; and (3) this notice may not be removed
14 -  or altered from any source or modified source distribution.
15 *====================================================================*/
16
17#ifndef  LEPTONICA_LIST_H
18#define  LEPTONICA_LIST_H
19
20/*
21 *   list.h
22 *
23 *       Cell for double-linked lists
24 *
25 *       This allows composition of a list of cells with 
26 *           prev, next and data pointers.  Generic data
27 *           structures hang on the list cell data pointers.
28 *
29 *       The list is not circular because that would add much
30 *           complexity in traversing the list under general
31 *           conditions where list cells can be added and removed.
32 *           The only disadvantage of not having the head point to
33 *           the last cell is that the list must be traversed to
34 *           find its tail.  However, this traversal is fast, and
35 *           the listRemoveFromTail() function updates the tail
36 *           so there is no searching overhead with repeated use.
37 *
38 *       The list macros are used to run through a list, and their
39 *       use is encouraged.  They are invoked, e.g., as
40 *
41 *             DLLIST  *head, *elem;
42 *             ...
43 *             L_BEGIN_LIST_FORWARD(head, elem)
44 *                 <do something with elem and/or elem->data >
45 *             L_END_LIST
46 *
47 */
48
49struct DoubleLinkedList
50{
51    struct DoubleLinkedList    *prev;
52    struct DoubleLinkedList    *next;
53    void                       *data;
54};
55typedef struct DoubleLinkedList    DLLIST;
56
57
58    /*  Simple list traverse macros */
59#define L_BEGIN_LIST_FORWARD(head, element) \
60        { \
61        DLLIST   *_leptvar_nextelem_; \
62        for ((element) = (head); (element); (element) = _leptvar_nextelem_) { \
63            _leptvar_nextelem_ = (element)->next;
64
65
66#define L_BEGIN_LIST_REVERSE(tail, element) \
67        { \
68        DLLIST   *_leptvar_prevelem_; \
69        for ((element) = (tail); (element); (element) = _leptvar_prevelem_) { \
70            _leptvar_prevelem_ = (element)->prev;
71
72
73#define L_END_LIST    }}
74
75
76#endif  /* LEPTONICA_LIST_H */