📄 gparamspecs.c
字号:
return cmp; } return 0; }}static voidparam_object_init (GParamSpec *pspec){ /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */}static voidparam_object_set_default (GParamSpec *pspec, GValue *value){ value->data[0].v_pointer = NULL;}static gbooleanparam_object_validate (GParamSpec *pspec, GValue *value){ 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 gintparam_object_values_cmp (GParamSpec *pspec, const GValue *value1, const GValue *value2){ 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;}/* --- type initialization --- */GType *g_param_spec_types = NULL;voidg_param_spec_types_init (void) /* sync with gtype.c */{ const guint n_types = 20; GType type, *spec_types, *spec_types_bound; g_param_spec_types = g_new0 (GType, n_types); spec_types = g_param_spec_types; spec_types_bound = g_param_spec_types + n_types; /* G_TYPE_PARAM_CHAR */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecChar), /* instance_size */ 16, /* n_preallocs */ param_char_init, /* instance_init */ G_TYPE_CHAR, /* value_type */ NULL, /* finalize */ param_char_set_default, /* value_set_default */ param_char_validate, /* value_validate */ param_int_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamChar", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_CHAR); } /* G_TYPE_PARAM_UCHAR */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUChar), /* instance_size */ 16, /* n_preallocs */ param_uchar_init, /* instance_init */ G_TYPE_UCHAR, /* value_type */ NULL, /* finalize */ param_uchar_set_default, /* value_set_default */ param_uchar_validate, /* value_validate */ param_uint_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamUChar", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_UCHAR); } /* G_TYPE_PARAM_BOOLEAN */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecBoolean), /* instance_size */ 16, /* n_preallocs */ NULL, /* instance_init */ G_TYPE_BOOLEAN, /* value_type */ NULL, /* finalize */ param_boolean_set_default, /* value_set_default */ param_boolean_validate, /* value_validate */ param_int_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamBoolean", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_BOOLEAN); } /* G_TYPE_PARAM_INT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecInt), /* instance_size */ 16, /* n_preallocs */ param_int_init, /* instance_init */ G_TYPE_INT, /* value_type */ NULL, /* finalize */ param_int_set_default, /* value_set_default */ param_int_validate, /* value_validate */ param_int_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamInt", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_INT); } /* G_TYPE_PARAM_UINT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUInt), /* instance_size */ 16, /* n_preallocs */ param_uint_init, /* instance_init */ G_TYPE_UINT, /* value_type */ NULL, /* finalize */ param_uint_set_default, /* value_set_default */ param_uint_validate, /* value_validate */ param_uint_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamUInt", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_UINT); } /* G_TYPE_PARAM_LONG */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecLong), /* instance_size */ 16, /* n_preallocs */ param_long_init, /* instance_init */ G_TYPE_LONG, /* value_type */ NULL, /* finalize */ param_long_set_default, /* value_set_default */ param_long_validate, /* value_validate */ param_long_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamLong", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_LONG); } /* G_TYPE_PARAM_ULONG */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecULong), /* instance_size */ 16, /* n_preallocs */ param_ulong_init, /* instance_init */ G_TYPE_ULONG, /* value_type */ NULL, /* finalize */ param_ulong_set_default, /* value_set_default */ param_ulong_validate, /* value_validate */ param_ulong_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamULong", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_ULONG); } /* G_TYPE_PARAM_INT64 */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecInt64), /* instance_size */ 16, /* n_preallocs */ param_int64_init, /* instance_init */ G_TYPE_INT64, /* value_type */ NULL, /* finalize */ param_int64_set_default, /* value_set_default */ param_int64_validate, /* value_validate */ param_int64_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamInt64", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_INT64); } /* G_TYPE_PARAM_UINT64 */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUInt64), /* instance_size */ 16, /* n_preallocs */ param_uint64_init, /* instance_init */ G_TYPE_UINT64, /* value_type */ NULL, /* finalize */ param_uint64_set_default, /* value_set_default */ param_uint64_validate, /* value_validate */ param_uint64_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamUInt64", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_UINT64); } /* G_TYPE_PARAM_UNICHAR */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecUnichar), /* instance_size */ 16, /* n_preallocs */ param_unichar_init, /* instance_init */ G_TYPE_UINT, /* value_type */ NULL, /* finalize */ param_unichar_set_default, /* value_set_default */ param_unichar_validate, /* value_validate */ param_unichar_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamUnichar", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_UNICHAR); } /* G_TYPE_PARAM_ENUM */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecEnum), /* instance_size */ 16, /* n_preallocs */ param_enum_init, /* instance_init */ G_TYPE_ENUM, /* value_type */ param_enum_finalize, /* finalize */ param_enum_set_default, /* value_set_default */ param_enum_validate, /* value_validate */ param_long_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamEnum", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_ENUM); } /* G_TYPE_PARAM_FLAGS */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecFlags), /* instance_size */ 16, /* n_preallocs */ param_flags_init, /* instance_init */ G_TYPE_FLAGS, /* value_type */ param_flags_finalize, /* finalize */ param_flags_set_default, /* value_set_default */ param_flags_validate, /* value_validate */ param_ulong_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamFlags", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_FLAGS); } /* G_TYPE_PARAM_FLOAT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecFloat), /* instance_size */ 16, /* n_preallocs */ param_float_init, /* instance_init */ G_TYPE_FLOAT, /* value_type */ NULL, /* finalize */ param_float_set_default, /* value_set_default */ param_float_validate, /* value_validate */ param_float_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamFloat", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_FLOAT); } /* G_TYPE_PARAM_DOUBLE */ { static const GParamSpecTypeInfo pspec_info = { 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); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_DOUBLE); } /* G_TYPE_PARAM_STRING */ { static const GParamSpecTypeInfo pspec_info = { 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); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_STRING); } /* G_TYPE_PARAM_PARAM */ { static const GParamSpecTypeInfo pspec_info = { 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); *spec_types++ = type; 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); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_BOXED); } /* G_TYPE_PARAM_POINTER */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecPointer), /* instance_size */ 0, /* n_preallocs */ param_pointer_init, /* instance_init */ G_TYPE_POINTER, /* value_type */ NULL, /* finalize */ param_pointer_set_default, /* value_set_default */ param_pointer_validate, /* value_validate */ param_pointer_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamPointer", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_POINTER); } /* G_TYPE_PARAM_VALUE_ARRAY */ { static /* const */ GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecValueArray), /* instance_size */ 0, /* n_preallocs */ param_value_array_init, /* instance_init */ 0xdeadbeef, /* value_type, assigned further down */ 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 */ }; pspec_info.value_type = G_TYPE_VALUE_ARRAY; type = g_param_type_register_static ("GParamValueArray", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_VALUE_ARRAY); } /* G_TYPE_PARAM_OBJECT */ { static const GParamSpecTypeInfo pspec_info = { sizeof (GParamSpecObject), /* instance_size */ 16, /* n_preallocs */ param_object_init, /* instance_init */ G_TYPE_OBJECT, /* value_type */ NULL, /* finalize */ param_object_set_default, /* value_set_default */ param_object_validate, /* value_validate */ param_object_values_cmp, /* values_cmp */ }; type = g_param_type_register_static ("GParamObject", &pspec_info); *spec_types++ = type; g_assert (type == G_TYPE_PARAM_OBJECT); } g_assert (spec_types == spec_types_bound);}/* --- GParamSpec initialization --- */GParamSpec*g_param_spec_char (const gchar *name, const gchar *nick, const gchar *blurb, gint8 minimum, gint8 maximum, gint8 default_value, GParamFlags flags){ GParamSpecChar *cspec; g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR, name, nick, blurb, flags); cspec->minimum = minimum; cspec->maximum = maximum; cspec->default_value = default_value; return G_PARAM_SPEC (cspec);}GParamSpec*g_param_spec_uchar (const gchar *name, const gchar *nick,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -