home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / include / prclist.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.8 KB  |  116 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. ** Append an element "_e" to the end of the list "_l"
  63. */
  64. #define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l)
  65.  
  66. /*
  67. ** Insert an element "_e" at the head of the list "_l"
  68. */
  69. #define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l)
  70.  
  71. /* Return the head/tail of the list */
  72. #define PR_LIST_HEAD(_l) (_l)->next
  73. #define PR_LIST_TAIL(_l) (_l)->prev
  74.  
  75. /*
  76. ** Remove the element "_e" from it's circular list.
  77. */
  78. #define PR_REMOVE_LINK(_e)           \
  79.     PR_BEGIN_MACRO               \
  80.     (_e)->prev->next = (_e)->next; \
  81.     (_e)->next->prev = (_e)->prev; \
  82.     PR_END_MACRO
  83.  
  84. /*
  85. ** Remove the element "_e" from it's circular list. Also initializes the
  86. ** linkage.
  87. */
  88. #define PR_REMOVE_AND_INIT_LINK(_e)    \
  89.     PR_BEGIN_MACRO               \
  90.     (_e)->prev->next = (_e)->next; \
  91.     (_e)->next->prev = (_e)->prev; \
  92.     (_e)->next = (_e);           \
  93.     (_e)->prev = (_e);           \
  94.     PR_END_MACRO
  95.  
  96. /*
  97. ** Return non-zero if the given circular list "_l" is empty, zero if the
  98. ** circular list is not empty
  99. */
  100. #define PR_CLIST_IS_EMPTY(_l) \
  101.     ((_l)->next == (_l))
  102.  
  103. /*
  104. ** Initialize a circular list
  105. */
  106. #define PR_INIT_CLIST(_l)  \
  107.     PR_BEGIN_MACRO       \
  108.     (_l)->next = (_l); \
  109.     (_l)->prev = (_l); \
  110.     PR_END_MACRO
  111.  
  112. #define PR_INIT_STATIC_CLIST(_l) \
  113.     {(_l), (_l)}
  114.  
  115. #endif /* prclist_h___ */
  116.