libg722_1  0.0.1
slist.h
00001 /* slist.h -- generalised singly linked lists
00002 
00003    Copyright (C) 2000, 2004, 2009 Free Software Foundation, Inc.
00004    Written by Gary V. Vaughan, 2000
00005 
00006    NOTE: The canonical source of this file is maintained with the
00007    GNU Libtool package.  Report bugs to bug-libtool@gnu.org.
00008 
00009 GNU Libltdl is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2 of the License, or (at your option) any later version.
00013 
00014 As a special exception to the GNU Lesser General Public License,
00015 if you distribute this file as part of a program or library that
00016 is built using GNU Libtool, you may include this file under the
00017 same distribution terms that you use for the rest of that program.
00018 
00019 GNU Libltdl is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 GNU Lesser General Public License for more details.
00023 
00024 You should have received a copy of the GNU Lesser General Public
00025 License along with GNU Libltdl; see the file COPYING.LIB.  If not, a
00026 copy can be downloaded from  http://www.gnu.org/licenses/lgpl.html,
00027 or obtained by writing to the Free Software Foundation, Inc.,
00028 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00029 */
00030 
00031 /* A generalised list.  This is deliberately transparent so that you
00032    can make the NEXT field of all your chained data structures first,
00033    and then cast them to `(SList *)' so that they can be manipulated
00034    by this API.
00035 
00036    Alternatively, you can generate raw SList elements using slist_new(),
00037    and put the element data in the USERDATA field.  Either way you
00038    get to manage the memory involved by yourself.
00039 */
00040 
00041 #if !defined(SLIST_H)
00042 #define SLIST_H 1
00043 
00044 #if defined(LTDL)
00045 #  include <libltdl/lt__glibc.h>
00046 #  include <libltdl/lt_system.h>
00047 #else
00048 #  define LT_SCOPE
00049 #endif
00050 
00051 #include <stddef.h>
00052 
00053 #if defined(__cplusplus)
00054 extern "C" {
00055 #endif
00056 
00057 typedef struct slist {
00058   struct slist *next;           /* chain forward pointer*/
00059   const void *userdata;         /* for boxed `SList' item */
00060 } SList;
00061 
00062 typedef void *  SListCallback   (SList *item, void *userdata);
00063 typedef int     SListCompare    (const SList *item1, const SList *item2,
00064                                  void *userdata);
00065 
00066 LT_SCOPE SList *slist_concat    (SList *head, SList *tail);
00067 LT_SCOPE SList *slist_cons      (SList *item, SList *slist);
00068 
00069 LT_SCOPE SList *slist_delete    (SList *slist, void (*delete_fct) (void *item));
00070 LT_SCOPE SList *slist_remove    (SList **phead, SListCallback *find,
00071                                  void *matchdata);
00072 LT_SCOPE SList *slist_reverse   (SList *slist);
00073 LT_SCOPE SList *slist_sort      (SList *slist, SListCompare *compare,
00074                                  void *userdata);
00075 
00076 LT_SCOPE SList *slist_tail      (SList *slist);
00077 LT_SCOPE SList *slist_nth       (SList *slist, size_t n);
00078 LT_SCOPE void * slist_find      (SList *slist, SListCallback *find,
00079                                  void *matchdata);
00080 LT_SCOPE size_t slist_length    (SList *slist);
00081 
00082 LT_SCOPE void * slist_foreach   (SList *slist, SListCallback *foreach,
00083                                  void *userdata);
00084 
00085 LT_SCOPE SList *slist_box       (const void *userdata);
00086 LT_SCOPE void * slist_unbox     (SList *item);
00087 
00088 #if defined(__cplusplus)
00089 }
00090 #endif
00091 
00092 #if !defined(LTDL)
00093 #  undef LT_SCOPE
00094 #endif
00095 
00096 #endif /*!defined(SLIST_H)*/