1 | /* vim: set sw=4: -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
---|
2 | /* |
---|
3 | rsvg-defs.c: Manage SVG defs and references. |
---|
4 | |
---|
5 | Copyright (C) 2000 Eazel, Inc. |
---|
6 | |
---|
7 | This program is free software; you can redistribute it and/or |
---|
8 | modify it under the terms of the GNU Library General Public License as |
---|
9 | published by the Free Software Foundation; either version 2 of the |
---|
10 | License, or (at your option) any later version. |
---|
11 | |
---|
12 | This program is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
15 | Library General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU Library General Public |
---|
18 | License along with this program; if not, write to the |
---|
19 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
20 | Boston, MA 02111-1307, USA. |
---|
21 | |
---|
22 | Author: Raph Levien <raph@artofcode.com> |
---|
23 | */ |
---|
24 | |
---|
25 | #include "config.h" |
---|
26 | #include "rsvg-private.h" |
---|
27 | #include "rsvg-defs.h" |
---|
28 | |
---|
29 | #include <glib/ghash.h> |
---|
30 | #include <glib/gmem.h> |
---|
31 | #include <glib/gstrfuncs.h> |
---|
32 | #include <glib/gmessages.h> |
---|
33 | |
---|
34 | struct _RsvgDefs { |
---|
35 | GHashTable *hash; |
---|
36 | GPtrArray *unnamed; |
---|
37 | }; |
---|
38 | |
---|
39 | static void |
---|
40 | rsvg_defs_free_value (gpointer value) |
---|
41 | { |
---|
42 | RsvgDefVal *def_val = (RsvgDefVal *)value; |
---|
43 | def_val->free (def_val); |
---|
44 | } |
---|
45 | |
---|
46 | RsvgDefs * |
---|
47 | rsvg_defs_new (void) |
---|
48 | { |
---|
49 | RsvgDefs *result = g_new (RsvgDefs, 1); |
---|
50 | |
---|
51 | result->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, rsvg_defs_free_value); |
---|
52 | result->unnamed = g_ptr_array_new (); |
---|
53 | |
---|
54 | return result; |
---|
55 | } |
---|
56 | |
---|
57 | RsvgDefVal * |
---|
58 | rsvg_defs_lookup (const RsvgDefs *defs, const char *name) |
---|
59 | { |
---|
60 | return (RsvgDefVal *)g_hash_table_lookup (defs->hash, name); |
---|
61 | } |
---|
62 | |
---|
63 | void |
---|
64 | rsvg_defs_set (RsvgDefs *defs, const char *name, RsvgDefVal *val) |
---|
65 | { |
---|
66 | if (name == NULL) |
---|
67 | g_ptr_array_add(defs->unnamed, val); |
---|
68 | else if (name[0] == '\0') |
---|
69 | g_ptr_array_add(defs->unnamed, val); |
---|
70 | else |
---|
71 | g_hash_table_insert (defs->hash, g_strdup (name), val); |
---|
72 | } |
---|
73 | |
---|
74 | void |
---|
75 | rsvg_defs_free (RsvgDefs *defs) |
---|
76 | { |
---|
77 | guint i; |
---|
78 | |
---|
79 | g_hash_table_destroy (defs->hash); |
---|
80 | |
---|
81 | for (i = 0; i < defs->unnamed->len; i++) |
---|
82 | ((RsvgDefVal *)g_ptr_array_index(defs->unnamed, i))->free(g_ptr_array_index(defs->unnamed, i)); |
---|
83 | g_ptr_array_free(defs->unnamed, TRUE); |
---|
84 | |
---|
85 | g_free (defs); |
---|
86 | } |
---|