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 
62 private import glib.Str;
63 
64 
65 
66 
67 /**
68  * Description
69  * Arrays are similar to standard C arrays, except that they grow
70  * automatically as elements are added.
71  * Array elements can be of any size (though all elements of one array
72  * are the same size), and the array can be automatically cleared to
73  * '0's and zero-terminated.
74  * To create a new array use g_array_new().
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  * To access an element of an array, use g_array_index().
79  * To set the size of an array, use g_array_set_size().
80  * To free an array, use g_array_free().
81  * $(DDOC_COMMENT example)
82  */
83 public class ArrayG
84 {
85 	
86 	/** the main Gtk struct */
87 	protected GArray* gArray;
88 	
89 	
90 	public GArray* getArrayGStruct()
91 	{
92 		return gArray;
93 	}
94 	
95 	
96 	/** the main Gtk struct as a void* */
97 	protected void* getStruct()
98 	{
99 		return cast(void*)gArray;
100 	}
101 	
102 	/**
103 	 * Sets our main struct and passes it to the parent class
104 	 */
105 	public this (GArray* gArray)
106 	{
107 		this.gArray = gArray;
108 	}
109 	
110 	/**
111 	 */
112 	
113 	/**
114 	 * Creates a new GArray with a reference count of 1.
115 	 * Params:
116 	 * zeroTerminated = TRUE if the array should have an extra element at
117 	 * the end which is set to 0.
118 	 * clear = TRUE if GArray elements should be automatically cleared
119 	 * to 0 when they are allocated.
120 	 * elementSize = the size of each element in bytes.
121 	 * Throws: ConstructionException GTK+ fails to create the object.
122 	 */
123 	public this (int zeroTerminated, int clear, uint elementSize)
124 	{
125 		// GArray * g_array_new (gboolean zero_terminated,  gboolean clear_,  guint element_size);
126 		auto p = g_array_new(zeroTerminated, clear, elementSize);
127 		if(p is null)
128 		{
129 			throw new ConstructionException("null returned by g_array_new(zeroTerminated, clear, elementSize)");
130 		}
131 		this(cast(GArray*) p);
132 	}
133 	
134 	/**
135 	 * Creates a new GArray with reserved_size elements preallocated and
136 	 * a reference count of 1. This avoids frequent reallocation, if you
137 	 * are going to add many elements to the array. Note however that the
138 	 * size of the array is still 0.
139 	 * Params:
140 	 * zeroTerminated = TRUE if the array should have an extra element at
141 	 * the end with all bits cleared.
142 	 * clear = TRUE if all bits in the array should be cleared to 0 on
143 	 * allocation.
144 	 * elementSize = size of each element in the array.
145 	 * reservedSize = number of elements preallocated.
146 	 * Returns: the new GArray.
147 	 */
148 	public static ArrayG sizedNew(int zeroTerminated, int clear, uint elementSize, uint reservedSize)
149 	{
150 		// GArray * g_array_sized_new (gboolean zero_terminated,  gboolean clear_,  guint element_size,  guint reserved_size);
151 		auto p = g_array_sized_new(zeroTerminated, clear, elementSize, reservedSize);
152 		
153 		if(p is null)
154 		{
155 			return null;
156 		}
157 		
158 		return new ArrayG(cast(GArray*) p);
159 	}
160 	
161 	/**
162 	 * Atomically increments the reference count of array by one. This
163 	 * function is MT-safe and may be called from any thread.
164 	 * Since 2.22
165 	 * Returns: The passed in GArray.
166 	 */
167 	public ArrayG doref()
168 	{
169 		// GArray * g_array_ref (GArray *array);
170 		auto p = g_array_ref(gArray);
171 		
172 		if(p is null)
173 		{
174 			return null;
175 		}
176 		
177 		return new ArrayG(cast(GArray*) p);
178 	}
179 	
180 	/**
181 	 * Atomically decrements the reference count of array by one. If the
182 	 * reference count drops to 0, all memory allocated by the array is
183 	 * released. This function is MT-safe and may be called from any
184 	 * thread.
185 	 * Since 2.22
186 	 */
187 	public void unref()
188 	{
189 		// void g_array_unref (GArray *array);
190 		g_array_unref(gArray);
191 	}
192 	
193 	/**
194 	 * Gets the size of the elements in array.
195 	 * Since 2.22
196 	 * Returns: Size of each element, in bytes.
197 	 */
198 	public uint getElementSize()
199 	{
200 		// guint g_array_get_element_size (GArray *array);
201 		return g_array_get_element_size(gArray);
202 	}
203 	
204 	/**
205 	 * Adds len elements onto the end of the array.
206 	 * Params:
207 	 * data = a pointer to the elements to append to the end of the array.
208 	 * len = the number of elements to append.
209 	 * Returns: the GArray.
210 	 */
211 	public ArrayG appendVals(void* data, uint len)
212 	{
213 		// GArray * g_array_append_vals (GArray *array,  gconstpointer data,  guint len);
214 		auto p = g_array_append_vals(gArray, data, len);
215 		
216 		if(p is null)
217 		{
218 			return null;
219 		}
220 		
221 		return new ArrayG(cast(GArray*) p);
222 	}
223 	
224 	/**
225 	 * Adds len elements onto the start of the array.
226 	 * This operation is slower than g_array_append_vals() since the
227 	 * existing elements in the array have to be moved to make space for
228 	 * the new elements.
229 	 * Params:
230 	 * data = a pointer to the elements to prepend to the start of the
231 	 * array.
232 	 * len = the number of elements to prepend.
233 	 * Returns: the GArray.
234 	 */
235 	public ArrayG prependVals(void* data, uint len)
236 	{
237 		// GArray * g_array_prepend_vals (GArray *array,  gconstpointer data,  guint len);
238 		auto p = g_array_prepend_vals(gArray, data, len);
239 		
240 		if(p is null)
241 		{
242 			return null;
243 		}
244 		
245 		return new ArrayG(cast(GArray*) p);
246 	}
247 	
248 	/**
249 	 * Inserts len elements into a GArray at the given index.
250 	 * Params:
251 	 * index = the index to place the elements at.
252 	 * data = a pointer to the elements to insert.
253 	 * len = the number of elements to insert.
254 	 * Returns: the GArray.
255 	 */
256 	public ArrayG insertVals(uint index, void* data, uint len)
257 	{
258 		// GArray * g_array_insert_vals (GArray *array,  guint index_,  gconstpointer data,  guint len);
259 		auto p = g_array_insert_vals(gArray, index, data, len);
260 		
261 		if(p is null)
262 		{
263 			return null;
264 		}
265 		
266 		return new ArrayG(cast(GArray*) p);
267 	}
268 	
269 	/**
270 	 * Removes the element at the given index from a GArray. The following
271 	 * elements are moved down one place.
272 	 * Params:
273 	 * index = the index of the element to remove.
274 	 * Returns: the GArray.
275 	 */
276 	public ArrayG removeIndex(uint index)
277 	{
278 		// GArray * g_array_remove_index (GArray *array,  guint index_);
279 		auto p = g_array_remove_index(gArray, index);
280 		
281 		if(p is null)
282 		{
283 			return null;
284 		}
285 		
286 		return new ArrayG(cast(GArray*) p);
287 	}
288 	
289 	/**
290 	 * Removes the element at the given index from a GArray. The last
291 	 * element in the array is used to fill in the space, so this function
292 	 * does not preserve the order of the GArray. But it is faster than
293 	 * g_array_remove_index().
294 	 * Params:
295 	 * index = the index of the element to remove.
296 	 * Returns: the GArray.
297 	 */
298 	public ArrayG removeIndexFast(uint index)
299 	{
300 		// GArray * g_array_remove_index_fast (GArray *array,  guint index_);
301 		auto p = g_array_remove_index_fast(gArray, index);
302 		
303 		if(p is null)
304 		{
305 			return null;
306 		}
307 		
308 		return new ArrayG(cast(GArray*) p);
309 	}
310 	
311 	/**
312 	 * Removes the given number of elements starting at the given index
313 	 * from a GArray. The following elements are moved to close the gap.
314 	 * Since 2.4
315 	 * Params:
316 	 * index = the index of the first element to remove.
317 	 * length = the number of elements to remove.
318 	 * Returns: the GArray.
319 	 */
320 	public ArrayG removeRange(uint index, uint length)
321 	{
322 		// GArray * g_array_remove_range (GArray *array,  guint index_,  guint length);
323 		auto p = g_array_remove_range(gArray, index, length);
324 		
325 		if(p is null)
326 		{
327 			return null;
328 		}
329 		
330 		return new ArrayG(cast(GArray*) p);
331 	}
332 	
333 	/**
334 	 * Sorts a GArray using compare_func which should be a qsort()-style
335 	 * comparison function (returns less than zero for first arg is less
336 	 * than second arg, zero for equal, greater zero if first arg is
337 	 * greater than second arg).
338 	 * If two array elements compare equal, their order in the sorted array
339 	 * is undefined.
340 	 * Params:
341 	 * compareFunc = comparison function.
342 	 */
343 	public void sort(GCompareFunc compareFunc)
344 	{
345 		// void g_array_sort (GArray *array,  GCompareFunc compare_func);
346 		g_array_sort(gArray, compareFunc);
347 	}
348 	
349 	/**
350 	 * Like g_array_sort(), but the comparison function receives an extra
351 	 * user data argument.
352 	 * Params:
353 	 * compareFunc = comparison function.
354 	 * userData = data to pass to compare_func.
355 	 */
356 	public void sortWithData(GCompareDataFunc compareFunc, void* userData)
357 	{
358 		// void g_array_sort_with_data (GArray *array,  GCompareDataFunc compare_func,  gpointer user_data);
359 		g_array_sort_with_data(gArray, compareFunc, userData);
360 	}
361 	
362 	/**
363 	 * Sets the size of the array, expanding it if necessary. If the array
364 	 * was created with clear_ set to TRUE, the new elements are set to 0.
365 	 * Params:
366 	 * length = the new size of the GArray.
367 	 * Returns: the GArray.
368 	 */
369 	public ArrayG setSize(uint length)
370 	{
371 		// GArray * g_array_set_size (GArray *array,  guint length);
372 		auto p = g_array_set_size(gArray, length);
373 		
374 		if(p is null)
375 		{
376 			return null;
377 		}
378 		
379 		return new ArrayG(cast(GArray*) p);
380 	}
381 	
382 	/**
383 	 * Frees the memory allocated for the GArray. If free_segment is
384 	 * TRUE it frees the memory block holding the elements as well and
385 	 * also each element if array has a element_free_func set. Pass
386 	 * FALSE if you want to free the GArray wrapper but preserve the
387 	 * underlying array for use elsewhere. If the reference count of array
388 	 * is greater than one, the GArray wrapper is preserved but the size
389 	 * of array will be set to zero.
390 	 * Note
391 	 * If array elements contain dynamically-allocated memory,
392 	 * they should be freed separately.
393 	 * Params:
394 	 * freeSegment = if TRUE the actual element data is freed as well.
395 	 * Returns: the element data if free_segment is FALSE, otherwise NULL. The element data should be freed using g_free().
396 	 */
397 	public string free(int freeSegment)
398 	{
399 		// gchar * g_array_free (GArray *array,  gboolean free_segment);
400 		return Str.toString(g_array_free(gArray, freeSegment));
401 	}
402 }