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

Generated on Tue Jul 5 14:14:40 2011 for ROOT_528-00b_version by  doxygen 1.5.1