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 module gobject.ValueArray;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Value;
30 private import gobject.c.functions;
31 public  import gobject.c.types;
32 public  import gtkc.gobjecttypes;
33 private import gtkd.Loader;
34 
35 
36 /**
37  * A #GValueArray contains an array of #GValue elements.
38  */
39 public class ValueArray
40 {
41 	/** the main Gtk struct */
42 	protected GValueArray* gValueArray;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GValueArray* getValueArrayStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gValueArray;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gValueArray;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GValueArray* gValueArray, bool ownedRef = false)
63 	{
64 		this.gValueArray = gValueArray;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 	~this ()
69 	{
70 		if ( Linker.isLoaded(LIBRARY_GOBJECT) && ownedRef )
71 			g_value_array_free(gValueArray);
72 	}
73 
74 
75 	/** */
76 	public static GType getType()
77 	{
78 		return g_value_array_get_type();
79 	}
80 
81 	/**
82 	 * Allocate and initialize a new #GValueArray, optionally preserve space
83 	 * for @n_prealloced elements. New arrays always contain 0 elements,
84 	 * regardless of the value of @n_prealloced.
85 	 *
86 	 * Deprecated: Use #GArray and g_array_sized_new() instead.
87 	 *
88 	 * Params:
89 	 *     nPrealloced = number of values to preallocate space for
90 	 *
91 	 * Returns: a newly allocated #GValueArray with 0 values
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(uint nPrealloced)
96 	{
97 		auto p = g_value_array_new(nPrealloced);
98 
99 		if(p is null)
100 		{
101 			throw new ConstructionException("null returned by new");
102 		}
103 
104 		this(cast(GValueArray*) p);
105 	}
106 
107 	/**
108 	 * Insert a copy of @value as last element of @value_array. If @value is
109 	 * %NULL, an uninitialized value is appended.
110 	 *
111 	 * Deprecated: Use #GArray and g_array_append_val() instead.
112 	 *
113 	 * Params:
114 	 *     value = #GValue to copy into #GValueArray, or %NULL
115 	 *
116 	 * Returns: the #GValueArray passed in as @value_array
117 	 */
118 	public ValueArray append(Value value)
119 	{
120 		auto p = g_value_array_append(gValueArray, (value is null) ? null : value.getValueStruct());
121 
122 		if(p is null)
123 		{
124 			return null;
125 		}
126 
127 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
128 	}
129 
130 	/**
131 	 * Construct an exact copy of a #GValueArray by duplicating all its
132 	 * contents.
133 	 *
134 	 * Deprecated: Use #GArray and g_array_ref() instead.
135 	 *
136 	 * Returns: Newly allocated copy of #GValueArray
137 	 */
138 	public ValueArray copy()
139 	{
140 		auto p = g_value_array_copy(gValueArray);
141 
142 		if(p is null)
143 		{
144 			return null;
145 		}
146 
147 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p, true);
148 	}
149 
150 	/**
151 	 * Free a #GValueArray including its contents.
152 	 *
153 	 * Deprecated: Use #GArray and g_array_unref() instead.
154 	 */
155 	public void free()
156 	{
157 		g_value_array_free(gValueArray);
158 		ownedRef = false;
159 	}
160 
161 	/**
162 	 * Return a pointer to the value at @index_ containd in @value_array.
163 	 *
164 	 * Deprecated: Use g_array_index() instead.
165 	 *
166 	 * Params:
167 	 *     index = index of the value of interest
168 	 *
169 	 * Returns: pointer to a value at @index_ in @value_array
170 	 */
171 	public Value getNth(uint index)
172 	{
173 		auto p = g_value_array_get_nth(gValueArray, index);
174 
175 		if(p is null)
176 		{
177 			return null;
178 		}
179 
180 		return ObjectG.getDObject!(Value)(cast(GValue*) p);
181 	}
182 
183 	/**
184 	 * Insert a copy of @value at specified position into @value_array. If @value
185 	 * is %NULL, an uninitialized value is inserted.
186 	 *
187 	 * Deprecated: Use #GArray and g_array_insert_val() instead.
188 	 *
189 	 * Params:
190 	 *     index = insertion position, must be <= value_array->;n_values
191 	 *     value = #GValue to copy into #GValueArray, or %NULL
192 	 *
193 	 * Returns: the #GValueArray passed in as @value_array
194 	 */
195 	public ValueArray insert(uint index, Value value)
196 	{
197 		auto p = g_value_array_insert(gValueArray, index, (value is null) ? null : value.getValueStruct());
198 
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
205 	}
206 
207 	/**
208 	 * Insert a copy of @value as first element of @value_array. If @value is
209 	 * %NULL, an uninitialized value is prepended.
210 	 *
211 	 * Deprecated: Use #GArray and g_array_prepend_val() instead.
212 	 *
213 	 * Params:
214 	 *     value = #GValue to copy into #GValueArray, or %NULL
215 	 *
216 	 * Returns: the #GValueArray passed in as @value_array
217 	 */
218 	public ValueArray prepend(Value value)
219 	{
220 		auto p = g_value_array_prepend(gValueArray, (value is null) ? null : value.getValueStruct());
221 
222 		if(p is null)
223 		{
224 			return null;
225 		}
226 
227 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
228 	}
229 
230 	/**
231 	 * Remove the value at position @index_ from @value_array.
232 	 *
233 	 * Deprecated: Use #GArray and g_array_remove_index() instead.
234 	 *
235 	 * Params:
236 	 *     index = position of value to remove, which must be less than
237 	 *         @value_array->n_values
238 	 *
239 	 * Returns: the #GValueArray passed in as @value_array
240 	 */
241 	public ValueArray remove(uint index)
242 	{
243 		auto p = g_value_array_remove(gValueArray, index);
244 
245 		if(p is null)
246 		{
247 			return null;
248 		}
249 
250 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
251 	}
252 
253 	/**
254 	 * Sort @value_array using @compare_func to compare the elements according to
255 	 * the semantics of #GCompareFunc.
256 	 *
257 	 * The current implementation uses the same sorting algorithm as standard
258 	 * C qsort() function.
259 	 *
260 	 * Deprecated: Use #GArray and g_array_sort().
261 	 *
262 	 * Params:
263 	 *     compareFunc = function to compare elements
264 	 *
265 	 * Returns: the #GValueArray passed in as @value_array
266 	 */
267 	public ValueArray sort(GCompareFunc compareFunc)
268 	{
269 		auto p = g_value_array_sort(gValueArray, compareFunc);
270 
271 		if(p is null)
272 		{
273 			return null;
274 		}
275 
276 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
277 	}
278 
279 	/**
280 	 * Sort @value_array using @compare_func to compare the elements according
281 	 * to the semantics of #GCompareDataFunc.
282 	 *
283 	 * The current implementation uses the same sorting algorithm as standard
284 	 * C qsort() function.
285 	 *
286 	 * Deprecated: Use #GArray and g_array_sort_with_data().
287 	 *
288 	 * Params:
289 	 *     compareFunc = function to compare elements
290 	 *     userData = extra data argument provided for @compare_func
291 	 *
292 	 * Returns: the #GValueArray passed in as @value_array
293 	 */
294 	public ValueArray sortWithData(GCompareDataFunc compareFunc, void* userData)
295 	{
296 		auto p = g_value_array_sort_with_data(gValueArray, compareFunc, userData);
297 
298 		if(p is null)
299 		{
300 			return null;
301 		}
302 
303 		return ObjectG.getDObject!(ValueArray)(cast(GValueArray*) p);
304 	}
305 }