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 gst.base.QueueArray;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gst.base.c.functions;
30 public  import gst.base.c.types;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * #GstQueueArray is an object that provides standard queue functionality
36  * based on an array instead of linked lists. This reduces the overhead
37  * caused by memory management by a large factor.
38  */
39 public class QueueArray
40 {
41 	/** the main Gtk struct */
42 	protected GstQueueArray* gstQueueArray;
43 	protected bool ownedRef;
44 
45 	/** Get the main Gtk struct */
46 	public GstQueueArray* getQueueArrayStruct(bool transferOwnership = false)
47 	{
48 		if (transferOwnership)
49 			ownedRef = false;
50 		return gstQueueArray;
51 	}
52 
53 	/** the main Gtk struct as a void* */
54 	protected void* getStruct()
55 	{
56 		return cast(void*)gstQueueArray;
57 	}
58 
59 	/**
60 	 * Sets our main struct and passes it to the parent class.
61 	 */
62 	public this (GstQueueArray* gstQueueArray, bool ownedRef = false)
63 	{
64 		this.gstQueueArray = gstQueueArray;
65 		this.ownedRef = ownedRef;
66 	}
67 
68 	~this ()
69 	{
70 		if ( Linker.isLoaded(LIBRARY_GSTBASE) && ownedRef )
71 			gst_queue_array_free(gstQueueArray);
72 	}
73 
74 
75 	/**
76 	 * Clears queue @array and frees all memory associated to it.
77 	 *
78 	 * Since: 1.16
79 	 */
80 	public void clear()
81 	{
82 		gst_queue_array_clear(gstQueueArray);
83 	}
84 
85 	/**
86 	 * Drops the queue element at position @idx from queue @array.
87 	 *
88 	 * Params:
89 	 *     idx = index to drop
90 	 *
91 	 * Returns: the dropped element
92 	 *
93 	 * Since: 1.2
94 	 */
95 	public void* dropElement(uint idx)
96 	{
97 		return gst_queue_array_drop_element(gstQueueArray, idx);
98 	}
99 
100 	/**
101 	 * Drops the queue element at position @idx from queue @array and copies the
102 	 * data of the element or structure that was removed into @p_struct if
103 	 * @p_struct is set (not NULL).
104 	 *
105 	 * Params:
106 	 *     idx = index to drop
107 	 *     pStruct = address into which to store the data of the dropped structure, or NULL
108 	 *
109 	 * Returns: TRUE on success, or FALSE on error
110 	 *
111 	 * Since: 1.6
112 	 */
113 	public bool dropStruct(uint idx, void* pStruct)
114 	{
115 		return gst_queue_array_drop_struct(gstQueueArray, idx, pStruct) != 0;
116 	}
117 
118 	/**
119 	 * Finds an element in the queue @array, either by comparing every element
120 	 * with @func or by looking up @data if no compare function @func is provided,
121 	 * and returning the index of the found element.
122 	 *
123 	 * Params:
124 	 *     func = comparison function, or %NULL to find @data by value
125 	 *     data = data for comparison function
126 	 *
127 	 * Returns: Index of the found element or -1 if nothing was found.
128 	 *
129 	 * Since: 1.2
130 	 */
131 	public uint find(GCompareFunc func, void* data)
132 	{
133 		return gst_queue_array_find(gstQueueArray, func, data);
134 	}
135 
136 	/**
137 	 * Frees queue @array and all memory associated to it.
138 	 *
139 	 * Since: 1.2
140 	 */
141 	public void free()
142 	{
143 		gst_queue_array_free(gstQueueArray);
144 		ownedRef = false;
145 	}
146 
147 	/**
148 	 * Returns the length of the queue @array
149 	 *
150 	 * Returns: the length of the queue @array.
151 	 *
152 	 * Since: 1.2
153 	 */
154 	public uint getLength()
155 	{
156 		return gst_queue_array_get_length(gstQueueArray);
157 	}
158 
159 	/**
160 	 * Checks if the queue @array is empty.
161 	 *
162 	 * Returns: %TRUE if the queue @array is empty
163 	 *
164 	 * Since: 1.2
165 	 */
166 	public bool isEmpty()
167 	{
168 		return gst_queue_array_is_empty(gstQueueArray) != 0;
169 	}
170 
171 	/**
172 	 * Returns the head of the queue @array and does not
173 	 * remove it from the queue.
174 	 *
175 	 * Returns: The head of the queue
176 	 *
177 	 * Since: 1.2
178 	 */
179 	public void* peekHead()
180 	{
181 		return gst_queue_array_peek_head(gstQueueArray);
182 	}
183 
184 	/**
185 	 * Returns the head of the queue @array without removing it from the queue.
186 	 *
187 	 * Returns: pointer to element or struct, or NULL if @array was empty. The
188 	 *     data pointed to by the returned pointer stays valid only as long as
189 	 *     the queue array is not modified further!
190 	 *
191 	 * Since: 1.6
192 	 */
193 	public void* peekHeadStruct()
194 	{
195 		return gst_queue_array_peek_head_struct(gstQueueArray);
196 	}
197 
198 	/**
199 	 * Returns the item at @idx in @array, but does not remove it from the queue.
200 	 *
201 	 * Returns: The item, or %NULL if @idx was out of bounds
202 	 *
203 	 * Since: 1.16
204 	 */
205 	public void* peekNth(uint idx)
206 	{
207 		return gst_queue_array_peek_nth(gstQueueArray, idx);
208 	}
209 
210 	/**
211 	 * Returns the item at @idx in @array, but does not remove it from the queue.
212 	 *
213 	 * Returns: The item, or %NULL if @idx was out of bounds
214 	 *
215 	 * Since: 1.16
216 	 */
217 	public void* peekNthStruct(uint idx)
218 	{
219 		return gst_queue_array_peek_nth_struct(gstQueueArray, idx);
220 	}
221 
222 	/**
223 	 * Returns the tail of the queue @array, but does not remove it from the queue.
224 	 *
225 	 * Returns: The tail of the queue
226 	 *
227 	 * Since: 1.14
228 	 */
229 	public void* peekTail()
230 	{
231 		return gst_queue_array_peek_tail(gstQueueArray);
232 	}
233 
234 	/**
235 	 * Returns the tail of the queue @array, but does not remove it from the queue.
236 	 *
237 	 * Returns: The tail of the queue
238 	 *
239 	 * Since: 1.14
240 	 */
241 	public void* peekTailStruct()
242 	{
243 		return gst_queue_array_peek_tail_struct(gstQueueArray);
244 	}
245 
246 	/**
247 	 * Returns and head of the queue @array and removes
248 	 * it from the queue.
249 	 *
250 	 * Returns: The head of the queue
251 	 *
252 	 * Since: 1.2
253 	 */
254 	public void* popHead()
255 	{
256 		return gst_queue_array_pop_head(gstQueueArray);
257 	}
258 
259 	/**
260 	 * Returns the head of the queue @array and removes it from the queue.
261 	 *
262 	 * Returns: pointer to element or struct, or NULL if @array was empty. The
263 	 *     data pointed to by the returned pointer stays valid only as long as
264 	 *     the queue array is not modified further!
265 	 *
266 	 * Since: 1.6
267 	 */
268 	public void* popHeadStruct()
269 	{
270 		return gst_queue_array_pop_head_struct(gstQueueArray);
271 	}
272 
273 	/**
274 	 * Returns the tail of the queue @array and removes
275 	 * it from the queue.
276 	 *
277 	 * Returns: The tail of the queue
278 	 *
279 	 * Since: 1.14
280 	 */
281 	public void* popTail()
282 	{
283 		return gst_queue_array_pop_tail(gstQueueArray);
284 	}
285 
286 	/**
287 	 * Returns the tail of the queue @array and removes
288 	 * it from the queue.
289 	 *
290 	 * Returns: The tail of the queue
291 	 *
292 	 * Since: 1.14
293 	 */
294 	public void* popTailStruct()
295 	{
296 		return gst_queue_array_pop_tail_struct(gstQueueArray);
297 	}
298 
299 	/**
300 	 * Pushes @data to the tail of the queue @array.
301 	 *
302 	 * Params:
303 	 *     data = object to push
304 	 *
305 	 * Since: 1.2
306 	 */
307 	public void pushTail(void* data)
308 	{
309 		gst_queue_array_push_tail(gstQueueArray, data);
310 	}
311 
312 	/** */
313 	public void pushTailStruct(void* pStruct)
314 	{
315 		gst_queue_array_push_tail_struct(gstQueueArray, pStruct);
316 	}
317 
318 	/**
319 	 * Sets a function to clear an element of @array.
320 	 *
321 	 * The @clear_func will be called when an element in the array
322 	 * data segment is removed and when the array is freed and data
323 	 * segment is deallocated as well. @clear_func will be passed a
324 	 * pointer to the element to clear, rather than the element itself.
325 	 *
326 	 * Note that in contrast with other uses of #GDestroyNotify
327 	 * functions, @clear_func is expected to clear the contents of
328 	 * the array element it is given, but not free the element itself.
329 	 *
330 	 * Params:
331 	 *     clearFunc = a function to clear an element of @array
332 	 *
333 	 * Since: 1.16
334 	 */
335 	public void setClearFunc(GDestroyNotify clearFunc)
336 	{
337 		gst_queue_array_set_clear_func(gstQueueArray, clearFunc);
338 	}
339 
340 	/**
341 	 * Allocates a new #GstQueueArray object with an initial
342 	 * queue size of @initial_size.
343 	 *
344 	 * Params:
345 	 *     initialSize = Initial size of the new queue
346 	 *
347 	 * Returns: a new #GstQueueArray object
348 	 *
349 	 * Since: 1.2
350 	 *
351 	 * Throws: ConstructionException GTK+ fails to create the object.
352 	 */
353 	public this(uint initialSize)
354 	{
355 		auto __p = gst_queue_array_new(initialSize);
356 
357 		if(__p is null)
358 		{
359 			throw new ConstructionException("null returned by new");
360 		}
361 
362 		this(cast(GstQueueArray*) __p);
363 	}
364 
365 	/**
366 	 * Allocates a new #GstQueueArray object for elements (e.g. structures)
367 	 * of size @struct_size, with an initial queue size of @initial_size.
368 	 *
369 	 * Params:
370 	 *     structSize = Size of each element (e.g. structure) in the array
371 	 *     initialSize = Initial size of the new queue
372 	 *
373 	 * Returns: a new #GstQueueArray object
374 	 *
375 	 * Since: 1.6
376 	 *
377 	 * Throws: ConstructionException GTK+ fails to create the object.
378 	 */
379 	public this(size_t structSize, uint initialSize)
380 	{
381 		auto __p = gst_queue_array_new_for_struct(structSize, initialSize);
382 
383 		if(__p is null)
384 		{
385 			throw new ConstructionException("null returned by new_for_struct");
386 		}
387 
388 		this(cast(GstQueueArray*) __p);
389 	}
390 }