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