1/* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20/*
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 */
26
27#ifndef __G_DATASET_H__
28#define __G_DATASET_H__
29
30#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31#error "Only <glib.h> can be included directly."
32#endif
33
34#include <glib/gquark.h>
35
36G_BEGIN_DECLS
37
38typedef struct _GData GData;
39
40typedef void (*GDataForeachFunc) (GQuark key_id,
41 gpointer data,
42 gpointer user_data);
43
44/* Keyed Data List
45 */
46GLIB_AVAILABLE_IN_ALL
47void g_datalist_init (GData **datalist);
48GLIB_AVAILABLE_IN_ALL
49void g_datalist_clear (GData **datalist);
50GLIB_AVAILABLE_IN_ALL
51gpointer g_datalist_id_get_data (GData **datalist,
52 GQuark key_id);
53GLIB_AVAILABLE_IN_ALL
54void g_datalist_id_set_data_full (GData **datalist,
55 GQuark key_id,
56 gpointer data,
57 GDestroyNotify destroy_func);
58GLIB_AVAILABLE_IN_2_74
59void g_datalist_id_remove_multiple (GData **datalist,
60 GQuark *keys,
61 gsize n_keys);
62
63typedef gpointer (*GDuplicateFunc) (gpointer data, gpointer user_data);
64
65GLIB_AVAILABLE_IN_2_34
66gpointer g_datalist_id_dup_data (GData **datalist,
67 GQuark key_id,
68 GDuplicateFunc dup_func,
69 gpointer user_data);
70GLIB_AVAILABLE_IN_2_34
71gboolean g_datalist_id_replace_data (GData **datalist,
72 GQuark key_id,
73 gpointer oldval,
74 gpointer newval,
75 GDestroyNotify destroy,
76 GDestroyNotify *old_destroy);
77
78GLIB_AVAILABLE_IN_ALL
79gpointer g_datalist_id_remove_no_notify (GData **datalist,
80 GQuark key_id);
81GLIB_AVAILABLE_IN_ALL
82void g_datalist_foreach (GData **datalist,
83 GDataForeachFunc func,
84 gpointer user_data);
85
86/**
87 * G_DATALIST_FLAGS_MASK:
88 *
89 * A bitmask that restricts the possible flags passed to
90 * g_datalist_set_flags(). Passing a flags value where
91 * flags & ~G_DATALIST_FLAGS_MASK != 0 is an error.
92 */
93#define G_DATALIST_FLAGS_MASK 0x3
94
95GLIB_AVAILABLE_IN_ALL
96void g_datalist_set_flags (GData **datalist,
97 guint flags);
98GLIB_AVAILABLE_IN_ALL
99void g_datalist_unset_flags (GData **datalist,
100 guint flags);
101GLIB_AVAILABLE_IN_ALL
102guint g_datalist_get_flags (GData **datalist);
103
104#define g_datalist_id_set_data(dl, q, d) \
105 g_datalist_id_set_data_full ((dl), (q), (d), NULL)
106#define g_datalist_id_remove_data(dl, q) \
107 g_datalist_id_set_data ((dl), (q), NULL)
108#define g_datalist_set_data_full(dl, k, d, f) \
109 g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
110#define g_datalist_remove_no_notify(dl, k) \
111 g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
112#define g_datalist_set_data(dl, k, d) \
113 g_datalist_set_data_full ((dl), (k), (d), NULL)
114#define g_datalist_remove_data(dl, k) \
115 g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
116
117/* Location Associated Keyed Data
118 */
119GLIB_AVAILABLE_IN_ALL
120void g_dataset_destroy (gconstpointer dataset_location);
121GLIB_AVAILABLE_IN_ALL
122gpointer g_dataset_id_get_data (gconstpointer dataset_location,
123 GQuark key_id);
124GLIB_AVAILABLE_IN_ALL
125gpointer g_datalist_get_data (GData **datalist,
126 const gchar *key);
127GLIB_AVAILABLE_IN_ALL
128void g_dataset_id_set_data_full (gconstpointer dataset_location,
129 GQuark key_id,
130 gpointer data,
131 GDestroyNotify destroy_func);
132GLIB_AVAILABLE_IN_ALL
133gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location,
134 GQuark key_id);
135GLIB_AVAILABLE_IN_ALL
136void g_dataset_foreach (gconstpointer dataset_location,
137 GDataForeachFunc func,
138 gpointer user_data);
139#define g_dataset_id_set_data(l, k, d) \
140 g_dataset_id_set_data_full ((l), (k), (d), NULL)
141#define g_dataset_id_remove_data(l, k) \
142 g_dataset_id_set_data ((l), (k), NULL)
143#define g_dataset_get_data(l, k) \
144 (g_dataset_id_get_data ((l), g_quark_try_string (k)))
145#define g_dataset_set_data_full(l, k, d, f) \
146 g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
147#define g_dataset_remove_no_notify(l, k) \
148 g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
149#define g_dataset_set_data(l, k, d) \
150 g_dataset_set_data_full ((l), (k), (d), NULL)
151#define g_dataset_remove_data(l, k) \
152 g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
153
154G_END_DECLS
155
156#endif /* __G_DATASET_H__ */
157