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