diff options
Diffstat (limited to 'gobject/gparamspecs.c')
-rw-r--r-- | gobject/gparamspecs.c | 706 |
1 files changed, 328 insertions, 378 deletions
diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index 358041c35..44dca645d 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -1,5 +1,5 @@ /* GObject - GLib Type, Object, Parameter and Signal Library - * Copyright (C) 1997, 1998, 1999, 2000 Tim Janik and Red Hat, Inc. + * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,6 +24,7 @@ #include "gparamspecs.h" #include "gvaluecollector.h" +#include "gvaluearray.h" #include <string.h> #include "../config.h" /* for SIZEOF_LONG */ @@ -33,7 +34,7 @@ /* --- param spec functions --- */ static void -param_spec_char_init (GParamSpec *pspec) +param_char_init (GParamSpec *pspec) { GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec); @@ -62,7 +63,7 @@ param_char_validate (GParamSpec *pspec, } static void -param_spec_uchar_init (GParamSpec *pspec) +param_uchar_init (GParamSpec *pspec) { GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec); @@ -109,7 +110,7 @@ param_boolean_validate (GParamSpec *pspec, } static void -param_spec_int_init (GParamSpec *pspec) +param_int_init (GParamSpec *pspec) { GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); @@ -149,7 +150,7 @@ param_int_values_cmp (GParamSpec *pspec, } static void -param_spec_uint_init (GParamSpec *pspec) +param_uint_init (GParamSpec *pspec) { GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec); @@ -189,7 +190,7 @@ param_uint_values_cmp (GParamSpec *pspec, } static void -param_spec_long_init (GParamSpec *pspec) +param_long_init (GParamSpec *pspec) { GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec); @@ -234,7 +235,7 @@ param_long_values_cmp (GParamSpec *pspec, } static void -param_spec_ulong_init (GParamSpec *pspec) +param_ulong_init (GParamSpec *pspec) { GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec); @@ -278,7 +279,7 @@ param_ulong_values_cmp (GParamSpec *pspec, } static void -param_spec_enum_init (GParamSpec *pspec) +param_enum_init (GParamSpec *pspec) { GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); @@ -287,7 +288,7 @@ param_spec_enum_init (GParamSpec *pspec) } static void -param_spec_enum_finalize (GParamSpec *pspec) +param_enum_finalize (GParamSpec *pspec) { GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM)); @@ -323,7 +324,7 @@ param_enum_validate (GParamSpec *pspec, } static void -param_spec_flags_init (GParamSpec *pspec) +param_flags_init (GParamSpec *pspec) { GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); @@ -332,7 +333,7 @@ param_spec_flags_init (GParamSpec *pspec) } static void -param_spec_flags_finalize (GParamSpec *pspec) +param_flags_finalize (GParamSpec *pspec) { GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS)); @@ -369,7 +370,7 @@ param_flags_validate (GParamSpec *pspec, } static void -param_spec_float_init (GParamSpec *pspec) +param_float_init (GParamSpec *pspec) { GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec); @@ -412,7 +413,7 @@ param_float_values_cmp (GParamSpec *pspec, } static void -param_spec_double_init (GParamSpec *pspec) +param_double_init (GParamSpec *pspec) { GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec); @@ -455,7 +456,7 @@ param_double_values_cmp (GParamSpec *pspec, } static void -param_spec_string_init (GParamSpec *pspec) +param_string_init (GParamSpec *pspec) { GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); @@ -468,7 +469,7 @@ param_spec_string_init (GParamSpec *pspec) } static void -param_spec_string_finalize (GParamSpec *pspec) +param_string_finalize (GParamSpec *pspec) { GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING)); @@ -546,7 +547,7 @@ param_string_values_cmp (GParamSpec *pspec, } static void -param_spec_param_init (GParamSpec *pspec) +param_param_init (GParamSpec *pspec) { /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */ } @@ -566,7 +567,7 @@ param_param_validate (GParamSpec *pspec, GParamSpec *param = value->data[0].v_pointer; guint changed = 0; - if (param && !g_type_is_a (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) + if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) { g_param_spec_unref (param); value->data[0].v_pointer = NULL; @@ -577,299 +578,300 @@ param_param_validate (GParamSpec *pspec, } static void -param_spec_pointer_init (GParamSpec *pspec) +param_boxed_init (GParamSpec *pspec) { - /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ + /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ } static void -param_pointer_set_default (GParamSpec *pspec, - GValue *value) +param_boxed_set_default (GParamSpec *pspec, + GValue *value) { value->data[0].v_pointer = NULL; } static gboolean -param_pointer_validate (GParamSpec *pspec, - GValue *value) +param_boxed_validate (GParamSpec *pspec, + GValue *value) { - /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ + /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ guint changed = 0; + + /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */ return changed; } static gint -param_pointer_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) +param_boxed_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) { - return value1->data[0].v_pointer != value2->data[0].v_pointer; + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; } static void -param_spec_ccallback_init (GParamSpec *pspec) +param_pointer_init (GParamSpec *pspec) { - /* GParamSpecCCallback *spec = G_PARAM_SPEC_CCALLBACK (pspec); */ + /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ } static void -param_ccallback_set_default (GParamSpec *pspec, - GValue *value) +param_pointer_set_default (GParamSpec *pspec, + GValue *value) { value->data[0].v_pointer = NULL; - value->data[1].v_pointer = NULL; } static gboolean -param_ccallback_validate (GParamSpec *pspec, - GValue *value) +param_pointer_validate (GParamSpec *pspec, + GValue *value) { - /* GParamSpecCCallback *spec = G_PARAM_SPEC_CCALLBACK (pspec); */ + /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ guint changed = 0; return changed; } static gint -param_ccallback_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) +param_pointer_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) { - return (value1->data[0].v_pointer != value2->data[0].v_pointer || - value1->data[1].v_pointer != value2->data[1].v_pointer); + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; + + /* not much to compare here, try to at least provide stable lesser/greater result */ + + return p1 < p2 ? -1 : p1 > p2; } static void -param_spec_boxed_init (GParamSpec *pspec) +param_closure_init (GParamSpec *pspec) { - /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ + /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */ } static void -param_boxed_set_default (GParamSpec *pspec, - GValue *value) +param_closure_set_default (GParamSpec *pspec, + GValue *value) { value->data[0].v_pointer = NULL; } static gboolean -param_boxed_validate (GParamSpec *pspec, - GValue *value) +param_closure_validate (GParamSpec *pspec, + GValue *value) { - /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ + /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */ + /* GClosure *closure = value->data[0].v_pointer; */ guint changed = 0; - /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */ - + /* we don't actually have necessary means to ensure closure validity */ + return changed; } static gint -param_boxed_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) +param_closure_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) { - return value1->data[0].v_pointer != value2->data[0].v_pointer; -} + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; -static void -param_spec_object_init (GParamSpec *pspec) -{ - /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ -} + /* not much to compare here, try to at least provide stable lesser/greater result */ -static void -param_spec_interface_init (GParamSpec *pspec) -{ - /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ + return p1 < p2 ? -1 : p1 > p2; } static void -param_object_set_default (GParamSpec *pspec, - GValue *value) +param_value_array_init (GParamSpec *pspec) { - value->data[0].v_pointer = NULL; + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + + aspec->element_spec = NULL; + aspec->fixed_n_elements = 0; /* disable */ } -static gboolean -param_object_validate (GParamSpec *pspec, - GValue *value) +static inline guint +value_array_ensure_size (GValueArray *value_array, + guint fixed_n_elements) { - GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); - GObject *object = value->data[0].v_pointer; guint changed = 0; - - if (object && !g_type_is_a (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) + + if (fixed_n_elements) { - g_object_unref (object); - value->data[0].v_pointer = NULL; - changed++; + while (value_array->n_values < fixed_n_elements) + { + g_value_array_append (value_array, NULL); + changed++; + } + while (value_array->n_values > fixed_n_elements) + { + g_value_array_remove (value_array, value_array->n_values - 1); + changed++; + } } - return changed; } -static gint -param_object_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) +static void +param_value_array_finalize (GParamSpec *pspec) { - return value1->data[0].v_pointer != value2->data[0].v_pointer; + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY)); + + if (aspec->element_spec) + { + g_param_spec_unref (aspec->element_spec); + aspec->element_spec = NULL; + } + + parent_class->finalize (pspec); } static void -param_interface_set_default (GParamSpec *pspec, - GValue *value) +param_value_array_set_default (GParamSpec *pspec, + GValue *value) { - value->data[0].v_pointer = NULL; + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + + g_return_if_fail (value->data[0].v_pointer != NULL); /* paranoid */ + + /* g_value_reset (value); already done */ + value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements); } static gboolean -param_interface_validate (GParamSpec *pspec, - GValue *value) +param_value_array_validate (GParamSpec *pspec, + GValue *value) { + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GValueArray *value_array = value->data[0].v_pointer; guint changed = 0; - - if (value->data[0].v_pointer == NULL) - changed++; - return changed; -} + g_return_val_if_fail (value->data[0].v_pointer != NULL, FALSE); /* paranoid */ -static gint -param_interface_values_cmp (GParamSpec *pspec, - const GValue *value1, - const GValue *value2) -{ - return value1->data[0].v_pointer != value2->data[0].v_pointer; -} + /* ensure array size validity */ + changed += value_array_ensure_size (value_array, aspec->fixed_n_elements); -static void -value_exch_memcpy (GValue *value1, - GValue *value2) -{ - GValue tmp_value; - memcpy (&tmp_value.data, &value1->data, sizeof (value1->data)); - memcpy (&value1->data, &value2->data, sizeof (value1->data)); - memcpy (&value2->data, &tmp_value.data, sizeof (value2->data)); -} + /* ensure array values validity against a present element spec */ + if (aspec->element_spec) + { + GParamSpec *element_spec = aspec->element_spec; + guint i; -static void -value_exch_long_int (GValue *value1, - GValue *value2) -{ - glong tmp = value1->data[0].v_long; - value1->data[0].v_long = value2->data[0].v_int; - value2->data[0].v_int = tmp; -} + for (i = 0; i < value_array->n_values; i++) + { + GValue *element = value_array->values + i; -static void -value_exch_long_uint (GValue *value1, - GValue *value2) -{ - glong tmp = value1->data[0].v_long; - value1->data[0].v_long = value2->data[0].v_uint; - value2->data[0].v_uint = tmp; -} + /* need to fixup value type, or ensure that the array value is initialized at all */ + if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec))) + { + if (G_VALUE_TYPE (element) != 0) + g_value_unset (element); + g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec)); + g_param_value_set_default (element_spec, element); + changed++; + } + /* validate array value against element_spec */ + changed += g_param_value_validate (element_spec, element); + } + } -static void -value_exch_ulong_int (GValue *value1, - GValue *value2) -{ - gulong tmp = value1->data[0].v_ulong; - value1->data[0].v_ulong = value2->data[0].v_int; - value2->data[0].v_int = tmp; + return changed; } -static void -value_exch_ulong_uint (GValue *value1, - GValue *value2) +static gint +param_value_array_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) { - gulong tmp = value1->data[0].v_ulong; - value1->data[0].v_ulong = value2->data[0].v_uint; - value2->data[0].v_uint = tmp; -} + GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); + GValueArray *value_array1 = value1->data[0].v_pointer; + GValueArray *value_array2 = value2->data[0].v_pointer; -static void -value_exch_float_int (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_int; - value2->data[0].v_int = 0.5 + tmp; -} + g_return_val_if_fail (value1->data[0].v_pointer != NULL, -1); /* paranoid */ + g_return_val_if_fail (value2->data[0].v_pointer != NULL, 1); /* paranoid */ -static void -value_exch_float_uint (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_uint; - value2->data[0].v_uint = 0.5 + tmp; -} + if (value_array1->n_values != value_array2->n_values) + return value_array1->n_values < value_array2->n_values ? -1 : 1; + else if (!aspec->element_spec) + { + /* we need an element specification for comparisons, so there's not much + * to compare here, try to at least provide stable lesser/greater result + */ + return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values; + } + else /* value_array1->n_values == value_array2->n_values */ + { + guint i; -static void -value_exch_float_long (GValue *value1, - GValue *value2) -{ - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_long; - value2->data[0].v_long = 0.5 + tmp; + for (i = 0; i < value_array1->n_values; i++) + { + GValue *element1 = value_array1->values + i; + GValue *element2 = value_array2->values + i; + gint cmp; + + /* need corresponding element types, provide stable result otherwise */ + if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2)) + return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1; + cmp = g_param_values_cmp (aspec->element_spec, element1, element2); + if (cmp) + return cmp; + } + return 0; + } } static void -value_exch_float_ulong (GValue *value1, - GValue *value2) +param_object_init (GParamSpec *pspec) { - gfloat tmp = value1->data[0].v_float; - value1->data[0].v_float = value2->data[0].v_ulong; - value2->data[0].v_ulong = 0.5 + tmp; + /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ } static void -value_exch_double_int (GValue *value1, - GValue *value2) +param_object_set_default (GParamSpec *pspec, + GValue *value) { - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_int; - value2->data[0].v_int = 0.5 + tmp; + value->data[0].v_pointer = NULL; } -static void -value_exch_double_uint (GValue *value1, - GValue *value2) +static gboolean +param_object_validate (GParamSpec *pspec, + GValue *value) { - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_uint; - value2->data[0].v_uint = 0.5 + tmp; + GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); + GObject *object = value->data[0].v_pointer; + guint changed = 0; + + if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) + { + g_object_unref (object); + value->data[0].v_pointer = NULL; + changed++; + } + + return changed; } -static void -value_exch_double_long (GValue *value1, - GValue *value2) +static gint +param_object_values_cmp (GParamSpec *pspec, + const GValue *value1, + const GValue *value2) { - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_long; - value2->data[0].v_long = 0.5 + tmp; -} + guint8 *p1 = value1->data[0].v_pointer; + guint8 *p2 = value2->data[0].v_pointer; -static void -value_exch_double_ulong (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_ulong; - value2->data[0].v_ulong = 0.5 + tmp; -} + /* not much to compare here, try to at least provide stable lesser/greater result */ -static void -value_exch_double_float (GValue *value1, - GValue *value2) -{ - gdouble tmp = value1->data[0].v_double; - value1->data[0].v_double = value2->data[0].v_float; - value2->data[0].v_float = tmp; + return p1 < p2 ? -1 : p1 > p2; } @@ -885,7 +887,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecChar), /* instance_size */ 16, /* n_preallocs */ - param_spec_char_init, /* instance_init */ + param_char_init, /* instance_init */ G_TYPE_CHAR, /* value_type */ NULL, /* finalize */ param_char_set_default, /* value_set_default */ @@ -902,7 +904,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUChar), /* instance_size */ 16, /* n_preallocs */ - param_spec_uchar_init, /* instance_init */ + param_uchar_init, /* instance_init */ G_TYPE_UCHAR, /* value_type */ NULL, /* finalize */ param_uchar_set_default, /* value_set_default */ @@ -936,7 +938,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecInt), /* instance_size */ 16, /* n_preallocs */ - param_spec_int_init, /* instance_init */ + param_int_init, /* instance_init */ G_TYPE_INT, /* value_type */ NULL, /* finalize */ param_int_set_default, /* value_set_default */ @@ -953,7 +955,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUInt), /* instance_size */ 16, /* n_preallocs */ - param_spec_uint_init, /* instance_init */ + param_uint_init, /* instance_init */ G_TYPE_UINT, /* value_type */ NULL, /* finalize */ param_uint_set_default, /* value_set_default */ @@ -970,7 +972,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecLong), /* instance_size */ 16, /* n_preallocs */ - param_spec_long_init, /* instance_init */ + param_long_init, /* instance_init */ G_TYPE_LONG, /* value_type */ NULL, /* finalize */ param_long_set_default, /* value_set_default */ @@ -987,7 +989,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecULong), /* instance_size */ 16, /* n_preallocs */ - param_spec_ulong_init, /* instance_init */ + param_ulong_init, /* instance_init */ G_TYPE_ULONG, /* value_type */ NULL, /* finalize */ param_ulong_set_default, /* value_set_default */ @@ -1004,9 +1006,9 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecEnum), /* instance_size */ 16, /* n_preallocs */ - param_spec_enum_init, /* instance_init */ + param_enum_init, /* instance_init */ G_TYPE_ENUM, /* value_type */ - param_spec_enum_finalize, /* finalize */ + param_enum_finalize, /* finalize */ param_enum_set_default, /* value_set_default */ param_enum_validate, /* value_validate */ param_long_values_cmp, /* values_cmp */ @@ -1019,11 +1021,11 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecFlags), /* instance_size */ - 16, /* n_preallocs */ - param_spec_flags_init, /* instance_init */ + sizeof (GParamSpecFlags), /* instance_size */ + 16, /* n_preallocs */ + param_flags_init, /* instance_init */ G_TYPE_FLAGS, /* value_type */ - param_spec_flags_finalize,/* finalize */ + param_flags_finalize, /* finalize */ param_flags_set_default, /* value_set_default */ param_flags_validate, /* value_validate */ param_ulong_values_cmp, /* values_cmp */ @@ -1038,7 +1040,7 @@ g_param_spec_types_init (void) /* sync with gtype.c */ static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecFloat), /* instance_size */ 16, /* n_preallocs */ - param_spec_float_init, /* instance_init */ + param_float_init, /* instance_init */ G_TYPE_FLOAT, /* value_type */ NULL, /* finalize */ param_float_set_default, /* value_set_default */ @@ -1053,14 +1055,14 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecDouble), /* instance_size */ - 16, /* n_preallocs */ - param_spec_double_init, /* instance_init */ - G_TYPE_DOUBLE, /* value_type */ - NULL, /* finalize */ - param_double_set_default, /* value_set_default */ - param_double_validate, /* value_validate */ - param_double_values_cmp, /* values_cmp */ + sizeof (GParamSpecDouble), /* instance_size */ + 16, /* n_preallocs */ + param_double_init, /* instance_init */ + G_TYPE_DOUBLE, /* value_type */ + NULL, /* finalize */ + param_double_set_default, /* value_set_default */ + param_double_validate, /* value_validate */ + param_double_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamDouble", &pspec_info); g_assert (type == G_TYPE_PARAM_DOUBLE); @@ -1070,14 +1072,14 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecString), /* instance_size */ - 16, /* n_preallocs */ - param_spec_string_init, /* instance_init */ - G_TYPE_STRING, /* value_type */ - param_spec_string_finalize, /* finalize */ - param_string_set_default, /* value_set_default */ - param_string_validate, /* value_validate */ - param_string_values_cmp, /* values_cmp */ + sizeof (GParamSpecString), /* instance_size */ + 16, /* n_preallocs */ + param_string_init, /* instance_init */ + G_TYPE_STRING, /* value_type */ + param_string_finalize, /* finalize */ + param_string_set_default, /* value_set_default */ + param_string_validate, /* value_validate */ + param_string_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamString", &pspec_info); g_assert (type == G_TYPE_PARAM_STRING); @@ -1087,26 +1089,43 @@ g_param_spec_types_init (void) /* sync with gtype.c */ */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecParam), /* instance_size */ - 16, /* n_preallocs */ - param_spec_param_init, /* instance_init */ - G_TYPE_PARAM, /* value_type */ - NULL, /* finalize */ - param_param_set_default, /* value_set_default */ - param_param_validate, /* value_validate */ - param_pointer_values_cmp, /* values_cmp */ + sizeof (GParamSpecParam), /* instance_size */ + 16, /* n_preallocs */ + param_param_init, /* instance_init */ + G_TYPE_PARAM, /* value_type */ + NULL, /* finalize */ + param_param_set_default, /* value_set_default */ + param_param_validate, /* value_validate */ + param_pointer_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamParam", &pspec_info); g_assert (type == G_TYPE_PARAM_PARAM); } + /* G_TYPE_PARAM_BOXED + */ + { + static const GParamSpecTypeInfo pspec_info = { + sizeof (GParamSpecBoxed), /* instance_size */ + 4, /* n_preallocs */ + param_boxed_init, /* instance_init */ + G_TYPE_BOXED, /* value_type */ + NULL, /* finalize */ + param_boxed_set_default, /* value_set_default */ + param_boxed_validate, /* value_validate */ + param_boxed_values_cmp, /* values_cmp */ + }; + type = g_param_type_register_static ("GParamBoxed", &pspec_info); + g_assert (type == G_TYPE_PARAM_BOXED); + } + /* G_TYPE_PARAM_POINTER */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecPointer), /* instance_size */ 0, /* n_preallocs */ - param_spec_pointer_init, /* instance_init */ + param_pointer_init, /* instance_init */ G_TYPE_POINTER, /* value_type */ NULL, /* finalize */ param_pointer_set_default, /* value_set_default */ @@ -1117,47 +1136,47 @@ g_param_spec_types_init (void) /* sync with gtype.c */ g_assert (type == G_TYPE_PARAM_POINTER); } - /* G_TYPE_PARAM_CCALLBACK + /* G_TYPE_PARAM_VALUE_ARRAY */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecCCallback), /* instance_size */ - 0, /* n_preallocs */ - param_spec_ccallback_init, /* instance_init */ - G_TYPE_CCALLBACK, /* value_type */ - NULL, /* finalize */ - param_ccallback_set_default, /* value_set_default */ - param_ccallback_validate, /* value_validate */ - param_ccallback_values_cmp, /* values_cmp */ + sizeof (GParamSpecValueArray), /* instance_size */ + 0, /* n_preallocs */ + param_value_array_init, /* instance_init */ + G_TYPE_VALUE_ARRAY, /* value_type */ + param_value_array_finalize, /* finalize */ + param_value_array_set_default, /* value_set_default */ + param_value_array_validate, /* value_validate */ + param_value_array_values_cmp, /* values_cmp */ }; - type = g_param_type_register_static ("GParamCCallback", &pspec_info); - g_assert (type == G_TYPE_PARAM_CCALLBACK); + type = g_param_type_register_static ("GParamValueArray", &pspec_info); + g_assert (type == G_TYPE_PARAM_VALUE_ARRAY); } - - /* G_TYPE_PARAM_BOXED + + /* G_TYPE_PARAM_CLOSURE */ { static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecBoxed), /* instance_size */ - 4, /* n_preallocs */ - param_spec_boxed_init, /* instance_init */ - G_TYPE_BOXED, /* value_type */ - NULL, /* finalize */ - param_boxed_set_default, /* value_set_default */ - param_boxed_validate, /* value_validate */ - param_boxed_values_cmp, /* values_cmp */ + sizeof (GParamSpecClosure), /* instance_size */ + 0, /* n_preallocs */ + param_closure_init, /* instance_init */ + G_TYPE_CLOSURE, /* value_type */ + NULL, /* finalize */ + param_closure_set_default, /* value_set_default */ + param_closure_validate, /* value_validate */ + param_closure_values_cmp, /* values_cmp */ }; - type = g_param_type_register_static ("GParamBoxed", &pspec_info); - g_assert (type == G_TYPE_PARAM_BOXED); + type = g_param_type_register_static ("GParamClosure", &pspec_info); + g_assert (type == G_TYPE_PARAM_CLOSURE); } - + /* G_TYPE_PARAM_OBJECT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecObject), /* instance_size */ 16, /* n_preallocs */ - param_spec_object_init, /* instance_init */ + param_object_init, /* instance_init */ G_TYPE_OBJECT, /* value_type */ NULL, /* finalize */ param_object_set_default, /* value_set_default */ @@ -1167,79 +1186,6 @@ g_param_spec_types_init (void) /* sync with gtype.c */ type = g_param_type_register_static ("GParamObject", &pspec_info); g_assert (type == G_TYPE_PARAM_OBJECT); } - - /* G_TYPE_PARAM_INTERFACE - */ - { - static const GParamSpecTypeInfo pspec_info = { - sizeof (GParamSpecInterface), /* instance_size */ - 4, /* n_preallocs */ - param_spec_interface_init, /* instance_init */ - G_TYPE_INTERFACE, /* value_type */ - NULL, /* finalize */ - param_interface_set_default, /* value_set_default */ - param_interface_validate, /* value_validate */ - param_interface_values_cmp, /* values_cmp */ - }; - type = g_param_type_register_static ("GParamInterface", &pspec_info); - g_assert (type == G_TYPE_PARAM_INTERFACE); - } - - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UCHAR, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_BOOLEAN, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_BOOLEAN, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_INT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_UINT, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_INT, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_ENUM, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_CHAR, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UCHAR, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_BOOLEAN, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_INT, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UINT, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ULONG, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ENUM, value_exch_long_int); - g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_FLAGS, value_exch_long_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_CHAR, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UCHAR, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_BOOLEAN, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_INT, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UINT, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_ENUM, value_exch_ulong_int); - g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_FLAGS, value_exch_ulong_uint); - g_value_register_exchange_func (G_TYPE_ENUM, G_TYPE_FLAGS, value_exch_memcpy); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_CHAR, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UCHAR, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_BOOLEAN, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_INT, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UINT, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_LONG, value_exch_float_long); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ULONG, value_exch_float_ulong); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ENUM, value_exch_float_int); - g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_FLAGS, value_exch_float_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_CHAR, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UCHAR, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_BOOLEAN, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_INT, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UINT, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_LONG, value_exch_double_long); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ULONG, value_exch_double_ulong); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ENUM, value_exch_double_int); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLAGS, value_exch_double_uint); - g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLOAT, value_exch_double_float); } @@ -1553,6 +1499,28 @@ g_param_spec_param (const gchar *name, } GParamSpec* +g_param_spec_boxed (const gchar *name, + const gchar *nick, + const gchar *blurb, + GType boxed_type, + GParamFlags flags) +{ + GParamSpecBoxed *bspec; + + g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL); + g_return_val_if_fail (G_TYPE_IS_DERIVED (boxed_type), NULL); + + bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED, + name, + nick, + blurb, + flags); + G_PARAM_SPEC (bspec)->value_type = boxed_type; + + return G_PARAM_SPEC (bspec); +} + +GParamSpec* g_param_spec_pointer (const gchar *name, const gchar *nick, const gchar *blurb, @@ -1569,41 +1537,45 @@ g_param_spec_pointer (const gchar *name, } GParamSpec* -g_param_spec_ccallback (const gchar *name, - const gchar *nick, - const gchar *blurb, - GParamFlags flags) +g_param_spec_value_array (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamSpec *element_spec, + GParamFlags flags) { - GParamSpecCCallback *cspec; + GParamSpecValueArray *aspec; + + if (element_spec) + g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL); - cspec = g_param_spec_internal (G_TYPE_PARAM_CCALLBACK, + aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY, name, nick, blurb, flags); - return G_PARAM_SPEC (cspec); + if (element_spec) + { + aspec->element_spec = g_param_spec_ref (element_spec); + g_param_spec_sink (element_spec); + } + + return G_PARAM_SPEC (aspec); } GParamSpec* -g_param_spec_boxed (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType boxed_type, - GParamFlags flags) +g_param_spec_closure (const gchar *name, + const gchar *nick, + const gchar *blurb, + GParamFlags flags) { - GParamSpecBoxed *bspec; - - g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL); - g_return_val_if_fail (G_TYPE_IS_DERIVED (boxed_type), NULL); + GParamSpecClosure *cspec; - bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED, + cspec = g_param_spec_internal (G_TYPE_PARAM_CLOSURE, name, nick, blurb, flags); - G_PARAM_SPEC (bspec)->value_type = boxed_type; - - return G_PARAM_SPEC (bspec); + return G_PARAM_SPEC (cspec); } GParamSpec* @@ -1626,25 +1598,3 @@ g_param_spec_object (const gchar *name, return G_PARAM_SPEC (ospec); } - -GParamSpec* -g_param_spec_interface (const gchar *name, - const gchar *nick, - const gchar *blurb, - GType interface_type, - GParamFlags flags) -{ - GParamSpecInterface *ispec; - - g_return_val_if_fail (G_TYPE_IS_INTERFACE (interface_type), NULL); - - ispec = g_param_spec_internal (G_TYPE_PARAM_INTERFACE, - name, - nick, - blurb, - flags); - G_PARAM_SPEC (ispec)->value_type = interface_type; - - return G_PARAM_SPEC (ispec); -} - |