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  * Conversion parameters:
26  * inFile  = glib-Keyed-Data-Lists.html
27  * outPack = glib
28  * outFile = DataList
29  * strct   = GData
30  * realStrct=
31  * ctorStrct=
32  * clss    = DataList
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_datalist_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.DataList;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 
61 private import glib.Str;
62 
63 
64 
65 
66 /**
67  * Keyed data lists provide lists of arbitrary data elements which can
68  * be accessed either with a string or with a GQuark corresponding to
69  * the string.
70  *
71  * The GQuark methods are quicker, since the strings have to be
72  * converted to GQuarks anyway.
73  *
74  * Data lists are used for associating arbitrary data with GObjects,
75  * using g_object_set_data() and related functions.
76  *
77  * To create a datalist, use g_datalist_init().
78  *
79  * To add data elements to a datalist use g_datalist_id_set_data(),
80  * g_datalist_id_set_data_full(), g_datalist_set_data() and
81  * g_datalist_set_data_full().
82  *
83  * To get data elements from a datalist use g_datalist_id_get_data()
84  * and g_datalist_get_data().
85  *
86  * To iterate over all data elements in a datalist use
87  * g_datalist_foreach() (not thread-safe).
88  *
89  * To remove data elements from a datalist use
90  * g_datalist_id_remove_data() and g_datalist_remove_data().
91  *
92  * To remove all data elements from a datalist, use g_datalist_clear().
93  */
94 public class DataList
95 {
96 	
97 	/** the main Gtk struct */
98 	protected GData* gData;
99 	
100 	
101 	public GData* getDataListStruct()
102 	{
103 		return gData;
104 	}
105 	
106 	
107 	/** the main Gtk struct as a void* */
108 	protected void* getStruct()
109 	{
110 		return cast(void*)gData;
111 	}
112 	
113 	/**
114 	 * Sets our main struct and passes it to the parent class
115 	 */
116 	public this (GData* gData)
117 	{
118 		this.gData = gData;
119 	}
120 	
121 	/**
122 	 */
123 	
124 	/**
125 	 * Resets the datalist to NULL. It does not free any memory or call
126 	 * any destroy functions.
127 	 * Params:
128 	 * datalist = a pointer to a pointer to a datalist.
129 	 */
130 	public static void init(GData** datalist)
131 	{
132 		// void g_datalist_init (GData **datalist);
133 		g_datalist_init(datalist);
134 	}
135 	
136 	/**
137 	 * Sets the data corresponding to the given GQuark id, and the
138 	 * function to be called when the element is removed from the datalist.
139 	 * Any previous data with the same key is removed, and its destroy
140 	 * function is called.
141 	 * Params:
142 	 * datalist = a datalist.
143 	 * keyId = the GQuark to identify the data element.
144 	 * data = the data element or NULL to remove any previous element
145 	 * corresponding to key_id. [allow-none]
146 	 * destroyFunc = the function to call when the data element is
147 	 * removed. This function will be called with the data
148 	 * element and can be used to free any memory allocated
149 	 * for it. If data is NULL, then destroy_func must
150 	 * also be NULL.
151 	 */
152 	public static void idSetDataFull(GData** datalist, GQuark keyId, void* data, GDestroyNotify destroyFunc)
153 	{
154 		// void g_datalist_id_set_data_full (GData **datalist,  GQuark key_id,  gpointer data,  GDestroyNotify destroy_func);
155 		g_datalist_id_set_data_full(datalist, keyId, data, destroyFunc);
156 	}
157 	
158 	/**
159 	 * Retrieves the data element corresponding to key_id.
160 	 * Params:
161 	 * datalist = a datalist.
162 	 * keyId = the GQuark identifying a data element.
163 	 * Returns: the data element, or NULL if it is not found.
164 	 */
165 	public static void* idGetData(GData** datalist, GQuark keyId)
166 	{
167 		// gpointer g_datalist_id_get_data (GData **datalist,  GQuark key_id);
168 		return g_datalist_id_get_data(datalist, keyId);
169 	}
170 	
171 	/**
172 	 * Removes an element, without calling its destroy notification
173 	 * function.
174 	 * Params:
175 	 * datalist = a datalist.
176 	 * keyId = the GQuark identifying a data element.
177 	 * Returns: the data previously stored at key_id, or NULL if none.
178 	 */
179 	public static void* idRemoveNoNotify(GData** datalist, GQuark keyId)
180 	{
181 		// gpointer g_datalist_id_remove_no_notify (GData **datalist,  GQuark key_id);
182 		return g_datalist_id_remove_no_notify(datalist, keyId);
183 	}
184 	
185 	/**
186 	 * This is a variant of g_datalist_id_get_data() which
187 	 * returns a 'duplicate' of the value. dup_func defines the
188 	 * meaning of 'duplicate' in this context, it could e.g.
189 	 * take a reference on a ref-counted object.
190 	 * If the key_id is not set in the datalist then dup_func
191 	 * will be called with a NULL argument.
192 	 * Note that dup_func is called while the datalist is locked, so it
193 	 * is not allowed to read or modify the datalist.
194 	 * This function can be useful to avoid races when multiple
195 	 * threads are using the same datalist and the same key.
196 	 * Since 2.34
197 	 * Params:
198 	 * datalist = location of a datalist
199 	 * keyId = the GQuark identifying a data element
200 	 * dupFunc = function to duplicate the old value. [allow-none]
201 	 * userData = passed as user_data to dup_func. [allow-none]
202 	 * Returns: the result of calling dup_func on the value associated with key_id in datalist, or NULL if not set. If dup_func is NULL, the value is returned unmodified.
203 	 */
204 	public static void* idDupData(GData** datalist, GQuark keyId, GDuplicateFunc dupFunc, void* userData)
205 	{
206 		// gpointer g_datalist_id_dup_data (GData **datalist,  GQuark key_id,  GDuplicateFunc dup_func,  gpointer user_data);
207 		return g_datalist_id_dup_data(datalist, keyId, dupFunc, userData);
208 	}
209 	
210 	/**
211 	 * Compares the member that is associated with key_id in
212 	 * datalist to oldval, and if they are the same, replace
213 	 * oldval with newval.
214 	 * This is like a typical atomic compare-and-exchange
215 	 * operation, for a member of datalist.
216 	 * If the previous value was replaced then ownership of the
217 	 * old value (oldval) is passed to the caller, including
218 	 * the registred destroy notify for it (passed out in old_destroy).
219 	 * Its up to the caller to free this as he wishes, which may
220 	 * or may not include using old_destroy as sometimes replacement
221 	 * should not destroy the object in the normal way.
222 	 * Return: TRUE if the existing value for key_id was replaced
223 	 *  by newval, FALSE otherwise.
224 	 * Since 2.34
225 	 * Params:
226 	 * datalist = location of a datalist
227 	 * keyId = the GQuark identifying a data element
228 	 * oldval = the old value to compare against. [allow-none]
229 	 * newval = the new value to replace it with. [allow-none]
230 	 * destroy = destroy notify for the new value. [allow-none]
231 	 * oldDestroy = destroy notify for the existing value. [allow-none]
232 	 */
233 	public static int idReplaceData(GData** datalist, GQuark keyId, void* oldval, void* newval, GDestroyNotify destroy, GDestroyNotify* oldDestroy)
234 	{
235 		// gboolean g_datalist_id_replace_data (GData **datalist,  GQuark key_id,  gpointer oldval,  gpointer newval,  GDestroyNotify destroy,  GDestroyNotify *old_destroy);
236 		return g_datalist_id_replace_data(datalist, keyId, oldval, newval, destroy, oldDestroy);
237 	}
238 	
239 	/**
240 	 * Gets a data element, using its string identifier. This is slower than
241 	 * g_datalist_id_get_data() because it compares strings.
242 	 * Params:
243 	 * datalist = a datalist.
244 	 * key = the string identifying a data element.
245 	 * Returns: the data element, or NULL if it is not found.
246 	 */
247 	public static void* getData(GData** datalist, string key)
248 	{
249 		// gpointer g_datalist_get_data (GData **datalist,  const gchar *key);
250 		return g_datalist_get_data(datalist, Str.toStringz(key));
251 	}
252 	
253 	/**
254 	 * Calls the given function for each data element of the datalist. The
255 	 * function is called with each data element's GQuark id and data,
256 	 * together with the given user_data parameter. Note that this
257 	 * function is NOT thread-safe. So unless datalist can be protected
258 	 * from any modifications during invocation of this function, it should
259 	 * not be called.
260 	 * Params:
261 	 * datalist = a datalist.
262 	 * func = the function to call for each data element.
263 	 * userData = user data to pass to the function.
264 	 */
265 	public static void foreac(GData** datalist, GDataForeachFunc func, void* userData)
266 	{
267 		// void g_datalist_foreach (GData **datalist,  GDataForeachFunc func,  gpointer user_data);
268 		g_datalist_foreach(datalist, func, userData);
269 	}
270 	
271 	/**
272 	 * Frees all the data elements of the datalist.
273 	 * The data elements' destroy functions are called
274 	 * if they have been set.
275 	 * Params:
276 	 * datalist = a datalist.
277 	 */
278 	public static void clear(GData** datalist)
279 	{
280 		// void g_datalist_clear (GData **datalist);
281 		g_datalist_clear(datalist);
282 	}
283 	
284 	/**
285 	 * Turns on flag values for a data list. This function is used
286 	 * to keep a small number of boolean flags in an object with
287 	 * a data list without using any additional space. It is
288 	 * not generally useful except in circumstances where space
289 	 * is very tight. (It is used in the base GObject type, for
290 	 * example.)
291 	 * Since 2.8
292 	 * Params:
293 	 * datalist = pointer to the location that holds a list
294 	 * flags = the flags to turn on. The values of the flags are
295 	 * restricted by G_DATALIST_FLAGS_MASK (currently
296 	 * 3; giving two possible boolean flags).
297 	 * A value for flags that doesn't fit within the mask is
298 	 * an error.
299 	 */
300 	public static void setFlags(GData** datalist, uint flags)
301 	{
302 		// void g_datalist_set_flags (GData **datalist,  guint flags);
303 		g_datalist_set_flags(datalist, flags);
304 	}
305 	
306 	/**
307 	 * Turns off flag values for a data list. See g_datalist_unset_flags()
308 	 * Since 2.8
309 	 * Params:
310 	 * datalist = pointer to the location that holds a list
311 	 * flags = the flags to turn off. The values of the flags are
312 	 * restricted by G_DATALIST_FLAGS_MASK (currently
313 	 * 3: giving two possible boolean flags).
314 	 * A value for flags that doesn't fit within the mask is
315 	 * an error.
316 	 */
317 	public static void unsetFlags(GData** datalist, uint flags)
318 	{
319 		// void g_datalist_unset_flags (GData **datalist,  guint flags);
320 		g_datalist_unset_flags(datalist, flags);
321 	}
322 	
323 	/**
324 	 * Gets flags values packed in together with the datalist.
325 	 * See g_datalist_set_flags().
326 	 * Since 2.8
327 	 * Params:
328 	 * datalist = pointer to the location that holds a list
329 	 * Returns: the flags of the datalist
330 	 */
331 	public static uint getFlags(GData** datalist)
332 	{
333 		// guint g_datalist_get_flags (GData **datalist);
334 		return g_datalist_get_flags(datalist);
335 	}
336 }