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