home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prclist.h < prev    next >
C/C++ Source or Header  |  1998-07-21  |  3KB  |  122 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prclist_h___
  20. #define prclist_h___
  21.  
  22. #include "prtypes.h"
  23.  
  24. typedef struct PRCListStr PRCList;
  25.  
  26. /*
  27. ** Circular linked list
  28. */
  29. struct PRCListStr {
  30.     PRCList    *next;
  31.     PRCList    *prev;
  32. };
  33.  
  34. /*
  35. ** Insert element "_e" into the list, before "_l".
  36. */
  37. #define PR_INSERT_BEFORE(_e,_l)     \
  38.     PR_BEGIN_MACRO         \
  39.     (_e)->next = (_l);     \
  40.     (_e)->prev = (_l)->prev; \
  41.     (_l)->prev->next = (_e); \
  42.     (_l)->prev = (_e);     \
  43.     PR_END_MACRO
  44.  
  45. /*
  46. ** Insert element "_e" into the list, after "_l".
  47. */
  48. #define PR_INSERT_AFTER(_e,_l)     \
  49.     PR_BEGIN_MACRO         \
  50.     (_e)->next = (_l)->next; \
  51.     (_e)->prev = (_l);     \
  52.     (_l)->next->prev = (_e); \
  53.     (_l)->next = (_e);     \
  54.     PR_END_MACRO
  55.  
  56. /*
  57. ** Return the element following element "_e"
  58. */
  59. #define PR_NEXT_LINK(_e)     \
  60.         ((_e)->next)
  61. /*
  62. ** Return the element preceding element "_e"
  63. */
  64. #define PR_PREV_LINK(_e)     \
  65.         ((_e)->prev)
  66.  
  67. /*
  68. ** Append an element "_e" to the end of the list "_l"
  69. */
  70. #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
  71.  
  72. /*
  73. ** Insert an element "_e" at the head of the list "_l"
  74. */
  75. #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
  76.  
  77. /* Return the head/tail of the list */
  78. #define PR_LIST_HEAD(_l) (_l)->next
  79. #define PR_LIST_TAIL(_l) (_l)->prev
  80.  
  81. /*
  82. ** Remove the element "_e" from it's circular list.
  83. */
  84. #define PR_REMOVE_LINK(_e)           \
  85.     PR_BEGIN_MACRO               \
  86.     (_e)->prev->next = (_e)->next; \
  87.     (_e)->next->prev = (_e)->prev; \
  88.     PR_END_MACRO
  89.  
  90. /*
  91. ** Remove the element "_e" from it's circular list. Also initializes the
  92. ** linkage.
  93. */
  94. #define PR_REMOVE_AND_INIT_LINK(_e)    \
  95.     PR_BEGIN_MACRO               \
  96.     (_e)->prev->next = (_e)->next; \
  97.     (_e)->next->prev = (_e)->prev; \
  98.     (_e)->next = (_e);           \
  99.     (_e)->prev = (_e);           \
  100.     PR_END_MACRO
  101.  
  102. /*
  103. ** Return non-zero if the given circular list "_l" is empty, zero if the
  104. ** circular list is not empty
  105. */
  106. #define PR_CLIST_IS_EMPTY(_l) \
  107.     ((_l)->next == (_l))
  108.  
  109. /*
  110. ** Initialize a circular list
  111. */
  112. #define PR_INIT_CLIST(_l)  \
  113.     PR_BEGIN_MACRO       \
  114.     (_l)->next = (_l); \
  115.     (_l)->prev = (_l); \
  116.     PR_END_MACRO
  117.  
  118. #define PR_INIT_STATIC_CLIST(_l) \
  119.     {(_l), (_l)}
  120.  
  121. #endif /* prclist_h___ */
  122.