1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * gsf-docprop-vector.c: A type implementing OLE Document Property vectors using a GValueArray
5 * Copyright (C) 2004-2006 Frank Chiulli (fc-linux@cox.net)
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-docprop-vector.h>
24 #include <gsf/gsf-impl-utils.h>
27 struct _GsfDocPropVector {
32 typedef GObjectClass GsfDocPropVectorClass;
34 #define GSF_DOCPROP_VECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GSF_DOCPROP_VECTOR_TYPE, GsfDocPropVectorClass))
35 #define GSF_DOCPROP_VECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GSF_DOCPROP_VECTOR_TYPE, GsfDocPropVectorClass))
36 #define IS_GSF_DOCPROP_VECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GSF_DOCPROP_VECTOR_TYPE))
38 static GObjectClass *parent_class;
41 gsf_value_get_docprop_varray (GValue const *value)
43 GsfDocPropVector *v = gsf_value_get_docprop_vector (value);
44 return v ? v->gva : NULL;
48 * gsf_docprop_value_get_vector
49 * @value: A GValue of type #GsfDocPropVector.
51 * This function returns a pointer to the GsfDocPropVector structure in @value.
52 * No additional references are created.
54 * Returns: A pointer to the #GsfDocPropVector structure in @value
57 gsf_value_get_docprop_vector (GValue const *value)
59 g_return_val_if_fail (VAL_IS_GSF_DOCPROP_VECTOR (value), NULL);
61 return (GsfDocPropVector *) g_value_get_object (value);
65 * gsf_docprop_vector_append
66 * @vector: The vector to which the GValue will be added
67 * @value: The GValue to add to @vector
69 * Insert a copy of @value as the last element of @vector.
72 gsf_docprop_vector_append (GsfDocPropVector *vector, GValue *value)
74 g_return_if_fail (vector != NULL);
75 g_return_if_fail (value != NULL);
77 if (G_IS_VALUE (value))
78 vector->gva = g_value_array_append (vector->gva, value);
82 * gsf_docprop_vector_as_string
83 * @vector: The #GsfDocPropVector from which GValues will be extracted.
85 * This function returns a string which represents all the GValues in @vector.
86 * The caller is responsible for freeing the result.
88 * Returns: a string of comma-separated values
91 gsf_docprop_vector_as_string (GsfDocPropVector const *vector)
98 g_return_val_if_fail (vector != NULL, NULL);
99 g_return_val_if_fail (vector->gva != NULL, NULL);
101 rstring = g_new0 (gchar, 1);
102 num_values = vector->gva->n_values;
104 for (i = 0; i < num_values; i++) {
108 v = g_value_array_get_nth (vector->gva, i);
109 str = g_strdup_value_contents (v);
110 rstring = g_strconcat (rstring, str, ",", NULL);
118 gsf_docprop_vector_finalize (GObject *obj)
120 GsfDocPropVector *vector = (GsfDocPropVector *) obj;
121 if (vector->gva != NULL) {
122 g_value_array_free (vector->gva);
125 parent_class->finalize (obj);
129 gsf_docprop_vector_class_init (GObjectClass *gobject_class)
131 parent_class = g_type_class_peek (G_TYPE_OBJECT);
132 gobject_class->finalize = gsf_docprop_vector_finalize;
136 gsf_docprop_vector_init (GsfDocPropVector *vector)
138 vector->gva = g_value_array_new (0);
141 GSF_CLASS (GsfDocPropVector, gsf_docprop_vector,
142 gsf_docprop_vector_class_init, gsf_docprop_vector_init,
146 * gsf_docprop_vector_new
148 * This function creates a new gsf_docprop_vector object.
150 * Returns: GsfDocPropVector*
153 gsf_docprop_vector_new (void)
155 return g_object_new (GSF_DOCPROP_VECTOR_TYPE, NULL);