1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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 Public
15 * 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.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 /* collect a single argument value from a va_list.
28 * this is implemented as a huge macro <shrug>, because we can't
29 * pass va_list variables by reference on some systems.
30 * the corresponding prototype would be:
31 * static inline gchar*
32 * gtk_arg_collect_value (GtkArg *arg,
35 #define GTK_ARG_COLLECT_VALUE(arg, var_args, _error) \
38 GtkType fundamental_type; \
40 fundamental_type = GTK_FUNDAMENTAL_TYPE (arg->type); \
43 switch (fundamental_type) \
45 case GTK_TYPE_INVALID: \
46 error_msg = g_strdup ("invalid untyped argument"); \
50 /* we just ignore this type, since it arithmetically just requires \
51 * us to not move the var_args pointer any further. callers need to \
52 * check for the validity of GTK_TYPE_NONE themselves. \
54 * error_msg = g_strdup ("invalid argument type `void'"); \
58 /* everything smaller than an int is guarranteed to be \
62 GTK_VALUE_CHAR (*arg) = va_arg (var_args, gint); \
64 case GTK_TYPE_UCHAR: \
65 GTK_VALUE_UCHAR (*arg) = va_arg (var_args, guint); \
68 GTK_VALUE_BOOL (*arg) = va_arg (var_args, gint); \
71 GTK_VALUE_INT (*arg) = va_arg (var_args, gint); \
74 GTK_VALUE_UINT (*arg) = va_arg (var_args, guint); \
77 GTK_VALUE_ENUM (*arg) = va_arg (var_args, gint); \
79 case GTK_TYPE_FLAGS: \
80 GTK_VALUE_FLAGS (*arg) = va_arg (var_args, guint); \
83 /* we collect longs as glongs since they differ in size with \
84 * integers on some platforms \
87 GTK_VALUE_LONG (*arg) = va_arg (var_args, glong); \
89 case GTK_TYPE_ULONG: \
90 GTK_VALUE_ULONG (*arg) = va_arg (var_args, gulong); \
93 /* floats are always passed as doubles \
95 case GTK_TYPE_FLOAT: \
96 /* GTK_VALUE_FLOAT (*arg) = va_arg (var_args, gfloat); */ \
97 GTK_VALUE_FLOAT (*arg) = va_arg (var_args, gdouble); \
99 case GTK_TYPE_DOUBLE: \
100 GTK_VALUE_DOUBLE (*arg) = va_arg (var_args, gdouble); \
103 /* collect pointer values \
105 case GTK_TYPE_STRING: \
106 GTK_VALUE_STRING (*arg) = va_arg (var_args, gchar*); \
108 case GTK_TYPE_POINTER: \
109 GTK_VALUE_POINTER (*arg) = va_arg (var_args, gpointer); \
111 case GTK_TYPE_BOXED: \
112 GTK_VALUE_BOXED (*arg) = va_arg (var_args, gpointer); \
115 /* structured types \
117 case GTK_TYPE_SIGNAL: \
118 GTK_VALUE_SIGNAL (*arg).f = va_arg (var_args, GtkSignalFunc); \
119 GTK_VALUE_SIGNAL (*arg).d = va_arg (var_args, gpointer); \
122 /* we do some extra sanity checking when collecting objects, \
123 * i.e. if the object pointer is not NULL, we check whether we \
124 * actually got an object pointer within the desired class branch. \
126 case G_TYPE_OBJECT: \
127 GTK_VALUE_OBJECT (*arg) = va_arg (var_args, GtkObject*); \
128 if (GTK_VALUE_OBJECT (*arg) != NULL) \
130 register GtkObject *object = GTK_VALUE_OBJECT (*arg); \
132 if (((GTypeInstance*) object)->g_class == NULL) \
133 error_msg = g_strconcat ("invalid unclassed object pointer for argument type `", \
134 gtk_type_name (arg->type), \
137 else if (!gtk_type_is_a (GTK_OBJECT_TYPE (object), arg->type)) \
138 error_msg = g_strconcat ("invalid object `", \
139 gtk_type_name (G_OBJECT_TYPE (object)), \
140 "' for argument type `", \
141 gtk_type_name (arg->type), \
148 error_msg = g_strconcat ("unsupported argument type `", \
149 gtk_type_name (arg->type), \
155 _error = error_msg; /* return error_msg; */ \