added Vector_foreach*() functions
authorEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 3 Jul 2005 09:12:31 +0000 (09:12 +0000)
committerEnrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
Sun, 3 Jul 2005 09:12:31 +0000 (09:12 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2113 94cd875c-1c1d-0410-91d2-eb244daf1a30

util-vserver/ensc_vector/Makefile-files
util-vserver/ensc_vector/vector-foreach.c [new file with mode: 0644]
util-vserver/ensc_vector/vector.h
util-vserver/ensc_vector/vector.hc

index b2d9aa7..6fb511a 100644 (file)
@@ -16,6 +16,7 @@
 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 ENSC_VECTOR_SRCS =             ensc_vector/vector-clear.c \
+                               ensc_vector/vector-foreach.c \
                                ensc_vector/vector-free.c \
                                ensc_vector/vector-init.c \
                                ensc_vector/vector-insert.c \
diff --git a/util-vserver/ensc_vector/vector-foreach.c b/util-vserver/ensc_vector/vector-foreach.c
new file mode 100644 (file)
index 0000000..ea9db5f
--- /dev/null
@@ -0,0 +1,34 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+//  
+// 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; version 2 of the License.
+//  
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vector.h"
+
+void
+Vector_foreach(struct Vector *vec, void (*func)(void *, void *), void *data)
+{
+  char *       ptr  = Vector_begin(vec);
+  char * const end  = Vector_end(vec);
+  size_t const step = vec->elem_size;
+
+  for (; ptr<end; ptr += step)
+    func(ptr, data);
+}
index a6e01f1..bca1a6d 100644 (file)
@@ -46,7 +46,11 @@ void Vector_popback(struct Vector *);
 void   Vector_resize(struct Vector *vec);
 void   Vector_clear(struct Vector *vec);
 void   Vector_zeroEnd(struct Vector *vec);
+void   Vector_foreach(struct Vector *vec, void (*func)(void *, void *), void *);
 
+static void            Vector_foreach_const(struct Vector const *vec,
+                                            void (*func)(void const *, void *),
+                                            void *);
 static void const *    Vector_searchSelfOrg_const(struct Vector const *, void const *key,
                                                   int (*compar)(const void *, const void *),
                                                   VectorSelfOrgMethod method);
index 2e5493c..ad8ad54 100644 (file)
@@ -59,3 +59,12 @@ Vector_searchSelfOrg_const(struct Vector const *vec, void const *key,
 {
   return Vector_searchSelfOrg((struct Vector *)(vec), key, compare, method);
 }
+
+static inline UNUSED void
+Vector_foreach_const(struct Vector const *vec, void (*func)(void const *, void *),
+                    void *data)
+{
+  Vector_foreach((struct Vector *)(vec),
+                (void (*)(void *, void *))(func),
+                data);
+}