/gecko_api/include/prclist.h
C++ Header | 140 lines | 52 code | 16 blank | 72 comment | 1 complexity | cb22d0c6f48ef26d0550c113b2e1348b MD5 | raw file
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2/* ***** BEGIN LICENSE BLOCK ***** 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * http://www.mozilla.org/MPL/ 9 * 10 * Software distributed under the License is distributed on an "AS IS" basis, 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 * for the specific language governing rights and limitations under the 13 * License. 14 * 15 * The Original Code is the Netscape Portable Runtime (NSPR). 16 * 17 * The Initial Developer of the Original Code is 18 * Netscape Communications Corporation. 19 * Portions created by the Initial Developer are Copyright (C) 1998-2000 20 * the Initial Developer. All Rights Reserved. 21 * 22 * Contributor(s): 23 * 24 * Alternatively, the contents of this file may be used under the terms of 25 * either the GNU General Public License Version 2 or later (the "GPL"), or 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 * in which case the provisions of the GPL or the LGPL are applicable instead 28 * of those above. If you wish to allow use of your version of this file only 29 * under the terms of either the GPL or the LGPL, and not to allow others to 30 * use your version of this file under the terms of the MPL, indicate your 31 * decision by deleting the provisions above and replace them with the notice 32 * and other provisions required by the GPL or the LGPL. If you do not delete 33 * the provisions above, a recipient may use your version of this file under 34 * the terms of any one of the MPL, the GPL or the LGPL. 35 * 36 * ***** END LICENSE BLOCK ***** */ 37 38#ifndef prclist_h___ 39#define prclist_h___ 40 41#include "prtypes.h" 42 43typedef struct PRCListStr PRCList; 44 45/* 46** Circular linked list 47*/ 48struct PRCListStr { 49 PRCList *next; 50 PRCList *prev; 51}; 52 53/* 54** Insert element "_e" into the list, before "_l". 55*/ 56#define PR_INSERT_BEFORE(_e,_l) \ 57 PR_BEGIN_MACRO \ 58 (_e)->next = (_l); \ 59 (_e)->prev = (_l)->prev; \ 60 (_l)->prev->next = (_e); \ 61 (_l)->prev = (_e); \ 62 PR_END_MACRO 63 64/* 65** Insert element "_e" into the list, after "_l". 66*/ 67#define PR_INSERT_AFTER(_e,_l) \ 68 PR_BEGIN_MACRO \ 69 (_e)->next = (_l)->next; \ 70 (_e)->prev = (_l); \ 71 (_l)->next->prev = (_e); \ 72 (_l)->next = (_e); \ 73 PR_END_MACRO 74 75/* 76** Return the element following element "_e" 77*/ 78#define PR_NEXT_LINK(_e) \ 79 ((_e)->next) 80/* 81** Return the element preceding element "_e" 82*/ 83#define PR_PREV_LINK(_e) \ 84 ((_e)->prev) 85 86/* 87** Append an element "_e" to the end of the list "_l" 88*/ 89#define PR_APPEND_LINK(_e,_l) PR_INSERT_BEFORE(_e,_l) 90 91/* 92** Insert an element "_e" at the head of the list "_l" 93*/ 94#define PR_INSERT_LINK(_e,_l) PR_INSERT_AFTER(_e,_l) 95 96/* Return the head/tail of the list */ 97#define PR_LIST_HEAD(_l) (_l)->next 98#define PR_LIST_TAIL(_l) (_l)->prev 99 100/* 101** Remove the element "_e" from it's circular list. 102*/ 103#define PR_REMOVE_LINK(_e) \ 104 PR_BEGIN_MACRO \ 105 (_e)->prev->next = (_e)->next; \ 106 (_e)->next->prev = (_e)->prev; \ 107 PR_END_MACRO 108 109/* 110** Remove the element "_e" from it's circular list. Also initializes the 111** linkage. 112*/ 113#define PR_REMOVE_AND_INIT_LINK(_e) \ 114 PR_BEGIN_MACRO \ 115 (_e)->prev->next = (_e)->next; \ 116 (_e)->next->prev = (_e)->prev; \ 117 (_e)->next = (_e); \ 118 (_e)->prev = (_e); \ 119 PR_END_MACRO 120 121/* 122** Return non-zero if the given circular list "_l" is empty, zero if the 123** circular list is not empty 124*/ 125#define PR_CLIST_IS_EMPTY(_l) \ 126 ((_l)->next == (_l)) 127 128/* 129** Initialize a circular list 130*/ 131#define PR_INIT_CLIST(_l) \ 132 PR_BEGIN_MACRO \ 133 (_l)->next = (_l); \ 134 (_l)->prev = (_l); \ 135 PR_END_MACRO 136 137#define PR_INIT_STATIC_CLIST(_l) \ 138 {(_l), (_l)} 139 140#endif /* prclist_h___ */