xlist.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * xlist.h : a simple doubly linked list in C (header file)
00003  *****************************************************************************
00004  * Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research
00005  *                         Organisation (CSIRO) Australia
00006  * Copyright (C) 2000-2004 the VideoLAN team
00007  *
00008  * $Id$
00009  *
00010  * Authors: Conrad Parker <Conrad.Parker@csiro.au>
00011  *          Andre Pang <Andre.Pang@csiro.au>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00026  *****************************************************************************/
00027 
00028 
00029 #ifndef __XLIST__
00030 #define __XLIST__
00031 
00032 /**
00033  * A doubly linked list
00034  */
00035 typedef struct _XList XList;
00036 
00037 struct _XList {
00038   XList * prev;
00039   XList * next;
00040   void * data;
00041 };
00042 
00043 /**
00044  * Signature of a cloning function.
00045  */
00046 typedef void * (*XCloneFunc) (void * data);
00047 
00048 /**
00049  * Signature of a freeing function.
00050  */
00051 typedef void * (*XFreeFunc) (void * data);
00052 
00053 /** Create a new list
00054  * \return a new list
00055  */
00056 XList * xlist_new (void);
00057 
00058 /**
00059  * Clone a list using the default clone function
00060  * \param list the list to clone
00061  * \returns a newly cloned list
00062  */
00063 XList * xlist_clone (XList * list);
00064 
00065 /**
00066  * Clone a list using a custom clone function
00067  * \param list the list to clone
00068  * \param clone the function to use to clone a list item
00069  * \returns a newly cloned list
00070  */
00071 XList * xlist_clone_with (XList * list, XCloneFunc clone);
00072 
00073 /**
00074  * Return the tail element of a list
00075  * \param list the list
00076  * \returns the tail element
00077  */
00078 XList * xlist_tail (XList * list);
00079 
00080 /**
00081  * Prepend a new node to a list containing given data
00082  * \param list the list
00083  * \param data the data element of the newly created node
00084  * \returns the new list head
00085  */
00086 XList * xlist_prepend (XList * list, void * data);
00087 
00088 /**
00089  * Append a new node to a list containing given data
00090  * \param list the list
00091  * \param data the data element of the newly created node
00092  * \returns the head of the list
00093  */
00094 XList * xlist_append (XList * list, void * data);
00095 
00096 /**
00097  * Add a new node containing given data before a given node
00098  * \param list the list
00099  * \param data the data element of the newly created node
00100  * \param node the node before which to add the newly created node
00101  * \returns the head of the list (which may have changed)
00102  */
00103 XList * xlist_add_before (XList * list, void * data, XList * node);
00104 
00105 /**
00106  * Add a new node containing given data after a given node
00107  * \param list the list
00108  * \param data the data element of the newly created node
00109  * \param node the node after which to add the newly created node
00110  * \returns the head of the list
00111  */
00112 XList * xlist_add_after (XList * list, void * data, XList * node);
00113 
00114 /**
00115  * Find the first node containing given data in a list
00116  * \param list the list
00117  * \param data the data element to find
00118  * \returns the first node containing given data, or NULL if it is not found
00119  */
00120 XList * xlist_find (XList * list, void * data);
00121 
00122 /**
00123  * Remove a node from a list
00124  * \param list the list
00125  * \param node the node to remove
00126  * \returns the head of the list (which may have changed)
00127  */
00128 XList * xlist_remove (XList * list, XList * node);
00129 
00130 /**
00131  * Query the number of items in a list
00132  * \param list the list
00133  * \returns the number of nodes in the list
00134  */
00135 int xlist_length (XList * list);
00136 
00137 /**
00138  * Query if a list is empty, ie. contains no items
00139  * \param list the list
00140  * \returns 1 if the list is empty, 0 otherwise
00141  */
00142 int xlist_is_empty (XList * list);
00143 
00144 /**
00145  * Query if the list is singleton, ie. contains exactly one item
00146  * \param list the list
00147  * \returns 1 if the list is singleton, 0 otherwise
00148  */
00149 int xlist_is_singleton (XList * list);
00150 
00151 /**
00152  * Free a list, using a given function to free each data element
00153  * \param list the list
00154  * \param free_func a function to free each data element
00155  * \returns NULL on success
00156  */
00157 XList * xlist_free_with (XList * list, XFreeFunc free_func);
00158 
00159 /**
00160  * Free a list, using anx_free() to free each data element
00161  * \param list the list
00162  * \returns NULL on success
00163  */
00164 XList * xlist_free (XList * list);
00165 
00166 #endif /* __XLIST__ */
00167 
00168 

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1