1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-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.
24 #include "gparamspecs.h"
26 #include "gvaluecollector.h"
27 #include "gvaluearray.h"
29 #include "../config.h" /* for SIZEOF_LONG */
31 #define G_FLOAT_EPSILON (1e-30)
32 #define G_DOUBLE_EPSILON (1e-90)
35 /* --- param spec functions --- */
37 param_char_init (GParamSpec *pspec)
39 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
41 cspec->minimum = 0x7f;
42 cspec->maximum = 0x80;
43 cspec->default_value = 0;
47 param_char_set_default (GParamSpec *pspec,
50 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
54 param_char_validate (GParamSpec *pspec,
57 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
58 gint oval = value->data[0].v_int;
60 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
62 return value->data[0].v_int != oval;
66 param_uchar_init (GParamSpec *pspec)
68 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
71 uspec->maximum = 0xff;
72 uspec->default_value = 0;
76 param_uchar_set_default (GParamSpec *pspec,
79 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
83 param_uchar_validate (GParamSpec *pspec,
86 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
87 guint oval = value->data[0].v_uint;
89 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
91 return value->data[0].v_uint != oval;
95 param_boolean_set_default (GParamSpec *pspec,
98 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
102 param_boolean_validate (GParamSpec *pspec,
105 gint oval = value->data[0].v_int;
107 value->data[0].v_int = value->data[0].v_int != FALSE;
109 return value->data[0].v_int != oval;
113 param_int_init (GParamSpec *pspec)
115 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
117 ispec->minimum = 0x7fffffff;
118 ispec->maximum = 0x80000000;
119 ispec->default_value = 0;
123 param_int_set_default (GParamSpec *pspec,
126 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
130 param_int_validate (GParamSpec *pspec,
133 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
134 gint oval = value->data[0].v_int;
136 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
138 return value->data[0].v_int != oval;
142 param_int_values_cmp (GParamSpec *pspec,
143 const GValue *value1,
144 const GValue *value2)
146 if (value1->data[0].v_int < value2->data[0].v_int)
149 return value1->data[0].v_int > value2->data[0].v_int;
153 param_uint_init (GParamSpec *pspec)
155 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
158 uspec->maximum = 0xffffffff;
159 uspec->default_value = 0;
163 param_uint_set_default (GParamSpec *pspec,
166 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
170 param_uint_validate (GParamSpec *pspec,
173 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
174 guint oval = value->data[0].v_uint;
176 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
178 return value->data[0].v_uint != oval;
182 param_uint_values_cmp (GParamSpec *pspec,
183 const GValue *value1,
184 const GValue *value2)
186 if (value1->data[0].v_uint < value2->data[0].v_uint)
189 return value1->data[0].v_uint > value2->data[0].v_uint;
193 param_long_init (GParamSpec *pspec)
195 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
198 lspec->minimum = 0x7fffffff;
199 lspec->maximum = 0x80000000;
200 #else /* SIZEOF_LONG != 4 (8) */
201 lspec->minimum = 0x7fffffffffffffff;
202 lspec->maximum = 0x8000000000000000;
204 lspec->default_value = 0;
208 param_long_set_default (GParamSpec *pspec,
211 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
215 param_long_validate (GParamSpec *pspec,
218 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
219 glong oval = value->data[0].v_long;
221 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
223 return value->data[0].v_long != oval;
227 param_long_values_cmp (GParamSpec *pspec,
228 const GValue *value1,
229 const GValue *value2)
231 if (value1->data[0].v_long < value2->data[0].v_long)
234 return value1->data[0].v_long > value2->data[0].v_long;
238 param_ulong_init (GParamSpec *pspec)
240 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
244 uspec->maximum = 0xffffffff;
245 #else /* SIZEOF_LONG != 4 (8) */
246 uspec->maximum = 0xffffffffffffffff;
248 uspec->default_value = 0;
252 param_ulong_set_default (GParamSpec *pspec,
255 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
259 param_ulong_validate (GParamSpec *pspec,
262 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
263 gulong oval = value->data[0].v_ulong;
265 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
267 return value->data[0].v_ulong != oval;
271 param_ulong_values_cmp (GParamSpec *pspec,
272 const GValue *value1,
273 const GValue *value2)
275 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
278 return value1->data[0].v_ulong > value2->data[0].v_ulong;
282 param_unichar_init (GParamSpec *pspec)
284 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
286 uspec->default_value = 0;
290 param_unichar_set_default (GParamSpec *pspec,
293 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
297 param_unichar_validate (GParamSpec *pspec,
300 gunichar oval = value->data[0].v_uint;
301 gboolean changed = FALSE;
303 if (!g_unichar_validate (oval))
305 value->data[0].v_uint = 0;
313 param_unichar_values_cmp (GParamSpec *pspec,
314 const GValue *value1,
315 const GValue *value2)
317 if (value1->data[0].v_uint < value2->data[0].v_uint)
320 return value1->data[0].v_uint > value2->data[0].v_uint;
324 param_enum_init (GParamSpec *pspec)
326 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
328 espec->enum_class = NULL;
329 espec->default_value = 0;
333 param_enum_finalize (GParamSpec *pspec)
335 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
336 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
338 if (espec->enum_class)
340 g_type_class_unref (espec->enum_class);
341 espec->enum_class = NULL;
344 parent_class->finalize (pspec);
348 param_enum_set_default (GParamSpec *pspec,
351 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
355 param_enum_validate (GParamSpec *pspec,
358 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
359 glong oval = value->data[0].v_long;
361 if (!espec->enum_class ||
362 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
363 value->data[0].v_long = espec->default_value;
365 return value->data[0].v_long != oval;
369 param_flags_init (GParamSpec *pspec)
371 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
373 fspec->flags_class = NULL;
374 fspec->default_value = 0;
378 param_flags_finalize (GParamSpec *pspec)
380 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
381 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
383 if (fspec->flags_class)
385 g_type_class_unref (fspec->flags_class);
386 fspec->flags_class = NULL;
389 parent_class->finalize (pspec);
393 param_flags_set_default (GParamSpec *pspec,
396 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
400 param_flags_validate (GParamSpec *pspec,
403 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
404 gulong oval = value->data[0].v_ulong;
406 if (fspec->flags_class)
407 value->data[0].v_ulong &= fspec->flags_class->mask;
409 value->data[0].v_ulong = fspec->default_value;
411 return value->data[0].v_ulong != oval;
415 param_float_init (GParamSpec *pspec)
417 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
419 fspec->minimum = G_MINFLOAT;
420 fspec->maximum = G_MAXFLOAT;
421 fspec->default_value = 0;
422 fspec->epsilon = G_FLOAT_EPSILON;
426 param_float_set_default (GParamSpec *pspec,
429 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
433 param_float_validate (GParamSpec *pspec,
436 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
437 gfloat oval = value->data[0].v_float;
439 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
441 return value->data[0].v_float != oval;
445 param_float_values_cmp (GParamSpec *pspec,
446 const GValue *value1,
447 const GValue *value2)
449 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
451 if (value1->data[0].v_float < value2->data[0].v_float)
452 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
454 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
458 param_double_init (GParamSpec *pspec)
460 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
462 dspec->minimum = G_MINDOUBLE;
463 dspec->maximum = G_MAXDOUBLE;
464 dspec->default_value = 0;
465 dspec->epsilon = G_DOUBLE_EPSILON;
469 param_double_set_default (GParamSpec *pspec,
472 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
476 param_double_validate (GParamSpec *pspec,
479 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
480 gdouble oval = value->data[0].v_double;
482 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
484 return value->data[0].v_double != oval;
488 param_double_values_cmp (GParamSpec *pspec,
489 const GValue *value1,
490 const GValue *value2)
492 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
494 if (value1->data[0].v_double < value2->data[0].v_double)
495 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
497 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
501 param_string_init (GParamSpec *pspec)
503 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
505 sspec->default_value = NULL;
506 sspec->cset_first = NULL;
507 sspec->cset_nth = NULL;
508 sspec->substitutor = '_';
509 sspec->null_fold_if_empty = FALSE;
510 sspec->ensure_non_null = FALSE;
514 param_string_finalize (GParamSpec *pspec)
516 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
517 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
519 g_free (sspec->default_value);
520 g_free (sspec->cset_first);
521 g_free (sspec->cset_nth);
522 sspec->default_value = NULL;
523 sspec->cset_first = NULL;
524 sspec->cset_nth = NULL;
526 parent_class->finalize (pspec);
530 param_string_set_default (GParamSpec *pspec,
533 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
537 param_string_validate (GParamSpec *pspec,
540 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
541 gchar *string = value->data[0].v_pointer;
544 if (string && string[0])
548 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
550 string[0] = sspec->substitutor;
554 for (s = string + 1; *s; s++)
555 if (!strchr (sspec->cset_nth, *s))
557 *s = sspec->substitutor;
561 if (sspec->null_fold_if_empty && string && string[0] == 0)
563 g_free (value->data[0].v_pointer);
564 value->data[0].v_pointer = NULL;
566 string = value->data[0].v_pointer;
568 if (sspec->ensure_non_null && !string)
570 value->data[0].v_pointer = g_strdup ("");
572 string = value->data[0].v_pointer;
579 param_string_values_cmp (GParamSpec *pspec,
580 const GValue *value1,
581 const GValue *value2)
583 if (!value1->data[0].v_pointer)
584 return value2->data[0].v_pointer != NULL ? -1 : 0;
585 else if (!value2->data[0].v_pointer)
586 return value1->data[0].v_pointer != NULL;
588 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
592 param_param_init (GParamSpec *pspec)
594 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
598 param_param_set_default (GParamSpec *pspec,
601 value->data[0].v_pointer = NULL;
605 param_param_validate (GParamSpec *pspec,
608 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
609 GParamSpec *param = value->data[0].v_pointer;
612 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
614 g_param_spec_unref (param);
615 value->data[0].v_pointer = NULL;
623 param_boxed_init (GParamSpec *pspec)
625 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
629 param_boxed_set_default (GParamSpec *pspec,
632 value->data[0].v_pointer = NULL;
636 param_boxed_validate (GParamSpec *pspec,
639 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
642 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
648 param_boxed_values_cmp (GParamSpec *pspec,
649 const GValue *value1,
650 const GValue *value2)
652 guint8 *p1 = value1->data[0].v_pointer;
653 guint8 *p2 = value2->data[0].v_pointer;
655 /* not much to compare here, try to at least provide stable lesser/greater result */
657 return p1 < p2 ? -1 : p1 > p2;
661 param_pointer_init (GParamSpec *pspec)
663 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
667 param_pointer_set_default (GParamSpec *pspec,
670 value->data[0].v_pointer = NULL;
674 param_pointer_validate (GParamSpec *pspec,
677 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
684 param_pointer_values_cmp (GParamSpec *pspec,
685 const GValue *value1,
686 const GValue *value2)
688 guint8 *p1 = value1->data[0].v_pointer;
689 guint8 *p2 = value2->data[0].v_pointer;
691 /* not much to compare here, try to at least provide stable lesser/greater result */
693 return p1 < p2 ? -1 : p1 > p2;
697 param_closure_init (GParamSpec *pspec)
699 /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */
703 param_closure_set_default (GParamSpec *pspec,
706 value->data[0].v_pointer = NULL;
710 param_closure_validate (GParamSpec *pspec,
713 /* GParamSpecClosure *cspec = G_PARAM_SPEC_CLOSURE (pspec); */
714 /* GClosure *closure = value->data[0].v_pointer; */
717 /* we don't actually have necessary means to ensure closure validity */
723 param_closure_values_cmp (GParamSpec *pspec,
724 const GValue *value1,
725 const GValue *value2)
727 guint8 *p1 = value1->data[0].v_pointer;
728 guint8 *p2 = value2->data[0].v_pointer;
730 /* not much to compare here, try to at least provide stable lesser/greater result */
732 return p1 < p2 ? -1 : p1 > p2;
736 param_value_array_init (GParamSpec *pspec)
738 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
740 aspec->element_spec = NULL;
741 aspec->fixed_n_elements = 0; /* disable */
745 value_array_ensure_size (GValueArray *value_array,
746 guint fixed_n_elements)
750 if (fixed_n_elements)
752 while (value_array->n_values < fixed_n_elements)
754 g_value_array_append (value_array, NULL);
757 while (value_array->n_values > fixed_n_elements)
759 g_value_array_remove (value_array, value_array->n_values - 1);
767 param_value_array_finalize (GParamSpec *pspec)
769 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
770 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
772 if (aspec->element_spec)
774 g_param_spec_unref (aspec->element_spec);
775 aspec->element_spec = NULL;
778 parent_class->finalize (pspec);
782 param_value_array_set_default (GParamSpec *pspec,
785 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
787 g_return_if_fail (value->data[0].v_pointer != NULL); /* paranoid */
789 /* g_value_reset (value); already done */
790 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
794 param_value_array_validate (GParamSpec *pspec,
797 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
798 GValueArray *value_array = value->data[0].v_pointer;
801 g_return_val_if_fail (value->data[0].v_pointer != NULL, FALSE); /* paranoid */
803 /* ensure array size validity */
804 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
806 /* ensure array values validity against a present element spec */
807 if (aspec->element_spec)
809 GParamSpec *element_spec = aspec->element_spec;
812 for (i = 0; i < value_array->n_values; i++)
814 GValue *element = value_array->values + i;
816 /* need to fixup value type, or ensure that the array value is initialized at all */
817 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
819 if (G_VALUE_TYPE (element) != 0)
820 g_value_unset (element);
821 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
822 g_param_value_set_default (element_spec, element);
825 /* validate array value against element_spec */
826 changed += g_param_value_validate (element_spec, element);
834 param_value_array_values_cmp (GParamSpec *pspec,
835 const GValue *value1,
836 const GValue *value2)
838 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
839 GValueArray *value_array1 = value1->data[0].v_pointer;
840 GValueArray *value_array2 = value2->data[0].v_pointer;
842 g_return_val_if_fail (value1->data[0].v_pointer != NULL, -1); /* paranoid */
843 g_return_val_if_fail (value2->data[0].v_pointer != NULL, 1); /* paranoid */
845 if (value_array1->n_values != value_array2->n_values)
846 return value_array1->n_values < value_array2->n_values ? -1 : 1;
847 else if (!aspec->element_spec)
849 /* we need an element specification for comparisons, so there's not much
850 * to compare here, try to at least provide stable lesser/greater result
852 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
854 else /* value_array1->n_values == value_array2->n_values */
858 for (i = 0; i < value_array1->n_values; i++)
860 GValue *element1 = value_array1->values + i;
861 GValue *element2 = value_array2->values + i;
864 /* need corresponding element types, provide stable result otherwise */
865 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
866 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
867 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
876 param_object_init (GParamSpec *pspec)
878 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
882 param_object_set_default (GParamSpec *pspec,
885 value->data[0].v_pointer = NULL;
889 param_object_validate (GParamSpec *pspec,
892 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
893 GObject *object = value->data[0].v_pointer;
896 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
898 g_object_unref (object);
899 value->data[0].v_pointer = NULL;
907 param_object_values_cmp (GParamSpec *pspec,
908 const GValue *value1,
909 const GValue *value2)
911 guint8 *p1 = value1->data[0].v_pointer;
912 guint8 *p2 = value2->data[0].v_pointer;
914 /* not much to compare here, try to at least provide stable lesser/greater result */
916 return p1 < p2 ? -1 : p1 > p2;
920 /* --- type initialization --- */
922 g_param_spec_types_init (void) /* sync with gtype.c */
929 static const GParamSpecTypeInfo pspec_info = {
930 sizeof (GParamSpecChar), /* instance_size */
931 16, /* n_preallocs */
932 param_char_init, /* instance_init */
933 G_TYPE_CHAR, /* value_type */
935 param_char_set_default, /* value_set_default */
936 param_char_validate, /* value_validate */
937 param_int_values_cmp, /* values_cmp */
939 type = g_param_type_register_static ("GParamChar", &pspec_info);
940 g_assert (type == G_TYPE_PARAM_CHAR);
943 /* G_TYPE_PARAM_UCHAR
946 static const GParamSpecTypeInfo pspec_info = {
947 sizeof (GParamSpecUChar), /* instance_size */
948 16, /* n_preallocs */
949 param_uchar_init, /* instance_init */
950 G_TYPE_UCHAR, /* value_type */
952 param_uchar_set_default, /* value_set_default */
953 param_uchar_validate, /* value_validate */
954 param_uint_values_cmp, /* values_cmp */
956 type = g_param_type_register_static ("GParamUChar", &pspec_info);
957 g_assert (type == G_TYPE_PARAM_UCHAR);
960 /* G_TYPE_PARAM_BOOLEAN
963 static const GParamSpecTypeInfo pspec_info = {
964 sizeof (GParamSpecBoolean), /* instance_size */
965 16, /* n_preallocs */
966 NULL, /* instance_init */
967 G_TYPE_BOOLEAN, /* value_type */
969 param_boolean_set_default, /* value_set_default */
970 param_boolean_validate, /* value_validate */
971 param_int_values_cmp, /* values_cmp */
973 type = g_param_type_register_static ("GParamBoolean", &pspec_info);
974 g_assert (type == G_TYPE_PARAM_BOOLEAN);
980 static const GParamSpecTypeInfo pspec_info = {
981 sizeof (GParamSpecInt), /* instance_size */
982 16, /* n_preallocs */
983 param_int_init, /* instance_init */
984 G_TYPE_INT, /* value_type */
986 param_int_set_default, /* value_set_default */
987 param_int_validate, /* value_validate */
988 param_int_values_cmp, /* values_cmp */
990 type = g_param_type_register_static ("GParamInt", &pspec_info);
991 g_assert (type == G_TYPE_PARAM_INT);
997 static const GParamSpecTypeInfo pspec_info = {
998 sizeof (GParamSpecUInt), /* instance_size */
999 16, /* n_preallocs */
1000 param_uint_init, /* instance_init */
1001 G_TYPE_UINT, /* value_type */
1002 NULL, /* finalize */
1003 param_uint_set_default, /* value_set_default */
1004 param_uint_validate, /* value_validate */
1005 param_uint_values_cmp, /* values_cmp */
1007 type = g_param_type_register_static ("GParamUInt", &pspec_info);
1008 g_assert (type == G_TYPE_PARAM_UINT);
1011 /* G_TYPE_PARAM_LONG
1014 static const GParamSpecTypeInfo pspec_info = {
1015 sizeof (GParamSpecLong), /* instance_size */
1016 16, /* n_preallocs */
1017 param_long_init, /* instance_init */
1018 G_TYPE_LONG, /* value_type */
1019 NULL, /* finalize */
1020 param_long_set_default, /* value_set_default */
1021 param_long_validate, /* value_validate */
1022 param_long_values_cmp, /* values_cmp */
1024 type = g_param_type_register_static ("GParamLong", &pspec_info);
1025 g_assert (type == G_TYPE_PARAM_LONG);
1028 /* G_TYPE_PARAM_ULONG
1031 static const GParamSpecTypeInfo pspec_info = {
1032 sizeof (GParamSpecULong), /* instance_size */
1033 16, /* n_preallocs */
1034 param_ulong_init, /* instance_init */
1035 G_TYPE_ULONG, /* value_type */
1036 NULL, /* finalize */
1037 param_ulong_set_default, /* value_set_default */
1038 param_ulong_validate, /* value_validate */
1039 param_ulong_values_cmp, /* values_cmp */
1041 type = g_param_type_register_static ("GParamULong", &pspec_info);
1042 g_assert (type == G_TYPE_PARAM_ULONG);
1045 /* G_TYPE_PARAM_UNICHAR
1048 static const GParamSpecTypeInfo pspec_info = {
1049 sizeof (GParamSpecUnichar), /* instance_size */
1050 16, /* n_preallocs */
1051 param_unichar_init, /* instance_init */
1052 G_TYPE_UINT, /* value_type */
1053 NULL, /* finalize */
1054 param_unichar_set_default, /* value_set_default */
1055 param_unichar_validate, /* value_validate */
1056 param_unichar_values_cmp, /* values_cmp */
1058 type = g_param_type_register_static ("GParamUnichar", &pspec_info);
1059 g_assert (type == G_TYPE_PARAM_UNICHAR);
1062 /* G_TYPE_PARAM_ENUM
1065 static const GParamSpecTypeInfo pspec_info = {
1066 sizeof (GParamSpecEnum), /* instance_size */
1067 16, /* n_preallocs */
1068 param_enum_init, /* instance_init */
1069 G_TYPE_ENUM, /* value_type */
1070 param_enum_finalize, /* finalize */
1071 param_enum_set_default, /* value_set_default */
1072 param_enum_validate, /* value_validate */
1073 param_long_values_cmp, /* values_cmp */
1075 type = g_param_type_register_static ("GParamEnum", &pspec_info);
1076 g_assert (type == G_TYPE_PARAM_ENUM);
1079 /* G_TYPE_PARAM_FLAGS
1082 static const GParamSpecTypeInfo pspec_info = {
1083 sizeof (GParamSpecFlags), /* instance_size */
1084 16, /* n_preallocs */
1085 param_flags_init, /* instance_init */
1086 G_TYPE_FLAGS, /* value_type */
1087 param_flags_finalize, /* finalize */
1088 param_flags_set_default, /* value_set_default */
1089 param_flags_validate, /* value_validate */
1090 param_ulong_values_cmp, /* values_cmp */
1092 type = g_param_type_register_static ("GParamFlags", &pspec_info);
1093 g_assert (type == G_TYPE_PARAM_FLAGS);
1096 /* G_TYPE_PARAM_FLOAT
1099 static const GParamSpecTypeInfo pspec_info = {
1100 sizeof (GParamSpecFloat), /* instance_size */
1101 16, /* n_preallocs */
1102 param_float_init, /* instance_init */
1103 G_TYPE_FLOAT, /* value_type */
1104 NULL, /* finalize */
1105 param_float_set_default, /* value_set_default */
1106 param_float_validate, /* value_validate */
1107 param_float_values_cmp, /* values_cmp */
1109 type = g_param_type_register_static ("GParamFloat", &pspec_info);
1110 g_assert (type == G_TYPE_PARAM_FLOAT);
1113 /* G_TYPE_PARAM_DOUBLE
1116 static const GParamSpecTypeInfo pspec_info = {
1117 sizeof (GParamSpecDouble), /* instance_size */
1118 16, /* n_preallocs */
1119 param_double_init, /* instance_init */
1120 G_TYPE_DOUBLE, /* value_type */
1121 NULL, /* finalize */
1122 param_double_set_default, /* value_set_default */
1123 param_double_validate, /* value_validate */
1124 param_double_values_cmp, /* values_cmp */
1126 type = g_param_type_register_static ("GParamDouble", &pspec_info);
1127 g_assert (type == G_TYPE_PARAM_DOUBLE);
1130 /* G_TYPE_PARAM_STRING
1133 static const GParamSpecTypeInfo pspec_info = {
1134 sizeof (GParamSpecString), /* instance_size */
1135 16, /* n_preallocs */
1136 param_string_init, /* instance_init */
1137 G_TYPE_STRING, /* value_type */
1138 param_string_finalize, /* finalize */
1139 param_string_set_default, /* value_set_default */
1140 param_string_validate, /* value_validate */
1141 param_string_values_cmp, /* values_cmp */
1143 type = g_param_type_register_static ("GParamString", &pspec_info);
1144 g_assert (type == G_TYPE_PARAM_STRING);
1147 /* G_TYPE_PARAM_PARAM
1150 static const GParamSpecTypeInfo pspec_info = {
1151 sizeof (GParamSpecParam), /* instance_size */
1152 16, /* n_preallocs */
1153 param_param_init, /* instance_init */
1154 G_TYPE_PARAM, /* value_type */
1155 NULL, /* finalize */
1156 param_param_set_default, /* value_set_default */
1157 param_param_validate, /* value_validate */
1158 param_pointer_values_cmp, /* values_cmp */
1160 type = g_param_type_register_static ("GParamParam", &pspec_info);
1161 g_assert (type == G_TYPE_PARAM_PARAM);
1164 /* G_TYPE_PARAM_BOXED
1167 static const GParamSpecTypeInfo pspec_info = {
1168 sizeof (GParamSpecBoxed), /* instance_size */
1169 4, /* n_preallocs */
1170 param_boxed_init, /* instance_init */
1171 G_TYPE_BOXED, /* value_type */
1172 NULL, /* finalize */
1173 param_boxed_set_default, /* value_set_default */
1174 param_boxed_validate, /* value_validate */
1175 param_boxed_values_cmp, /* values_cmp */
1177 type = g_param_type_register_static ("GParamBoxed", &pspec_info);
1178 g_assert (type == G_TYPE_PARAM_BOXED);
1181 /* G_TYPE_PARAM_POINTER
1184 static const GParamSpecTypeInfo pspec_info = {
1185 sizeof (GParamSpecPointer), /* instance_size */
1186 0, /* n_preallocs */
1187 param_pointer_init, /* instance_init */
1188 G_TYPE_POINTER, /* value_type */
1189 NULL, /* finalize */
1190 param_pointer_set_default, /* value_set_default */
1191 param_pointer_validate, /* value_validate */
1192 param_pointer_values_cmp, /* values_cmp */
1194 type = g_param_type_register_static ("GParamPointer", &pspec_info);
1195 g_assert (type == G_TYPE_PARAM_POINTER);
1198 /* G_TYPE_PARAM_VALUE_ARRAY
1201 static const GParamSpecTypeInfo pspec_info = {
1202 sizeof (GParamSpecValueArray), /* instance_size */
1203 0, /* n_preallocs */
1204 param_value_array_init, /* instance_init */
1205 G_TYPE_VALUE_ARRAY, /* value_type */
1206 param_value_array_finalize, /* finalize */
1207 param_value_array_set_default, /* value_set_default */
1208 param_value_array_validate, /* value_validate */
1209 param_value_array_values_cmp, /* values_cmp */
1211 type = g_param_type_register_static ("GParamValueArray", &pspec_info);
1212 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1215 /* G_TYPE_PARAM_CLOSURE
1218 static const GParamSpecTypeInfo pspec_info = {
1219 sizeof (GParamSpecClosure), /* instance_size */
1220 0, /* n_preallocs */
1221 param_closure_init, /* instance_init */
1222 G_TYPE_CLOSURE, /* value_type */
1223 NULL, /* finalize */
1224 param_closure_set_default, /* value_set_default */
1225 param_closure_validate, /* value_validate */
1226 param_closure_values_cmp, /* values_cmp */
1228 type = g_param_type_register_static ("GParamClosure", &pspec_info);
1229 g_assert (type == G_TYPE_PARAM_CLOSURE);
1232 /* G_TYPE_PARAM_OBJECT
1235 static const GParamSpecTypeInfo pspec_info = {
1236 sizeof (GParamSpecObject), /* instance_size */
1237 16, /* n_preallocs */
1238 param_object_init, /* instance_init */
1239 G_TYPE_OBJECT, /* value_type */
1240 NULL, /* finalize */
1241 param_object_set_default, /* value_set_default */
1242 param_object_validate, /* value_validate */
1243 param_object_values_cmp, /* values_cmp */
1245 type = g_param_type_register_static ("GParamObject", &pspec_info);
1246 g_assert (type == G_TYPE_PARAM_OBJECT);
1251 /* --- GParamSpec initialization --- */
1253 g_param_spec_char (const gchar *name,
1258 gint8 default_value,
1261 GParamSpecChar *cspec;
1263 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1265 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1271 cspec->minimum = minimum;
1272 cspec->maximum = maximum;
1273 cspec->default_value = default_value;
1275 return G_PARAM_SPEC (cspec);
1279 g_param_spec_uchar (const gchar *name,
1284 guint8 default_value,
1287 GParamSpecUChar *uspec;
1289 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1291 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1297 uspec->minimum = minimum;
1298 uspec->maximum = maximum;
1299 uspec->default_value = default_value;
1301 return G_PARAM_SPEC (uspec);
1305 g_param_spec_boolean (const gchar *name,
1308 gboolean default_value,
1311 GParamSpecBoolean *bspec;
1313 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1315 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1321 bspec->default_value = default_value;
1323 return G_PARAM_SPEC (bspec);
1327 g_param_spec_int (const gchar *name,
1335 GParamSpecInt *ispec;
1337 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1339 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1345 ispec->minimum = minimum;
1346 ispec->maximum = maximum;
1347 ispec->default_value = default_value;
1349 return G_PARAM_SPEC (ispec);
1353 g_param_spec_uint (const gchar *name,
1358 guint default_value,
1361 GParamSpecUInt *uspec;
1363 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1365 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1371 uspec->minimum = minimum;
1372 uspec->maximum = maximum;
1373 uspec->default_value = default_value;
1375 return G_PARAM_SPEC (uspec);
1379 g_param_spec_long (const gchar *name,
1384 glong default_value,
1387 GParamSpecLong *lspec;
1389 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1391 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1397 lspec->minimum = minimum;
1398 lspec->maximum = maximum;
1399 lspec->default_value = default_value;
1401 return G_PARAM_SPEC (lspec);
1405 g_param_spec_ulong (const gchar *name,
1410 gulong default_value,
1413 GParamSpecULong *uspec;
1415 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1417 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1423 uspec->minimum = minimum;
1424 uspec->maximum = maximum;
1425 uspec->default_value = default_value;
1427 return G_PARAM_SPEC (uspec);
1431 g_param_spec_unichar (const gchar *name,
1434 gunichar default_value,
1437 GParamSpecUnichar *uspec;
1439 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1445 uspec->default_value = default_value;
1447 return G_PARAM_SPEC (uspec);
1451 g_param_spec_enum (const gchar *name,
1458 GParamSpecEnum *espec;
1459 GEnumClass *enum_class;
1461 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
1463 enum_class = g_type_class_ref (enum_type);
1465 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
1467 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
1473 espec->enum_class = enum_class;
1474 espec->default_value = default_value;
1475 G_PARAM_SPEC (espec)->value_type = enum_type;
1477 return G_PARAM_SPEC (espec);
1481 g_param_spec_flags (const gchar *name,
1485 guint default_value,
1488 GParamSpecFlags *fspec;
1489 GFlagsClass *flags_class;
1491 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
1493 flags_class = g_type_class_ref (flags_type);
1495 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
1497 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
1503 fspec->flags_class = flags_class;
1504 fspec->default_value = default_value;
1505 G_PARAM_SPEC (fspec)->value_type = flags_type;
1507 return G_PARAM_SPEC (fspec);
1511 g_param_spec_float (const gchar *name,
1516 gfloat default_value,
1519 GParamSpecFloat *fspec;
1521 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1523 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
1529 fspec->minimum = minimum;
1530 fspec->maximum = maximum;
1531 fspec->default_value = default_value;
1533 return G_PARAM_SPEC (fspec);
1537 g_param_spec_double (const gchar *name,
1542 gdouble default_value,
1545 GParamSpecDouble *dspec;
1547 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1549 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
1555 dspec->minimum = minimum;
1556 dspec->maximum = maximum;
1557 dspec->default_value = default_value;
1559 return G_PARAM_SPEC (dspec);
1563 g_param_spec_string (const gchar *name,
1566 const gchar *default_value,
1569 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
1574 g_free (sspec->default_value);
1575 sspec->default_value = g_strdup (default_value);
1577 return G_PARAM_SPEC (sspec);
1581 g_param_spec_param (const gchar *name,
1587 GParamSpecParam *pspec;
1589 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
1591 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
1596 G_PARAM_SPEC (pspec)->value_type = param_type;
1598 return G_PARAM_SPEC (pspec);
1602 g_param_spec_boxed (const gchar *name,
1608 GParamSpecBoxed *bspec;
1610 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
1611 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
1613 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
1618 G_PARAM_SPEC (bspec)->value_type = boxed_type;
1620 return G_PARAM_SPEC (bspec);
1624 g_param_spec_pointer (const gchar *name,
1629 GParamSpecPointer *pspec;
1631 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
1636 return G_PARAM_SPEC (pspec);
1640 g_param_spec_value_array (const gchar *name,
1643 GParamSpec *element_spec,
1646 GParamSpecValueArray *aspec;
1649 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
1651 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
1658 aspec->element_spec = g_param_spec_ref (element_spec);
1659 g_param_spec_sink (element_spec);
1662 return G_PARAM_SPEC (aspec);
1666 g_param_spec_closure (const gchar *name,
1671 GParamSpecClosure *cspec;
1673 cspec = g_param_spec_internal (G_TYPE_PARAM_CLOSURE,
1678 return G_PARAM_SPEC (cspec);
1682 g_param_spec_object (const gchar *name,
1688 GParamSpecObject *ospec;
1690 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
1692 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
1697 G_PARAM_SPEC (ospec)->value_type = object_type;
1699 return G_PARAM_SPEC (ospec);