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