1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 lists of data elements which are accessible by a string or #GQuark identifier.
7 <!-- ##### SECTION Long_Description ##### -->
9 Keyed data lists provide lists of arbitrary data elements which can be accessed
10 either with a string or with a #GQuark corresponding to the
14 The #GQuark methods are quicker, since the strings have to be converted to
18 Data lists are used for associating arbitrary data with
19 #GObjects, using g_object_set_data() and related functions.
23 To create a datalist, use g_datalist_init().
26 To add data elements to a datalist use g_datalist_id_set_data(),
27 g_datalist_id_set_data_full(), g_datalist_set_data()
28 and g_datalist_set_data_full().
31 To get data elements from a datalist use g_datalist_id_get_data() and
32 g_datalist_get_data().
35 To iterate over all data elements in a datalist use g_datalist_foreach().
38 To remove data elements from a datalist use g_datalist_id_remove_data() and
39 g_datalist_remove_data().
42 To remove all data elements from a datalist, use g_datalist_clear().
45 <!-- ##### SECTION See_Also ##### -->
50 <!-- ##### SECTION Stability_Level ##### -->
53 <!-- ##### STRUCT GData ##### -->
55 The #GData struct is an opaque data structure to represent a
56 <link linkend="glib-Keyed-Data-Lists">Keyed Data List</link>.
57 It should only be accessed via the following functions.
61 <!-- ##### FUNCTION g_datalist_init ##### -->
63 Resets the datalist to %NULL.
64 It does not free any memory or call any destroy functions.
67 @datalist: a pointer to a pointer to a datalist.
70 <!-- ##### MACRO g_datalist_id_set_data ##### -->
72 Sets the data corresponding to the given #GQuark id.
73 Any previous data with the same key is removed, and its
74 destroy function is called.
78 @q: the #GQuark to identify the data element.
79 @d: the data element, or %NULL to remove any previous element
83 <!-- ##### FUNCTION g_datalist_id_set_data_full ##### -->
85 Sets the data corresponding to the given #GQuark id, and the function to
86 be called when the element is removed from the datalist.
87 Any previous data with the same key is removed, and its
88 destroy function is called.
91 @datalist: a datalist.
92 @key_id: the #GQuark to identify the data element.
93 @data: the data element or %NULL to remove any previous element
94 corresponding to @key_id.
95 @destroy_func: the function to call when the data element is removed. This
96 function will be called with the data element and can be used to free any
97 memory allocated for it. If @data is %NULL, then @destroy_func must
101 <!-- ##### FUNCTION g_datalist_id_get_data ##### -->
103 Retrieves the data element corresponding to @key_id.
106 @datalist: a datalist.
107 @key_id: the #GQuark identifying a data element.
108 @Returns: the data element, or %NULL if it is not found.
111 <!-- ##### MACRO g_datalist_id_remove_data ##### -->
113 Removes an element, using its #GQuark identifier.
117 @q: the #GQuark identifying the data element.
120 <!-- ##### FUNCTION g_datalist_id_remove_no_notify ##### -->
122 Removes an element, without calling its destroy notification function.
125 @datalist: a datalist.
126 @key_id: the #GQuark identifying a data element.
127 @Returns: the data previously stored at @key_id, or %NULL if none.
130 <!-- ##### MACRO g_datalist_set_data ##### -->
132 Sets the data element corresponding to the given string identifier.
136 @k: the string to identify the data element.
137 @d: the data element, or %NULL to remove any previous element
141 <!-- ##### MACRO g_datalist_set_data_full ##### -->
143 Sets the data element corresponding to the given string identifier, and the
144 function to be called when the data element is removed.
148 @k: the string to identify the data element.
149 @d: the data element, or %NULL to remove any previous element corresponding to
151 @f: the function to call when the data element is removed. This
152 function will be called with the data element and can be used to free any
153 memory allocated for it. If @d is %NULL, then @f must also be %NULL.
156 <!-- ##### MACRO g_datalist_get_data ##### -->
158 Gets a data element, using its string identifer.
159 This is slower than g_datalist_id_get_data() because the string is first
160 converted to a #GQuark.
164 @k: the string identifying a data element.
165 @Returns: the data element, or %NULL if it is not found.
168 <!-- ##### MACRO g_datalist_remove_data ##### -->
170 Removes an element using its string identifier.
171 The data element's destroy function is called if it has been set.
175 @k: the string identifying the data element.
178 <!-- ##### MACRO g_datalist_remove_no_notify ##### -->
180 Removes an element, without calling its destroy notifier.
184 @k: the string identifying the data element.
187 <!-- ##### FUNCTION g_datalist_foreach ##### -->
189 Calls the given function for each data element of the datalist.
190 The function is called with each data element's #GQuark id and data,
191 together with the given @user_data parameter.
194 @datalist: a datalist.
195 @func: the function to call for each data element.
196 @user_data: user data to pass to the function.
199 <!-- ##### FUNCTION g_datalist_clear ##### -->
201 Frees all the data elements of the datalist.
202 The data elements' destroy functions are called if they have been set.
205 @datalist: a datalist.
208 <!-- ##### FUNCTION g_datalist_set_flags ##### -->
217 <!-- ##### FUNCTION g_datalist_unset_flags ##### -->
226 <!-- ##### FUNCTION g_datalist_get_flags ##### -->
235 <!-- ##### MACRO G_DATALIST_FLAGS_MASK ##### -->