00001 /** \addtogroup lib 00002 @{ */ 00003 /** 00004 * \defgroup list Linked list library 00005 * 00006 * The linked list library provides a set of functions for 00007 * manipulating linked lists. 00008 * 00009 * A linked list is made up of elements where the first element \b 00010 * must be a pointer. This pointer is used by the linked list library 00011 * to form lists of the elements. 00012 * 00013 * Lists are declared with the LIST() macro. The declaration specifies 00014 * the name of the list that later is used with all list functions. 00015 * 00016 * Lists can be manipulated by inserting or removing elements from 00017 * either sides of the list (list_push(), list_add(), list_pop(), 00018 * list_chop()). A specified element can also be removed from inside a 00019 * list with list_remove(). The head and tail of a list can be 00020 * extracted using list_head() and list_tail(), respecitively. 00021 * 00022 * @{ 00023 */ 00024 00025 /** 00026 * \file 00027 * Linked list manipulation routines. 00028 * \author Adam Dunkels <adam@sics.se> 00029 * 00030 * 00031 */ 00032 00033 00034 00035 /* 00036 * Copyright (c) 2004, Swedish Institute of Computer Science. 00037 * All rights reserved. 00038 * 00039 * Redistribution and use in source and binary forms, with or without 00040 * modification, are permitted provided that the following conditions 00041 * are met: 00042 * 1. Redistributions of source code must retain the above copyright 00043 * notice, this list of conditions and the following disclaimer. 00044 * 2. Redistributions in binary form must reproduce the above copyright 00045 * notice, this list of conditions and the following disclaimer in the 00046 * documentation and/or other materials provided with the distribution. 00047 * 3. Neither the name of the Institute nor the names of its contributors 00048 * may be used to endorse or promote products derived from this software 00049 * without specific prior written permission. 00050 * 00051 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00052 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00053 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00054 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00055 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00056 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00057 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00058 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00059 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00060 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00061 * SUCH DAMAGE. 00062 * 00063 * This file is part of the Contiki operating system. 00064 * 00065 * Author: Adam Dunkels <adam@sics.se> 00066 * 00067 * $Id: list.h,v 1.1 2006/06/17 22:41:18 adamdunkels Exp $ 00068 */ 00069 #ifndef __LIST_H__ 00070 #define __LIST_H__ 00071 00072 #define LIST_CONCAT2(s1, s2) s1##s2 00073 #define LIST_CONCAT(s1, s2) LIST_CONCAT2(s1, s2) 00074 00075 /** 00076 * Declare a linked list. 00077 * 00078 * This macro declares a linked list with the specified \c type. The 00079 * type \b must be a structure (\c struct) with its first element 00080 * being a pointer. This pointer is used by the linked list library to 00081 * form the linked lists. 00082 * 00083 * \param name The name of the list. 00084 */ 00085 #define LIST(name) \ 00086 static void *LIST_CONCAT(name,_list) = NULL; \ 00087 static list_t name = (list_t)&LIST_CONCAT(name,_list) 00088 00089 /** 00090 * The linked list type. 00091 * 00092 */ 00093 typedef void ** list_t; 00094 00095 void list_init(list_t list); 00096 void * list_head(list_t list); 00097 void * list_tail(list_t list); 00098 void * list_pop (list_t list); 00099 void list_push(list_t list, void *item); 00100 00101 void * list_chop(list_t list); 00102 00103 void list_add(list_t list, void *item); 00104 void list_remove(list_t list, void *item); 00105 00106 int list_length(list_t list); 00107 00108 void list_copy(list_t dest, list_t src); 00109 00110 void list_insert(list_t list, void *previtem, void *newitem); 00111 00112 #endif /* __LIST_H__ */ 00113 00114 /** @} */ 00115 /** @} */