1 | /* |
---|
2 | rsvg-defs.c: Manage SVG defs and references. |
---|
3 | |
---|
4 | Copyright (C) 2000 Eazel, Inc. |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU General Public License as |
---|
8 | published by the Free Software Foundation; either version 2 of the |
---|
9 | License, or (at your option) any later version. |
---|
10 | |
---|
11 | This program 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 | General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public |
---|
17 | License along with this program; if not, write to the |
---|
18 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | |
---|
21 | Author: Raph Levien <raph@artofcode.com> |
---|
22 | */ |
---|
23 | |
---|
24 | #include <glib.h> |
---|
25 | #include "rsvg-defs.h" |
---|
26 | |
---|
27 | struct _RsvgDefs { |
---|
28 | GHashTable *hash; |
---|
29 | }; |
---|
30 | |
---|
31 | RsvgDefs * |
---|
32 | rsvg_defs_new (void) |
---|
33 | { |
---|
34 | RsvgDefs *result = g_new (RsvgDefs, 1); |
---|
35 | |
---|
36 | result->hash = g_hash_table_new (g_str_hash, g_str_equal); |
---|
37 | |
---|
38 | return result; |
---|
39 | } |
---|
40 | |
---|
41 | RsvgDefVal * |
---|
42 | rsvg_defs_lookup (const RsvgDefs *defs, const char *name) |
---|
43 | { |
---|
44 | return (RsvgDefVal *)g_hash_table_lookup (defs->hash, name); |
---|
45 | } |
---|
46 | |
---|
47 | void |
---|
48 | rsvg_defs_set (RsvgDefs *defs, const char *name, RsvgDefVal *val) |
---|
49 | { |
---|
50 | g_hash_table_insert (defs->hash, g_strdup (name), val); |
---|
51 | } |
---|
52 | |
---|
53 | static void |
---|
54 | rsvg_defs_free_each (gpointer key, gpointer value, gpointer user_data) |
---|
55 | { |
---|
56 | RsvgDefVal *def_val = (RsvgDefVal *)value; |
---|
57 | g_free (key); |
---|
58 | def_val->free (def_val); |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | rsvg_defs_free (RsvgDefs *defs) |
---|
63 | { |
---|
64 | g_hash_table_foreach (defs->hash, rsvg_defs_free_each, NULL); |
---|
65 | g_hash_table_destroy (defs->hash); |
---|
66 | g_free (defs); |
---|
67 | } |
---|