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  = gstreamer-GstIterator.html
27  * outPack = gstreamer
28  * outFile = Iterator
29  * strct   = GstIterator
30  * realStrct=
31  * ctorStrct=
32  * clss    = Iterator
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_iterator_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ListG
47  * 	- gthread.Mutex
48  * 	- gobject.ObjectG
49  * 	- gobject.Value
50  * structWrap:
51  * 	- GList* -> ListG
52  * 	- GMutex* -> Mutex
53  * 	- GObject* -> ObjectG
54  * 	- GValue* -> Value
55  * 	- GstIterator* -> Iterator
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gstreamer.Iterator;
62 
63 public  import gstreamerc.gstreamertypes;
64 
65 private import gstreamerc.gstreamer;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 
70 private import glib.ListG;
71 private import gthread.Mutex;
72 private import gobject.ObjectG;
73 private import gobject.Value;
74 
75 
76 
77 
78 /**
79  * A GstIterator is used to retrieve multiple objects from another object in
80  * a threadsafe way.
81  *
82  * Various GStreamer objects provide access to their internal structures using
83  * an iterator.
84  *
85  * In general, whenever calling a GstIterator function results in your code
86  * receiving a refcounted object, the refcount for that object will have been
87  * increased. Your code is responsible for unrefing that object after use.
88  *
89  * The basic use pattern of an iterator is as follows:
90  *
91  * $(DDOC_COMMENT example)
92  *
93  * Last reviewed on 2009-06-16 (0.10.24)
94  */
95 public class Iterator
96 {
97 	
98 	/** the main Gtk struct */
99 	protected GstIterator* gstIterator;
100 	
101 	
102 	public GstIterator* getIteratorStruct()
103 	{
104 		return gstIterator;
105 	}
106 	
107 	
108 	/** the main Gtk struct as a void* */
109 	protected void* getStruct()
110 	{
111 		return cast(void*)gstIterator;
112 	}
113 	
114 	/**
115 	 * Sets our main struct and passes it to the parent class
116 	 */
117 	public this (GstIterator* gstIterator)
118 	{
119 		this.gstIterator = gstIterator;
120 	}
121 	
122 	/**
123 	 */
124 	
125 	/**
126 	 * Create a new iterator. This function is mainly used for objects
127 	 * implementing the next/resync/free function to iterate a data structure.
128 	 * For each item retrieved, the item function is called with the lock
129 	 * held. The free function is called when the iterator is freed.
130 	 * Params:
131 	 * size = the size of the iterator structure
132 	 * type = GType of children
133 	 * lock = pointer to a GMutex.
134 	 * masterCookie = pointer to a guint32 that is changed when the items in the
135 	 * iterator changed.
136 	 * copy = copy function
137 	 * next = function to get next item
138 	 * item = function to call on each item retrieved
139 	 * resync = function to resync the iterator
140 	 * free = function to free the iterator
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this (uint size, GType type, Mutex lock, ref uint masterCookie, GstIteratorCopyFunction copy, GstIteratorNextFunction next, GstIteratorItemFunction item, GstIteratorResyncFunction resync, GstIteratorFreeFunction free)
144 	{
145 		// GstIterator * gst_iterator_new (guint size,  GType type,  GMutex *lock,  guint32 *master_cookie,  GstIteratorCopyFunction copy,  GstIteratorNextFunction next,  GstIteratorItemFunction item,  GstIteratorResyncFunction resync,  GstIteratorFreeFunction free);
146 		auto p = gst_iterator_new(size, type, (lock is null) ? null : lock.getMutexStruct(), &masterCookie, copy, next, item, resync, free);
147 		if(p is null)
148 		{
149 			throw new ConstructionException("null returned by gst_iterator_new(size, type, (lock is null) ? null : lock.getMutexStruct(), &masterCookie, copy, next, item, resync, free)");
150 		}
151 		this(cast(GstIterator*) p);
152 	}
153 	
154 	/**
155 	 * Create a new iterator designed for iterating list.
156 	 * The list you iterate is usually part of a data structure owner and is
157 	 * protected with lock.
158 	 * The iterator will use lock to retrieve the next item of the list and it
159 	 * will then call the item function before releasing lock again.
160 	 * When a concurrent update to the list is performed, usually by owner while
161 	 * holding lock, master_cookie will be updated. The iterator implementation
162 	 * will notice the update of the cookie and will return GST_ITERATOR_RESYNC to
163 	 * the user of the iterator in the next call to gst_iterator_next().
164 	 * Params:
165 	 * type = GType of elements
166 	 * lock = pointer to a GMutex protecting the list.
167 	 * masterCookie = pointer to a guint32 that is incremented when the list
168 	 * is changed.
169 	 * list = pointer to the list
170 	 * owner = object owning the list
171 	 * item = function to call on each item retrieved
172 	 * Throws: ConstructionException GTK+ fails to create the object.
173 	 */
174 	public this (GType type, Mutex lock, uint* masterCookie, ref ListG list, ObjectG owner, GstIteratorItemFunction item)
175 	{
176 		// GstIterator * gst_iterator_new_list (GType type,  GMutex *lock,  guint32 *master_cookie,  GList **list,  GObject *owner,  GstIteratorItemFunction item);
177 		GList* outlist = (list is null) ? null : list.getListGStruct();
178 		
179 		auto p = gst_iterator_new_list(type, (lock is null) ? null : lock.getMutexStruct(), masterCookie, &outlist, (owner is null) ? null : owner.getObjectGStruct(), item);
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by gst_iterator_new_list(type, (lock is null) ? null : lock.getMutexStruct(), masterCookie, &outlist, (owner is null) ? null : owner.getObjectGStruct(), item)");
183 		}
184 		
185 		list = ObjectG.getDObject!(ListG)(outlist);
186 		this(cast(GstIterator*) p);
187 	}
188 	
189 	/**
190 	 * This GstIterator is a convenient iterator for the common
191 	 * case where a GstIterator needs to be returned but only
192 	 * a single object has to be considered. This happens often
193 	 * for the GstPadIterIntLinkFunction.
194 	 * Params:
195 	 * type = GType of the passed object
196 	 * object = object that this iterator should return
197 	 * Throws: ConstructionException GTK+ fails to create the object.
198 	 */
199 	public this (GType type, Value object)
200 	{
201 		// GstIterator * gst_iterator_new_single (GType type,  const GValue *object);
202 		auto p = gst_iterator_new_single(type, (object is null) ? null : object.getValueStruct());
203 		if(p is null)
204 		{
205 			throw new ConstructionException("null returned by gst_iterator_new_single(type, (object is null) ? null : object.getValueStruct())");
206 		}
207 		this(cast(GstIterator*) p);
208 	}
209 	
210 	/**
211 	 * Copy the iterator and its state.
212 	 * Returns: a new copy of it.
213 	 */
214 	public Iterator copy()
215 	{
216 		// GstIterator * gst_iterator_copy (const GstIterator *it);
217 		auto p = gst_iterator_copy(gstIterator);
218 		
219 		if(p is null)
220 		{
221 			return null;
222 		}
223 		
224 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
225 	}
226 	
227 	/**
228 	 * Free the iterator.
229 	 * MT safe.
230 	 */
231 	public void free()
232 	{
233 		// void gst_iterator_free (GstIterator *it);
234 		gst_iterator_free(gstIterator);
235 	}
236 	
237 	/**
238 	 * Get the next item from the iterator in elem.
239 	 * Only when this function returns GST_ITERATOR_OK, elem will contain a valid
240 	 * value. elem must have been initialized to the type of the iterator or
241 	 * initialized to zeroes with g_value_unset(). The caller is responsible for
242 	 * unsetting or resetting elem with g_value_unset() or g_value_reset()
243 	 * after usage.
244 	 * When this function returns GST_ITERATOR_DONE, no more elements can be
245 	 * retrieved from it.
246 	 * A return value of GST_ITERATOR_RESYNC indicates that the element list was
247 	 * concurrently updated. The user of it should call gst_iterator_resync() to
248 	 * get the newly updated list.
249 	 * A return value of GST_ITERATOR_ERROR indicates an unrecoverable fatal error.
250 	 * Params:
251 	 * elem = pointer to hold next element. [out caller-allocates]
252 	 * Returns: The result of the iteration. Unset elem after usage. MT safe.
253 	 */
254 	public GstIteratorResult next(Value elem)
255 	{
256 		// GstIteratorResult gst_iterator_next (GstIterator *it,  GValue *elem);
257 		return gst_iterator_next(gstIterator, (elem is null) ? null : elem.getValueStruct());
258 	}
259 	
260 	/**
261 	 * Resync the iterator. this function is mostly called
262 	 * after gst_iterator_next() returned GST_ITERATOR_RESYNC.
263 	 * When an iterator was pushed on it, it will automatically be popped again
264 	 * with this function.
265 	 * MT safe.
266 	 */
267 	public void resync()
268 	{
269 		// void gst_iterator_resync (GstIterator *it);
270 		gst_iterator_resync(gstIterator);
271 	}
272 	
273 	/**
274 	 * Pushes other iterator onto it. All calls performed on it are
275 	 * forwarded to other. If other returns GST_ITERATOR_DONE, it is
276 	 * popped again and calls are handled by it again.
277 	 * This function is mainly used by objects implementing the iterator
278 	 * next function to recurse into substructures.
279 	 * When gst_iterator_resync() is called on it, other will automatically be
280 	 * popped.
281 	 * MT safe.
282 	 * Params:
283 	 * other = The GstIterator to push
284 	 */
285 	public void push(Iterator other)
286 	{
287 		// void gst_iterator_push (GstIterator *it,  GstIterator *other);
288 		gst_iterator_push(gstIterator, (other is null) ? null : other.getIteratorStruct());
289 	}
290 	
291 	/**
292 	 * Create a new iterator from an existing iterator. The new iterator
293 	 * will only return those elements that match the given compare function func.
294 	 * The first parameter that is passed to func is the GValue of the current
295 	 * iterator element and the second parameter is user_data. func should
296 	 * return 0 for elements that should be included in the filtered iterator.
297 	 * When this iterator is freed, it will also be freed.
298 	 * Params:
299 	 * func = the compare function to select elements. [scope call]
300 	 * userData = user data passed to the compare function. [closure]
301 	 * Returns: a new GstIterator. MT safe. [transfer full]
302 	 */
303 	public Iterator filter(GCompareFunc func, Value userData)
304 	{
305 		// GstIterator * gst_iterator_filter (GstIterator *it,  GCompareFunc func,  const GValue *user_data);
306 		auto p = gst_iterator_filter(gstIterator, func, (userData is null) ? null : userData.getValueStruct());
307 		
308 		if(p is null)
309 		{
310 			return null;
311 		}
312 		
313 		return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p);
314 	}
315 	
316 	/**
317 	 * Folds func over the elements of iter. That is to say, func will be called
318 	 * as func (object, ret, user_data) for each object in it. The normal use
319 	 * of this procedure is to accumulate the results of operating on the objects in
320 	 * ret.
321 	 * This procedure can be used (and is used internally) to implement the
322 	 * gst_iterator_foreach() and gst_iterator_find_custom() operations.
323 	 * The fold will proceed as long as func returns TRUE. When the iterator has no
324 	 * more arguments, GST_ITERATOR_DONE will be returned. If func returns FALSE,
325 	 * the fold will stop, and GST_ITERATOR_OK will be returned. Errors or resyncs
326 	 * will cause fold to return GST_ITERATOR_ERROR or GST_ITERATOR_RESYNC as
327 	 * appropriate.
328 	 * The iterator will not be freed.
329 	 * Params:
330 	 * func = the fold function. [scope call]
331 	 * ret = the seed value passed to the fold function
332 	 * userData = user data passed to the fold function. [closure]
333 	 * Returns: A GstIteratorResult, as described above. MT safe.
334 	 */
335 	public GstIteratorResult fold(GstIteratorFoldFunction func, Value ret, void* userData)
336 	{
337 		// GstIteratorResult gst_iterator_fold (GstIterator *it,  GstIteratorFoldFunction func,  GValue *ret,  gpointer user_data);
338 		return gst_iterator_fold(gstIterator, func, (ret is null) ? null : ret.getValueStruct(), userData);
339 	}
340 	
341 	/**
342 	 * Iterate over all element of it and call the given function func for
343 	 * each element.
344 	 * Params:
345 	 * func = the function to call for each element. [scope call]
346 	 * userData = user data passed to the function. [closure]
347 	 * Returns: the result call to gst_iterator_fold(). The iterator will not be freed. MT safe.
348 	 */
349 	public GstIteratorResult foreac(GstIteratorForeachFunction func, void* userData)
350 	{
351 		// GstIteratorResult gst_iterator_foreach (GstIterator *it,  GstIteratorForeachFunction func,  gpointer user_data);
352 		return gst_iterator_foreach(gstIterator, func, userData);
353 	}
354 	
355 	/**
356 	 * Find the first element in it that matches the compare function func.
357 	 * func should return 0 when the element is found. The first parameter
358 	 * to func will be the current element of the iterator and the
359 	 * second parameter will be user_data.
360 	 * The result will be stored in elem if a result is found.
361 	 * The iterator will not be freed.
362 	 * This function will return FALSE if an error happened to the iterator
363 	 * or if the element wasn't found.
364 	 * Params:
365 	 * func = the compare function to use. [scope call]
366 	 * elem = pointer to a GValue where to store the result. [out]
367 	 * userData = user data passed to the compare function. [closure]
368 	 * Returns: Returns TRUE if the element was found, else FALSE. MT safe.
369 	 */
370 	public int findCustom(GCompareFunc func, Value elem, void* userData)
371 	{
372 		// gboolean gst_iterator_find_custom (GstIterator *it,  GCompareFunc func,  GValue *elem,  gpointer user_data);
373 		return gst_iterator_find_custom(gstIterator, func, (elem is null) ? null : elem.getValueStruct(), userData);
374 	}
375 }