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 glib.VariantIter; 26 27 private import glib.Str; 28 private import glib.Variant; 29 private import glib.c.functions; 30 public import glib.c.types; 31 private import gtkd.Loader; 32 33 34 /** 35 * #GVariantIter is an opaque data structure and can only be accessed 36 * using the following functions. 37 */ 38 public class VariantIter 39 { 40 /** the main Gtk struct */ 41 protected GVariantIter* gVariantIter; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GVariantIter* getVariantIterStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gVariantIter; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gVariantIter; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GVariantIter* gVariantIter, bool ownedRef = false) 62 { 63 this.gVariantIter = gVariantIter; 64 this.ownedRef = ownedRef; 65 } 66 67 ~this () 68 { 69 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 70 g_variant_iter_free(gVariantIter); 71 } 72 73 74 /** 75 * Creates a new heap-allocated #GVariantIter to iterate over the 76 * container that was being iterated over by @iter. Iteration begins on 77 * the new iterator from the current position of the old iterator but 78 * the two copies are independent past that point. 79 * 80 * Use g_variant_iter_free() to free the return value when you no longer 81 * need it. 82 * 83 * A reference is taken to the container that @iter is iterating over 84 * and will be related only when g_variant_iter_free() is called. 85 * 86 * Returns: a new heap-allocated #GVariantIter 87 * 88 * Since: 2.24 89 */ 90 public VariantIter copy() 91 { 92 auto __p = g_variant_iter_copy(gVariantIter); 93 94 if(__p is null) 95 { 96 return null; 97 } 98 99 return new VariantIter(cast(GVariantIter*) __p, true); 100 } 101 102 /** 103 * Frees a heap-allocated #GVariantIter. Only call this function on 104 * iterators that were returned by g_variant_iter_new() or 105 * g_variant_iter_copy(). 106 * 107 * Since: 2.24 108 */ 109 public void free() 110 { 111 g_variant_iter_free(gVariantIter); 112 ownedRef = false; 113 } 114 115 /** 116 * Initialises (without allocating) a #GVariantIter. @iter may be 117 * completely uninitialised prior to this call; its old value is 118 * ignored. 119 * 120 * The iterator remains valid for as long as @value exists, and need not 121 * be freed in any way. 122 * 123 * Params: 124 * value = a container #GVariant 125 * 126 * Returns: the number of items in @value 127 * 128 * Since: 2.24 129 */ 130 public size_t init(Variant value) 131 { 132 return g_variant_iter_init(gVariantIter, (value is null) ? null : value.getVariantStruct()); 133 } 134 135 /** 136 * Queries the number of child items in the container that we are 137 * iterating over. This is the total number of items -- not the number 138 * of items remaining. 139 * 140 * This function might be useful for preallocation of arrays. 141 * 142 * Returns: the number of children in the container 143 * 144 * Since: 2.24 145 */ 146 public size_t nChildren() 147 { 148 return g_variant_iter_n_children(gVariantIter); 149 } 150 151 /** 152 * Gets the next item in the container. If no more items remain then 153 * %NULL is returned. 154 * 155 * Use g_variant_unref() to drop your reference on the return value when 156 * you no longer need it. 157 * 158 * Here is an example for iterating with g_variant_iter_next_value(): 159 * |[<!-- language="C" --> 160 * // recursively iterate a container 161 * void 162 * iterate_container_recursive (GVariant *container) 163 * { 164 * GVariantIter iter; 165 * GVariant *child; 166 * 167 * g_variant_iter_init (&iter, container); 168 * while ((child = g_variant_iter_next_value (&iter))) 169 * { 170 * g_print ("type '%s'\n", g_variant_get_type_string (child)); 171 * 172 * if (g_variant_is_container (child)) 173 * iterate_container_recursive (child); 174 * 175 * g_variant_unref (child); 176 * } 177 * } 178 * ]| 179 * 180 * Returns: a #GVariant, or %NULL 181 * 182 * Since: 2.24 183 */ 184 public Variant nextValue() 185 { 186 auto __p = g_variant_iter_next_value(gVariantIter); 187 188 if(__p is null) 189 { 190 return null; 191 } 192 193 return new Variant(cast(GVariant*) __p, true); 194 } 195 }