1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module glib.garray; 7 8 import glib.gtypes; 9 10 11 12 struct GBytes; 13 14 struct GArray 15 { 16 gchar* data; 17 guint len; 18 } 19 20 struct GByteArray 21 { 22 guint8 *data; 23 guint len; 24 } 25 26 struct GPtrArray 27 { 28 gpointer *pdata; 29 guint len; 30 } 31 32 auto g_array_append_val(A, V)(A a, V v) 33 { 34 return g_array_append_vals(a, &v, 1); 35 } 36 37 auto g_array_prepend_val(A, V)(A a, V v) 38 { 39 return g_array_prepend_vals(a, &v, 1); 40 } 41 42 auto g_array_insert_val(A, I, V)(A a, I i, V v) 43 { 44 return g_array_insert_vals(a, i, &v, 1); 45 } 46 47 auto g_array_index(A, I, T)(A a, I i) 48 { 49 // TODO: check this 50 return cast(T*)(a.data[i*T.sizeof]); 51 } 52 // #define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)]) 53 54 55 extern(C) { 56 57 GArray* g_array_new (gboolean zero_terminated, 58 gboolean clear_, 59 guint element_size); 60 GArray* g_array_sized_new (gboolean zero_terminated, 61 gboolean clear_, 62 guint element_size, 63 guint reserved_size); 64 65 gchar* g_array_free (GArray *array, 66 gboolean free_segment); 67 68 GArray *g_array_ref (GArray *array); 69 70 void g_array_unref (GArray *array); 71 72 guint g_array_get_element_size (GArray *array); 73 74 GArray* g_array_append_vals (GArray *array, 75 gconstpointer data, 76 guint len); 77 78 GArray* g_array_prepend_vals (GArray *array, 79 gconstpointer data, 80 guint len); 81 82 GArray* g_array_insert_vals (GArray *array, 83 guint index_, 84 gconstpointer data, 85 guint len); 86 87 GArray* g_array_set_size (GArray *array, 88 guint length); 89 90 GArray* g_array_remove_index (GArray *array, 91 guint index_); 92 93 GArray* g_array_remove_index_fast (GArray *array, 94 guint index_); 95 96 GArray* g_array_remove_range (GArray *array, 97 guint index_, 98 guint length); 99 100 void g_array_sort (GArray *array, 101 GCompareFunc compare_func); 102 103 void g_array_sort_with_data (GArray *array, 104 GCompareDataFunc compare_func, 105 gpointer user_data); 106 107 void g_array_set_clear_func (GArray *array, 108 GDestroyNotify clear_func); 109 110 extern(D) { 111 auto g_ptr_array_index(A, I)(A a, I i) 112 { return a.pdata[i]; } 113 } 114 115 GPtrArray* g_ptr_array_new (); 116 117 GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func); 118 119 GPtrArray* g_ptr_array_sized_new (guint reserved_size); 120 121 GPtrArray* g_ptr_array_new_full (guint reserved_size, 122 GDestroyNotify element_free_func); 123 124 gpointer* g_ptr_array_free (GPtrArray *array, 125 gboolean free_seg); 126 127 GPtrArray* g_ptr_array_ref (GPtrArray *array); 128 129 void g_ptr_array_unref (GPtrArray *array); 130 131 void g_ptr_array_set_free_func (GPtrArray *array, 132 GDestroyNotify element_free_func); 133 134 void g_ptr_array_set_size (GPtrArray *array, 135 gint length); 136 137 gpointer g_ptr_array_remove_index (GPtrArray *array, 138 guint index_); 139 140 gpointer g_ptr_array_remove_index_fast (GPtrArray *array, 141 guint index_); 142 143 gboolean g_ptr_array_remove (GPtrArray *array, 144 gpointer data); 145 146 gboolean g_ptr_array_remove_fast (GPtrArray *array, 147 gpointer data); 148 149 GPtrArray *g_ptr_array_remove_range (GPtrArray *array, 150 guint index_, 151 guint length); 152 153 void g_ptr_array_add (GPtrArray *array, 154 gpointer data); 155 156 void g_ptr_array_insert (GPtrArray *array, 157 gint index_, 158 gpointer data); 159 160 void g_ptr_array_sort (GPtrArray *array, 161 GCompareFunc compare_func); 162 163 void g_ptr_array_sort_with_data (GPtrArray *array, 164 GCompareDataFunc compare_func, 165 gpointer user_data); 166 167 void g_ptr_array_foreach (GPtrArray *array, 168 GFunc func, 169 gpointer user_data); 170 171 172 173 GByteArray* g_byte_array_new (); 174 175 GByteArray* g_byte_array_new_take (guint8 *data, 176 gsize len); 177 178 GByteArray* g_byte_array_sized_new (guint reserved_size); 179 180 guint8* g_byte_array_free (GByteArray *array, 181 gboolean free_segment); 182 183 GBytes* g_byte_array_free_to_bytes (GByteArray *array); 184 185 GByteArray *g_byte_array_ref (GByteArray *array); 186 187 void g_byte_array_unref (GByteArray *array); 188 189 GByteArray* g_byte_array_append (GByteArray *array, 190 const(guint8) *data, 191 guint len); 192 193 GByteArray* g_byte_array_prepend (GByteArray *array, 194 const(guint8) *data, 195 guint len); 196 197 GByteArray* g_byte_array_set_size (GByteArray *array, 198 guint length); 199 200 GByteArray* g_byte_array_remove_index (GByteArray *array, 201 guint index_); 202 203 GByteArray* g_byte_array_remove_index_fast (GByteArray *array, 204 guint index_); 205 206 GByteArray* g_byte_array_remove_range (GByteArray *array, 207 guint index_, 208 guint length); 209 210 void g_byte_array_sort (GByteArray *array, 211 GCompareFunc compare_func); 212 213 void g_byte_array_sort_with_data (GByteArray *array, 214 GCompareDataFunc compare_func, 215 gpointer user_data); 216 217 } // extern (C)