1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * gvaluecollector.h: GValue varargs stubs
21 #ifndef __G_VALUE_COLLECTOR_H__
22 #define __G_VALUE_COLLECTOR_H__
27 #endif /* __cplusplus */
30 /* we may want to add aggregate types here some day, if requested
31 * by users. the basic C types are covered already, everything
32 * smaller than an int is promoted to an integer and floats are
33 * always promoted to doubles for varargs call constructions.
40 G_VALUE_COLLECT_DOUBLE,
41 G_VALUE_COLLECT_POINTER
53 /* G_PARAM_COLLECT_VALUE() collects a parameter's variable arguments
54 * from a va_list. we have to implement the varargs collection as a
55 * macro, because on some systems va_list variables cannot be passed
57 * param_value is supposed to be initialized according to the param
58 * type to be collected.
59 * the param_spec argument is optional, but probably needed by most
60 * param class' param_collect_value() implementations.
61 * var_args is the va_list variable and may be evaluated multiple times.
62 * __error is a gchar** variable that will be modified to hold a g_new()
63 * allocated error messages if something fails.
65 #define G_PARAM_COLLECT_VALUE(param_value, param_spec, var_args, __error) \
67 GValue *_value = (param_value); \
68 GParamSpecClass *_pclass = g_type_class_ref (_value->g_type); \
69 GParamSpec *_pspec = (param_spec); \
70 gchar *_error_msg = NULL; \
71 guint _collect_type = _pclass->collect_type; \
72 guint _nth_value = 0; \
75 g_param_spec_ref (_pspec); \
76 g_value_reset (_value); \
77 while (_collect_type && !_error_msg) \
79 GParamCValue _cvalue; \
81 memset (&_cvalue, 0, sizeof (_cvalue)); \
82 switch (_collect_type) \
84 case G_VALUE_COLLECT_INT: \
85 _cvalue.v_int = va_arg ((var_args), gint); \
87 case G_VALUE_COLLECT_LONG: \
88 _cvalue.v_long = va_arg ((var_args), glong); \
90 case G_VALUE_COLLECT_DOUBLE: \
91 _cvalue.v_double = va_arg ((var_args), gdouble); \
93 case G_VALUE_COLLECT_POINTER: \
94 _cvalue.v_pointer = va_arg ((var_args), gpointer); \
97 _error_msg = g_strdup_printf ("%s: invalid collect type (%d) used for %s", \
100 "G_PARAM_COLLECT_VALUE()"); \
103 _error_msg = _pclass->param_collect_value (_value, \
109 *(__error) = _error_msg; \
111 g_param_spec_unref (_pspec); \
112 g_type_class_unref (_pclass); \
116 /* G_PARAM_LCOPY_VALUE() collects a parameter's variable argument
117 * locations from a va_list. usage is analogous to G_PARAM_COLLECT_VALUE().
119 #define G_PARAM_LCOPY_VALUE(param_value, param_spec, var_args, __error) \
121 GValue *_value = (param_value); \
122 GParamSpecClass *_pclass = g_type_class_ref (_value->g_type); \
123 GParamSpec *_pspec = (param_spec); \
124 gchar *_error_msg = NULL; \
125 guint _lcopy_type = _pclass->lcopy_type; \
126 guint _nth_value = 0; \
129 g_param_spec_ref (_pspec); \
130 while (_lcopy_type && !_error_msg) \
132 GParamCValue _cvalue; \
134 memset (&_cvalue, 0, sizeof (_cvalue)); \
135 switch (_lcopy_type) \
137 case G_VALUE_COLLECT_INT: \
138 _cvalue.v_int = va_arg ((var_args), gint); \
140 case G_VALUE_COLLECT_LONG: \
141 _cvalue.v_long = va_arg ((var_args), glong); \
143 case G_VALUE_COLLECT_DOUBLE: \
144 _cvalue.v_double = va_arg ((var_args), gdouble); \
146 case G_VALUE_COLLECT_POINTER: \
147 _cvalue.v_pointer = va_arg ((var_args), gpointer); \
150 _error_msg = g_strdup_printf ("%s: invalid collect type (%d) used for %s", \
153 "G_PARAM_LCOPY_VALUE()"); \
156 _error_msg = _pclass->param_lcopy_value (_value, \
162 *(__error) = _error_msg; \
164 g_param_spec_unref (_pspec); \
165 g_type_class_unref (_pclass); \
172 #endif /* __cplusplus */
174 #endif /* __G_VALUE_COLLECTOR_H__ */