00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __G_VALUE_COLLECTOR_H__
00022 #define __G_VALUE_COLLECTOR_H__
00023
00024 #include <glib-object.h>
00025
00026 G_BEGIN_DECLS
00027
00028
00029
00030
00031
00032
00033 enum
00034 {
00035 G_VALUE_COLLECT_INT = 'i',
00036 G_VALUE_COLLECT_LONG = 'l',
00037 G_VALUE_COLLECT_INT64 = 'q',
00038 G_VALUE_COLLECT_DOUBLE = 'd',
00039 G_VALUE_COLLECT_POINTER = 'p'
00040 };
00041
00042
00043
00044
00045 union _GTypeCValue
00046 {
00047 gint v_int;
00048 glong v_long;
00049 gint64 v_int64;
00050 gdouble v_double;
00051 gpointer v_pointer;
00052 };
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #define G_VALUE_COLLECT(value, var_args, flags, __error) \
00066 G_STMT_START { \
00067 GValue *_value = (value); \
00068 guint _flags = (flags); \
00069 GType _value_type = G_VALUE_TYPE (_value); \
00070 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
00071 gchar *_collect_format = _vtable->collect_format; \
00072 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
00073 guint _n_values = 0; \
00074 \
00075 if (_vtable->value_free) \
00076 _vtable->value_free (_value); \
00077 _value->g_type = _value_type; \
00078 memset (_value->data, 0, sizeof (_value->data)); \
00079 while (*_collect_format) \
00080 { \
00081 GTypeCValue *_cvalue = _cvalues + _n_values++; \
00082 \
00083 switch (*_collect_format++) \
00084 { \
00085 case G_VALUE_COLLECT_INT: \
00086 _cvalue->v_int = va_arg ((var_args), gint); \
00087 break; \
00088 case G_VALUE_COLLECT_LONG: \
00089 _cvalue->v_long = va_arg ((var_args), glong); \
00090 break; \
00091 case G_VALUE_COLLECT_INT64: \
00092 _cvalue->v_int64 = va_arg ((var_args), gint64); \
00093 break; \
00094 case G_VALUE_COLLECT_DOUBLE: \
00095 _cvalue->v_double = va_arg ((var_args), gdouble); \
00096 break; \
00097 case G_VALUE_COLLECT_POINTER: \
00098 _cvalue->v_pointer = va_arg ((var_args), gpointer); \
00099 break; \
00100 default: \
00101 g_assert_not_reached (); \
00102 } \
00103 } \
00104 *(__error) = _vtable->collect_value (_value, \
00105 _n_values, \
00106 _cvalues, \
00107 _flags); \
00108 } G_STMT_END
00109
00110
00111
00112
00113
00114 #define G_VALUE_LCOPY(value, var_args, flags, __error) \
00115 G_STMT_START { \
00116 const GValue *_value = (value); \
00117 guint _flags = (flags); \
00118 GType _value_type = G_VALUE_TYPE (_value); \
00119 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
00120 gchar *_lcopy_format = _vtable->lcopy_format; \
00121 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
00122 guint _n_values = 0; \
00123 \
00124 while (*_lcopy_format) \
00125 { \
00126 GTypeCValue *_cvalue = _cvalues + _n_values++; \
00127 \
00128 switch (*_lcopy_format++) \
00129 { \
00130 case G_VALUE_COLLECT_INT: \
00131 _cvalue->v_int = va_arg ((var_args), gint); \
00132 break; \
00133 case G_VALUE_COLLECT_LONG: \
00134 _cvalue->v_long = va_arg ((var_args), glong); \
00135 break; \
00136 case G_VALUE_COLLECT_INT64: \
00137 _cvalue->v_int64 = va_arg ((var_args), gint64); \
00138 break; \
00139 case G_VALUE_COLLECT_DOUBLE: \
00140 _cvalue->v_double = va_arg ((var_args), gdouble); \
00141 break; \
00142 case G_VALUE_COLLECT_POINTER: \
00143 _cvalue->v_pointer = va_arg ((var_args), gpointer); \
00144 break; \
00145 default: \
00146 g_assert_not_reached (); \
00147 } \
00148 } \
00149 *(__error) = _vtable->lcopy_value (_value, \
00150 _n_values, \
00151 _cvalues, \
00152 _flags); \
00153 } G_STMT_END
00154
00155
00156 #define G_VALUE_COLLECT_FORMAT_MAX_LENGTH (8)
00157
00158 G_END_DECLS
00159
00160 #endif