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