1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <data/variable.h>
20 #include "psppire-var-ptr.h"
23 /* This module registers a type with Glib to hold pointers
24 to a {struct variable}. It also registers some tranformation functions so
25 that variables may be converted to strings and ints.
26 Note that the type is just a pointer. It's the user's responsibility to
27 ensure that it always points to something valid.
31 /* Shallow copy the pointer */
33 variable_copy (gpointer var)
38 /* Do nothing. It's a pointer only! */
40 variable_free (gpointer var)
45 /* Convert to a string, by using the variable's name */
47 variable_to_string (const GValue *src,
50 const struct variable *v = g_value_get_boxed (src);
53 g_value_set_string (dest, "");
55 g_value_set_string (dest, var_get_name (v));
59 /* Convert to an int, using the dictionary index. */
61 variable_to_int (const GValue *src,
64 const struct variable *v = g_value_get_boxed (src);
67 g_value_set_int (dest, -1);
69 g_value_set_int (dest, var_get_dict_index (v));
76 psppire_var_ptr_get_type (void)
82 t = g_boxed_type_register_static ("psppire-var-ptr",
83 (GBoxedCopyFunc) variable_copy,
84 (GBoxedFreeFunc) variable_free);
86 g_value_register_transform_func (t, G_TYPE_STRING,
89 g_value_register_transform_func (t, G_TYPE_INT,