1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of version 2.1 of the GNU Lesser General Public
9 * License as published by the Free Software Foundation.
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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #include <gsf-config.h>
23 #include <gsf/gsf-infile-impl.h>
24 #include <gsf/gsf-impl-utils.h>
28 #define GET_CLASS(instance) G_TYPE_INSTANCE_GET_CLASS (instance, GSF_INFILE_TYPE, GsfInfileClass)
31 * gsf_infile_num_children :
32 * @infile : the structured storage
34 * Returns: the number of children the storage has, or -1 if the storage can not
38 gsf_infile_num_children (GsfInfile *infile)
40 g_return_val_if_fail (infile != NULL, -1);
42 return GET_CLASS (infile)->num_children (infile);
46 * gsf_infile_name_by_index :
50 * Returns: the utf8 encoded name of the @i-th child
51 * <emphasis>DO NOT FREE THE STRING.</emphasis>
54 gsf_infile_name_by_index (GsfInfile *infile, int i)
56 g_return_val_if_fail (infile != NULL, NULL);
58 return GET_CLASS (infile)->name_by_index (infile, i);
62 * gsf_infile_child_by_index :
63 * @infile : #GsfInfile
66 * TODO : For 2.0 api will change to include a GError.
67 * Returns: a newly created child which must be unrefed.
70 gsf_infile_child_by_index (GsfInfile *infile, int i)
75 g_return_val_if_fail (GSF_INFILE (infile) != NULL, NULL);
77 res = GET_CLASS (infile)->child_by_index (infile, i, &err);
80 char const *iname = gsf_input_name (GSF_INPUT (infile));
81 g_warning ("Unable to get child[%d] for infile '%s' because : %s",
82 i, iname ? iname : "?", err->message);
84 g_return_val_if_fail (res == NULL, NULL); /* be anal */
91 * gsf_infile_child_by_name :
92 * @infile : #GsfInfile
95 * TODO : For 2.0 api will change to include a GError.
96 * Returns: a newly created child which must be unrefed.
99 gsf_infile_child_by_name (GsfInfile *infile, char const *name)
104 g_return_val_if_fail (GSF_INFILE (infile) != NULL, NULL);
105 g_return_val_if_fail (name != NULL, NULL);
107 res = GET_CLASS (infile)->child_by_name (infile, name, &err);
110 char const *iname = gsf_input_name (GSF_INPUT (infile));
111 g_warning ("Unable to get child['%s'] for infile '%s' because : %s",
112 name, iname ? iname : "?", err->message);
114 g_return_val_if_fail (res == NULL, NULL); /* be anal */
121 * gsf_infile_child_by_vname :
123 * @Varargs : A %NULL terminated list of names
125 * Returns: a newly created child which must be unrefed.
128 gsf_infile_child_by_vname (GsfInfile *infile, ...)
133 va_start (names, infile);
134 res = gsf_infile_child_by_vaname (infile, names);
141 * gsf_infile_child_by_vaname :
142 * @infile : #GsfInfile
143 * @names : A %NULL terminated array of names (e.g. from g_strsplit)
147 * Returns: a newly created child which must be unrefed.
150 gsf_infile_child_by_vaname (GsfInfile *infile, va_list names)
152 GsfInput *child = GSF_INPUT (infile);
153 GsfInfile *tmp = NULL;
156 g_return_val_if_fail (GSF_IS_INFILE (infile), NULL);
158 while (NULL != (name = va_arg (names, char const *))) {
159 child = gsf_infile_child_by_name (infile, name);
163 g_object_unref (G_OBJECT (tmp));
165 g_return_val_if_fail (GSF_IS_INFILE (child), NULL);
167 infile = tmp = GSF_INFILE (child);
174 * gsf_infile_child_by_aname :
175 * @infile : #GsfInfile
176 * @names : A %NULL terminated array of names (e.g. from g_strsplit)
180 * Returns: a newly created child which must be unrefed.
183 gsf_infile_child_by_aname (GsfInfile *infile, char const *names[])
185 GsfInput *child = GSF_INPUT (infile);
186 GsfInfile *tmp = NULL;
188 g_return_val_if_fail (GSF_IS_INFILE (infile), NULL);
189 g_return_val_if_fail (names != NULL, NULL);
191 for (;*names ; names++) {
192 child = gsf_infile_child_by_name (infile, *names);
194 g_object_unref (G_OBJECT (tmp));
198 g_return_val_if_fail (GSF_IS_INFILE (child), NULL);
200 infile = tmp = GSF_INFILE (child);
206 GSF_CLASS_ABSTRACT (GsfInfile, gsf_infile, NULL, NULL, GSF_INPUT_TYPE)