[17276] | 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 |
---|
[18274] | 7 | modify it under the terms of the GNU Library General Public License as |
---|
[17276] | 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 |
---|
[18274] | 14 | Library General Public License for more details. |
---|
[17276] | 15 | |
---|
[18274] | 16 | You should have received a copy of the GNU Library General Public |
---|
[17276] | 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 | |
---|
[18274] | 24 | #include "config.h" |
---|
[17276] | 25 | #include "rsvg-defs.h" |
---|
| 26 | |
---|
[18274] | 27 | #include <glib/ghash.h> |
---|
| 28 | #include <glib/gmem.h> |
---|
| 29 | #include <glib/gstrfuncs.h> |
---|
| 30 | |
---|
[17276] | 31 | struct _RsvgDefs { |
---|
| 32 | GHashTable *hash; |
---|
| 33 | }; |
---|
| 34 | |
---|
| 35 | RsvgDefs * |
---|
| 36 | rsvg_defs_new (void) |
---|
| 37 | { |
---|
| 38 | RsvgDefs *result = g_new (RsvgDefs, 1); |
---|
| 39 | |
---|
| 40 | result->hash = g_hash_table_new (g_str_hash, g_str_equal); |
---|
| 41 | |
---|
| 42 | return result; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | RsvgDefVal * |
---|
| 46 | rsvg_defs_lookup (const RsvgDefs *defs, const char *name) |
---|
| 47 | { |
---|
| 48 | return (RsvgDefVal *)g_hash_table_lookup (defs->hash, name); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void |
---|
| 52 | rsvg_defs_set (RsvgDefs *defs, const char *name, RsvgDefVal *val) |
---|
| 53 | { |
---|
| 54 | g_hash_table_insert (defs->hash, g_strdup (name), val); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | static void |
---|
| 58 | rsvg_defs_free_each (gpointer key, gpointer value, gpointer user_data) |
---|
| 59 | { |
---|
| 60 | RsvgDefVal *def_val = (RsvgDefVal *)value; |
---|
| 61 | g_free (key); |
---|
| 62 | def_val->free (def_val); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void |
---|
| 66 | rsvg_defs_free (RsvgDefs *defs) |
---|
| 67 | { |
---|
| 68 | g_hash_table_foreach (defs->hash, rsvg_defs_free_each, NULL); |
---|
| 69 | g_hash_table_destroy (defs->hash); |
---|
| 70 | g_free (defs); |
---|
| 71 | } |
---|