Fix bug with -0.0L in previous patch.
[gnulib.git] / lib / gl_list.h
index b97a6a4..1a2f9fb 100644 (file)
@@ -1,11 +1,11 @@
 /* Abstract sequential list data type.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006-2007 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
-   This program is free software; you can redistribute it and/or modify
+   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifndef _GL_LIST_H
 #define _GL_LIST_H
@@ -102,6 +101,10 @@ typedef bool (*gl_listelement_equals_fn) (const void *elt1, const void *elt2);
    NULL denotes a function that depends only on the pointer itself.  */
 typedef size_t (*gl_listelement_hashcode_fn) (const void *elt);
 
+/* Type of function used to dispose an element once it's removed from a list.
+   NULL denotes a no-op.  */
+typedef void (*gl_listelement_dispose_fn) (const void *elt);
+
 struct gl_list_impl;
 /* Type representing an entire list.  */
 typedef struct gl_list_impl * gl_list_t;
@@ -122,11 +125,13 @@ typedef const struct gl_list_implementation * gl_list_implementation_t;
    GL_RBTREEHASH_LIST.
    EQUALS_FN is an element comparison function or NULL.
    HASHCODE_FN is an element hash code function or NULL.
+   DISPOSE_FN is an element disposal function or NULL.
    ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
    the list. The implementation may verify this at runtime.  */
 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
                                       gl_listelement_equals_fn equals_fn,
                                       gl_listelement_hashcode_fn hashcode_fn,
+                                      gl_listelement_dispose_fn dispose_fn,
                                       bool allow_duplicates);
 
 /* Create a list with given contents.
@@ -135,6 +140,7 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
    GL_RBTREEHASH_LIST.
    EQUALS_FN is an element comparison function or NULL.
    HASHCODE_FN is an element hash code function or NULL.
+   DISPOSE_FN is an element disposal function or NULL.
    ALLOW_DUPLICATES is false if duplicate elements shall not be allowed in
    the list. The implementation may verify this at runtime.
    COUNT is the number of initial elements.
@@ -142,6 +148,7 @@ extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
                                 gl_listelement_equals_fn equals_fn,
                                 gl_listelement_hashcode_fn hashcode_fn,
+                                gl_listelement_dispose_fn dispose_fn,
                                 bool allow_duplicates,
                                 size_t count, const void **contents);
 
@@ -364,10 +371,12 @@ struct gl_list_implementation
   gl_list_t (*create_empty) (gl_list_implementation_t implementation,
                             gl_listelement_equals_fn equals_fn,
                             gl_listelement_hashcode_fn hashcode_fn,
+                            gl_listelement_dispose_fn dispose_fn,
                             bool allow_duplicates);
   gl_list_t (*create) (gl_list_implementation_t implementation,
                       gl_listelement_equals_fn equals_fn,
                       gl_listelement_hashcode_fn hashcode_fn,
+                      gl_listelement_dispose_fn dispose_fn,
                       bool allow_duplicates,
                       size_t count, const void **contents);
   size_t (*size) (gl_list_t list);
@@ -429,6 +438,7 @@ struct gl_list_impl_base
   const struct gl_list_implementation *vtable;
   gl_listelement_equals_fn equals_fn;
   gl_listelement_hashcode_fn hashcode_fn;
+  gl_listelement_dispose_fn dispose_fn;
   bool allow_duplicates;
 };
 
@@ -443,10 +453,11 @@ static inline gl_list_t
 gl_list_create_empty (gl_list_implementation_t implementation,
                      gl_listelement_equals_fn equals_fn,
                      gl_listelement_hashcode_fn hashcode_fn,
+                     gl_listelement_dispose_fn dispose_fn,
                      bool allow_duplicates)
 {
   return implementation->create_empty (implementation, equals_fn, hashcode_fn,
-                                      allow_duplicates);
+                                      dispose_fn, allow_duplicates);
 }
 
 # define gl_list_create gl_list_create_inline
@@ -454,11 +465,12 @@ static inline gl_list_t
 gl_list_create (gl_list_implementation_t implementation,
                gl_listelement_equals_fn equals_fn,
                gl_listelement_hashcode_fn hashcode_fn,
+               gl_listelement_dispose_fn dispose_fn,
                bool allow_duplicates,
                size_t count, const void **contents)
 {
   return implementation->create (implementation, equals_fn, hashcode_fn,
-                                allow_duplicates, count, contents);
+                                dispose_fn, allow_duplicates, count, contents);
 }
 
 # define gl_list_size gl_list_size_inline