1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 * Copyright (C) 2010 Christian Persch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
29 #include "gparamspecs.h"
30 #include "gvaluecollector.h"
31 #include "gvaluearray.h"
35 * SECTION:param_value_types
36 * @short_description: Standard Parameter and Value Types
37 * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
38 * @title: Parameters and Values
40 * #GValue provides an abstract container structure which can be
41 * copied, transformed and compared while holding a value of any
42 * (derived) type, which is registered as a #GType with a
43 * #GTypeValueTable in its #GTypeInfo structure. Parameter
44 * specifications for most value types can be created as #GParamSpec
45 * derived instances, to implement e.g. #GObject properties which
46 * operate on #GValue containers.
48 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
49 * characters can be letters, numbers or a '-'.
50 * All other characters are replaced by a '-' during construction.
54 #define G_FLOAT_EPSILON (1e-30)
55 #define G_DOUBLE_EPSILON (1e-90)
58 /* --- param spec functions --- */
60 param_char_init (GParamSpec *pspec)
62 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
64 cspec->minimum = 0x7f;
65 cspec->maximum = 0x80;
66 cspec->default_value = 0;
70 param_char_set_default (GParamSpec *pspec,
73 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
77 param_char_validate (GParamSpec *pspec,
80 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
81 gint oval = value->data[0].v_int;
83 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
85 return value->data[0].v_int != oval;
89 param_uchar_init (GParamSpec *pspec)
91 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
94 uspec->maximum = 0xff;
95 uspec->default_value = 0;
99 param_uchar_set_default (GParamSpec *pspec,
102 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
106 param_uchar_validate (GParamSpec *pspec,
109 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
110 guint oval = value->data[0].v_uint;
112 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
114 return value->data[0].v_uint != oval;
118 param_boolean_set_default (GParamSpec *pspec,
121 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
125 param_boolean_validate (GParamSpec *pspec,
128 gint oval = value->data[0].v_int;
130 value->data[0].v_int = value->data[0].v_int != FALSE;
132 return value->data[0].v_int != oval;
136 param_int_init (GParamSpec *pspec)
138 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
140 ispec->minimum = 0x7fffffff;
141 ispec->maximum = 0x80000000;
142 ispec->default_value = 0;
146 param_int_set_default (GParamSpec *pspec,
149 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
153 param_int_validate (GParamSpec *pspec,
156 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
157 gint oval = value->data[0].v_int;
159 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
161 return value->data[0].v_int != oval;
165 param_int_values_cmp (GParamSpec *pspec,
166 const GValue *value1,
167 const GValue *value2)
169 if (value1->data[0].v_int < value2->data[0].v_int)
172 return value1->data[0].v_int > value2->data[0].v_int;
176 param_uint_init (GParamSpec *pspec)
178 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
181 uspec->maximum = 0xffffffff;
182 uspec->default_value = 0;
186 param_uint_set_default (GParamSpec *pspec,
189 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
193 param_uint_validate (GParamSpec *pspec,
196 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
197 guint oval = value->data[0].v_uint;
199 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
201 return value->data[0].v_uint != oval;
205 param_uint_values_cmp (GParamSpec *pspec,
206 const GValue *value1,
207 const GValue *value2)
209 if (value1->data[0].v_uint < value2->data[0].v_uint)
212 return value1->data[0].v_uint > value2->data[0].v_uint;
216 param_long_init (GParamSpec *pspec)
218 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
221 lspec->minimum = 0x7fffffff;
222 lspec->maximum = 0x80000000;
223 #else /* SIZEOF_LONG != 4 (8) */
224 lspec->minimum = 0x7fffffffffffffff;
225 lspec->maximum = 0x8000000000000000;
227 lspec->default_value = 0;
231 param_long_set_default (GParamSpec *pspec,
234 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
238 param_long_validate (GParamSpec *pspec,
241 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
242 glong oval = value->data[0].v_long;
244 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
246 return value->data[0].v_long != oval;
250 param_long_values_cmp (GParamSpec *pspec,
251 const GValue *value1,
252 const GValue *value2)
254 if (value1->data[0].v_long < value2->data[0].v_long)
257 return value1->data[0].v_long > value2->data[0].v_long;
261 param_ulong_init (GParamSpec *pspec)
263 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
267 uspec->maximum = 0xffffffff;
268 #else /* SIZEOF_LONG != 4 (8) */
269 uspec->maximum = 0xffffffffffffffff;
271 uspec->default_value = 0;
275 param_ulong_set_default (GParamSpec *pspec,
278 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
282 param_ulong_validate (GParamSpec *pspec,
285 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
286 gulong oval = value->data[0].v_ulong;
288 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
290 return value->data[0].v_ulong != oval;
294 param_ulong_values_cmp (GParamSpec *pspec,
295 const GValue *value1,
296 const GValue *value2)
298 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
301 return value1->data[0].v_ulong > value2->data[0].v_ulong;
305 param_int64_init (GParamSpec *pspec)
307 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
309 lspec->minimum = G_MININT64;
310 lspec->maximum = G_MAXINT64;
311 lspec->default_value = 0;
315 param_int64_set_default (GParamSpec *pspec,
318 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
322 param_int64_validate (GParamSpec *pspec,
325 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
326 gint64 oval = value->data[0].v_int64;
328 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
330 return value->data[0].v_int64 != oval;
334 param_int64_values_cmp (GParamSpec *pspec,
335 const GValue *value1,
336 const GValue *value2)
338 if (value1->data[0].v_int64 < value2->data[0].v_int64)
341 return value1->data[0].v_int64 > value2->data[0].v_int64;
345 param_uint64_init (GParamSpec *pspec)
347 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
350 uspec->maximum = G_MAXUINT64;
351 uspec->default_value = 0;
355 param_uint64_set_default (GParamSpec *pspec,
358 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
362 param_uint64_validate (GParamSpec *pspec,
365 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
366 guint64 oval = value->data[0].v_uint64;
368 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
370 return value->data[0].v_uint64 != oval;
374 param_uint64_values_cmp (GParamSpec *pspec,
375 const GValue *value1,
376 const GValue *value2)
378 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
381 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
385 param_unichar_init (GParamSpec *pspec)
387 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
389 uspec->default_value = 0;
393 param_unichar_set_default (GParamSpec *pspec,
396 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
400 param_unichar_validate (GParamSpec *pspec,
403 gunichar oval = value->data[0].v_uint;
404 gboolean changed = FALSE;
406 if (!g_unichar_validate (oval))
408 value->data[0].v_uint = 0;
416 param_unichar_values_cmp (GParamSpec *pspec,
417 const GValue *value1,
418 const GValue *value2)
420 if (value1->data[0].v_uint < value2->data[0].v_uint)
423 return value1->data[0].v_uint > value2->data[0].v_uint;
427 param_enum_init (GParamSpec *pspec)
429 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
431 espec->enum_class = NULL;
432 espec->default_value = 0;
436 param_enum_finalize (GParamSpec *pspec)
438 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
439 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
441 if (espec->enum_class)
443 g_type_class_unref (espec->enum_class);
444 espec->enum_class = NULL;
447 parent_class->finalize (pspec);
451 param_enum_set_default (GParamSpec *pspec,
454 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
458 param_enum_validate (GParamSpec *pspec,
461 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
462 glong oval = value->data[0].v_long;
464 if (!espec->enum_class ||
465 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
466 value->data[0].v_long = espec->default_value;
468 return value->data[0].v_long != oval;
472 param_flags_init (GParamSpec *pspec)
474 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
476 fspec->flags_class = NULL;
477 fspec->default_value = 0;
481 param_flags_finalize (GParamSpec *pspec)
483 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
484 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
486 if (fspec->flags_class)
488 g_type_class_unref (fspec->flags_class);
489 fspec->flags_class = NULL;
492 parent_class->finalize (pspec);
496 param_flags_set_default (GParamSpec *pspec,
499 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
503 param_flags_validate (GParamSpec *pspec,
506 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
507 gulong oval = value->data[0].v_ulong;
509 if (fspec->flags_class)
510 value->data[0].v_ulong &= fspec->flags_class->mask;
512 value->data[0].v_ulong = fspec->default_value;
514 return value->data[0].v_ulong != oval;
518 param_float_init (GParamSpec *pspec)
520 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
522 fspec->minimum = -G_MAXFLOAT;
523 fspec->maximum = G_MAXFLOAT;
524 fspec->default_value = 0;
525 fspec->epsilon = G_FLOAT_EPSILON;
529 param_float_set_default (GParamSpec *pspec,
532 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
536 param_float_validate (GParamSpec *pspec,
539 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
540 gfloat oval = value->data[0].v_float;
542 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
544 return value->data[0].v_float != oval;
548 param_float_values_cmp (GParamSpec *pspec,
549 const GValue *value1,
550 const GValue *value2)
552 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
554 if (value1->data[0].v_float < value2->data[0].v_float)
555 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
557 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
561 param_double_init (GParamSpec *pspec)
563 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
565 dspec->minimum = -G_MAXDOUBLE;
566 dspec->maximum = G_MAXDOUBLE;
567 dspec->default_value = 0;
568 dspec->epsilon = G_DOUBLE_EPSILON;
572 param_double_set_default (GParamSpec *pspec,
575 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
579 param_double_validate (GParamSpec *pspec,
582 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
583 gdouble oval = value->data[0].v_double;
585 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
587 return value->data[0].v_double != oval;
591 param_double_values_cmp (GParamSpec *pspec,
592 const GValue *value1,
593 const GValue *value2)
595 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
597 if (value1->data[0].v_double < value2->data[0].v_double)
598 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
600 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
604 param_string_init (GParamSpec *pspec)
606 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
608 sspec->default_value = NULL;
609 sspec->cset_first = NULL;
610 sspec->cset_nth = NULL;
611 sspec->substitutor = '_';
612 sspec->null_fold_if_empty = FALSE;
613 sspec->ensure_non_null = FALSE;
617 param_string_finalize (GParamSpec *pspec)
619 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
620 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
622 g_free (sspec->default_value);
623 g_free (sspec->cset_first);
624 g_free (sspec->cset_nth);
625 sspec->default_value = NULL;
626 sspec->cset_first = NULL;
627 sspec->cset_nth = NULL;
629 parent_class->finalize (pspec);
633 param_string_set_default (GParamSpec *pspec,
636 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
640 param_string_validate (GParamSpec *pspec,
643 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
644 gchar *string = value->data[0].v_pointer;
647 if (string && string[0])
651 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
653 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
655 value->data[0].v_pointer = g_strdup (string);
656 string = value->data[0].v_pointer;
657 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
659 string[0] = sspec->substitutor;
663 for (s = string + 1; *s; s++)
664 if (!strchr (sspec->cset_nth, *s))
666 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
668 value->data[0].v_pointer = g_strdup (string);
669 s = (gchar*) value->data[0].v_pointer + (s - string);
670 string = value->data[0].v_pointer;
671 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
673 *s = sspec->substitutor;
677 if (sspec->null_fold_if_empty && string && string[0] == 0)
679 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
680 g_free (value->data[0].v_pointer);
682 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
683 value->data[0].v_pointer = NULL;
685 string = value->data[0].v_pointer;
687 if (sspec->ensure_non_null && !string)
689 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
690 value->data[0].v_pointer = g_strdup ("");
692 string = value->data[0].v_pointer;
699 param_string_values_cmp (GParamSpec *pspec,
700 const GValue *value1,
701 const GValue *value2)
703 if (!value1->data[0].v_pointer)
704 return value2->data[0].v_pointer != NULL ? -1 : 0;
705 else if (!value2->data[0].v_pointer)
706 return value1->data[0].v_pointer != NULL;
708 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
712 param_param_init (GParamSpec *pspec)
714 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
718 param_param_set_default (GParamSpec *pspec,
721 value->data[0].v_pointer = NULL;
725 param_param_validate (GParamSpec *pspec,
728 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
729 GParamSpec *param = value->data[0].v_pointer;
732 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
734 g_param_spec_unref (param);
735 value->data[0].v_pointer = NULL;
743 param_boxed_init (GParamSpec *pspec)
745 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
749 param_boxed_set_default (GParamSpec *pspec,
752 value->data[0].v_pointer = NULL;
756 param_boxed_validate (GParamSpec *pspec,
759 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
762 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
768 param_boxed_values_cmp (GParamSpec *pspec,
769 const GValue *value1,
770 const GValue *value2)
772 guint8 *p1 = value1->data[0].v_pointer;
773 guint8 *p2 = value2->data[0].v_pointer;
775 /* not much to compare here, try to at least provide stable lesser/greater result */
777 return p1 < p2 ? -1 : p1 > p2;
781 param_pointer_init (GParamSpec *pspec)
783 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
787 param_pointer_set_default (GParamSpec *pspec,
790 value->data[0].v_pointer = NULL;
794 param_pointer_validate (GParamSpec *pspec,
797 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
804 param_pointer_values_cmp (GParamSpec *pspec,
805 const GValue *value1,
806 const GValue *value2)
808 guint8 *p1 = value1->data[0].v_pointer;
809 guint8 *p2 = value2->data[0].v_pointer;
811 /* not much to compare here, try to at least provide stable lesser/greater result */
813 return p1 < p2 ? -1 : p1 > p2;
817 param_value_array_init (GParamSpec *pspec)
819 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
821 aspec->element_spec = NULL;
822 aspec->fixed_n_elements = 0; /* disable */
826 value_array_ensure_size (GValueArray *value_array,
827 guint fixed_n_elements)
831 if (fixed_n_elements)
833 while (value_array->n_values < fixed_n_elements)
835 g_value_array_append (value_array, NULL);
838 while (value_array->n_values > fixed_n_elements)
840 g_value_array_remove (value_array, value_array->n_values - 1);
848 param_value_array_finalize (GParamSpec *pspec)
850 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
851 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
853 if (aspec->element_spec)
855 g_param_spec_unref (aspec->element_spec);
856 aspec->element_spec = NULL;
859 parent_class->finalize (pspec);
863 param_value_array_set_default (GParamSpec *pspec,
866 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
868 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
869 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
871 if (value->data[0].v_pointer)
873 /* g_value_reset (value); already done */
874 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
879 param_value_array_validate (GParamSpec *pspec,
882 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
883 GValueArray *value_array = value->data[0].v_pointer;
886 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
887 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
889 if (value->data[0].v_pointer)
891 /* ensure array size validity */
892 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
894 /* ensure array values validity against a present element spec */
895 if (aspec->element_spec)
897 GParamSpec *element_spec = aspec->element_spec;
900 for (i = 0; i < value_array->n_values; i++)
902 GValue *element = value_array->values + i;
904 /* need to fixup value type, or ensure that the array value is initialized at all */
905 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
907 if (G_VALUE_TYPE (element) != 0)
908 g_value_unset (element);
909 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
910 g_param_value_set_default (element_spec, element);
913 /* validate array value against element_spec */
914 changed += g_param_value_validate (element_spec, element);
923 param_value_array_values_cmp (GParamSpec *pspec,
924 const GValue *value1,
925 const GValue *value2)
927 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
928 GValueArray *value_array1 = value1->data[0].v_pointer;
929 GValueArray *value_array2 = value2->data[0].v_pointer;
931 if (!value_array1 || !value_array2)
932 return value_array2 ? -1 : value_array1 != value_array2;
934 if (value_array1->n_values != value_array2->n_values)
935 return value_array1->n_values < value_array2->n_values ? -1 : 1;
936 else if (!aspec->element_spec)
938 /* we need an element specification for comparisons, so there's not much
939 * to compare here, try to at least provide stable lesser/greater result
941 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
943 else /* value_array1->n_values == value_array2->n_values */
947 for (i = 0; i < value_array1->n_values; i++)
949 GValue *element1 = value_array1->values + i;
950 GValue *element2 = value_array2->values + i;
953 /* need corresponding element types, provide stable result otherwise */
954 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
955 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
956 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
965 param_object_init (GParamSpec *pspec)
967 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
971 param_object_set_default (GParamSpec *pspec,
974 value->data[0].v_pointer = NULL;
978 param_object_validate (GParamSpec *pspec,
981 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
982 GObject *object = value->data[0].v_pointer;
985 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
987 g_object_unref (object);
988 value->data[0].v_pointer = NULL;
996 param_object_values_cmp (GParamSpec *pspec,
997 const GValue *value1,
998 const GValue *value2)
1000 guint8 *p1 = value1->data[0].v_pointer;
1001 guint8 *p2 = value2->data[0].v_pointer;
1003 /* not much to compare here, try to at least provide stable lesser/greater result */
1005 return p1 < p2 ? -1 : p1 > p2;
1009 param_override_init (GParamSpec *pspec)
1011 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1015 param_override_finalize (GParamSpec *pspec)
1017 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1018 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1020 if (ospec->overridden)
1022 g_param_spec_unref (ospec->overridden);
1023 ospec->overridden = NULL;
1026 parent_class->finalize (pspec);
1030 param_override_set_default (GParamSpec *pspec,
1033 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1035 g_param_value_set_default (ospec->overridden, value);
1039 param_override_validate (GParamSpec *pspec,
1042 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1044 return g_param_value_validate (ospec->overridden, value);
1048 param_override_values_cmp (GParamSpec *pspec,
1049 const GValue *value1,
1050 const GValue *value2)
1052 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1054 return g_param_values_cmp (ospec->overridden, value1, value2);
1058 param_gtype_init (GParamSpec *pspec)
1063 param_gtype_set_default (GParamSpec *pspec,
1066 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1068 value->data[0].v_long = tspec->is_a_type;
1072 param_gtype_validate (GParamSpec *pspec,
1075 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1076 GType gtype = value->data[0].v_long;
1079 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1081 value->data[0].v_long = tspec->is_a_type;
1089 param_gtype_values_cmp (GParamSpec *pspec,
1090 const GValue *value1,
1091 const GValue *value2)
1093 GType p1 = value1->data[0].v_long;
1094 GType p2 = value2->data[0].v_long;
1096 /* not much to compare here, try to at least provide stable lesser/greater result */
1098 return p1 < p2 ? -1 : p1 > p2;
1102 param_variant_init (GParamSpec *pspec)
1104 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1107 vspec->default_value = NULL;
1111 param_variant_finalize (GParamSpec *pspec)
1113 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1114 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1116 if (vspec->default_value)
1117 g_variant_unref (vspec->default_value);
1118 g_variant_type_free (vspec->type);
1120 parent_class->finalize (pspec);
1124 param_variant_set_default (GParamSpec *pspec,
1127 value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1128 value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1132 param_variant_validate (GParamSpec *pspec,
1135 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1136 GVariant *variant = value->data[0].v_pointer;
1138 if ((variant == NULL && vspec->default_value != NULL) ||
1139 (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1141 g_param_value_set_default (pspec, value);
1149 param_variant_values_cmp (GParamSpec *pspec,
1150 const GValue *value1,
1151 const GValue *value2)
1153 GVariant *v1 = value1->data[0].v_pointer;
1154 GVariant *v2 = value2->data[0].v_pointer;
1156 return v1 < v2 ? -1 : v2 > v1;
1159 /* --- type initialization --- */
1160 GType *g_param_spec_types = NULL;
1163 g_param_spec_types_init (void)
1165 const guint n_types = 23;
1166 GType type, *spec_types, *spec_types_bound;
1168 g_param_spec_types = g_new0 (GType, n_types);
1169 spec_types = g_param_spec_types;
1170 spec_types_bound = g_param_spec_types + n_types;
1172 /* G_TYPE_PARAM_CHAR
1175 static const GParamSpecTypeInfo pspec_info = {
1176 sizeof (GParamSpecChar), /* instance_size */
1177 16, /* n_preallocs */
1178 param_char_init, /* instance_init */
1179 G_TYPE_CHAR, /* value_type */
1180 NULL, /* finalize */
1181 param_char_set_default, /* value_set_default */
1182 param_char_validate, /* value_validate */
1183 param_int_values_cmp, /* values_cmp */
1185 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1186 *spec_types++ = type;
1187 g_assert (type == G_TYPE_PARAM_CHAR);
1190 /* G_TYPE_PARAM_UCHAR
1193 static const GParamSpecTypeInfo pspec_info = {
1194 sizeof (GParamSpecUChar), /* instance_size */
1195 16, /* n_preallocs */
1196 param_uchar_init, /* instance_init */
1197 G_TYPE_UCHAR, /* value_type */
1198 NULL, /* finalize */
1199 param_uchar_set_default, /* value_set_default */
1200 param_uchar_validate, /* value_validate */
1201 param_uint_values_cmp, /* values_cmp */
1203 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1204 *spec_types++ = type;
1205 g_assert (type == G_TYPE_PARAM_UCHAR);
1208 /* G_TYPE_PARAM_BOOLEAN
1211 static const GParamSpecTypeInfo pspec_info = {
1212 sizeof (GParamSpecBoolean), /* instance_size */
1213 16, /* n_preallocs */
1214 NULL, /* instance_init */
1215 G_TYPE_BOOLEAN, /* value_type */
1216 NULL, /* finalize */
1217 param_boolean_set_default, /* value_set_default */
1218 param_boolean_validate, /* value_validate */
1219 param_int_values_cmp, /* values_cmp */
1221 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1222 *spec_types++ = type;
1223 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1229 static const GParamSpecTypeInfo pspec_info = {
1230 sizeof (GParamSpecInt), /* instance_size */
1231 16, /* n_preallocs */
1232 param_int_init, /* instance_init */
1233 G_TYPE_INT, /* value_type */
1234 NULL, /* finalize */
1235 param_int_set_default, /* value_set_default */
1236 param_int_validate, /* value_validate */
1237 param_int_values_cmp, /* values_cmp */
1239 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1240 *spec_types++ = type;
1241 g_assert (type == G_TYPE_PARAM_INT);
1244 /* G_TYPE_PARAM_UINT
1247 static const GParamSpecTypeInfo pspec_info = {
1248 sizeof (GParamSpecUInt), /* instance_size */
1249 16, /* n_preallocs */
1250 param_uint_init, /* instance_init */
1251 G_TYPE_UINT, /* value_type */
1252 NULL, /* finalize */
1253 param_uint_set_default, /* value_set_default */
1254 param_uint_validate, /* value_validate */
1255 param_uint_values_cmp, /* values_cmp */
1257 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1258 *spec_types++ = type;
1259 g_assert (type == G_TYPE_PARAM_UINT);
1262 /* G_TYPE_PARAM_LONG
1265 static const GParamSpecTypeInfo pspec_info = {
1266 sizeof (GParamSpecLong), /* instance_size */
1267 16, /* n_preallocs */
1268 param_long_init, /* instance_init */
1269 G_TYPE_LONG, /* value_type */
1270 NULL, /* finalize */
1271 param_long_set_default, /* value_set_default */
1272 param_long_validate, /* value_validate */
1273 param_long_values_cmp, /* values_cmp */
1275 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1276 *spec_types++ = type;
1277 g_assert (type == G_TYPE_PARAM_LONG);
1280 /* G_TYPE_PARAM_ULONG
1283 static const GParamSpecTypeInfo pspec_info = {
1284 sizeof (GParamSpecULong), /* instance_size */
1285 16, /* n_preallocs */
1286 param_ulong_init, /* instance_init */
1287 G_TYPE_ULONG, /* value_type */
1288 NULL, /* finalize */
1289 param_ulong_set_default, /* value_set_default */
1290 param_ulong_validate, /* value_validate */
1291 param_ulong_values_cmp, /* values_cmp */
1293 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1294 *spec_types++ = type;
1295 g_assert (type == G_TYPE_PARAM_ULONG);
1298 /* G_TYPE_PARAM_INT64
1301 static const GParamSpecTypeInfo pspec_info = {
1302 sizeof (GParamSpecInt64), /* instance_size */
1303 16, /* n_preallocs */
1304 param_int64_init, /* instance_init */
1305 G_TYPE_INT64, /* value_type */
1306 NULL, /* finalize */
1307 param_int64_set_default, /* value_set_default */
1308 param_int64_validate, /* value_validate */
1309 param_int64_values_cmp, /* values_cmp */
1311 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1312 *spec_types++ = type;
1313 g_assert (type == G_TYPE_PARAM_INT64);
1316 /* G_TYPE_PARAM_UINT64
1319 static const GParamSpecTypeInfo pspec_info = {
1320 sizeof (GParamSpecUInt64), /* instance_size */
1321 16, /* n_preallocs */
1322 param_uint64_init, /* instance_init */
1323 G_TYPE_UINT64, /* value_type */
1324 NULL, /* finalize */
1325 param_uint64_set_default, /* value_set_default */
1326 param_uint64_validate, /* value_validate */
1327 param_uint64_values_cmp, /* values_cmp */
1329 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1330 *spec_types++ = type;
1331 g_assert (type == G_TYPE_PARAM_UINT64);
1334 /* G_TYPE_PARAM_UNICHAR
1337 static const GParamSpecTypeInfo pspec_info = {
1338 sizeof (GParamSpecUnichar), /* instance_size */
1339 16, /* n_preallocs */
1340 param_unichar_init, /* instance_init */
1341 G_TYPE_UINT, /* value_type */
1342 NULL, /* finalize */
1343 param_unichar_set_default, /* value_set_default */
1344 param_unichar_validate, /* value_validate */
1345 param_unichar_values_cmp, /* values_cmp */
1347 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1348 *spec_types++ = type;
1349 g_assert (type == G_TYPE_PARAM_UNICHAR);
1352 /* G_TYPE_PARAM_ENUM
1355 static const GParamSpecTypeInfo pspec_info = {
1356 sizeof (GParamSpecEnum), /* instance_size */
1357 16, /* n_preallocs */
1358 param_enum_init, /* instance_init */
1359 G_TYPE_ENUM, /* value_type */
1360 param_enum_finalize, /* finalize */
1361 param_enum_set_default, /* value_set_default */
1362 param_enum_validate, /* value_validate */
1363 param_long_values_cmp, /* values_cmp */
1365 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1366 *spec_types++ = type;
1367 g_assert (type == G_TYPE_PARAM_ENUM);
1370 /* G_TYPE_PARAM_FLAGS
1373 static const GParamSpecTypeInfo pspec_info = {
1374 sizeof (GParamSpecFlags), /* instance_size */
1375 16, /* n_preallocs */
1376 param_flags_init, /* instance_init */
1377 G_TYPE_FLAGS, /* value_type */
1378 param_flags_finalize, /* finalize */
1379 param_flags_set_default, /* value_set_default */
1380 param_flags_validate, /* value_validate */
1381 param_ulong_values_cmp, /* values_cmp */
1383 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1384 *spec_types++ = type;
1385 g_assert (type == G_TYPE_PARAM_FLAGS);
1388 /* G_TYPE_PARAM_FLOAT
1391 static const GParamSpecTypeInfo pspec_info = {
1392 sizeof (GParamSpecFloat), /* instance_size */
1393 16, /* n_preallocs */
1394 param_float_init, /* instance_init */
1395 G_TYPE_FLOAT, /* value_type */
1396 NULL, /* finalize */
1397 param_float_set_default, /* value_set_default */
1398 param_float_validate, /* value_validate */
1399 param_float_values_cmp, /* values_cmp */
1401 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1402 *spec_types++ = type;
1403 g_assert (type == G_TYPE_PARAM_FLOAT);
1406 /* G_TYPE_PARAM_DOUBLE
1409 static const GParamSpecTypeInfo pspec_info = {
1410 sizeof (GParamSpecDouble), /* instance_size */
1411 16, /* n_preallocs */
1412 param_double_init, /* instance_init */
1413 G_TYPE_DOUBLE, /* value_type */
1414 NULL, /* finalize */
1415 param_double_set_default, /* value_set_default */
1416 param_double_validate, /* value_validate */
1417 param_double_values_cmp, /* values_cmp */
1419 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1420 *spec_types++ = type;
1421 g_assert (type == G_TYPE_PARAM_DOUBLE);
1424 /* G_TYPE_PARAM_STRING
1427 static const GParamSpecTypeInfo pspec_info = {
1428 sizeof (GParamSpecString), /* instance_size */
1429 16, /* n_preallocs */
1430 param_string_init, /* instance_init */
1431 G_TYPE_STRING, /* value_type */
1432 param_string_finalize, /* finalize */
1433 param_string_set_default, /* value_set_default */
1434 param_string_validate, /* value_validate */
1435 param_string_values_cmp, /* values_cmp */
1437 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1438 *spec_types++ = type;
1439 g_assert (type == G_TYPE_PARAM_STRING);
1442 /* G_TYPE_PARAM_PARAM
1445 static const GParamSpecTypeInfo pspec_info = {
1446 sizeof (GParamSpecParam), /* instance_size */
1447 16, /* n_preallocs */
1448 param_param_init, /* instance_init */
1449 G_TYPE_PARAM, /* value_type */
1450 NULL, /* finalize */
1451 param_param_set_default, /* value_set_default */
1452 param_param_validate, /* value_validate */
1453 param_pointer_values_cmp, /* values_cmp */
1455 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1456 *spec_types++ = type;
1457 g_assert (type == G_TYPE_PARAM_PARAM);
1460 /* G_TYPE_PARAM_BOXED
1463 static const GParamSpecTypeInfo pspec_info = {
1464 sizeof (GParamSpecBoxed), /* instance_size */
1465 4, /* n_preallocs */
1466 param_boxed_init, /* instance_init */
1467 G_TYPE_BOXED, /* value_type */
1468 NULL, /* finalize */
1469 param_boxed_set_default, /* value_set_default */
1470 param_boxed_validate, /* value_validate */
1471 param_boxed_values_cmp, /* values_cmp */
1473 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1474 *spec_types++ = type;
1475 g_assert (type == G_TYPE_PARAM_BOXED);
1478 /* G_TYPE_PARAM_POINTER
1481 static const GParamSpecTypeInfo pspec_info = {
1482 sizeof (GParamSpecPointer), /* instance_size */
1483 0, /* n_preallocs */
1484 param_pointer_init, /* instance_init */
1485 G_TYPE_POINTER, /* value_type */
1486 NULL, /* finalize */
1487 param_pointer_set_default, /* value_set_default */
1488 param_pointer_validate, /* value_validate */
1489 param_pointer_values_cmp, /* values_cmp */
1491 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1492 *spec_types++ = type;
1493 g_assert (type == G_TYPE_PARAM_POINTER);
1496 /* G_TYPE_PARAM_VALUE_ARRAY
1499 static /* const */ GParamSpecTypeInfo pspec_info = {
1500 sizeof (GParamSpecValueArray), /* instance_size */
1501 0, /* n_preallocs */
1502 param_value_array_init, /* instance_init */
1503 0xdeadbeef, /* value_type, assigned further down */
1504 param_value_array_finalize, /* finalize */
1505 param_value_array_set_default, /* value_set_default */
1506 param_value_array_validate, /* value_validate */
1507 param_value_array_values_cmp, /* values_cmp */
1509 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1510 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1511 *spec_types++ = type;
1512 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1515 /* G_TYPE_PARAM_OBJECT
1518 static const GParamSpecTypeInfo pspec_info = {
1519 sizeof (GParamSpecObject), /* instance_size */
1520 16, /* n_preallocs */
1521 param_object_init, /* instance_init */
1522 G_TYPE_OBJECT, /* value_type */
1523 NULL, /* finalize */
1524 param_object_set_default, /* value_set_default */
1525 param_object_validate, /* value_validate */
1526 param_object_values_cmp, /* values_cmp */
1528 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1529 *spec_types++ = type;
1530 g_assert (type == G_TYPE_PARAM_OBJECT);
1533 /* G_TYPE_PARAM_OVERRIDE
1536 static const GParamSpecTypeInfo pspec_info = {
1537 sizeof (GParamSpecOverride), /* instance_size */
1538 16, /* n_preallocs */
1539 param_override_init, /* instance_init */
1540 G_TYPE_NONE, /* value_type */
1541 param_override_finalize, /* finalize */
1542 param_override_set_default, /* value_set_default */
1543 param_override_validate, /* value_validate */
1544 param_override_values_cmp, /* values_cmp */
1546 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1547 *spec_types++ = type;
1548 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1551 /* G_TYPE_PARAM_GTYPE
1554 GParamSpecTypeInfo pspec_info = {
1555 sizeof (GParamSpecGType), /* instance_size */
1556 0, /* n_preallocs */
1557 param_gtype_init, /* instance_init */
1558 0xdeadbeef, /* value_type, assigned further down */
1559 NULL, /* finalize */
1560 param_gtype_set_default, /* value_set_default */
1561 param_gtype_validate, /* value_validate */
1562 param_gtype_values_cmp, /* values_cmp */
1564 pspec_info.value_type = G_TYPE_GTYPE;
1565 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1566 *spec_types++ = type;
1567 g_assert (type == G_TYPE_PARAM_GTYPE);
1570 /* G_TYPE_PARAM_VARIANT
1573 const GParamSpecTypeInfo pspec_info = {
1574 sizeof (GParamSpecVariant), /* instance_size */
1575 0, /* n_preallocs */
1576 param_variant_init, /* instance_init */
1577 G_TYPE_VARIANT, /* value_type */
1578 param_variant_finalize, /* finalize */
1579 param_variant_set_default, /* value_set_default */
1580 param_variant_validate, /* value_validate */
1581 param_variant_values_cmp, /* values_cmp */
1583 type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1584 *spec_types++ = type;
1585 g_assert (type == G_TYPE_PARAM_VARIANT);
1588 g_assert (spec_types == spec_types_bound);
1591 /* --- GParamSpec initialization --- */
1594 * g_param_spec_char: (skip)
1595 * @name: canonical name of the property specified
1596 * @nick: nick name for the property specified
1597 * @blurb: description of the property specified
1598 * @minimum: minimum value for the property specified
1599 * @maximum: maximum value for the property specified
1600 * @default_value: default value for the property specified
1601 * @flags: flags for the property specified
1603 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1605 * Returns: a newly created parameter specification
1608 g_param_spec_char (const gchar *name,
1613 gint8 default_value,
1616 GParamSpecChar *cspec;
1618 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1620 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1626 cspec->minimum = minimum;
1627 cspec->maximum = maximum;
1628 cspec->default_value = default_value;
1630 return G_PARAM_SPEC (cspec);
1634 * g_param_spec_uchar: (skip)
1635 * @name: canonical name of the property specified
1636 * @nick: nick name for the property specified
1637 * @blurb: description of the property specified
1638 * @minimum: minimum value for the property specified
1639 * @maximum: maximum value for the property specified
1640 * @default_value: default value for the property specified
1641 * @flags: flags for the property specified
1643 * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1645 * Returns: a newly created parameter specification
1648 g_param_spec_uchar (const gchar *name,
1653 guint8 default_value,
1656 GParamSpecUChar *uspec;
1658 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1660 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1666 uspec->minimum = minimum;
1667 uspec->maximum = maximum;
1668 uspec->default_value = default_value;
1670 return G_PARAM_SPEC (uspec);
1674 * g_param_spec_boolean: (skip)
1675 * @name: canonical name of the property specified
1676 * @nick: nick name for the property specified
1677 * @blurb: description of the property specified
1678 * @default_value: default value for the property specified
1679 * @flags: flags for the property specified
1681 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1684 * See g_param_spec_internal() for details on property names.
1686 * Returns: a newly created parameter specification
1689 g_param_spec_boolean (const gchar *name,
1692 gboolean default_value,
1695 GParamSpecBoolean *bspec;
1697 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1699 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1705 bspec->default_value = default_value;
1707 return G_PARAM_SPEC (bspec);
1711 * g_param_spec_int: (skip)
1712 * @name: canonical name of the property specified
1713 * @nick: nick name for the property specified
1714 * @blurb: description of the property specified
1715 * @minimum: minimum value for the property specified
1716 * @maximum: maximum value for the property specified
1717 * @default_value: default value for the property specified
1718 * @flags: flags for the property specified
1720 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1722 * See g_param_spec_internal() for details on property names.
1724 * Returns: a newly created parameter specification
1727 g_param_spec_int (const gchar *name,
1735 GParamSpecInt *ispec;
1737 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1739 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1745 ispec->minimum = minimum;
1746 ispec->maximum = maximum;
1747 ispec->default_value = default_value;
1749 return G_PARAM_SPEC (ispec);
1753 * g_param_spec_uint: (skip)
1754 * @name: canonical name of the property specified
1755 * @nick: nick name for the property specified
1756 * @blurb: description of the property specified
1757 * @minimum: minimum value for the property specified
1758 * @maximum: maximum value for the property specified
1759 * @default_value: default value for the property specified
1760 * @flags: flags for the property specified
1762 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1764 * See g_param_spec_internal() for details on property names.
1766 * Returns: a newly created parameter specification
1769 g_param_spec_uint (const gchar *name,
1774 guint default_value,
1777 GParamSpecUInt *uspec;
1779 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1781 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1787 uspec->minimum = minimum;
1788 uspec->maximum = maximum;
1789 uspec->default_value = default_value;
1791 return G_PARAM_SPEC (uspec);
1795 * g_param_spec_long: (skip)
1796 * @name: canonical name of the property specified
1797 * @nick: nick name for the property specified
1798 * @blurb: description of the property specified
1799 * @minimum: minimum value for the property specified
1800 * @maximum: maximum value for the property specified
1801 * @default_value: default value for the property specified
1802 * @flags: flags for the property specified
1804 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1806 * See g_param_spec_internal() for details on property names.
1808 * Returns: a newly created parameter specification
1811 g_param_spec_long (const gchar *name,
1816 glong default_value,
1819 GParamSpecLong *lspec;
1821 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1823 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1829 lspec->minimum = minimum;
1830 lspec->maximum = maximum;
1831 lspec->default_value = default_value;
1833 return G_PARAM_SPEC (lspec);
1837 * g_param_spec_ulong: (skip)
1838 * @name: canonical name of the property specified
1839 * @nick: nick name for the property specified
1840 * @blurb: description of the property specified
1841 * @minimum: minimum value for the property specified
1842 * @maximum: maximum value for the property specified
1843 * @default_value: default value for the property specified
1844 * @flags: flags for the property specified
1846 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
1849 * See g_param_spec_internal() for details on property names.
1851 * Returns: a newly created parameter specification
1854 g_param_spec_ulong (const gchar *name,
1859 gulong default_value,
1862 GParamSpecULong *uspec;
1864 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1866 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1872 uspec->minimum = minimum;
1873 uspec->maximum = maximum;
1874 uspec->default_value = default_value;
1876 return G_PARAM_SPEC (uspec);
1880 * g_param_spec_int64: (skip)
1881 * @name: canonical name of the property specified
1882 * @nick: nick name for the property specified
1883 * @blurb: description of the property specified
1884 * @minimum: minimum value for the property specified
1885 * @maximum: maximum value for the property specified
1886 * @default_value: default value for the property specified
1887 * @flags: flags for the property specified
1889 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1891 * See g_param_spec_internal() for details on property names.
1893 * Returns: a newly created parameter specification
1896 g_param_spec_int64 (const gchar *name,
1901 gint64 default_value,
1904 GParamSpecInt64 *lspec;
1906 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1908 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1914 lspec->minimum = minimum;
1915 lspec->maximum = maximum;
1916 lspec->default_value = default_value;
1918 return G_PARAM_SPEC (lspec);
1922 * g_param_spec_uint64: (skip)
1923 * @name: canonical name of the property specified
1924 * @nick: nick name for the property specified
1925 * @blurb: description of the property specified
1926 * @minimum: minimum value for the property specified
1927 * @maximum: maximum value for the property specified
1928 * @default_value: default value for the property specified
1929 * @flags: flags for the property specified
1931 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1934 * See g_param_spec_internal() for details on property names.
1936 * Returns: a newly created parameter specification
1939 g_param_spec_uint64 (const gchar *name,
1944 guint64 default_value,
1947 GParamSpecUInt64 *uspec;
1949 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1951 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1957 uspec->minimum = minimum;
1958 uspec->maximum = maximum;
1959 uspec->default_value = default_value;
1961 return G_PARAM_SPEC (uspec);
1965 * g_param_spec_unichar: (skip)
1966 * @name: canonical name of the property specified
1967 * @nick: nick name for the property specified
1968 * @blurb: description of the property specified
1969 * @default_value: default value for the property specified
1970 * @flags: flags for the property specified
1972 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1973 * property. #GValue structures for this property can be accessed with
1974 * g_value_set_uint() and g_value_get_uint().
1976 * See g_param_spec_internal() for details on property names.
1978 * Returns: a newly created parameter specification
1981 g_param_spec_unichar (const gchar *name,
1984 gunichar default_value,
1987 GParamSpecUnichar *uspec;
1989 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1995 uspec->default_value = default_value;
1997 return G_PARAM_SPEC (uspec);
2001 * g_param_spec_enum: (skip)
2002 * @name: canonical name of the property specified
2003 * @nick: nick name for the property specified
2004 * @blurb: description of the property specified
2005 * @enum_type: a #GType derived from %G_TYPE_ENUM
2006 * @default_value: default value for the property specified
2007 * @flags: flags for the property specified
2009 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2012 * See g_param_spec_internal() for details on property names.
2014 * Returns: a newly created parameter specification
2017 g_param_spec_enum (const gchar *name,
2024 GParamSpecEnum *espec;
2025 GEnumClass *enum_class;
2027 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2029 enum_class = g_type_class_ref (enum_type);
2031 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2033 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2039 espec->enum_class = enum_class;
2040 espec->default_value = default_value;
2041 G_PARAM_SPEC (espec)->value_type = enum_type;
2043 return G_PARAM_SPEC (espec);
2047 * g_param_spec_flags: (skip)
2048 * @name: canonical name of the property specified
2049 * @nick: nick name for the property specified
2050 * @blurb: description of the property specified
2051 * @flags_type: a #GType derived from %G_TYPE_FLAGS
2052 * @default_value: default value for the property specified
2053 * @flags: flags for the property specified
2055 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2058 * See g_param_spec_internal() for details on property names.
2060 * Returns: a newly created parameter specification
2063 g_param_spec_flags (const gchar *name,
2067 guint default_value,
2070 GParamSpecFlags *fspec;
2071 GFlagsClass *flags_class;
2073 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2075 flags_class = g_type_class_ref (flags_type);
2077 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2079 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2085 fspec->flags_class = flags_class;
2086 fspec->default_value = default_value;
2087 G_PARAM_SPEC (fspec)->value_type = flags_type;
2089 return G_PARAM_SPEC (fspec);
2093 * g_param_spec_float: (skip)
2094 * @name: canonical name of the property specified
2095 * @nick: nick name for the property specified
2096 * @blurb: description of the property specified
2097 * @minimum: minimum value for the property specified
2098 * @maximum: maximum value for the property specified
2099 * @default_value: default value for the property specified
2100 * @flags: flags for the property specified
2102 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2104 * See g_param_spec_internal() for details on property names.
2106 * Returns: a newly created parameter specification
2109 g_param_spec_float (const gchar *name,
2114 gfloat default_value,
2117 GParamSpecFloat *fspec;
2119 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2121 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2127 fspec->minimum = minimum;
2128 fspec->maximum = maximum;
2129 fspec->default_value = default_value;
2131 return G_PARAM_SPEC (fspec);
2135 * g_param_spec_double: (skip)
2136 * @name: canonical name of the property specified
2137 * @nick: nick name for the property specified
2138 * @blurb: description of the property specified
2139 * @minimum: minimum value for the property specified
2140 * @maximum: maximum value for the property specified
2141 * @default_value: default value for the property specified
2142 * @flags: flags for the property specified
2144 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2147 * See g_param_spec_internal() for details on property names.
2149 * Returns: a newly created parameter specification
2152 g_param_spec_double (const gchar *name,
2157 gdouble default_value,
2160 GParamSpecDouble *dspec;
2162 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2164 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2170 dspec->minimum = minimum;
2171 dspec->maximum = maximum;
2172 dspec->default_value = default_value;
2174 return G_PARAM_SPEC (dspec);
2178 * g_param_spec_string: (skip)
2179 * @name: canonical name of the property specified
2180 * @nick: nick name for the property specified
2181 * @blurb: description of the property specified
2182 * @default_value: default value for the property specified
2183 * @flags: flags for the property specified
2185 * Creates a new #GParamSpecString instance.
2187 * See g_param_spec_internal() for details on property names.
2189 * Returns: a newly created parameter specification
2192 g_param_spec_string (const gchar *name,
2195 const gchar *default_value,
2198 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2203 g_free (sspec->default_value);
2204 sspec->default_value = g_strdup (default_value);
2206 return G_PARAM_SPEC (sspec);
2210 * g_param_spec_param: (skip)
2211 * @name: canonical name of the property specified
2212 * @nick: nick name for the property specified
2213 * @blurb: description of the property specified
2214 * @param_type: a #GType derived from %G_TYPE_PARAM
2215 * @flags: flags for the property specified
2217 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2220 * See g_param_spec_internal() for details on property names.
2222 * Returns: a newly created parameter specification
2225 g_param_spec_param (const gchar *name,
2231 GParamSpecParam *pspec;
2233 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2235 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2240 G_PARAM_SPEC (pspec)->value_type = param_type;
2242 return G_PARAM_SPEC (pspec);
2246 * g_param_spec_boxed: (skip)
2247 * @name: canonical name of the property specified
2248 * @nick: nick name for the property specified
2249 * @blurb: description of the property specified
2250 * @boxed_type: %G_TYPE_BOXED derived type of this property
2251 * @flags: flags for the property specified
2253 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2256 * See g_param_spec_internal() for details on property names.
2258 * Returns: a newly created parameter specification
2261 g_param_spec_boxed (const gchar *name,
2267 GParamSpecBoxed *bspec;
2269 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2270 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2272 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2277 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2279 return G_PARAM_SPEC (bspec);
2283 * g_param_spec_pointer: (skip)
2284 * @name: canonical name of the property specified
2285 * @nick: nick name for the property specified
2286 * @blurb: description of the property specified
2287 * @flags: flags for the property specified
2289 * Creates a new #GParamSpecPoiner instance specifying a pointer property.
2291 * See g_param_spec_internal() for details on property names.
2293 * Returns: a newly created parameter specification
2296 g_param_spec_pointer (const gchar *name,
2301 GParamSpecPointer *pspec;
2303 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2308 return G_PARAM_SPEC (pspec);
2312 * g_param_spec_gtype: (skip)
2313 * @name: canonical name of the property specified
2314 * @nick: nick name for the property specified
2315 * @blurb: description of the property specified
2316 * @is_a_type: a #GType whose subtypes are allowed as values
2317 * of the property (use %G_TYPE_NONE for any type)
2318 * @flags: flags for the property specified
2320 * Creates a new #GParamSpecGType instance specifying a
2321 * %G_TYPE_GTYPE property.
2323 * See g_param_spec_internal() for details on property names.
2327 * Returns: a newly created parameter specification
2330 g_param_spec_gtype (const gchar *name,
2336 GParamSpecGType *tspec;
2338 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2344 tspec->is_a_type = is_a_type;
2346 return G_PARAM_SPEC (tspec);
2350 * g_param_spec_value_array: (skip)
2351 * @name: canonical name of the property specified
2352 * @nick: nick name for the property specified
2353 * @blurb: description of the property specified
2354 * @element_spec: a #GParamSpec describing the elements contained in
2355 * arrays of this property, may be %NULL
2356 * @flags: flags for the property specified
2358 * Creates a new #GParamSpecValueArray instance specifying a
2359 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2360 * %G_TYPE_BOXED type, as such, #GValue structures for this property
2361 * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2363 * See g_param_spec_internal() for details on property names.
2365 * Returns: a newly created parameter specification
2368 g_param_spec_value_array (const gchar *name,
2371 GParamSpec *element_spec,
2374 GParamSpecValueArray *aspec;
2377 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2379 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2386 aspec->element_spec = g_param_spec_ref (element_spec);
2387 g_param_spec_sink (element_spec);
2390 return G_PARAM_SPEC (aspec);
2394 * g_param_spec_object: (skip)
2395 * @name: canonical name of the property specified
2396 * @nick: nick name for the property specified
2397 * @blurb: description of the property specified
2398 * @object_type: %G_TYPE_OBJECT derived type of this property
2399 * @flags: flags for the property specified
2401 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2404 * See g_param_spec_internal() for details on property names.
2406 * Returns: a newly created parameter specification
2409 g_param_spec_object (const gchar *name,
2415 GParamSpecObject *ospec;
2417 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2419 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2424 G_PARAM_SPEC (ospec)->value_type = object_type;
2426 return G_PARAM_SPEC (ospec);
2430 * g_param_spec_override: (skip)
2431 * @name: the name of the property.
2432 * @overridden: The property that is being overridden
2434 * Creates a new property of type #GParamSpecOverride. This is used
2435 * to direct operations to another paramspec, and will not be directly
2436 * useful unless you are implementing a new base type similar to GObject.
2440 * Returns: the newly created #GParamSpec
2443 g_param_spec_override (const gchar *name,
2444 GParamSpec *overridden)
2448 g_return_val_if_fail (name != NULL, NULL);
2449 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2451 /* Dereference further redirections for property that was passed in
2455 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2457 overridden = indirect;
2462 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2466 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2467 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2473 * g_param_spec_variant: (skip)
2474 * @name: canonical name of the property specified
2475 * @nick: nick name for the property specified
2476 * @blurb: description of the property specified
2477 * @type: a #GVariantType
2478 * @default_value: (allow-none): a #GVariant of type @type to use as the
2479 * default value, or %NULL
2480 * @flags: flags for the property specified
2482 * Creates a new #GParamSpecVariant instance specifying a #GVariant
2485 * If @default_value is floating, it is consumed.
2487 * See g_param_spec_internal() for details on property names.
2489 * Returns: the newly created #GParamSpec
2494 g_param_spec_variant (const gchar *name,
2497 const GVariantType *type,
2498 GVariant *default_value,
2501 GParamSpecVariant *vspec;
2503 g_return_val_if_fail (type != NULL, NULL);
2504 g_return_val_if_fail (default_value == NULL ||
2505 g_variant_is_of_type (default_value, type), NULL);
2507 vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2513 vspec->type = g_variant_type_copy (type);
2515 vspec->default_value = g_variant_ref_sink (default_value);
2517 return G_PARAM_SPEC (vspec);