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