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