Minor doc markup fix.
[glib.git] / gobject / gvaluecollector.h
blobe9379968a368971c03df84bdfb27f5ad3c2c15fc
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 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__
24 #include <glib-object.h>
26 G_BEGIN_DECLS
28 /* we may want to add aggregate types here some day, if requested
29 * by users. the basic C types are covered already, everything
30 * smaller than an int is promoted to an integer and floats are
31 * always promoted to doubles for varargs call constructions.
33 enum /*< skip >*/
35 G_VALUE_COLLECT_INT = 'i',
36 G_VALUE_COLLECT_LONG = 'l',
37 G_VALUE_COLLECT_INT64 = 'q',
38 G_VALUE_COLLECT_DOUBLE = 'd',
39 G_VALUE_COLLECT_POINTER = 'p'
43 /* vararg union holding actuall values collected
45 union _GTypeCValue
47 gint v_int;
48 glong v_long;
49 gint64 v_int64;
50 gdouble v_double;
51 gpointer v_pointer;
55 /* G_VALUE_COLLECT() collects a variable argument value
56 * from a va_list. we have to implement the varargs collection as a
57 * macro, because on some systems va_list variables cannot be passed
58 * by reference.
59 * value is supposed to be initialized according to the value
60 * type to be collected.
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_VALUE_COLLECT(value, var_args, flags, __error) \
66 G_STMT_START { \
67 GValue *_value = (value); \
68 guint _flags = (flags); \
69 GType _value_type = G_VALUE_TYPE (_value); \
70 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
71 gchar *_collect_format = _vtable->collect_format; \
72 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
73 guint _n_values = 0; \
75 if (_vtable->value_free) \
76 _vtable->value_free (_value); \
77 _value->g_type = _value_type; /* value_meminit() from gvalue.c */ \
78 memset (_value->data, 0, sizeof (_value->data)); \
79 while (*_collect_format) \
80 { \
81 GTypeCValue *_cvalue = _cvalues + _n_values++; \
83 switch (*_collect_format++) \
84 { \
85 case G_VALUE_COLLECT_INT: \
86 _cvalue->v_int = va_arg ((var_args), gint); \
87 break; \
88 case G_VALUE_COLLECT_LONG: \
89 _cvalue->v_long = va_arg ((var_args), glong); \
90 break; \
91 case G_VALUE_COLLECT_INT64: \
92 _cvalue->v_int64 = va_arg ((var_args), gint64); \
93 break; \
94 case G_VALUE_COLLECT_DOUBLE: \
95 _cvalue->v_double = va_arg ((var_args), gdouble); \
96 break; \
97 case G_VALUE_COLLECT_POINTER: \
98 _cvalue->v_pointer = va_arg ((var_args), gpointer); \
99 break; \
100 default: \
101 g_assert_not_reached (); \
104 *(__error) = _vtable->collect_value (_value, \
105 _n_values, \
106 _cvalues, \
107 _flags); \
108 } G_STMT_END
111 /* G_VALUE_LCOPY() collects a value's variable argument
112 * locations from a va_list. usage is analogous to G_VALUE_COLLECT().
114 #define G_VALUE_LCOPY(value, var_args, flags, __error) \
115 G_STMT_START { \
116 const GValue *_value = (value); \
117 guint _flags = (flags); \
118 GType _value_type = G_VALUE_TYPE (_value); \
119 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
120 gchar *_lcopy_format = _vtable->lcopy_format; \
121 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
122 guint _n_values = 0; \
124 while (*_lcopy_format) \
126 GTypeCValue *_cvalue = _cvalues + _n_values++; \
128 switch (*_lcopy_format++) \
130 case G_VALUE_COLLECT_INT: \
131 _cvalue->v_int = va_arg ((var_args), gint); \
132 break; \
133 case G_VALUE_COLLECT_LONG: \
134 _cvalue->v_long = va_arg ((var_args), glong); \
135 break; \
136 case G_VALUE_COLLECT_INT64: \
137 _cvalue->v_int64 = va_arg ((var_args), gint64); \
138 break; \
139 case G_VALUE_COLLECT_DOUBLE: \
140 _cvalue->v_double = va_arg ((var_args), gdouble); \
141 break; \
142 case G_VALUE_COLLECT_POINTER: \
143 _cvalue->v_pointer = va_arg ((var_args), gpointer); \
144 break; \
145 default: \
146 g_assert_not_reached (); \
149 *(__error) = _vtable->lcopy_value (_value, \
150 _n_values, \
151 _cvalues, \
152 _flags); \
153 } G_STMT_END
156 #define G_VALUE_COLLECT_FORMAT_MAX_LENGTH (8)
158 G_END_DECLS
160 #endif /* __G_VALUE_COLLECTOR_H__ */