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_int64_init (GParamSpec *pspec)
284 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
286 lspec->minimum = G_MININT64;
287 lspec->maximum = G_MAXINT64;
288 lspec->default_value = 0;
292 param_int64_set_default (GParamSpec *pspec,
295 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
299 param_int64_validate (GParamSpec *pspec,
302 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
303 gint64 oval = value->data[0].v_int64;
305 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
307 return value->data[0].v_int64 != oval;
311 param_int64_values_cmp (GParamSpec *pspec,
312 const GValue *value1,
313 const GValue *value2)
315 if (value1->data[0].v_int64 < value2->data[0].v_int64)
318 return value1->data[0].v_int64 > value2->data[0].v_int64;
322 param_uint64_init (GParamSpec *pspec)
324 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
327 uspec->maximum = G_MAXUINT64;
328 uspec->default_value = 0;
332 param_uint64_set_default (GParamSpec *pspec,
335 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
339 param_uint64_validate (GParamSpec *pspec,
342 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
343 guint64 oval = value->data[0].v_uint64;
345 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
347 return value->data[0].v_uint64 != oval;
351 param_uint64_values_cmp (GParamSpec *pspec,
352 const GValue *value1,
353 const GValue *value2)
355 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
358 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
362 param_unichar_init (GParamSpec *pspec)
364 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
366 uspec->default_value = 0;
370 param_unichar_set_default (GParamSpec *pspec,
373 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
377 param_unichar_validate (GParamSpec *pspec,
380 gunichar oval = value->data[0].v_uint;
381 gboolean changed = FALSE;
383 if (!g_unichar_validate (oval))
385 value->data[0].v_uint = 0;
393 param_unichar_values_cmp (GParamSpec *pspec,
394 const GValue *value1,
395 const GValue *value2)
397 if (value1->data[0].v_uint < value2->data[0].v_uint)
400 return value1->data[0].v_uint > value2->data[0].v_uint;
404 param_enum_init (GParamSpec *pspec)
406 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
408 espec->enum_class = NULL;
409 espec->default_value = 0;
413 param_enum_finalize (GParamSpec *pspec)
415 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
416 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
418 if (espec->enum_class)
420 g_type_class_unref (espec->enum_class);
421 espec->enum_class = NULL;
424 parent_class->finalize (pspec);
428 param_enum_set_default (GParamSpec *pspec,
431 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
435 param_enum_validate (GParamSpec *pspec,
438 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
439 glong oval = value->data[0].v_long;
441 if (!espec->enum_class ||
442 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
443 value->data[0].v_long = espec->default_value;
445 return value->data[0].v_long != oval;
449 param_flags_init (GParamSpec *pspec)
451 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
453 fspec->flags_class = NULL;
454 fspec->default_value = 0;
458 param_flags_finalize (GParamSpec *pspec)
460 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
461 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
463 if (fspec->flags_class)
465 g_type_class_unref (fspec->flags_class);
466 fspec->flags_class = NULL;
469 parent_class->finalize (pspec);
473 param_flags_set_default (GParamSpec *pspec,
476 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
480 param_flags_validate (GParamSpec *pspec,
483 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
484 gulong oval = value->data[0].v_ulong;
486 if (fspec->flags_class)
487 value->data[0].v_ulong &= fspec->flags_class->mask;
489 value->data[0].v_ulong = fspec->default_value;
491 return value->data[0].v_ulong != oval;
495 param_float_init (GParamSpec *pspec)
497 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
499 fspec->minimum = G_MINFLOAT;
500 fspec->maximum = G_MAXFLOAT;
501 fspec->default_value = 0;
502 fspec->epsilon = G_FLOAT_EPSILON;
506 param_float_set_default (GParamSpec *pspec,
509 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
513 param_float_validate (GParamSpec *pspec,
516 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
517 gfloat oval = value->data[0].v_float;
519 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
521 return value->data[0].v_float != oval;
525 param_float_values_cmp (GParamSpec *pspec,
526 const GValue *value1,
527 const GValue *value2)
529 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
531 if (value1->data[0].v_float < value2->data[0].v_float)
532 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
534 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
538 param_double_init (GParamSpec *pspec)
540 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
542 dspec->minimum = G_MINDOUBLE;
543 dspec->maximum = G_MAXDOUBLE;
544 dspec->default_value = 0;
545 dspec->epsilon = G_DOUBLE_EPSILON;
549 param_double_set_default (GParamSpec *pspec,
552 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
556 param_double_validate (GParamSpec *pspec,
559 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
560 gdouble oval = value->data[0].v_double;
562 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
564 return value->data[0].v_double != oval;
568 param_double_values_cmp (GParamSpec *pspec,
569 const GValue *value1,
570 const GValue *value2)
572 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
574 if (value1->data[0].v_double < value2->data[0].v_double)
575 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
577 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
581 param_string_init (GParamSpec *pspec)
583 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
585 sspec->default_value = NULL;
586 sspec->cset_first = NULL;
587 sspec->cset_nth = NULL;
588 sspec->substitutor = '_';
589 sspec->null_fold_if_empty = FALSE;
590 sspec->ensure_non_null = FALSE;
594 param_string_finalize (GParamSpec *pspec)
596 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
597 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
599 g_free (sspec->default_value);
600 g_free (sspec->cset_first);
601 g_free (sspec->cset_nth);
602 sspec->default_value = NULL;
603 sspec->cset_first = NULL;
604 sspec->cset_nth = NULL;
606 parent_class->finalize (pspec);
610 param_string_set_default (GParamSpec *pspec,
613 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
617 param_string_validate (GParamSpec *pspec,
620 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
621 gchar *string = value->data[0].v_pointer;
624 if (string && string[0])
628 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
630 string[0] = sspec->substitutor;
634 for (s = string + 1; *s; s++)
635 if (!strchr (sspec->cset_nth, *s))
637 *s = sspec->substitutor;
641 if (sspec->null_fold_if_empty && string && string[0] == 0)
643 g_free (value->data[0].v_pointer);
644 value->data[0].v_pointer = NULL;
646 string = value->data[0].v_pointer;
648 if (sspec->ensure_non_null && !string)
650 value->data[0].v_pointer = g_strdup ("");
652 string = value->data[0].v_pointer;
659 param_string_values_cmp (GParamSpec *pspec,
660 const GValue *value1,
661 const GValue *value2)
663 if (!value1->data[0].v_pointer)
664 return value2->data[0].v_pointer != NULL ? -1 : 0;
665 else if (!value2->data[0].v_pointer)
666 return value1->data[0].v_pointer != NULL;
668 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
672 param_param_init (GParamSpec *pspec)
674 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
678 param_param_set_default (GParamSpec *pspec,
681 value->data[0].v_pointer = NULL;
685 param_param_validate (GParamSpec *pspec,
688 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
689 GParamSpec *param = value->data[0].v_pointer;
692 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
694 g_param_spec_unref (param);
695 value->data[0].v_pointer = NULL;
703 param_boxed_init (GParamSpec *pspec)
705 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
709 param_boxed_set_default (GParamSpec *pspec,
712 value->data[0].v_pointer = NULL;
716 param_boxed_validate (GParamSpec *pspec,
719 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
722 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
728 param_boxed_values_cmp (GParamSpec *pspec,
729 const GValue *value1,
730 const GValue *value2)
732 guint8 *p1 = value1->data[0].v_pointer;
733 guint8 *p2 = value2->data[0].v_pointer;
735 /* not much to compare here, try to at least provide stable lesser/greater result */
737 return p1 < p2 ? -1 : p1 > p2;
741 param_pointer_init (GParamSpec *pspec)
743 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
747 param_pointer_set_default (GParamSpec *pspec,
750 value->data[0].v_pointer = NULL;
754 param_pointer_validate (GParamSpec *pspec,
757 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
764 param_pointer_values_cmp (GParamSpec *pspec,
765 const GValue *value1,
766 const GValue *value2)
768 guint8 *p1 = value1->data[0].v_pointer;
769 guint8 *p2 = value2->data[0].v_pointer;
771 /* not much to compare here, try to at least provide stable lesser/greater result */
773 return p1 < p2 ? -1 : p1 > p2;
777 param_value_array_init (GParamSpec *pspec)
779 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
781 aspec->element_spec = NULL;
782 aspec->fixed_n_elements = 0; /* disable */
786 value_array_ensure_size (GValueArray *value_array,
787 guint fixed_n_elements)
791 if (fixed_n_elements)
793 while (value_array->n_values < fixed_n_elements)
795 g_value_array_append (value_array, NULL);
798 while (value_array->n_values > fixed_n_elements)
800 g_value_array_remove (value_array, value_array->n_values - 1);
808 param_value_array_finalize (GParamSpec *pspec)
810 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
811 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
813 if (aspec->element_spec)
815 g_param_spec_unref (aspec->element_spec);
816 aspec->element_spec = NULL;
819 parent_class->finalize (pspec);
823 param_value_array_set_default (GParamSpec *pspec,
826 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
828 g_return_if_fail (value->data[0].v_pointer != NULL); /* paranoid */
830 /* g_value_reset (value); already done */
831 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
835 param_value_array_validate (GParamSpec *pspec,
838 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
839 GValueArray *value_array = value->data[0].v_pointer;
842 g_return_val_if_fail (value->data[0].v_pointer != NULL, FALSE); /* paranoid */
844 /* ensure array size validity */
845 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
847 /* ensure array values validity against a present element spec */
848 if (aspec->element_spec)
850 GParamSpec *element_spec = aspec->element_spec;
853 for (i = 0; i < value_array->n_values; i++)
855 GValue *element = value_array->values + i;
857 /* need to fixup value type, or ensure that the array value is initialized at all */
858 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
860 if (G_VALUE_TYPE (element) != 0)
861 g_value_unset (element);
862 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
863 g_param_value_set_default (element_spec, element);
866 /* validate array value against element_spec */
867 changed += g_param_value_validate (element_spec, element);
875 param_value_array_values_cmp (GParamSpec *pspec,
876 const GValue *value1,
877 const GValue *value2)
879 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
880 GValueArray *value_array1 = value1->data[0].v_pointer;
881 GValueArray *value_array2 = value2->data[0].v_pointer;
883 g_return_val_if_fail (value1->data[0].v_pointer != NULL, -1); /* paranoid */
884 g_return_val_if_fail (value2->data[0].v_pointer != NULL, 1); /* paranoid */
886 if (value_array1->n_values != value_array2->n_values)
887 return value_array1->n_values < value_array2->n_values ? -1 : 1;
888 else if (!aspec->element_spec)
890 /* we need an element specification for comparisons, so there's not much
891 * to compare here, try to at least provide stable lesser/greater result
893 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
895 else /* value_array1->n_values == value_array2->n_values */
899 for (i = 0; i < value_array1->n_values; i++)
901 GValue *element1 = value_array1->values + i;
902 GValue *element2 = value_array2->values + i;
905 /* need corresponding element types, provide stable result otherwise */
906 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
907 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
908 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
917 param_object_init (GParamSpec *pspec)
919 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
923 param_object_set_default (GParamSpec *pspec,
926 value->data[0].v_pointer = NULL;
930 param_object_validate (GParamSpec *pspec,
933 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
934 GObject *object = value->data[0].v_pointer;
937 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
939 g_object_unref (object);
940 value->data[0].v_pointer = NULL;
948 param_object_values_cmp (GParamSpec *pspec,
949 const GValue *value1,
950 const GValue *value2)
952 guint8 *p1 = value1->data[0].v_pointer;
953 guint8 *p2 = value2->data[0].v_pointer;
955 /* not much to compare here, try to at least provide stable lesser/greater result */
957 return p1 < p2 ? -1 : p1 > p2;
961 /* --- type initialization --- */
963 g_param_spec_types_init (void) /* sync with gtype.c */
970 static const GParamSpecTypeInfo pspec_info = {
971 sizeof (GParamSpecChar), /* instance_size */
972 16, /* n_preallocs */
973 param_char_init, /* instance_init */
974 G_TYPE_CHAR, /* value_type */
976 param_char_set_default, /* value_set_default */
977 param_char_validate, /* value_validate */
978 param_int_values_cmp, /* values_cmp */
980 type = g_param_type_register_static ("GParamChar", &pspec_info);
981 g_assert (type == G_TYPE_PARAM_CHAR);
984 /* G_TYPE_PARAM_UCHAR
987 static const GParamSpecTypeInfo pspec_info = {
988 sizeof (GParamSpecUChar), /* instance_size */
989 16, /* n_preallocs */
990 param_uchar_init, /* instance_init */
991 G_TYPE_UCHAR, /* value_type */
993 param_uchar_set_default, /* value_set_default */
994 param_uchar_validate, /* value_validate */
995 param_uint_values_cmp, /* values_cmp */
997 type = g_param_type_register_static ("GParamUChar", &pspec_info);
998 g_assert (type == G_TYPE_PARAM_UCHAR);
1001 /* G_TYPE_PARAM_BOOLEAN
1004 static const GParamSpecTypeInfo pspec_info = {
1005 sizeof (GParamSpecBoolean), /* instance_size */
1006 16, /* n_preallocs */
1007 NULL, /* instance_init */
1008 G_TYPE_BOOLEAN, /* value_type */
1009 NULL, /* finalize */
1010 param_boolean_set_default, /* value_set_default */
1011 param_boolean_validate, /* value_validate */
1012 param_int_values_cmp, /* values_cmp */
1014 type = g_param_type_register_static ("GParamBoolean", &pspec_info);
1015 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1021 static const GParamSpecTypeInfo pspec_info = {
1022 sizeof (GParamSpecInt), /* instance_size */
1023 16, /* n_preallocs */
1024 param_int_init, /* instance_init */
1025 G_TYPE_INT, /* value_type */
1026 NULL, /* finalize */
1027 param_int_set_default, /* value_set_default */
1028 param_int_validate, /* value_validate */
1029 param_int_values_cmp, /* values_cmp */
1031 type = g_param_type_register_static ("GParamInt", &pspec_info);
1032 g_assert (type == G_TYPE_PARAM_INT);
1035 /* G_TYPE_PARAM_UINT
1038 static const GParamSpecTypeInfo pspec_info = {
1039 sizeof (GParamSpecUInt), /* instance_size */
1040 16, /* n_preallocs */
1041 param_uint_init, /* instance_init */
1042 G_TYPE_UINT, /* value_type */
1043 NULL, /* finalize */
1044 param_uint_set_default, /* value_set_default */
1045 param_uint_validate, /* value_validate */
1046 param_uint_values_cmp, /* values_cmp */
1048 type = g_param_type_register_static ("GParamUInt", &pspec_info);
1049 g_assert (type == G_TYPE_PARAM_UINT);
1052 /* G_TYPE_PARAM_LONG
1055 static const GParamSpecTypeInfo pspec_info = {
1056 sizeof (GParamSpecLong), /* instance_size */
1057 16, /* n_preallocs */
1058 param_long_init, /* instance_init */
1059 G_TYPE_LONG, /* value_type */
1060 NULL, /* finalize */
1061 param_long_set_default, /* value_set_default */
1062 param_long_validate, /* value_validate */
1063 param_long_values_cmp, /* values_cmp */
1065 type = g_param_type_register_static ("GParamLong", &pspec_info);
1066 g_assert (type == G_TYPE_PARAM_LONG);
1069 /* G_TYPE_PARAM_ULONG
1072 static const GParamSpecTypeInfo pspec_info = {
1073 sizeof (GParamSpecULong), /* instance_size */
1074 16, /* n_preallocs */
1075 param_ulong_init, /* instance_init */
1076 G_TYPE_ULONG, /* value_type */
1077 NULL, /* finalize */
1078 param_ulong_set_default, /* value_set_default */
1079 param_ulong_validate, /* value_validate */
1080 param_ulong_values_cmp, /* values_cmp */
1082 type = g_param_type_register_static ("GParamULong", &pspec_info);
1083 g_assert (type == G_TYPE_PARAM_ULONG);
1086 /* G_TYPE_PARAM_INT64
1089 static const GParamSpecTypeInfo pspec_info = {
1090 sizeof (GParamSpecInt64), /* instance_size */
1091 16, /* n_preallocs */
1092 param_int64_init, /* instance_init */
1093 G_TYPE_INT64, /* value_type */
1094 NULL, /* finalize */
1095 param_int64_set_default, /* value_set_default */
1096 param_int64_validate, /* value_validate */
1097 param_int64_values_cmp, /* values_cmp */
1099 type = g_param_type_register_static ("GParamInt64", &pspec_info);
1100 g_assert (type == G_TYPE_PARAM_INT64);
1103 /* G_TYPE_PARAM_UINT64
1106 static const GParamSpecTypeInfo pspec_info = {
1107 sizeof (GParamSpecUInt64), /* instance_size */
1108 16, /* n_preallocs */
1109 param_uint64_init, /* instance_init */
1110 G_TYPE_UINT64, /* value_type */
1111 NULL, /* finalize */
1112 param_uint64_set_default, /* value_set_default */
1113 param_uint64_validate, /* value_validate */
1114 param_uint64_values_cmp, /* values_cmp */
1116 type = g_param_type_register_static ("GParamUInt64", &pspec_info);
1117 g_assert (type == G_TYPE_PARAM_UINT64);
1120 /* G_TYPE_PARAM_UNICHAR
1123 static const GParamSpecTypeInfo pspec_info = {
1124 sizeof (GParamSpecUnichar), /* instance_size */
1125 16, /* n_preallocs */
1126 param_unichar_init, /* instance_init */
1127 G_TYPE_UINT, /* value_type */
1128 NULL, /* finalize */
1129 param_unichar_set_default, /* value_set_default */
1130 param_unichar_validate, /* value_validate */
1131 param_unichar_values_cmp, /* values_cmp */
1133 type = g_param_type_register_static ("GParamUnichar", &pspec_info);
1134 g_assert (type == G_TYPE_PARAM_UNICHAR);
1137 /* G_TYPE_PARAM_ENUM
1140 static const GParamSpecTypeInfo pspec_info = {
1141 sizeof (GParamSpecEnum), /* instance_size */
1142 16, /* n_preallocs */
1143 param_enum_init, /* instance_init */
1144 G_TYPE_ENUM, /* value_type */
1145 param_enum_finalize, /* finalize */
1146 param_enum_set_default, /* value_set_default */
1147 param_enum_validate, /* value_validate */
1148 param_long_values_cmp, /* values_cmp */
1150 type = g_param_type_register_static ("GParamEnum", &pspec_info);
1151 g_assert (type == G_TYPE_PARAM_ENUM);
1154 /* G_TYPE_PARAM_FLAGS
1157 static const GParamSpecTypeInfo pspec_info = {
1158 sizeof (GParamSpecFlags), /* instance_size */
1159 16, /* n_preallocs */
1160 param_flags_init, /* instance_init */
1161 G_TYPE_FLAGS, /* value_type */
1162 param_flags_finalize, /* finalize */
1163 param_flags_set_default, /* value_set_default */
1164 param_flags_validate, /* value_validate */
1165 param_ulong_values_cmp, /* values_cmp */
1167 type = g_param_type_register_static ("GParamFlags", &pspec_info);
1168 g_assert (type == G_TYPE_PARAM_FLAGS);
1171 /* G_TYPE_PARAM_FLOAT
1174 static const GParamSpecTypeInfo pspec_info = {
1175 sizeof (GParamSpecFloat), /* instance_size */
1176 16, /* n_preallocs */
1177 param_float_init, /* instance_init */
1178 G_TYPE_FLOAT, /* value_type */
1179 NULL, /* finalize */
1180 param_float_set_default, /* value_set_default */
1181 param_float_validate, /* value_validate */
1182 param_float_values_cmp, /* values_cmp */
1184 type = g_param_type_register_static ("GParamFloat", &pspec_info);
1185 g_assert (type == G_TYPE_PARAM_FLOAT);
1188 /* G_TYPE_PARAM_DOUBLE
1191 static const GParamSpecTypeInfo pspec_info = {
1192 sizeof (GParamSpecDouble), /* instance_size */
1193 16, /* n_preallocs */
1194 param_double_init, /* instance_init */
1195 G_TYPE_DOUBLE, /* value_type */
1196 NULL, /* finalize */
1197 param_double_set_default, /* value_set_default */
1198 param_double_validate, /* value_validate */
1199 param_double_values_cmp, /* values_cmp */
1201 type = g_param_type_register_static ("GParamDouble", &pspec_info);
1202 g_assert (type == G_TYPE_PARAM_DOUBLE);
1205 /* G_TYPE_PARAM_STRING
1208 static const GParamSpecTypeInfo pspec_info = {
1209 sizeof (GParamSpecString), /* instance_size */
1210 16, /* n_preallocs */
1211 param_string_init, /* instance_init */
1212 G_TYPE_STRING, /* value_type */
1213 param_string_finalize, /* finalize */
1214 param_string_set_default, /* value_set_default */
1215 param_string_validate, /* value_validate */
1216 param_string_values_cmp, /* values_cmp */
1218 type = g_param_type_register_static ("GParamString", &pspec_info);
1219 g_assert (type == G_TYPE_PARAM_STRING);
1222 /* G_TYPE_PARAM_PARAM
1225 static const GParamSpecTypeInfo pspec_info = {
1226 sizeof (GParamSpecParam), /* instance_size */
1227 16, /* n_preallocs */
1228 param_param_init, /* instance_init */
1229 G_TYPE_PARAM, /* value_type */
1230 NULL, /* finalize */
1231 param_param_set_default, /* value_set_default */
1232 param_param_validate, /* value_validate */
1233 param_pointer_values_cmp, /* values_cmp */
1235 type = g_param_type_register_static ("GParamParam", &pspec_info);
1236 g_assert (type == G_TYPE_PARAM_PARAM);
1239 /* G_TYPE_PARAM_BOXED
1242 static const GParamSpecTypeInfo pspec_info = {
1243 sizeof (GParamSpecBoxed), /* instance_size */
1244 4, /* n_preallocs */
1245 param_boxed_init, /* instance_init */
1246 G_TYPE_BOXED, /* value_type */
1247 NULL, /* finalize */
1248 param_boxed_set_default, /* value_set_default */
1249 param_boxed_validate, /* value_validate */
1250 param_boxed_values_cmp, /* values_cmp */
1252 type = g_param_type_register_static ("GParamBoxed", &pspec_info);
1253 g_assert (type == G_TYPE_PARAM_BOXED);
1256 /* G_TYPE_PARAM_POINTER
1259 static const GParamSpecTypeInfo pspec_info = {
1260 sizeof (GParamSpecPointer), /* instance_size */
1261 0, /* n_preallocs */
1262 param_pointer_init, /* instance_init */
1263 G_TYPE_POINTER, /* value_type */
1264 NULL, /* finalize */
1265 param_pointer_set_default, /* value_set_default */
1266 param_pointer_validate, /* value_validate */
1267 param_pointer_values_cmp, /* values_cmp */
1269 type = g_param_type_register_static ("GParamPointer", &pspec_info);
1270 g_assert (type == G_TYPE_PARAM_POINTER);
1273 /* G_TYPE_PARAM_VALUE_ARRAY
1276 static const GParamSpecTypeInfo pspec_info = {
1277 sizeof (GParamSpecValueArray), /* instance_size */
1278 0, /* n_preallocs */
1279 param_value_array_init, /* instance_init */
1280 G_TYPE_VALUE_ARRAY, /* value_type */
1281 param_value_array_finalize, /* finalize */
1282 param_value_array_set_default, /* value_set_default */
1283 param_value_array_validate, /* value_validate */
1284 param_value_array_values_cmp, /* values_cmp */
1286 type = g_param_type_register_static ("GParamValueArray", &pspec_info);
1287 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1290 /* G_TYPE_PARAM_OBJECT
1293 static const GParamSpecTypeInfo pspec_info = {
1294 sizeof (GParamSpecObject), /* instance_size */
1295 16, /* n_preallocs */
1296 param_object_init, /* instance_init */
1297 G_TYPE_OBJECT, /* value_type */
1298 NULL, /* finalize */
1299 param_object_set_default, /* value_set_default */
1300 param_object_validate, /* value_validate */
1301 param_object_values_cmp, /* values_cmp */
1303 type = g_param_type_register_static ("GParamObject", &pspec_info);
1304 g_assert (type == G_TYPE_PARAM_OBJECT);
1309 /* --- GParamSpec initialization --- */
1311 g_param_spec_char (const gchar *name,
1316 gint8 default_value,
1319 GParamSpecChar *cspec;
1321 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1323 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1329 cspec->minimum = minimum;
1330 cspec->maximum = maximum;
1331 cspec->default_value = default_value;
1333 return G_PARAM_SPEC (cspec);
1337 g_param_spec_uchar (const gchar *name,
1342 guint8 default_value,
1345 GParamSpecUChar *uspec;
1347 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1349 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1355 uspec->minimum = minimum;
1356 uspec->maximum = maximum;
1357 uspec->default_value = default_value;
1359 return G_PARAM_SPEC (uspec);
1363 g_param_spec_boolean (const gchar *name,
1366 gboolean default_value,
1369 GParamSpecBoolean *bspec;
1371 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1373 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1379 bspec->default_value = default_value;
1381 return G_PARAM_SPEC (bspec);
1385 g_param_spec_int (const gchar *name,
1393 GParamSpecInt *ispec;
1395 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1397 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1403 ispec->minimum = minimum;
1404 ispec->maximum = maximum;
1405 ispec->default_value = default_value;
1407 return G_PARAM_SPEC (ispec);
1411 g_param_spec_uint (const gchar *name,
1416 guint default_value,
1419 GParamSpecUInt *uspec;
1421 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1423 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1429 uspec->minimum = minimum;
1430 uspec->maximum = maximum;
1431 uspec->default_value = default_value;
1433 return G_PARAM_SPEC (uspec);
1437 g_param_spec_long (const gchar *name,
1442 glong default_value,
1445 GParamSpecLong *lspec;
1447 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1449 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1455 lspec->minimum = minimum;
1456 lspec->maximum = maximum;
1457 lspec->default_value = default_value;
1459 return G_PARAM_SPEC (lspec);
1463 g_param_spec_ulong (const gchar *name,
1468 gulong default_value,
1471 GParamSpecULong *uspec;
1473 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1475 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1481 uspec->minimum = minimum;
1482 uspec->maximum = maximum;
1483 uspec->default_value = default_value;
1485 return G_PARAM_SPEC (uspec);
1489 g_param_spec_int64 (const gchar *name,
1494 gint64 default_value,
1497 GParamSpecInt64 *lspec;
1499 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1501 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1507 lspec->minimum = minimum;
1508 lspec->maximum = maximum;
1509 lspec->default_value = default_value;
1511 return G_PARAM_SPEC (lspec);
1515 g_param_spec_uint64 (const gchar *name,
1520 guint64 default_value,
1523 GParamSpecUInt64 *uspec;
1525 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1527 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1533 uspec->minimum = minimum;
1534 uspec->maximum = maximum;
1535 uspec->default_value = default_value;
1537 return G_PARAM_SPEC (uspec);
1541 g_param_spec_unichar (const gchar *name,
1544 gunichar default_value,
1547 GParamSpecUnichar *uspec;
1549 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1555 uspec->default_value = default_value;
1557 return G_PARAM_SPEC (uspec);
1561 g_param_spec_enum (const gchar *name,
1568 GParamSpecEnum *espec;
1569 GEnumClass *enum_class;
1571 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
1573 enum_class = g_type_class_ref (enum_type);
1575 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
1577 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
1583 espec->enum_class = enum_class;
1584 espec->default_value = default_value;
1585 G_PARAM_SPEC (espec)->value_type = enum_type;
1587 return G_PARAM_SPEC (espec);
1591 g_param_spec_flags (const gchar *name,
1595 guint default_value,
1598 GParamSpecFlags *fspec;
1599 GFlagsClass *flags_class;
1601 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
1603 flags_class = g_type_class_ref (flags_type);
1605 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
1607 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
1613 fspec->flags_class = flags_class;
1614 fspec->default_value = default_value;
1615 G_PARAM_SPEC (fspec)->value_type = flags_type;
1617 return G_PARAM_SPEC (fspec);
1621 g_param_spec_float (const gchar *name,
1626 gfloat default_value,
1629 GParamSpecFloat *fspec;
1631 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1633 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
1639 fspec->minimum = minimum;
1640 fspec->maximum = maximum;
1641 fspec->default_value = default_value;
1643 return G_PARAM_SPEC (fspec);
1647 g_param_spec_double (const gchar *name,
1652 gdouble default_value,
1655 GParamSpecDouble *dspec;
1657 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1659 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
1665 dspec->minimum = minimum;
1666 dspec->maximum = maximum;
1667 dspec->default_value = default_value;
1669 return G_PARAM_SPEC (dspec);
1673 g_param_spec_string (const gchar *name,
1676 const gchar *default_value,
1679 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
1684 g_free (sspec->default_value);
1685 sspec->default_value = g_strdup (default_value);
1687 return G_PARAM_SPEC (sspec);
1691 g_param_spec_param (const gchar *name,
1697 GParamSpecParam *pspec;
1699 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
1701 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
1706 G_PARAM_SPEC (pspec)->value_type = param_type;
1708 return G_PARAM_SPEC (pspec);
1712 g_param_spec_boxed (const gchar *name,
1718 GParamSpecBoxed *bspec;
1720 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
1721 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
1723 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
1728 G_PARAM_SPEC (bspec)->value_type = boxed_type;
1730 return G_PARAM_SPEC (bspec);
1734 g_param_spec_pointer (const gchar *name,
1739 GParamSpecPointer *pspec;
1741 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
1746 return G_PARAM_SPEC (pspec);
1750 g_param_spec_value_array (const gchar *name,
1753 GParamSpec *element_spec,
1756 GParamSpecValueArray *aspec;
1759 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
1761 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
1768 aspec->element_spec = g_param_spec_ref (element_spec);
1769 g_param_spec_sink (element_spec);
1772 return G_PARAM_SPEC (aspec);
1776 g_param_spec_object (const gchar *name,
1782 GParamSpecObject *ospec;
1784 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
1786 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
1791 G_PARAM_SPEC (ospec)->value_type = object_type;
1793 return G_PARAM_SPEC (ospec);