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