garray.h

Go to the documentation of this file.
00001 /* GLIB - Library of useful routines for C programming
00002  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
00003  * Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the
00017  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 /*
00022  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
00023  * file for a list of people on the GLib Team.  See the ChangeLog
00024  * files for a list of changes.  These files are distributed with
00025  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
00026  */
00027 
00028 #ifndef __G_ARRAY_H__
00029 #define __G_ARRAY_H__
00030 
00031 #include <_ansi.h>
00032 #include <glib/gtypes.h>
00033 
00034 G_BEGIN_DECLS
00035 
00036 typedef struct _GArray          GArray;
00037 typedef struct _GByteArray      GByteArray;
00038 typedef struct _GPtrArray       GPtrArray;
00039 
00040 struct _GArray
00041 {
00042   gchar *data;
00043   guint len;
00044 };
00045 
00046 struct _GByteArray
00047 {
00048   guint8 *data;
00049   guint   len;
00050 };
00051 
00052 struct _GPtrArray
00053 {
00054   gpointer *pdata;
00055   guint     len;
00056 };
00057 
00058 /* Resizable arrays. remove fills any cleared spot and shortens the
00059  * array, while preserving the order. remove_fast will distort the
00060  * order by moving the last element to the position of the removed.
00061  */
00062 
00063 #define g_array_append_val(a,v)   g_array_append_vals (a, &(v), 1)
00064 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &(v), 1)
00065 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
00066 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
00067 
00068 IMPORT_C GArray* g_array_new               (gboolean          zero_terminated,
00069                                    gboolean          clear_,
00070                                    guint             element_size);
00071 IMPORT_C GArray* g_array_sized_new         (gboolean          zero_terminated,
00072                                    gboolean          clear_,
00073                                    guint             element_size,
00074                                    guint             reserved_size);
00075 IMPORT_C gchar*  g_array_free              (GArray           *array,
00076                                    gboolean          free_segment);
00077 IMPORT_C GArray* g_array_append_vals       (GArray           *array,
00078                                    gconstpointer     data,
00079                                    guint             len);
00080 IMPORT_C GArray* g_array_prepend_vals      (GArray           *array,
00081                                    gconstpointer     data,
00082                                    guint             len);
00083 IMPORT_C GArray* g_array_insert_vals       (GArray           *array,
00084                                    guint             index_,
00085                                    gconstpointer     data,
00086                                    guint             len);
00087 IMPORT_C GArray* g_array_set_size          (GArray           *array,
00088                                    guint             length);
00089 IMPORT_C GArray* g_array_remove_index      (GArray           *array,
00090                                    guint             index_);
00091 IMPORT_C GArray* g_array_remove_index_fast (GArray           *array,
00092                                    guint             index_);
00093 IMPORT_C GArray* g_array_remove_range      (GArray           *array,
00094                                    guint             index_,
00095                                    guint             length);
00096 IMPORT_C void    g_array_sort              (GArray           *array,
00097                                    GCompareFunc      compare_func);
00098 IMPORT_C void    g_array_sort_with_data    (GArray           *array,
00099                                    GCompareDataFunc  compare_func,
00100                                    gpointer          user_data);
00101 
00102 /* Resizable pointer array.  This interface is much less complicated
00103  * than the above.  Add appends a pointer.  Remove fills any cleared 
00104  * spot and shortens the array. remove_fast will again distort order.  
00105  */
00106 #define    g_ptr_array_index(array,index_) ((array)->pdata)[index_]
00107 IMPORT_C GPtrArray* g_ptr_array_new                (void);
00108 IMPORT_C GPtrArray* g_ptr_array_sized_new          (guint             reserved_size);
00109 IMPORT_C gpointer*  g_ptr_array_free               (GPtrArray        *array,
00110                                            gboolean          free_seg);
00111 IMPORT_C void       g_ptr_array_set_size           (GPtrArray        *array,
00112                                            gint              length);
00113 IMPORT_C gpointer   g_ptr_array_remove_index       (GPtrArray        *array,
00114                                            guint             index_);
00115 IMPORT_C gpointer   g_ptr_array_remove_index_fast  (GPtrArray        *array,
00116                                            guint             index_);
00117 IMPORT_C gboolean   g_ptr_array_remove             (GPtrArray        *array,
00118                                            gpointer          data);
00119 IMPORT_C gboolean   g_ptr_array_remove_fast        (GPtrArray        *array,
00120                                            gpointer          data);
00121 IMPORT_C void       g_ptr_array_remove_range       (GPtrArray        *array,
00122                                            guint             index_,
00123                                            guint             length);
00124 IMPORT_C void       g_ptr_array_add                (GPtrArray        *array,
00125                                            gpointer          data);
00126 IMPORT_C void       g_ptr_array_sort               (GPtrArray        *array,
00127                                            GCompareFunc      compare_func);
00128 IMPORT_C void       g_ptr_array_sort_with_data     (GPtrArray        *array,
00129                                            GCompareDataFunc  compare_func,
00130                                            gpointer          user_data);
00131 IMPORT_C void       g_ptr_array_foreach            (GPtrArray        *array,
00132                                            GFunc             func,
00133                                            gpointer          user_data);
00134 
00135 
00136 /* Byte arrays, an array of guint8.  Implemented as a GArray,
00137  * but type-safe.
00138  */
00139 
00140 IMPORT_C GByteArray* g_byte_array_new               (void);
00141 IMPORT_C GByteArray* g_byte_array_sized_new         (guint             reserved_size);
00142 IMPORT_C guint8*     g_byte_array_free              (GByteArray       *array,
00143                                             gboolean          free_segment);
00144 IMPORT_C GByteArray* g_byte_array_append            (GByteArray       *array,
00145                                             const guint8     *data,
00146                                             guint             len);
00147 IMPORT_C GByteArray* g_byte_array_prepend           (GByteArray       *array,
00148                                             const guint8     *data,
00149                                             guint             len);
00150 IMPORT_C GByteArray* g_byte_array_set_size          (GByteArray       *array,
00151                                             guint             length);
00152 IMPORT_C GByteArray* g_byte_array_remove_index      (GByteArray       *array,
00153                                             guint             index_);
00154 IMPORT_C GByteArray* g_byte_array_remove_index_fast (GByteArray       *array,
00155                                             guint             index_);
00156 IMPORT_C GByteArray* g_byte_array_remove_range      (GByteArray       *array,
00157                                             guint             index_,
00158                                             guint             length);
00159 IMPORT_C void        g_byte_array_sort              (GByteArray       *array,
00160                                             GCompareFunc      compare_func);
00161 IMPORT_C void        g_byte_array_sort_with_data    (GByteArray       *array,
00162                                             GCompareDataFunc  compare_func,
00163                                             gpointer          user_data);
00164 
00165 
00166 G_END_DECLS
00167 
00168 #endif /* __G_ARRAY_H__ */
00169 

Copyright © Nokia Corporation 2001-2008
Back to top