1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Arrays.html
27  * outPack = glib
28  * outFile = ArrayG
29  * strct   = GArray
30  * realStrct=
31  * ctorStrct=
32  * clss    = ArrayG
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_array_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * 	- GArray* -> ArrayG
49  * module aliases:
50  * local aliases:
51  * overrides:
52  */
53 
54 module glib.ArrayG;
55 
56 public  import gtkc.glibtypes;
57 
58 private import gtkc.glib;
59 private import glib.ConstructionException;
60 
61 private import glib.Str;
62 
63 
64 
65 /**
66  * Arrays are similar to standard C arrays, except that they grow
67  * automatically as elements are added.
68  *
69  * Array elements can be of any size (though all elements of one array
70  * are the same size), and the array can be automatically cleared to
71  * '0's and zero-terminated.
72  *
73  * To create a new array use g_array_new().
74  *
75  * To add elements to an array, use g_array_append_val(),
76  * g_array_append_vals(), g_array_prepend_val(), and
77  * g_array_prepend_vals().
78  *
79  * To access an element of an array, use g_array_index().
80  *
81  * To set the size of an array, use g_array_set_size().
82  *
83  * To free an array, use g_array_free().
84  *
85  * $(DDOC_COMMENT example)
86  */
87 public class ArrayG
88 {
89 	
90 	/** the main Gtk struct */
91 	protected GArray* gArray;
92 	
93 	
94 	/** Get the main Gtk struct */
95 	public GArray* getArrayGStruct()
96 	{
97 		return gArray;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected void* getStruct()
103 	{
104 		return cast(void*)gArray;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GArray* gArray)
111 	{
112 		this.gArray = gArray;
113 	}
114 	
115 	/**
116 	 */
117 	
118 	/**
119 	 * Creates a new GArray with a reference count of 1.
120 	 * Params:
121 	 * zeroTerminated = TRUE if the array should have an extra element at
122 	 * the end which is set to 0.
123 	 * clear = TRUE if GArray elements should be automatically cleared
124 	 * to 0 when they are allocated.
125 	 * elementSize = the size of each element in bytes.
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this (int zeroTerminated, int clear, uint elementSize)
129 	{
130 		// GArray * g_array_new (gboolean zero_terminated,  gboolean clear_,  guint element_size);
131 		auto p = g_array_new(zeroTerminated, clear, elementSize);
132 		if(p is null)
133 		{
134 			throw new ConstructionException("null returned by g_array_new(zeroTerminated, clear, elementSize)");
135 		}
136 		this(cast(GArray*) p);
137 	}
138 	
139 	/**
140 	 * Creates a new GArray with reserved_size elements preallocated and
141 	 * a reference count of 1. This avoids frequent reallocation, if you
142 	 * are going to add many elements to the array. Note however that the
143 	 * size of the array is still 0.
144 	 * Params:
145 	 * zeroTerminated = TRUE if the array should have an extra element at
146 	 * the end with all bits cleared.
147 	 * clear = TRUE if all bits in the array should be cleared to 0 on
148 	 * allocation.
149 	 * elementSize = size of each element in the array.
150 	 * reservedSize = number of elements preallocated.
151 	 * Returns: the new GArray.
152 	 */
153 	public static ArrayG sizedNew(int zeroTerminated, int clear, uint elementSize, uint reservedSize)
154 	{
155 		// GArray * g_array_sized_new (gboolean zero_terminated,  gboolean clear_,  guint element_size,  guint reserved_size);
156 		auto p = g_array_sized_new(zeroTerminated, clear, elementSize, reservedSize);
157 		
158 		if(p is null)
159 		{
160 			return null;
161 		}
162 		
163 		return new ArrayG(cast(GArray*) p);
164 	}
165 	
166 	/**
167 	 * Atomically increments the reference count of array by one. This
168 	 * function is MT-safe and may be called from any thread.
169 	 * Since 2.22
170 	 * Returns: The passed in GArray.
171 	 */
172 	public ArrayG doref()
173 	{
174 		// GArray * g_array_ref (GArray *array);
175 		auto p = g_array_ref(gArray);
176 		
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 		
182 		return new ArrayG(cast(GArray*) p);
183 	}
184 	
185 	/**
186 	 * Atomically decrements the reference count of array by one. If the
187 	 * reference count drops to 0, all memory allocated by the array is
188 	 * released. This function is MT-safe and may be called from any
189 	 * thread.
190 	 * Since 2.22
191 	 */
192 	public void unref()
193 	{
194 		// void g_array_unref (GArray *array);
195 		g_array_unref(gArray);
196 	}
197 	
198 	/**
199 	 * Gets the size of the elements in array.
200 	 * Since 2.22
201 	 * Returns: Size of each element, in bytes.
202 	 */
203 	public uint getElementSize()
204 	{
205 		// guint g_array_get_element_size (GArray *array);
206 		return g_array_get_element_size(gArray);
207 	}
208 	
209 	/**
210 	 * Adds len elements onto the end of the array.
211 	 * Params:
212 	 * data = a pointer to the elements to append to the end of the array.
213 	 * len = the number of elements to append.
214 	 * Returns: the GArray.
215 	 */
216 	public ArrayG appendVals(void* data, uint len)
217 	{
218 		// GArray * g_array_append_vals (GArray *array,  gconstpointer data,  guint len);
219 		auto p = g_array_append_vals(gArray, data, len);
220 		
221 		if(p is null)
222 		{
223 			return null;
224 		}
225 		
226 		return new ArrayG(cast(GArray*) p);
227 	}
228 	
229 	/**
230 	 * Adds len elements onto the start of the array.
231 	 * This operation is slower than g_array_append_vals() since the
232 	 * existing elements in the array have to be moved to make space for
233 	 * the new elements.
234 	 * Params:
235 	 * data = a pointer to the elements to prepend to the start of the
236 	 * array.
237 	 * len = the number of elements to prepend.
238 	 * Returns: the GArray.
239 	 */
240 	public ArrayG prependVals(void* data, uint len)
241 	{
242 		// GArray * g_array_prepend_vals (GArray *array,  gconstpointer data,  guint len);
243 		auto p = g_array_prepend_vals(gArray, data, len);
244 		
245 		if(p is null)
246 		{
247 			return null;
248 		}
249 		
250 		return new ArrayG(cast(GArray*) p);
251 	}
252 	
253 	/**
254 	 * Inserts len elements into a GArray at the given index.
255 	 * Params:
256 	 * index = the index to place the elements at.
257 	 * data = a pointer to the elements to insert.
258 	 * len = the number of elements to insert.
259 	 * Returns: the GArray.
260 	 */
261 	public ArrayG insertVals(uint index, void* data, uint len)
262 	{
263 		// GArray * g_array_insert_vals (GArray *array,  guint index_,  gconstpointer data,  guint len);
264 		auto p = g_array_insert_vals(gArray, index, data, len);
265 		
266 		if(p is null)
267 		{
268 			return null;
269 		}
270 		
271 		return new ArrayG(cast(GArray*) p);
272 	}
273 	
274 	/**
275 	 * Removes the element at the given index from a GArray. The following
276 	 * elements are moved down one place.
277 	 * Params:
278 	 * index = the index of the element to remove.
279 	 * Returns: the GArray.
280 	 */
281 	public ArrayG removeIndex(uint index)
282 	{
283 		// GArray * g_array_remove_index (GArray *array,  guint index_);
284 		auto p = g_array_remove_index(gArray, index);
285 		
286 		if(p is null)
287 		{
288 			return null;
289 		}
290 		
291 		return new ArrayG(cast(GArray*) p);
292 	}
293 	
294 	/**
295 	 * Removes the element at the given index from a GArray. The last
296 	 * element in the array is used to fill in the space, so this function
297 	 * does not preserve the order of the GArray. But it is faster than
298 	 * g_array_remove_index().
299 	 * Params:
300 	 * index = the index of the element to remove.
301 	 * Returns: the GArray.
302 	 */
303 	public ArrayG removeIndexFast(uint index)
304 	{
305 		// GArray * g_array_remove_index_fast (GArray *array,  guint index_);
306 		auto p = g_array_remove_index_fast(gArray, index);
307 		
308 		if(p is null)
309 		{
310 			return null;
311 		}
312 		
313 		return new ArrayG(cast(GArray*) p);
314 	}
315 	
316 	/**
317 	 * Removes the given number of elements starting at the given index
318 	 * from a GArray. The following elements are moved to close the gap.
319 	 * Since 2.4
320 	 * Params:
321 	 * index = the index of the first element to remove.
322 	 * length = the number of elements to remove.
323 	 * Returns: the GArray.
324 	 */
325 	public ArrayG removeRange(uint index, uint length)
326 	{
327 		// GArray * g_array_remove_range (GArray *array,  guint index_,  guint length);
328 		auto p = g_array_remove_range(gArray, index, length);
329 		
330 		if(p is null)
331 		{
332 			return null;
333 		}
334 		
335 		return new ArrayG(cast(GArray*) p);
336 	}
337 	
338 	/**
339 	 * Sorts a GArray using compare_func which should be a qsort()-style
340 	 * comparison function (returns less than zero for first arg is less
341 	 * than second arg, zero for equal, greater zero if first arg is
342 	 * greater than second arg).
343 	 * This is guaranteed to be a stable sort since version 2.32.
344 	 * Params:
345 	 * compareFunc = comparison function.
346 	 */
347 	public void sort(GCompareFunc compareFunc)
348 	{
349 		// void g_array_sort (GArray *array,  GCompareFunc compare_func);
350 		g_array_sort(gArray, compareFunc);
351 	}
352 	
353 	/**
354 	 * Like g_array_sort(), but the comparison function receives an extra
355 	 * user data argument.
356 	 * This is guaranteed to be a stable sort since version 2.32.
357 	 * There used to be a comment here about making the sort stable by
358 	 * using the addresses of the elements in the comparison function.
359 	 * This did not actually work, so any such code should be removed.
360 	 * Params:
361 	 * compareFunc = comparison function.
362 	 * userData = data to pass to compare_func.
363 	 */
364 	public void sortWithData(GCompareDataFunc compareFunc, void* userData)
365 	{
366 		// void g_array_sort_with_data (GArray *array,  GCompareDataFunc compare_func,  gpointer user_data);
367 		g_array_sort_with_data(gArray, compareFunc, userData);
368 	}
369 	
370 	/**
371 	 * Sets the size of the array, expanding it if necessary. If the array
372 	 * was created with clear_ set to TRUE, the new elements are set to 0.
373 	 * Params:
374 	 * length = the new size of the GArray.
375 	 * Returns: the GArray.
376 	 */
377 	public ArrayG setSize(uint length)
378 	{
379 		// GArray * g_array_set_size (GArray *array,  guint length);
380 		auto p = g_array_set_size(gArray, length);
381 		
382 		if(p is null)
383 		{
384 			return null;
385 		}
386 		
387 		return new ArrayG(cast(GArray*) p);
388 	}
389 	
390 	/**
391 	 * Sets a function to clear an element of array.
392 	 * The clear_func will be called when an element in the array
393 	 * data segment is removed and when the array is freed and data
394 	 * segment is deallocated as well.
395 	 * Note that in contrast with other uses of GDestroyNotify
396 	 * functions, clear_func is expected to clear the contents of
397 	 * the array element it is given, but not free the element itself.
398 	 * Since 2.32
399 	 * Params:
400 	 * clearFunc = a function to clear an element of array
401 	 */
402 	public void setClearFunc(GDestroyNotify clearFunc)
403 	{
404 		// void g_array_set_clear_func (GArray *array,  GDestroyNotify clear_func);
405 		g_array_set_clear_func(gArray, clearFunc);
406 	}
407 	
408 	/**
409 	 * Frees the memory allocated for the GArray. If free_segment is
410 	 * TRUE it frees the memory block holding the elements as well and
411 	 * also each element if array has a element_free_func set. Pass
412 	 * FALSE if you want to free the GArray wrapper but preserve the
413 	 * underlying array for use elsewhere. If the reference count of array
414 	 * is greater than one, the GArray wrapper is preserved but the size
415 	 * of array will be set to zero.
416 	 * Note
417 	 * If array elements contain dynamically-allocated memory,
418 	 * they should be freed separately.
419 	 * Params:
420 	 * freeSegment = if TRUE the actual element data is freed as well.
421 	 * Returns: the element data if free_segment is FALSE, otherwise NULL. The element data should be freed using g_free().
422 	 */
423 	public string free(int freeSegment)
424 	{
425 		// gchar * g_array_free (GArray *array,  gboolean free_segment);
426 		return Str.toString(g_array_free(gArray, freeSegment));
427 	}
428 }