GLib Reference Manual | ||||
---|---|---|---|---|
Top | Description |
#include <glib.h> #define g_dataset_id_set_data (l, k, d) void g_dataset_id_set_data_full (gconstpointer dataset_location
,GQuark key_id
,gpointer data
,GDestroyNotify destroy_func
); void (*GDestroyNotify) (gpointer data
); gpointer g_dataset_id_get_data (gconstpointer dataset_location
,GQuark key_id
); #define g_dataset_id_remove_data (l, k) gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location
,GQuark key_id
); #define g_dataset_set_data (l, k, d) #define g_dataset_set_data_full (l, k, d, f) #define g_dataset_get_data (l, k) #define g_dataset_remove_data (l, k) #define g_dataset_remove_no_notify (l, k) void g_dataset_foreach (gconstpointer dataset_location
,GDataForeachFunc func
,gpointer user_data
); void (*GDataForeachFunc) (GQuark key_id
,gpointer data
,gpointer user_data
); void g_dataset_destroy (gconstpointer dataset_location
);
Datasets associate groups of data elements with particular memory locations. These are useful if you need to associate data with a structure returned from an external library. Since you cannot modify the structure, you use its location in memory as the key into a dataset, where you can associate any number of data elements with it.
There are two forms of most of the dataset functions.
The first form uses strings to identify the data elements associated with
a location. The second form uses GQuark identifiers, which are created
with a call to g_quark_from_string()
or g_quark_from_static_string()
.
The second form is quicker, since it does not require looking up the string
in the hash table of GQuark identifiers.
There is no function to create a dataset. It is automatically created as soon as you add elements to it.
To add data elements to a dataset use g_dataset_id_set_data()
,
g_dataset_id_set_data_full()
, g_dataset_set_data()
and g_dataset_set_data_full()
.
To get data elements from a dataset use g_dataset_id_get_data()
and
g_dataset_get_data()
.
To iterate over all data elements in a dataset use g_dataset_foreach()
(not thread-safe).
To remove data elements from a dataset use g_dataset_id_remove_data()
and
g_dataset_remove_data()
.
To destroy a dataset, use g_dataset_destroy()
.
#define g_dataset_id_set_data(l, k, d)
Sets the data element associated with the given GQuark id. Any previous data with the same key is removed, and its destroy function is called.
|
the location identifying the dataset. |
|
the GQuark id to identify the data element. |
|
the data element. |
void g_dataset_id_set_data_full (gconstpointer dataset_location
,GQuark key_id
,gpointer data
,GDestroyNotify destroy_func
);
Sets the data element associated with the given GQuark id, and also the function to call when the data element is destroyed. Any previous data with the same key is removed, and its destroy function is called.
|
the location identifying the dataset. |
|
the GQuark id to identify the data element. |
|
the data element. |
|
the function to call when the data element is removed. This function will be called with the data element and can be used to free any memory allocated for it. |
void (*GDestroyNotify) (gpointer data
);
Specifies the type of function which is called when a data element is destroyed. It is passed the pointer to the data element and should free any memory and resources allocated for it.
|
the data element. |
gpointer g_dataset_id_get_data (gconstpointer dataset_location
,GQuark key_id
);
Gets the data element corresponding to a GQuark.
#define g_dataset_id_remove_data(l, k)
Removes a data element from a dataset. The data element's destroy function is called if it has been set.
|
the location identifying the dataset. |
|
the GQuark id identifying the data element. |
gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location
,GQuark key_id
);
Removes an element, without calling its destroy notification function.
#define g_dataset_set_data(l, k, d)
Sets the data corresponding to the given string identifier.
|
the location identifying the dataset. |
|
the string to identify the data element. |
|
the data element. |
#define g_dataset_set_data_full(l, k, d, f)
Sets the data corresponding to the given string identifier, and the function to call when the data element is destroyed.
|
the location identifying the dataset. |
|
the string to identify the data element. |
|
the data element. |
|
the function to call when the data element is removed. This function will be called with the data element and can be used to free any memory allocated for it. |
#define g_dataset_get_data(l, k)
Gets the data element corresponding to a string.
|
the location identifying the dataset. |
|
the string identifying the data element. |
Returns : |
the data element corresponding to the string, or NULL if it is not
found. |
#define g_dataset_remove_data(l, k)
Removes a data element corresponding to a string. Its destroy function is called if it has been set.
|
the location identifying the dataset. |
|
the string identifying the data element. |
#define g_dataset_remove_no_notify(l, k)
Removes an element, without calling its destroy notifier.
|
the location identifying the dataset. |
|
the string identifying the data element. |
void g_dataset_foreach (gconstpointer dataset_location
,GDataForeachFunc func
,gpointer user_data
);
Calls the given function for each data element which is associated with the
given location.
Note that this function is NOT thread-safe. So unless datalist
can be protected from any modifications during invocation of this
function, it should not be called.
|
the location identifying the dataset. |
|
the function to call for each data element. |
|
user data to pass to the function. |
void (*GDataForeachFunc) (GQuark key_id
,gpointer data
,gpointer user_data
);
Specifies the type of function passed to g_dataset_foreach()
.
It is called with each GQuark id and associated data element,
together with the user_data
parameter supplied to g_dataset_foreach()
.
|
the GQuark id to identifying the data element. |
|
the data element. |
|
user data passed to g_dataset_foreach() . |
void g_dataset_destroy (gconstpointer dataset_location
);
Destroys the dataset, freeing all memory allocated, and calling any destroy functions set for data elements.
|
the location identifying the dataset. |