add reserved fundamental ids for gtk types (for transition time). added
[platform/upstream/glib.git] / gobject / gvaluecollector.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  *
19  * gvaluecollector.h: GValue varargs stubs
20  */
21 #ifndef __G_VALUE_COLLECTOR_H__
22 #define __G_VALUE_COLLECTOR_H__
23
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28
29
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.
34  */
35 enum    /*< skip >*/
36 {
37   G_VALUE_COLLECT_NONE,
38   G_VALUE_COLLECT_INT,
39   G_VALUE_COLLECT_LONG,
40   G_VALUE_COLLECT_DOUBLE,
41   G_VALUE_COLLECT_POINTER
42 };
43
44 union _GParamCValue
45 {
46   gint     v_int;
47   glong    v_long;
48   gdouble  v_double;
49   gpointer v_pointer;
50 };
51
52
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
56  * by reference.
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.
64  */
65 #define G_PARAM_COLLECT_VALUE(param_value, param_spec, var_args, __error)               \
66 G_STMT_START {                                                                          \
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;                                                                 \
73                                                                                         \
74   if (_pspec)                                                                           \
75     g_param_spec_ref (_pspec);                                                          \
76   g_value_reset (_value);                                                               \
77   while (_collect_type && !_error_msg)                                                  \
78     {                                                                                   \
79       GParamCValue _cvalue;                                                             \
80                                                                                         \
81       memset (&_cvalue, 0, sizeof (_cvalue));                                           \
82       switch (_collect_type)                                                            \
83         {                                                                               \
84         case G_VALUE_COLLECT_INT:                                                       \
85           _cvalue.v_int = va_arg ((var_args), gint);                                    \
86           break;                                                                        \
87         case G_VALUE_COLLECT_LONG:                                                      \
88           _cvalue.v_long = va_arg ((var_args), glong);                                  \
89           break;                                                                        \
90         case G_VALUE_COLLECT_DOUBLE:                                                    \
91           _cvalue.v_double = va_arg ((var_args), gdouble);                              \
92           break;                                                                        \
93         case G_VALUE_COLLECT_POINTER:                                                   \
94           _cvalue.v_pointer = va_arg ((var_args), gpointer);                            \
95           break;                                                                        \
96         default:                                                                        \
97           _error_msg  = g_strdup_printf ("%s: invalid collect type (%d) used for %s",   \
98                                          G_STRLOC,                                      \
99                                          _collect_type,                                 \
100                                          "G_PARAM_COLLECT_VALUE()");                    \
101           continue;                                                                     \
102         }                                                                               \
103       _error_msg = _pclass->param_collect_value (_value,                                \
104                                                  _pspec,                                \
105                                                  _nth_value++,                          \
106                                                  &_collect_type,                        \
107                                                  &_cvalue);                             \
108     }                                                                                   \
109   *(__error) = _error_msg;                                                              \
110   if (_pspec)                                                                           \
111     g_param_spec_unref (_pspec);                                                        \
112   g_type_class_unref (_pclass);                                                         \
113 } G_STMT_END
114
115
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().
118  */
119 #define G_PARAM_LCOPY_VALUE(param_value, param_spec, var_args, __error)                 \
120 G_STMT_START {                                                                          \
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;                                                                 \
127                                                                                         \
128   if (_pspec)                                                                           \
129     g_param_spec_ref (_pspec);                                                          \
130   while (_lcopy_type && !_error_msg)                                                    \
131     {                                                                                   \
132       GParamCValue _cvalue;                                                             \
133                                                                                         \
134       memset (&_cvalue, 0, sizeof (_cvalue));                                           \
135       switch (_lcopy_type)                                                              \
136         {                                                                               \
137         case G_VALUE_COLLECT_INT:                                                       \
138           _cvalue.v_int = va_arg ((var_args), gint);                                    \
139           break;                                                                        \
140         case G_VALUE_COLLECT_LONG:                                                      \
141           _cvalue.v_long = va_arg ((var_args), glong);                                  \
142           break;                                                                        \
143         case G_VALUE_COLLECT_DOUBLE:                                                    \
144           _cvalue.v_double = va_arg ((var_args), gdouble);                              \
145           break;                                                                        \
146         case G_VALUE_COLLECT_POINTER:                                                   \
147           _cvalue.v_pointer = va_arg ((var_args), gpointer);                            \
148           break;                                                                        \
149         default:                                                                        \
150           _error_msg  = g_strdup_printf ("%s: invalid collect type (%d) used for %s",   \
151                                          G_STRLOC,                                      \
152                                          _lcopy_type,                                   \
153                                          "G_PARAM_LCOPY_VALUE()");                      \
154           continue;                                                                     \
155         }                                                                               \
156       _error_msg = _pclass->param_lcopy_value (_value,                                  \
157                                                _pspec,                                  \
158                                                _nth_value++,                            \
159                                                &_lcopy_type,                            \
160                                                &_cvalue);                               \
161     }                                                                                   \
162   *(__error) = _error_msg;                                                              \
163   if (_pspec)                                                                           \
164     g_param_spec_unref (_pspec);                                                        \
165   g_type_class_unref (_pclass);                                                         \
166 } G_STMT_END
167
168
169
170 #ifdef __cplusplus
171 }
172 #endif /* __cplusplus */
173
174 #endif /* __G_VALUE_COLLECTOR_H__ */