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.DataList;
26 
27 private import glib.Str;
28 private import glib.c.functions;
29 public  import glib.c.types;
30 public  import gtkc.glibtypes;
31 
32 
33 /** */
34 public struct DataList
35 {
36 
37 	/**
38 	 * Frees all the data elements of the datalist.
39 	 * The data elements' destroy functions are called
40 	 * if they have been set.
41 	 *
42 	 * Params:
43 	 *     datalist = a datalist.
44 	 */
45 	public static void clear(GData** datalist)
46 	{
47 		g_datalist_clear(datalist);
48 	}
49 
50 	/**
51 	 * Calls the given function for each data element of the datalist. The
52 	 * function is called with each data element's #GQuark id and data,
53 	 * together with the given @user_data parameter. Note that this
54 	 * function is NOT thread-safe. So unless @datalist can be protected
55 	 * from any modifications during invocation of this function, it should
56 	 * not be called.
57 	 *
58 	 * @func can make changes to @datalist, but the iteration will not
59 	 * reflect changes made during the g_datalist_foreach() call, other
60 	 * than skipping over elements that are removed.
61 	 *
62 	 * Params:
63 	 *     datalist = a datalist.
64 	 *     func = the function to call for each data element.
65 	 *     userData = user data to pass to the function.
66 	 */
67 	public static void foreac(GData** datalist, GDataForeachFunc func, void* userData)
68 	{
69 		g_datalist_foreach(datalist, func, userData);
70 	}
71 
72 	/**
73 	 * Gets a data element, using its string identifier. This is slower than
74 	 * g_datalist_id_get_data() because it compares strings.
75 	 *
76 	 * Params:
77 	 *     datalist = a datalist.
78 	 *     key = the string identifying a data element.
79 	 *
80 	 * Returns: the data element, or %NULL if it
81 	 *     is not found.
82 	 */
83 	public static void* getData(GData** datalist, string key)
84 	{
85 		return g_datalist_get_data(datalist, Str.toStringz(key));
86 	}
87 
88 	/**
89 	 * Gets flags values packed in together with the datalist.
90 	 * See g_datalist_set_flags().
91 	 *
92 	 * Params:
93 	 *     datalist = pointer to the location that holds a list
94 	 *
95 	 * Returns: the flags of the datalist
96 	 *
97 	 * Since: 2.8
98 	 */
99 	public static uint getFlags(GData** datalist)
100 	{
101 		return g_datalist_get_flags(datalist);
102 	}
103 
104 	/**
105 	 * This is a variant of g_datalist_id_get_data() which
106 	 * returns a 'duplicate' of the value. @dup_func defines the
107 	 * meaning of 'duplicate' in this context, it could e.g.
108 	 * take a reference on a ref-counted object.
109 	 *
110 	 * If the @key_id is not set in the datalist then @dup_func
111 	 * will be called with a %NULL argument.
112 	 *
113 	 * Note that @dup_func is called while the datalist is locked, so it
114 	 * is not allowed to read or modify the datalist.
115 	 *
116 	 * This function can be useful to avoid races when multiple
117 	 * threads are using the same datalist and the same key.
118 	 *
119 	 * Params:
120 	 *     datalist = location of a datalist
121 	 *     keyId = the #GQuark identifying a data element
122 	 *     dupFunc = function to duplicate the old value
123 	 *     userData = passed as user_data to @dup_func
124 	 *
125 	 * Returns: the result of calling @dup_func on the value
126 	 *     associated with @key_id in @datalist, or %NULL if not set.
127 	 *     If @dup_func is %NULL, the value is returned unmodified.
128 	 *
129 	 * Since: 2.34
130 	 */
131 	public static void* idDupData(GData** datalist, GQuark keyId, GDuplicateFunc dupFunc, void* userData)
132 	{
133 		return g_datalist_id_dup_data(datalist, keyId, dupFunc, userData);
134 	}
135 
136 	/**
137 	 * Retrieves the data element corresponding to @key_id.
138 	 *
139 	 * Params:
140 	 *     datalist = a datalist.
141 	 *     keyId = the #GQuark identifying a data element.
142 	 *
143 	 * Returns: the data element, or %NULL if
144 	 *     it is not found.
145 	 */
146 	public static void* idGetData(GData** datalist, GQuark keyId)
147 	{
148 		return g_datalist_id_get_data(datalist, keyId);
149 	}
150 
151 	/**
152 	 * Removes an element, without calling its destroy notification
153 	 * function.
154 	 *
155 	 * Params:
156 	 *     datalist = a datalist.
157 	 *     keyId = the #GQuark identifying a data element.
158 	 *
159 	 * Returns: the data previously stored at @key_id,
160 	 *     or %NULL if none.
161 	 */
162 	public static void* idRemoveNoNotify(GData** datalist, GQuark keyId)
163 	{
164 		return g_datalist_id_remove_no_notify(datalist, keyId);
165 	}
166 
167 	/**
168 	 * Compares the member that is associated with @key_id in
169 	 * @datalist to @oldval, and if they are the same, replace
170 	 * @oldval with @newval.
171 	 *
172 	 * This is like a typical atomic compare-and-exchange
173 	 * operation, for a member of @datalist.
174 	 *
175 	 * If the previous value was replaced then ownership of the
176 	 * old value (@oldval) is passed to the caller, including
177 	 * the registered destroy notify for it (passed out in @old_destroy).
178 	 * Its up to the caller to free this as he wishes, which may
179 	 * or may not include using @old_destroy as sometimes replacement
180 	 * should not destroy the object in the normal way.
181 	 *
182 	 * Params:
183 	 *     datalist = location of a datalist
184 	 *     keyId = the #GQuark identifying a data element
185 	 *     oldval = the old value to compare against
186 	 *     newval = the new value to replace it with
187 	 *     destroy = destroy notify for the new value
188 	 *     oldDestroy = destroy notify for the existing value
189 	 *
190 	 * Returns: %TRUE if the existing value for @key_id was replaced
191 	 *     by @newval, %FALSE otherwise.
192 	 *
193 	 * Since: 2.34
194 	 */
195 	public static bool idReplaceData(GData** datalist, GQuark keyId, void* oldval, void* newval, GDestroyNotify destroy, out GDestroyNotify oldDestroy)
196 	{
197 		return g_datalist_id_replace_data(datalist, keyId, oldval, newval, destroy, &oldDestroy) != 0;
198 	}
199 
200 	/**
201 	 * Sets the data corresponding to the given #GQuark id, and the
202 	 * function to be called when the element is removed from the datalist.
203 	 * Any previous data with the same key is removed, and its destroy
204 	 * function is called.
205 	 *
206 	 * Params:
207 	 *     datalist = a datalist.
208 	 *     keyId = the #GQuark to identify the data element.
209 	 *     data = the data element or %NULL to remove any previous element
210 	 *         corresponding to @key_id.
211 	 *     destroyFunc = the function to call when the data element is
212 	 *         removed. This function will be called with the data
213 	 *         element and can be used to free any memory allocated
214 	 *         for it. If @data is %NULL, then @destroy_func must
215 	 *         also be %NULL.
216 	 */
217 	public static void idSetDataFull(GData** datalist, GQuark keyId, void* data, GDestroyNotify destroyFunc)
218 	{
219 		g_datalist_id_set_data_full(datalist, keyId, data, destroyFunc);
220 	}
221 
222 	/**
223 	 * Resets the datalist to %NULL. It does not free any memory or call
224 	 * any destroy functions.
225 	 *
226 	 * Params:
227 	 *     datalist = a pointer to a pointer to a datalist.
228 	 */
229 	public static void init(GData** datalist)
230 	{
231 		g_datalist_init(datalist);
232 	}
233 
234 	/**
235 	 * Turns on flag values for a data list. This function is used
236 	 * to keep a small number of boolean flags in an object with
237 	 * a data list without using any additional space. It is
238 	 * not generally useful except in circumstances where space
239 	 * is very tight. (It is used in the base #GObject type, for
240 	 * example.)
241 	 *
242 	 * Params:
243 	 *     datalist = pointer to the location that holds a list
244 	 *     flags = the flags to turn on. The values of the flags are
245 	 *         restricted by %G_DATALIST_FLAGS_MASK (currently
246 	 *         3; giving two possible boolean flags).
247 	 *         A value for @flags that doesn't fit within the mask is
248 	 *         an error.
249 	 *
250 	 * Since: 2.8
251 	 */
252 	public static void setFlags(GData** datalist, uint flags)
253 	{
254 		g_datalist_set_flags(datalist, flags);
255 	}
256 
257 	/**
258 	 * Turns off flag values for a data list. See g_datalist_unset_flags()
259 	 *
260 	 * Params:
261 	 *     datalist = pointer to the location that holds a list
262 	 *     flags = the flags to turn off. The values of the flags are
263 	 *         restricted by %G_DATALIST_FLAGS_MASK (currently
264 	 *         3: giving two possible boolean flags).
265 	 *         A value for @flags that doesn't fit within the mask is
266 	 *         an error.
267 	 *
268 	 * Since: 2.8
269 	 */
270 	public static void unsetFlags(GData** datalist, uint flags)
271 	{
272 		g_datalist_unset_flags(datalist, flags);
273 	}
274 }