No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | rb-string-value-map.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | rb-string-value-map.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * Copyright (C) 2007 James Livingston <doclivingston@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * The Rhythmbox authors hereby grant permission for non-GPL compatible
10 * GStreamer plugins to be used and distributed together with GStreamer
11 * and Rhythmbox. This permission is above and beyond the permissions granted
12 * by the GPL license by which Rhythmbox is covered. If you modify this code
13 * you may extend this exception to your version of the code, but you are not
14 * obligated to do so. If you do not wish to do so, delete this exception
15 * statement from your version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 *
26 */
27
28 #include "config.h"
29
30 #include "rb-string-value-map.h"
31
32 #include "rb-util.h"
33
34 /**
35 * SECTION:rb-string-value-map
36 * @short_description: specialized hash table for storing string to GValue mappings
37 *
38 * Simplifies the use of string:GValue maps with respect to copying of the values
39 * inserted into the map. Except for rb_string_value_map_peek, the caller retains
40 * ownership of values passed in, and assumes ownership of all values returned.
41 */
42
43 static void rb_string_value_map_finalize (GObject *obj);
44
45
46 struct RBStringValueMapPrivate {
47 GHashTable *map;
48 };
49
50 G_DEFINE_TYPE (RBStringValueMap, rb_string_value_map, G_TYPE_OBJECT)
51
52
53 static void
54 rb_string_value_map_class_init (RBStringValueMapClass *klass)
55 {
56 GObjectClass *object_class = G_OBJECT_CLASS (klass);
57
58 object_class->finalize = rb_string_value_map_finalize;
59
60 g_type_class_add_private (klass, sizeof (RBStringValueMapPrivate));
61 }
62
63 static void
64 rb_string_value_map_init (RBStringValueMap *map)
65 {
66 map->priv = G_TYPE_INSTANCE_GET_PRIVATE (map, RB_TYPE_STRING_VALUE_MAP, RBStringValueMapPrivate);
67
68 map->priv->map = g_hash_table_new_full (g_str_hash,
69 g_str_equal,
70 (GDestroyNotify)g_free,
71 (GDestroyNotify)rb_value_free);
72 }
73
74 static void
75 rb_string_value_map_finalize (GObject *obj)
76 {
77 RBStringValueMap *map = RB_STRING_VALUE_MAP (obj);
78
79 g_hash_table_destroy (map->priv->map);
80
81 G_OBJECT_CLASS(rb_string_value_map_parent_class)->finalize (obj);
82 }
83
84 /**
85 * rb_string_value_map_new:
86 *
87 * Creates a new #RBStringValueMap
88 *
89 * Return value: new empty #RBStringValueMap
90 */
91 RBStringValueMap*
92 rb_string_value_map_new (void)
93 {
94 return g_object_new (RB_TYPE_STRING_VALUE_MAP, NULL);
95 }
96
97
98 /**
99 * rb_string_value_map_set:
100 * @map: a #RBStringValueMap
101 * @key: key to set
102 * @value: value to store
103 *
104 * Inserts a value into the map. The value is copied.
105 */
106 void
107 rb_string_value_map_set (RBStringValueMap *map,
108 const char *key,
109 const GValue *value)
110 {
111 GValue *val;
112
113 val = g_slice_new0 (GValue);
114 g_value_init (val, G_VALUE_TYPE (value));
115 g_value_copy (value, val);
116 g_hash_table_insert (map->priv->map, g_strdup(key), val);
117 }
118
119 /**
120 * rb_string_value_map_remove:
121 * @map: a #RBStringValueMap
122 * @key: key to remove
123 *
124 * Removes a value from the map.
125 *
126 * Return value: %TRUE if the value was found and removed
127 */
128 gboolean
129 rb_string_value_map_remove (RBStringValueMap *map,
130 const char *key)
131 {
132 return g_hash_table_remove (map->priv->map, key);
133 }
134
135 /**
136 * rb_string_value_map_size:
137 * @map: a #RBStringValueMap
138 *
139 * Returns the number of entries in the map.
140 *
141 * Return value: number of entries
142 */
143 guint
144 rb_string_value_map_size (RBStringValueMap *map)
145 {
146 return g_hash_table_size (map->priv->map);
147 }
148
149 /**
150 * rb_string_value_map_get:
151 * @map: a #RBStringValueMap
152 * @key: key to retrieve
153 * @out: returns a copy of the value in the map
154 *
155 * Locates and copies the value associated with the key.
156 *
157 * Return value: %TRUE if the value was found
158 */
159 gboolean
160 rb_string_value_map_get (RBStringValueMap *map,
161 const char *key,
162 GValue *out)
163 {
164 GValue *val;
165
166 val = g_hash_table_lookup (map->priv->map, key);
167
168 if (val == NULL)
169 return FALSE;
170
171 g_value_init (out, G_VALUE_TYPE (val));
172 g_value_copy (val, out);
173 return TRUE;
174 }
175
176 /**
177 * rb_string_value_map_peek:
178 * @map: a #RBStringValueMap
179 * @key: key to retrieve
180 *
181 * Locates the value associated with the key. This returns the
182 * GValue stored in the map, so it cannot be modified.
183 *
184 * Return value: the GValue associated with the key
185 */
186 const GValue*
187 rb_string_value_map_peek (RBStringValueMap *map,
188 const char *key)
189 {
190 return g_hash_table_lookup (map->priv->map, key);
191 }
192
193 /**
194 * rb_string_value_map_steal_hashtable:
195 * @map: a #RBStringValueMap
196 *
197 * Extracts and returns the underlying hash table from the map,
198 * and creates a new empty map.
199 *
200 * Return value: (transfer full): #GHashTable from the map
201 */
202 GHashTable*
203 rb_string_value_map_steal_hashtable (RBStringValueMap *map)
204 {
205 GHashTable *old;
206
207 old = map->priv->map;
208 map->priv->map = g_hash_table_new_full (g_str_hash,
209 g_str_equal,
210 (GDestroyNotify)g_free,
211 (GDestroyNotify)rb_value_free);
212
213 return old;
214 }