1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 associate groups of data elements with particular memory locations
7 <!-- ##### SECTION Long_Description ##### -->
9 Datasets associate groups of data elements with particular memory locations.
10 These are useful if you need to associate data with a structure returned
11 from an external library. Since you cannot modify the structure, you use
12 its location in memory as the key into a dataset, where you can associate
13 any number of data elements with it.
16 There are two forms of most of the dataset functions.
17 The first form uses strings to identify the data elements associated with
18 a location. The second form uses #GQuark identifiers, which are created
19 with a call to g_quark_from_string() or g_quark_from_static_string().
20 The second form is quicker, since it does not require looking up the string
21 in the hash table of #GQuark identifiers.
24 There is no function to create a dataset. It is automatically created as
25 soon as you add elements to it.
28 To add data elements to a dataset use g_dataset_id_set_data(),
29 g_dataset_id_set_data_full(), g_dataset_set_data()
30 and g_dataset_set_data_full().
33 To get data elements from a dataset use g_dataset_id_get_data() and
37 To iterate over all data elements in a dataset use g_dataset_foreach() (not thread-safe).
40 To remove data elements from a dataset use g_dataset_id_remove_data() and
41 g_dataset_remove_data().
44 To destroy a dataset, use g_dataset_destroy().
47 <!-- ##### SECTION See_Also ##### -->
52 <!-- ##### SECTION Stability_Level ##### -->
55 <!-- ##### MACRO g_dataset_id_set_data ##### -->
57 Sets the data element associated with the given #GQuark id.
58 Any previous data with the same key is removed, and its destroy function
62 @l: the location identifying the dataset.
63 @k: the #GQuark id to identify the data element.
67 <!-- ##### FUNCTION g_dataset_id_set_data_full ##### -->
69 Sets the data element associated with the given #GQuark id, and also the
70 function to call when the data element is destroyed.
71 Any previous data with the same key is removed, and its
72 destroy function is called.
75 @dataset_location: the location identifying the dataset.
76 @key_id: the #GQuark id to identify the data element.
77 @data: the data element.
78 @destroy_func: the function to call when the data element is removed. This
79 function will be called with the data element and can be used to free any
80 memory allocated for it.
83 <!-- ##### USER_FUNCTION GDestroyNotify ##### -->
85 Specifies the type of function which is called when a data element is
86 destroyed. It is passed the pointer to the data element and should free
87 any memory and resources allocated for it.
90 @data: the data element.
93 <!-- ##### FUNCTION g_dataset_id_get_data ##### -->
95 Gets the data element corresponding to a #GQuark.
98 @dataset_location: the location identifying the dataset.
99 @key_id: the #GQuark id to identify the data element.
100 @Returns: the data element corresponding to the #GQuark, or %NULL if it is
104 <!-- ##### MACRO g_dataset_id_remove_data ##### -->
106 Removes a data element from a dataset.
107 The data element's destroy function is called if it has been set.
110 @l: the location identifying the dataset.
111 @k: the #GQuark id identifying the data element.
114 <!-- ##### FUNCTION g_dataset_id_remove_no_notify ##### -->
116 Removes an element, without calling its destroy notification function.
119 @dataset_location: the location identifying the dataset.
120 @key_id: the #GQuark ID identifying the data element.
121 @Returns: the data previously stored at @key_id, or %NULL if none.
124 <!-- ##### MACRO g_dataset_set_data ##### -->
126 Sets the data corresponding to the given string identifier.
129 @l: the location identifying the dataset.
130 @k: the string to identify the data element.
131 @d: the data element.
134 <!-- ##### MACRO g_dataset_set_data_full ##### -->
136 Sets the data corresponding to the given string identifier, and the function
137 to call when the data element is destroyed.
140 @l: the location identifying the dataset.
141 @k: the string to identify the data element.
142 @d: the data element.
143 @f: the function to call when the data element is removed. This
144 function will be called with the data element and can be used to free any
145 memory allocated for it.
148 <!-- ##### MACRO g_dataset_get_data ##### -->
150 Gets the data element corresponding to a string.
153 @l: the location identifying the dataset.
154 @k: the string identifying the data element.
155 @Returns: the data element corresponding to the string, or %NULL if it is not
159 <!-- ##### MACRO g_dataset_remove_data ##### -->
161 Removes a data element corresponding to a string.
162 Its destroy function is called if it has been set.
165 @l: the location identifying the dataset.
166 @k: the string identifying the data element.
169 <!-- ##### MACRO g_dataset_remove_no_notify ##### -->
171 Removes an element, without calling its destroy notifier.
174 @l: the location identifying the dataset.
175 @k: the string identifying the data element.
178 <!-- ##### FUNCTION g_dataset_foreach ##### -->
180 Calls the given function for each data element which is associated with the
182 Note that this function is NOT thread-safe. So unless @datalist
183 can be protected from any modifications during invocation of this
184 function, it should not be called.
187 @dataset_location: the location identifying the dataset.
188 @func: the function to call for each data element.
189 @user_data: user data to pass to the function.
192 <!-- ##### USER_FUNCTION GDataForeachFunc ##### -->
194 Specifies the type of function passed to g_dataset_foreach().
195 It is called with each #GQuark id and associated data element,
196 together with the @user_data parameter supplied to g_dataset_foreach().
199 @key_id: the #GQuark id to identifying the data element.
200 @data: the data element.
201 @user_data: user data passed to g_dataset_foreach().
204 <!-- ##### FUNCTION g_dataset_destroy ##### -->
206 Destroys the dataset, freeing all memory allocated, and calling any
207 destroy functions set for data elements.
210 @dataset_location: the location identifying the dataset.