source: appstream-generator/build/girepo/glib/PtrArray.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 11.8 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.PtrArray;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ConstructionException;
26
27
28/**
29 * Contains the public fields of a pointer array.
30 */
31public class PtrArray
32{
33        /** the main Gtk struct */
34        protected GPtrArray* gPtrArray;
35        protected bool ownedRef;
36
37        /** Get the main Gtk struct */
38        public GPtrArray* getPtrArrayStruct()
39        {
40                return gPtrArray;
41        }
42
43        /** the main Gtk struct as a void* */
44        protected void* getStruct()
45        {
46                return cast(void*)gPtrArray;
47        }
48
49        /**
50         * Sets our main struct and passes it to the parent class.
51         */
52        public this (GPtrArray* gPtrArray, bool ownedRef = false)
53        {
54                this.gPtrArray = gPtrArray;
55                this.ownedRef = ownedRef;
56        }
57
58        /**
59         * Number of pointers in the array
60         */
61        public uint len ()
62        {
63                return gPtrArray.len;
64        }
65       
66        /**
67         * Returns the pointer at the given index of the pointer array.
68         *
69         * This does not perform bounds checking on the given index, so
70         * you are responsible for checking it against the array length.
71         */
72        public void* index (uint idx)
73        {
74                return (gPtrArray.pdata)[idx];
75        }
76
77        /**
78         */
79
80        /**
81         * Adds a pointer to the end of the pointer array. The array will grow
82         * in size automatically if necessary.
83         *
84         * Params:
85         *     data = the pointer to add
86         */
87        public void add(void* data)
88        {
89                g_ptr_array_add(gPtrArray, data);
90        }
91
92        /**
93         * Calls a function for each element of a #GPtrArray.
94         *
95         * Params:
96         *     func = the function to call for each array element
97         *     userData = user data to pass to the function
98         *
99         * Since: 2.4
100         */
101        public void foreac(GFunc func, void* userData)
102        {
103                g_ptr_array_foreach(gPtrArray, func, userData);
104        }
105
106        /**
107         * Frees the memory allocated for the #GPtrArray. If @free_seg is %TRUE
108         * it frees the memory block holding the elements as well. Pass %FALSE
109         * if you want to free the #GPtrArray wrapper but preserve the
110         * underlying array for use elsewhere. If the reference count of @array
111         * is greater than one, the #GPtrArray wrapper is preserved but the
112         * size of @array will be set to zero.
113         *
114         * If array contents point to dynamically-allocated memory, they should
115         * be freed separately if @free_seg is %TRUE and no #GDestroyNotify
116         * function has been set for @array.
117         *
118         * Params:
119         *     freeSeg = if %TRUE the actual pointer array is freed as well
120         *
121         * Returns: the pointer array if @free_seg is %FALSE, otherwise %NULL.
122         *     The pointer array should be freed using g_free().
123         */
124        public void** free(bool freeSeg)
125        {
126                return g_ptr_array_free(gPtrArray, freeSeg);
127        }
128
129        /**
130         * Inserts an element into the pointer array at the given index. The
131         * array will grow in size automatically if necessary.
132         *
133         * Params:
134         *     index = the index to place the new element at, or -1 to append
135         *     data = the pointer to add.
136         *
137         * Since: 2.40
138         */
139        public void insert(int index, void* data)
140        {
141                g_ptr_array_insert(gPtrArray, index, data);
142        }
143
144        /**
145         * Creates a new #GPtrArray with a reference count of 1.
146         *
147         * Returns: the new #GPtrArray
148         *
149         * Throws: ConstructionException GTK+ fails to create the object.
150         */
151        public this()
152        {
153                auto p = g_ptr_array_new();
154               
155                if(p is null)
156                {
157                        throw new ConstructionException("null returned by new");
158                }
159               
160                this(cast(GPtrArray*) p);
161        }
162
163        /**
164         * Creates a new #GPtrArray with @reserved_size pointers preallocated
165         * and a reference count of 1. This avoids frequent reallocation, if
166         * you are going to add many pointers to the array. Note however that
167         * the size of the array is still 0. It also set @element_free_func
168         * for freeing each element when the array is destroyed either via
169         * g_ptr_array_unref(), when g_ptr_array_free() is called with
170         * @free_segment set to %TRUE or when removing elements.
171         *
172         * Params:
173         *     reservedSize = number of pointers preallocated
174         *     elementFreeFunc = A function to free elements with
175         *         destroy @array or %NULL
176         *
177         * Returns: A new #GPtrArray
178         *
179         * Since: 2.30
180         *
181         * Throws: ConstructionException GTK+ fails to create the object.
182         */
183        public this(uint reservedSize, GDestroyNotify elementFreeFunc)
184        {
185                auto p = g_ptr_array_new_full(reservedSize, elementFreeFunc);
186               
187                if(p is null)
188                {
189                        throw new ConstructionException("null returned by new_full");
190                }
191               
192                this(cast(GPtrArray*) p);
193        }
194
195        /**
196         * Creates a new #GPtrArray with a reference count of 1 and use
197         * @element_free_func for freeing each element when the array is destroyed
198         * either via g_ptr_array_unref(), when g_ptr_array_free() is called with
199         * @free_segment set to %TRUE or when removing elements.
200         *
201         * Params:
202         *     elementFreeFunc = A function to free elements with
203         *         destroy @array or %NULL
204         *
205         * Returns: A new #GPtrArray
206         *
207         * Since: 2.22
208         *
209         * Throws: ConstructionException GTK+ fails to create the object.
210         */
211        public this(GDestroyNotify elementFreeFunc)
212        {
213                auto p = g_ptr_array_new_with_free_func(elementFreeFunc);
214               
215                if(p is null)
216                {
217                        throw new ConstructionException("null returned by new_with_free_func");
218                }
219               
220                this(cast(GPtrArray*) p);
221        }
222
223        /**
224         * Atomically increments the reference count of @array by one.
225         * This function is thread-safe and may be called from any thread.
226         *
227         * Returns: The passed in #GPtrArray
228         *
229         * Since: 2.22
230         */
231        public PtrArray doref()
232        {
233                auto p = g_ptr_array_ref(gPtrArray);
234               
235                if(p is null)
236                {
237                        return null;
238                }
239               
240                return new PtrArray(cast(GPtrArray*) p);
241        }
242
243        /**
244         * Removes the first occurrence of the given pointer from the pointer
245         * array. The following elements are moved down one place. If @array
246         * has a non-%NULL #GDestroyNotify function it is called for the
247         * removed element.
248         *
249         * It returns %TRUE if the pointer was removed, or %FALSE if the
250         * pointer was not found.
251         *
252         * Params:
253         *     data = the pointer to remove
254         *
255         * Returns: %TRUE if the pointer is removed, %FALSE if the pointer
256         *     is not found in the array
257         */
258        public bool remove(void* data)
259        {
260                return g_ptr_array_remove(gPtrArray, data) != 0;
261        }
262
263        /**
264         * Removes the first occurrence of the given pointer from the pointer
265         * array. The last element in the array is used to fill in the space,
266         * so this function does not preserve the order of the array. But it
267         * is faster than g_ptr_array_remove(). If @array has a non-%NULL
268         * #GDestroyNotify function it is called for the removed element.
269         *
270         * It returns %TRUE if the pointer was removed, or %FALSE if the
271         * pointer was not found.
272         *
273         * Params:
274         *     data = the pointer to remove
275         *
276         * Returns: %TRUE if the pointer was found in the array
277         */
278        public bool removeFast(void* data)
279        {
280                return g_ptr_array_remove_fast(gPtrArray, data) != 0;
281        }
282
283        /**
284         * Removes the pointer at the given index from the pointer array.
285         * The following elements are moved down one place. If @array has
286         * a non-%NULL #GDestroyNotify function it is called for the removed
287         * element.
288         *
289         * Params:
290         *     index = the index of the pointer to remove
291         *
292         * Returns: the pointer which was removed
293         */
294        public void* removeIndex(uint index)
295        {
296                return g_ptr_array_remove_index(gPtrArray, index);
297        }
298
299        /**
300         * Removes the pointer at the given index from the pointer array.
301         * The last element in the array is used to fill in the space, so
302         * this function does not preserve the order of the array. But it
303         * is faster than g_ptr_array_remove_index(). If @array has a non-%NULL
304         * #GDestroyNotify function it is called for the removed element.
305         *
306         * Params:
307         *     index = the index of the pointer to remove
308         *
309         * Returns: the pointer which was removed
310         */
311        public void* removeIndexFast(uint index)
312        {
313                return g_ptr_array_remove_index_fast(gPtrArray, index);
314        }
315
316        /**
317         * Removes the given number of pointers starting at the given index
318         * from a #GPtrArray. The following elements are moved to close the
319         * gap. If @array has a non-%NULL #GDestroyNotify function it is
320         * called for the removed elements.
321         *
322         * Params:
323         *     index = the index of the first pointer to remove
324         *     length = the number of pointers to remove
325         *
326         * Returns: the @array
327         *
328         * Since: 2.4
329         */
330        public PtrArray removeRange(uint index, uint length)
331        {
332                auto p = g_ptr_array_remove_range(gPtrArray, index, length);
333               
334                if(p is null)
335                {
336                        return null;
337                }
338               
339                return new PtrArray(cast(GPtrArray*) p);
340        }
341
342        /**
343         * Sets a function for freeing each element when @array is destroyed
344         * either via g_ptr_array_unref(), when g_ptr_array_free() is called
345         * with @free_segment set to %TRUE or when removing elements.
346         *
347         * Params:
348         *     elementFreeFunc = A function to free elements with
349         *         destroy @array or %NULL
350         *
351         * Since: 2.22
352         */
353        public void setFreeFunc(GDestroyNotify elementFreeFunc)
354        {
355                g_ptr_array_set_free_func(gPtrArray, elementFreeFunc);
356        }
357
358        /**
359         * Sets the size of the array. When making the array larger,
360         * newly-added elements will be set to %NULL. When making it smaller,
361         * if @array has a non-%NULL #GDestroyNotify function then it will be
362         * called for the removed elements.
363         *
364         * Params:
365         *     length = the new length of the pointer array
366         */
367        public void setSize(int length)
368        {
369                g_ptr_array_set_size(gPtrArray, length);
370        }
371
372        /**
373         * Creates a new #GPtrArray with @reserved_size pointers preallocated
374         * and a reference count of 1. This avoids frequent reallocation, if
375         * you are going to add many pointers to the array. Note however that
376         * the size of the array is still 0.
377         *
378         * Params:
379         *     reservedSize = number of pointers preallocated
380         *
381         * Returns: the new #GPtrArray
382         */
383        public static PtrArray sizedNew(uint reservedSize)
384        {
385                auto p = g_ptr_array_sized_new(reservedSize);
386               
387                if(p is null)
388                {
389                        return null;
390                }
391               
392                return new PtrArray(cast(GPtrArray*) p);
393        }
394
395        /**
396         * Sorts the array, using @compare_func which should be a qsort()-style
397         * comparison function (returns less than zero for first arg is less
398         * than second arg, zero for equal, greater than zero if irst arg is
399         * greater than second arg).
400         *
401         * Note that the comparison function for g_ptr_array_sort() doesn't
402         * take the pointers from the array as arguments, it takes pointers to
403         * the pointers in the array.
404         *
405         * This is guaranteed to be a stable sort since version 2.32.
406         *
407         * Params:
408         *     compareFunc = comparison function
409         */
410        public void sort(GCompareFunc compareFunc)
411        {
412                g_ptr_array_sort(gPtrArray, compareFunc);
413        }
414
415        /**
416         * Like g_ptr_array_sort(), but the comparison function has an extra
417         * user data argument.
418         *
419         * Note that the comparison function for g_ptr_array_sort_with_data()
420         * doesn't take the pointers from the array as arguments, it takes
421         * pointers to the pointers in the array.
422         *
423         * This is guaranteed to be a stable sort since version 2.32.
424         *
425         * Params:
426         *     compareFunc = comparison function
427         *     userData = data to pass to @compare_func
428         */
429        public void sortWithData(GCompareDataFunc compareFunc, void* userData)
430        {
431                g_ptr_array_sort_with_data(gPtrArray, compareFunc, userData);
432        }
433
434        /**
435         * Atomically decrements the reference count of @array by one. If the
436         * reference count drops to 0, the effect is the same as calling
437         * g_ptr_array_free() with @free_segment set to %TRUE. This function
438         * is MT-safe and may be called from any thread.
439         *
440         * Since: 2.22
441         */
442        public void unref()
443        {
444                g_ptr_array_unref(gPtrArray);
445        }
446}
Note: See TracBrowser for help on using the repository browser.