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 	 * Drops the queue element at position @idx from queue @array.
77 	 *
78 	 * Params:
79 	 *     idx = index to drop
80 	 *
81 	 * Returns: the dropped element
82 	 *
83 	 * Since: 1.2
84 	 */
85 	public void* dropElement(uint idx)
86 	{
87 		return gst_queue_array_drop_element(gstQueueArray, idx);
88 	}
89 
90 	/**
91 	 * Drops the queue element at position @idx from queue @array and copies the
92 	 * data of the element or structure that was removed into @p_struct if
93 	 * @p_struct is set (not NULL).
94 	 *
95 	 * Params:
96 	 *     idx = index to drop
97 	 *     pStruct = address into which to store the data of the dropped structure, or NULL
98 	 *
99 	 * Returns: TRUE on success, or FALSE on error
100 	 *
101 	 * Since: 1.6
102 	 */
103 	public bool dropStruct(uint idx, void* pStruct)
104 	{
105 		return gst_queue_array_drop_struct(gstQueueArray, idx, pStruct) != 0;
106 	}
107 
108 	/**
109 	 * Finds an element in the queue @array, either by comparing every element
110 	 * with @func or by looking up @data if no compare function @func is provided,
111 	 * and returning the index of the found element.
112 	 *
113 	 * Note that the index is not 0-based, but an internal index number with a
114 	 * random offset. The index can be used in connection with
115 	 * gst_queue_array_drop_element(). FIXME: return index 0-based and make
116 	 * gst_queue_array_drop_element() take a 0-based index.
117 	 *
118 	 * Params:
119 	 *     func = comparison function, or %NULL to find @data by value
120 	 *     data = data for comparison function
121 	 *
122 	 * Returns: Index of the found element or -1 if nothing was found.
123 	 *
124 	 * Since: 1.2
125 	 */
126 	public uint find(GCompareFunc func, void* data)
127 	{
128 		return gst_queue_array_find(gstQueueArray, func, data);
129 	}
130 
131 	/**
132 	 * Frees queue @array and all memory associated to it.
133 	 *
134 	 * Since: 1.2
135 	 */
136 	public void free()
137 	{
138 		gst_queue_array_free(gstQueueArray);
139 		ownedRef = false;
140 	}
141 
142 	/**
143 	 * Returns the length of the queue @array
144 	 *
145 	 * Returns: the length of the queue @array.
146 	 *
147 	 * Since: 1.2
148 	 */
149 	public uint getLength()
150 	{
151 		return gst_queue_array_get_length(gstQueueArray);
152 	}
153 
154 	/**
155 	 * Checks if the queue @array is empty.
156 	 *
157 	 * Returns: %TRUE if the queue @array is empty
158 	 *
159 	 * Since: 1.2
160 	 */
161 	public bool isEmpty()
162 	{
163 		return gst_queue_array_is_empty(gstQueueArray) != 0;
164 	}
165 
166 	/**
167 	 * Returns the head of the queue @array and does not
168 	 * remove it from the queue.
169 	 *
170 	 * Returns: The head of the queue
171 	 *
172 	 * Since: 1.2
173 	 */
174 	public void* peekHead()
175 	{
176 		return gst_queue_array_peek_head(gstQueueArray);
177 	}
178 
179 	/**
180 	 * Returns the head of the queue @array without removing it from the queue.
181 	 *
182 	 * Returns: pointer to element or struct, or NULL if @array was empty. The
183 	 *     data pointed to by the returned pointer stays valid only as long as
184 	 *     the queue array is not modified further!
185 	 *
186 	 * Since: 1.6
187 	 */
188 	public void* peekHeadStruct()
189 	{
190 		return gst_queue_array_peek_head_struct(gstQueueArray);
191 	}
192 
193 	/**
194 	 * Returns the tail of the queue @array, but does not remove it from the queue.
195 	 *
196 	 * Returns: The tail of the queue
197 	 *
198 	 * Since: 1.14
199 	 */
200 	public void* peekTail()
201 	{
202 		return gst_queue_array_peek_tail(gstQueueArray);
203 	}
204 
205 	/**
206 	 * Returns the tail of the queue @array, but does not remove it from the queue.
207 	 *
208 	 * Returns: The tail of the queue
209 	 *
210 	 * Since: 1.14
211 	 */
212 	public void* peekTailStruct()
213 	{
214 		return gst_queue_array_peek_tail_struct(gstQueueArray);
215 	}
216 
217 	/**
218 	 * Returns and head of the queue @array and removes
219 	 * it from the queue.
220 	 *
221 	 * Returns: The head of the queue
222 	 *
223 	 * Since: 1.2
224 	 */
225 	public void* popHead()
226 	{
227 		return gst_queue_array_pop_head(gstQueueArray);
228 	}
229 
230 	/**
231 	 * Returns the head of the queue @array and removes it from the queue.
232 	 *
233 	 * Returns: pointer to element or struct, or NULL if @array was empty. The
234 	 *     data pointed to by the returned pointer stays valid only as long as
235 	 *     the queue array is not modified further!
236 	 *
237 	 * Since: 1.6
238 	 */
239 	public void* popHeadStruct()
240 	{
241 		return gst_queue_array_pop_head_struct(gstQueueArray);
242 	}
243 
244 	/**
245 	 * Returns the tail of the queue @array and removes
246 	 * it from the queue.
247 	 *
248 	 * Returns: The tail of the queue
249 	 *
250 	 * Since: 1.14
251 	 */
252 	public void* popTail()
253 	{
254 		return gst_queue_array_pop_tail(gstQueueArray);
255 	}
256 
257 	/**
258 	 * Returns the tail of the queue @array and removes
259 	 * it from the queue.
260 	 *
261 	 * Returns: The tail of the queue
262 	 *
263 	 * Since: 1.14
264 	 */
265 	public void* popTailStruct()
266 	{
267 		return gst_queue_array_pop_tail_struct(gstQueueArray);
268 	}
269 
270 	/**
271 	 * Pushes @data to the tail of the queue @array.
272 	 *
273 	 * Params:
274 	 *     data = object to push
275 	 *
276 	 * Since: 1.2
277 	 */
278 	public void pushTail(void* data)
279 	{
280 		gst_queue_array_push_tail(gstQueueArray, data);
281 	}
282 
283 	/** */
284 	public void pushTailStruct(void* pStruct)
285 	{
286 		gst_queue_array_push_tail_struct(gstQueueArray, pStruct);
287 	}
288 
289 	/**
290 	 * Allocates a new #GstQueueArray object with an initial
291 	 * queue size of @initial_size.
292 	 *
293 	 * Params:
294 	 *     initialSize = Initial size of the new queue
295 	 *
296 	 * Returns: a new #GstQueueArray object
297 	 *
298 	 * Since: 1.2
299 	 *
300 	 * Throws: ConstructionException GTK+ fails to create the object.
301 	 */
302 	public this(uint initialSize)
303 	{
304 		auto p = gst_queue_array_new(initialSize);
305 
306 		if(p is null)
307 		{
308 			throw new ConstructionException("null returned by new");
309 		}
310 
311 		this(cast(GstQueueArray*) p);
312 	}
313 
314 	/**
315 	 * Allocates a new #GstQueueArray object for elements (e.g. structures)
316 	 * of size @struct_size, with an initial queue size of @initial_size.
317 	 *
318 	 * Params:
319 	 *     structSize = Size of each element (e.g. structure) in the array
320 	 *     initialSize = Initial size of the new queue
321 	 *
322 	 * Returns: a new #GstQueueArray object
323 	 *
324 	 * Since: 1.6
325 	 *
326 	 * Throws: ConstructionException GTK+ fails to create the object.
327 	 */
328 	public this(size_t structSize, uint initialSize)
329 	{
330 		auto p = gst_queue_array_new_for_struct(structSize, initialSize);
331 
332 		if(p is null)
333 		{
334 			throw new ConstructionException("null returned by new_for_struct");
335 		}
336 
337 		this(cast(GstQueueArray*) p);
338 	}
339 }