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 #define GLIB_DISABLE_DEPRECATION_WARNINGS
31 #include "gparamspecs.h"
32 #include "gtype-private.h"
33 #include "gvaluecollector.h"
35 #include "gvaluearray.h"
39 * SECTION:param_value_types
40 * @short_description: Standard Parameter and Value Types
41 * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
42 * @title: Parameters and Values
44 * #GValue provides an abstract container structure which can be
45 * copied, transformed and compared while holding a value of any
46 * (derived) type, which is registered as a #GType with a
47 * #GTypeValueTable in its #GTypeInfo structure. Parameter
48 * specifications for most value types can be created as #GParamSpec
49 * derived instances, to implement e.g. #GObject properties which
50 * operate on #GValue containers.
52 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
53 * characters can be letters, numbers or a '-'.
54 * All other characters are replaced by a '-' during construction.
58 #define G_FLOAT_EPSILON (1e-30)
59 #define G_DOUBLE_EPSILON (1e-90)
62 /* --- param spec functions --- */
64 param_char_init (GParamSpec *pspec)
66 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
68 cspec->minimum = 0x7f;
69 cspec->maximum = 0x80;
70 cspec->default_value = 0;
74 param_char_set_default (GParamSpec *pspec,
77 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
81 param_char_validate (GParamSpec *pspec,
84 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
85 gint oval = value->data[0].v_int;
87 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
89 return value->data[0].v_int != oval;
93 param_uchar_init (GParamSpec *pspec)
95 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
98 uspec->maximum = 0xff;
99 uspec->default_value = 0;
103 param_uchar_set_default (GParamSpec *pspec,
106 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
110 param_uchar_validate (GParamSpec *pspec,
113 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
114 guint oval = value->data[0].v_uint;
116 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
118 return value->data[0].v_uint != oval;
122 param_boolean_set_default (GParamSpec *pspec,
125 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
129 param_boolean_validate (GParamSpec *pspec,
132 gint oval = value->data[0].v_int;
134 value->data[0].v_int = value->data[0].v_int != FALSE;
136 return value->data[0].v_int != oval;
140 param_int_init (GParamSpec *pspec)
142 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
144 ispec->minimum = 0x7fffffff;
145 ispec->maximum = 0x80000000;
146 ispec->default_value = 0;
150 param_int_set_default (GParamSpec *pspec,
153 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
157 param_int_validate (GParamSpec *pspec,
160 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
161 gint oval = value->data[0].v_int;
163 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
165 return value->data[0].v_int != oval;
169 param_int_values_cmp (GParamSpec *pspec,
170 const GValue *value1,
171 const GValue *value2)
173 if (value1->data[0].v_int < value2->data[0].v_int)
176 return value1->data[0].v_int > value2->data[0].v_int;
180 param_uint_init (GParamSpec *pspec)
182 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
185 uspec->maximum = 0xffffffff;
186 uspec->default_value = 0;
190 param_uint_set_default (GParamSpec *pspec,
193 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
197 param_uint_validate (GParamSpec *pspec,
200 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
201 guint oval = value->data[0].v_uint;
203 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
205 return value->data[0].v_uint != oval;
209 param_uint_values_cmp (GParamSpec *pspec,
210 const GValue *value1,
211 const GValue *value2)
213 if (value1->data[0].v_uint < value2->data[0].v_uint)
216 return value1->data[0].v_uint > value2->data[0].v_uint;
220 param_long_init (GParamSpec *pspec)
222 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
225 lspec->minimum = 0x7fffffff;
226 lspec->maximum = 0x80000000;
227 #else /* SIZEOF_LONG != 4 (8) */
228 lspec->minimum = 0x7fffffffffffffff;
229 lspec->maximum = 0x8000000000000000;
231 lspec->default_value = 0;
235 param_long_set_default (GParamSpec *pspec,
238 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
242 param_long_validate (GParamSpec *pspec,
245 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
246 glong oval = value->data[0].v_long;
248 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
250 return value->data[0].v_long != oval;
254 param_long_values_cmp (GParamSpec *pspec,
255 const GValue *value1,
256 const GValue *value2)
258 if (value1->data[0].v_long < value2->data[0].v_long)
261 return value1->data[0].v_long > value2->data[0].v_long;
265 param_ulong_init (GParamSpec *pspec)
267 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
271 uspec->maximum = 0xffffffff;
272 #else /* SIZEOF_LONG != 4 (8) */
273 uspec->maximum = 0xffffffffffffffff;
275 uspec->default_value = 0;
279 param_ulong_set_default (GParamSpec *pspec,
282 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
286 param_ulong_validate (GParamSpec *pspec,
289 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
290 gulong oval = value->data[0].v_ulong;
292 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
294 return value->data[0].v_ulong != oval;
298 param_ulong_values_cmp (GParamSpec *pspec,
299 const GValue *value1,
300 const GValue *value2)
302 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
305 return value1->data[0].v_ulong > value2->data[0].v_ulong;
309 param_int64_init (GParamSpec *pspec)
311 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
313 lspec->minimum = G_MININT64;
314 lspec->maximum = G_MAXINT64;
315 lspec->default_value = 0;
319 param_int64_set_default (GParamSpec *pspec,
322 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
326 param_int64_validate (GParamSpec *pspec,
329 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
330 gint64 oval = value->data[0].v_int64;
332 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
334 return value->data[0].v_int64 != oval;
338 param_int64_values_cmp (GParamSpec *pspec,
339 const GValue *value1,
340 const GValue *value2)
342 if (value1->data[0].v_int64 < value2->data[0].v_int64)
345 return value1->data[0].v_int64 > value2->data[0].v_int64;
349 param_uint64_init (GParamSpec *pspec)
351 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
354 uspec->maximum = G_MAXUINT64;
355 uspec->default_value = 0;
359 param_uint64_set_default (GParamSpec *pspec,
362 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
366 param_uint64_validate (GParamSpec *pspec,
369 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
370 guint64 oval = value->data[0].v_uint64;
372 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
374 return value->data[0].v_uint64 != oval;
378 param_uint64_values_cmp (GParamSpec *pspec,
379 const GValue *value1,
380 const GValue *value2)
382 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
385 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
389 param_unichar_init (GParamSpec *pspec)
391 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
393 uspec->default_value = 0;
397 param_unichar_set_default (GParamSpec *pspec,
400 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
404 param_unichar_validate (GParamSpec *pspec,
407 gunichar oval = value->data[0].v_uint;
408 gboolean changed = FALSE;
410 if (!g_unichar_validate (oval))
412 value->data[0].v_uint = 0;
420 param_unichar_values_cmp (GParamSpec *pspec,
421 const GValue *value1,
422 const GValue *value2)
424 if (value1->data[0].v_uint < value2->data[0].v_uint)
427 return value1->data[0].v_uint > value2->data[0].v_uint;
431 param_enum_init (GParamSpec *pspec)
433 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
435 espec->enum_class = NULL;
436 espec->default_value = 0;
440 param_enum_finalize (GParamSpec *pspec)
442 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
443 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
445 if (espec->enum_class)
447 g_type_class_unref (espec->enum_class);
448 espec->enum_class = NULL;
451 parent_class->finalize (pspec);
455 param_enum_set_default (GParamSpec *pspec,
458 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
462 param_enum_validate (GParamSpec *pspec,
465 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
466 glong oval = value->data[0].v_long;
468 if (!espec->enum_class ||
469 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
470 value->data[0].v_long = espec->default_value;
472 return value->data[0].v_long != oval;
476 param_flags_init (GParamSpec *pspec)
478 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
480 fspec->flags_class = NULL;
481 fspec->default_value = 0;
485 param_flags_finalize (GParamSpec *pspec)
487 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
488 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
490 if (fspec->flags_class)
492 g_type_class_unref (fspec->flags_class);
493 fspec->flags_class = NULL;
496 parent_class->finalize (pspec);
500 param_flags_set_default (GParamSpec *pspec,
503 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
507 param_flags_validate (GParamSpec *pspec,
510 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
511 gulong oval = value->data[0].v_ulong;
513 if (fspec->flags_class)
514 value->data[0].v_ulong &= fspec->flags_class->mask;
516 value->data[0].v_ulong = fspec->default_value;
518 return value->data[0].v_ulong != oval;
522 param_float_init (GParamSpec *pspec)
524 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
526 fspec->minimum = -G_MAXFLOAT;
527 fspec->maximum = G_MAXFLOAT;
528 fspec->default_value = 0;
529 fspec->epsilon = G_FLOAT_EPSILON;
533 param_float_set_default (GParamSpec *pspec,
536 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
540 param_float_validate (GParamSpec *pspec,
543 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
544 gfloat oval = value->data[0].v_float;
546 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
548 return value->data[0].v_float != oval;
552 param_float_values_cmp (GParamSpec *pspec,
553 const GValue *value1,
554 const GValue *value2)
556 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
558 if (value1->data[0].v_float < value2->data[0].v_float)
559 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
561 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
565 param_double_init (GParamSpec *pspec)
567 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
569 dspec->minimum = -G_MAXDOUBLE;
570 dspec->maximum = G_MAXDOUBLE;
571 dspec->default_value = 0;
572 dspec->epsilon = G_DOUBLE_EPSILON;
576 param_double_set_default (GParamSpec *pspec,
579 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
583 param_double_validate (GParamSpec *pspec,
586 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
587 gdouble oval = value->data[0].v_double;
589 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
591 return value->data[0].v_double != oval;
595 param_double_values_cmp (GParamSpec *pspec,
596 const GValue *value1,
597 const GValue *value2)
599 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
601 if (value1->data[0].v_double < value2->data[0].v_double)
602 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
604 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
608 param_string_init (GParamSpec *pspec)
610 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
612 sspec->default_value = NULL;
613 sspec->cset_first = NULL;
614 sspec->cset_nth = NULL;
615 sspec->substitutor = '_';
616 sspec->null_fold_if_empty = FALSE;
617 sspec->ensure_non_null = FALSE;
621 param_string_finalize (GParamSpec *pspec)
623 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
624 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
626 g_free (sspec->default_value);
627 g_free (sspec->cset_first);
628 g_free (sspec->cset_nth);
629 sspec->default_value = NULL;
630 sspec->cset_first = NULL;
631 sspec->cset_nth = NULL;
633 parent_class->finalize (pspec);
637 param_string_set_default (GParamSpec *pspec,
640 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
644 param_string_validate (GParamSpec *pspec,
647 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
648 gchar *string = value->data[0].v_pointer;
651 if (string && string[0])
655 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
657 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
659 value->data[0].v_pointer = g_strdup (string);
660 string = value->data[0].v_pointer;
661 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
663 string[0] = sspec->substitutor;
667 for (s = string + 1; *s; s++)
668 if (!strchr (sspec->cset_nth, *s))
670 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
672 value->data[0].v_pointer = g_strdup (string);
673 s = (gchar*) value->data[0].v_pointer + (s - string);
674 string = value->data[0].v_pointer;
675 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
677 *s = sspec->substitutor;
681 if (sspec->null_fold_if_empty && string && string[0] == 0)
683 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
684 g_free (value->data[0].v_pointer);
686 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
687 value->data[0].v_pointer = NULL;
689 string = value->data[0].v_pointer;
691 if (sspec->ensure_non_null && !string)
693 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
694 value->data[0].v_pointer = g_strdup ("");
696 string = value->data[0].v_pointer;
703 param_string_values_cmp (GParamSpec *pspec,
704 const GValue *value1,
705 const GValue *value2)
707 if (!value1->data[0].v_pointer)
708 return value2->data[0].v_pointer != NULL ? -1 : 0;
709 else if (!value2->data[0].v_pointer)
710 return value1->data[0].v_pointer != NULL;
712 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
716 param_param_init (GParamSpec *pspec)
718 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
722 param_param_set_default (GParamSpec *pspec,
725 value->data[0].v_pointer = NULL;
729 param_param_validate (GParamSpec *pspec,
732 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
733 GParamSpec *param = value->data[0].v_pointer;
736 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
738 g_param_spec_unref (param);
739 value->data[0].v_pointer = NULL;
747 param_boxed_init (GParamSpec *pspec)
749 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
753 param_boxed_set_default (GParamSpec *pspec,
756 value->data[0].v_pointer = NULL;
760 param_boxed_validate (GParamSpec *pspec,
763 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
766 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
772 param_boxed_values_cmp (GParamSpec *pspec,
773 const GValue *value1,
774 const GValue *value2)
776 guint8 *p1 = value1->data[0].v_pointer;
777 guint8 *p2 = value2->data[0].v_pointer;
779 /* not much to compare here, try to at least provide stable lesser/greater result */
781 return p1 < p2 ? -1 : p1 > p2;
785 param_pointer_init (GParamSpec *pspec)
787 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
791 param_pointer_set_default (GParamSpec *pspec,
794 value->data[0].v_pointer = NULL;
798 param_pointer_validate (GParamSpec *pspec,
801 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
808 param_pointer_values_cmp (GParamSpec *pspec,
809 const GValue *value1,
810 const GValue *value2)
812 guint8 *p1 = value1->data[0].v_pointer;
813 guint8 *p2 = value2->data[0].v_pointer;
815 /* not much to compare here, try to at least provide stable lesser/greater result */
817 return p1 < p2 ? -1 : p1 > p2;
821 param_value_array_init (GParamSpec *pspec)
823 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
825 aspec->element_spec = NULL;
826 aspec->fixed_n_elements = 0; /* disable */
830 value_array_ensure_size (GValueArray *value_array,
831 guint fixed_n_elements)
835 if (fixed_n_elements)
837 while (value_array->n_values < fixed_n_elements)
839 g_value_array_append (value_array, NULL);
842 while (value_array->n_values > fixed_n_elements)
844 g_value_array_remove (value_array, value_array->n_values - 1);
852 param_value_array_finalize (GParamSpec *pspec)
854 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
855 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
857 if (aspec->element_spec)
859 g_param_spec_unref (aspec->element_spec);
860 aspec->element_spec = NULL;
863 parent_class->finalize (pspec);
867 param_value_array_set_default (GParamSpec *pspec,
870 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
872 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
873 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
875 if (value->data[0].v_pointer)
877 /* g_value_reset (value); already done */
878 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
883 param_value_array_validate (GParamSpec *pspec,
886 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
887 GValueArray *value_array = value->data[0].v_pointer;
890 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
891 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
893 if (value->data[0].v_pointer)
895 /* ensure array size validity */
896 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
898 /* ensure array values validity against a present element spec */
899 if (aspec->element_spec)
901 GParamSpec *element_spec = aspec->element_spec;
904 for (i = 0; i < value_array->n_values; i++)
906 GValue *element = value_array->values + i;
908 /* need to fixup value type, or ensure that the array value is initialized at all */
909 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
911 if (G_VALUE_TYPE (element) != 0)
912 g_value_unset (element);
913 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
914 g_param_value_set_default (element_spec, element);
917 /* validate array value against element_spec */
918 changed += g_param_value_validate (element_spec, element);
927 param_value_array_values_cmp (GParamSpec *pspec,
928 const GValue *value1,
929 const GValue *value2)
931 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
932 GValueArray *value_array1 = value1->data[0].v_pointer;
933 GValueArray *value_array2 = value2->data[0].v_pointer;
935 if (!value_array1 || !value_array2)
936 return value_array2 ? -1 : value_array1 != value_array2;
938 if (value_array1->n_values != value_array2->n_values)
939 return value_array1->n_values < value_array2->n_values ? -1 : 1;
940 else if (!aspec->element_spec)
942 /* we need an element specification for comparisons, so there's not much
943 * to compare here, try to at least provide stable lesser/greater result
945 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
947 else /* value_array1->n_values == value_array2->n_values */
951 for (i = 0; i < value_array1->n_values; i++)
953 GValue *element1 = value_array1->values + i;
954 GValue *element2 = value_array2->values + i;
957 /* need corresponding element types, provide stable result otherwise */
958 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
959 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
960 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
969 param_object_init (GParamSpec *pspec)
971 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
975 param_object_set_default (GParamSpec *pspec,
978 value->data[0].v_pointer = NULL;
982 param_object_validate (GParamSpec *pspec,
985 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
986 GObject *object = value->data[0].v_pointer;
989 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
991 g_object_unref (object);
992 value->data[0].v_pointer = NULL;
1000 param_object_values_cmp (GParamSpec *pspec,
1001 const GValue *value1,
1002 const GValue *value2)
1004 guint8 *p1 = value1->data[0].v_pointer;
1005 guint8 *p2 = value2->data[0].v_pointer;
1007 /* not much to compare here, try to at least provide stable lesser/greater result */
1009 return p1 < p2 ? -1 : p1 > p2;
1013 param_override_init (GParamSpec *pspec)
1015 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1019 param_override_finalize (GParamSpec *pspec)
1021 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1022 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1024 if (ospec->overridden)
1026 g_param_spec_unref (ospec->overridden);
1027 ospec->overridden = NULL;
1030 parent_class->finalize (pspec);
1034 param_override_set_default (GParamSpec *pspec,
1037 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1039 g_param_value_set_default (ospec->overridden, value);
1043 param_override_validate (GParamSpec *pspec,
1046 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1048 return g_param_value_validate (ospec->overridden, value);
1052 param_override_values_cmp (GParamSpec *pspec,
1053 const GValue *value1,
1054 const GValue *value2)
1056 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1058 return g_param_values_cmp (ospec->overridden, value1, value2);
1062 param_gtype_init (GParamSpec *pspec)
1067 param_gtype_set_default (GParamSpec *pspec,
1070 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1072 value->data[0].v_long = tspec->is_a_type;
1076 param_gtype_validate (GParamSpec *pspec,
1079 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1080 GType gtype = value->data[0].v_long;
1083 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1085 value->data[0].v_long = tspec->is_a_type;
1093 param_gtype_values_cmp (GParamSpec *pspec,
1094 const GValue *value1,
1095 const GValue *value2)
1097 GType p1 = value1->data[0].v_long;
1098 GType p2 = value2->data[0].v_long;
1100 /* not much to compare here, try to at least provide stable lesser/greater result */
1102 return p1 < p2 ? -1 : p1 > p2;
1106 param_variant_init (GParamSpec *pspec)
1108 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1111 vspec->default_value = NULL;
1115 param_variant_finalize (GParamSpec *pspec)
1117 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1118 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1120 if (vspec->default_value)
1121 g_variant_unref (vspec->default_value);
1122 g_variant_type_free (vspec->type);
1124 parent_class->finalize (pspec);
1128 param_variant_set_default (GParamSpec *pspec,
1131 value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1132 value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1136 param_variant_validate (GParamSpec *pspec,
1139 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1140 GVariant *variant = value->data[0].v_pointer;
1142 if ((variant == NULL && vspec->default_value != NULL) ||
1143 (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1145 g_param_value_set_default (pspec, value);
1153 param_variant_values_cmp (GParamSpec *pspec,
1154 const GValue *value1,
1155 const GValue *value2)
1157 GVariant *v1 = value1->data[0].v_pointer;
1158 GVariant *v2 = value2->data[0].v_pointer;
1160 return v1 < v2 ? -1 : v2 > v1;
1163 /* --- type initialization --- */
1164 GType *g_param_spec_types = NULL;
1167 _g_param_spec_types_init (void)
1169 const guint n_types = 23;
1170 GType type, *spec_types, *spec_types_bound;
1172 g_param_spec_types = g_new0 (GType, n_types);
1173 spec_types = g_param_spec_types;
1174 spec_types_bound = g_param_spec_types + n_types;
1176 /* G_TYPE_PARAM_CHAR
1179 static const GParamSpecTypeInfo pspec_info = {
1180 sizeof (GParamSpecChar), /* instance_size */
1181 16, /* n_preallocs */
1182 param_char_init, /* instance_init */
1183 G_TYPE_CHAR, /* value_type */
1184 NULL, /* finalize */
1185 param_char_set_default, /* value_set_default */
1186 param_char_validate, /* value_validate */
1187 param_int_values_cmp, /* values_cmp */
1189 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1190 *spec_types++ = type;
1191 g_assert (type == G_TYPE_PARAM_CHAR);
1194 /* G_TYPE_PARAM_UCHAR
1197 static const GParamSpecTypeInfo pspec_info = {
1198 sizeof (GParamSpecUChar), /* instance_size */
1199 16, /* n_preallocs */
1200 param_uchar_init, /* instance_init */
1201 G_TYPE_UCHAR, /* value_type */
1202 NULL, /* finalize */
1203 param_uchar_set_default, /* value_set_default */
1204 param_uchar_validate, /* value_validate */
1205 param_uint_values_cmp, /* values_cmp */
1207 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1208 *spec_types++ = type;
1209 g_assert (type == G_TYPE_PARAM_UCHAR);
1212 /* G_TYPE_PARAM_BOOLEAN
1215 static const GParamSpecTypeInfo pspec_info = {
1216 sizeof (GParamSpecBoolean), /* instance_size */
1217 16, /* n_preallocs */
1218 NULL, /* instance_init */
1219 G_TYPE_BOOLEAN, /* value_type */
1220 NULL, /* finalize */
1221 param_boolean_set_default, /* value_set_default */
1222 param_boolean_validate, /* value_validate */
1223 param_int_values_cmp, /* values_cmp */
1225 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1226 *spec_types++ = type;
1227 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1233 static const GParamSpecTypeInfo pspec_info = {
1234 sizeof (GParamSpecInt), /* instance_size */
1235 16, /* n_preallocs */
1236 param_int_init, /* instance_init */
1237 G_TYPE_INT, /* value_type */
1238 NULL, /* finalize */
1239 param_int_set_default, /* value_set_default */
1240 param_int_validate, /* value_validate */
1241 param_int_values_cmp, /* values_cmp */
1243 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1244 *spec_types++ = type;
1245 g_assert (type == G_TYPE_PARAM_INT);
1248 /* G_TYPE_PARAM_UINT
1251 static const GParamSpecTypeInfo pspec_info = {
1252 sizeof (GParamSpecUInt), /* instance_size */
1253 16, /* n_preallocs */
1254 param_uint_init, /* instance_init */
1255 G_TYPE_UINT, /* value_type */
1256 NULL, /* finalize */
1257 param_uint_set_default, /* value_set_default */
1258 param_uint_validate, /* value_validate */
1259 param_uint_values_cmp, /* values_cmp */
1261 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1262 *spec_types++ = type;
1263 g_assert (type == G_TYPE_PARAM_UINT);
1266 /* G_TYPE_PARAM_LONG
1269 static const GParamSpecTypeInfo pspec_info = {
1270 sizeof (GParamSpecLong), /* instance_size */
1271 16, /* n_preallocs */
1272 param_long_init, /* instance_init */
1273 G_TYPE_LONG, /* value_type */
1274 NULL, /* finalize */
1275 param_long_set_default, /* value_set_default */
1276 param_long_validate, /* value_validate */
1277 param_long_values_cmp, /* values_cmp */
1279 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1280 *spec_types++ = type;
1281 g_assert (type == G_TYPE_PARAM_LONG);
1284 /* G_TYPE_PARAM_ULONG
1287 static const GParamSpecTypeInfo pspec_info = {
1288 sizeof (GParamSpecULong), /* instance_size */
1289 16, /* n_preallocs */
1290 param_ulong_init, /* instance_init */
1291 G_TYPE_ULONG, /* value_type */
1292 NULL, /* finalize */
1293 param_ulong_set_default, /* value_set_default */
1294 param_ulong_validate, /* value_validate */
1295 param_ulong_values_cmp, /* values_cmp */
1297 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1298 *spec_types++ = type;
1299 g_assert (type == G_TYPE_PARAM_ULONG);
1302 /* G_TYPE_PARAM_INT64
1305 static const GParamSpecTypeInfo pspec_info = {
1306 sizeof (GParamSpecInt64), /* instance_size */
1307 16, /* n_preallocs */
1308 param_int64_init, /* instance_init */
1309 G_TYPE_INT64, /* value_type */
1310 NULL, /* finalize */
1311 param_int64_set_default, /* value_set_default */
1312 param_int64_validate, /* value_validate */
1313 param_int64_values_cmp, /* values_cmp */
1315 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1316 *spec_types++ = type;
1317 g_assert (type == G_TYPE_PARAM_INT64);
1320 /* G_TYPE_PARAM_UINT64
1323 static const GParamSpecTypeInfo pspec_info = {
1324 sizeof (GParamSpecUInt64), /* instance_size */
1325 16, /* n_preallocs */
1326 param_uint64_init, /* instance_init */
1327 G_TYPE_UINT64, /* value_type */
1328 NULL, /* finalize */
1329 param_uint64_set_default, /* value_set_default */
1330 param_uint64_validate, /* value_validate */
1331 param_uint64_values_cmp, /* values_cmp */
1333 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1334 *spec_types++ = type;
1335 g_assert (type == G_TYPE_PARAM_UINT64);
1338 /* G_TYPE_PARAM_UNICHAR
1341 static const GParamSpecTypeInfo pspec_info = {
1342 sizeof (GParamSpecUnichar), /* instance_size */
1343 16, /* n_preallocs */
1344 param_unichar_init, /* instance_init */
1345 G_TYPE_UINT, /* value_type */
1346 NULL, /* finalize */
1347 param_unichar_set_default, /* value_set_default */
1348 param_unichar_validate, /* value_validate */
1349 param_unichar_values_cmp, /* values_cmp */
1351 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1352 *spec_types++ = type;
1353 g_assert (type == G_TYPE_PARAM_UNICHAR);
1356 /* G_TYPE_PARAM_ENUM
1359 static const GParamSpecTypeInfo pspec_info = {
1360 sizeof (GParamSpecEnum), /* instance_size */
1361 16, /* n_preallocs */
1362 param_enum_init, /* instance_init */
1363 G_TYPE_ENUM, /* value_type */
1364 param_enum_finalize, /* finalize */
1365 param_enum_set_default, /* value_set_default */
1366 param_enum_validate, /* value_validate */
1367 param_long_values_cmp, /* values_cmp */
1369 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1370 *spec_types++ = type;
1371 g_assert (type == G_TYPE_PARAM_ENUM);
1374 /* G_TYPE_PARAM_FLAGS
1377 static const GParamSpecTypeInfo pspec_info = {
1378 sizeof (GParamSpecFlags), /* instance_size */
1379 16, /* n_preallocs */
1380 param_flags_init, /* instance_init */
1381 G_TYPE_FLAGS, /* value_type */
1382 param_flags_finalize, /* finalize */
1383 param_flags_set_default, /* value_set_default */
1384 param_flags_validate, /* value_validate */
1385 param_ulong_values_cmp, /* values_cmp */
1387 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1388 *spec_types++ = type;
1389 g_assert (type == G_TYPE_PARAM_FLAGS);
1392 /* G_TYPE_PARAM_FLOAT
1395 static const GParamSpecTypeInfo pspec_info = {
1396 sizeof (GParamSpecFloat), /* instance_size */
1397 16, /* n_preallocs */
1398 param_float_init, /* instance_init */
1399 G_TYPE_FLOAT, /* value_type */
1400 NULL, /* finalize */
1401 param_float_set_default, /* value_set_default */
1402 param_float_validate, /* value_validate */
1403 param_float_values_cmp, /* values_cmp */
1405 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1406 *spec_types++ = type;
1407 g_assert (type == G_TYPE_PARAM_FLOAT);
1410 /* G_TYPE_PARAM_DOUBLE
1413 static const GParamSpecTypeInfo pspec_info = {
1414 sizeof (GParamSpecDouble), /* instance_size */
1415 16, /* n_preallocs */
1416 param_double_init, /* instance_init */
1417 G_TYPE_DOUBLE, /* value_type */
1418 NULL, /* finalize */
1419 param_double_set_default, /* value_set_default */
1420 param_double_validate, /* value_validate */
1421 param_double_values_cmp, /* values_cmp */
1423 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1424 *spec_types++ = type;
1425 g_assert (type == G_TYPE_PARAM_DOUBLE);
1428 /* G_TYPE_PARAM_STRING
1431 static const GParamSpecTypeInfo pspec_info = {
1432 sizeof (GParamSpecString), /* instance_size */
1433 16, /* n_preallocs */
1434 param_string_init, /* instance_init */
1435 G_TYPE_STRING, /* value_type */
1436 param_string_finalize, /* finalize */
1437 param_string_set_default, /* value_set_default */
1438 param_string_validate, /* value_validate */
1439 param_string_values_cmp, /* values_cmp */
1441 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1442 *spec_types++ = type;
1443 g_assert (type == G_TYPE_PARAM_STRING);
1446 /* G_TYPE_PARAM_PARAM
1449 static const GParamSpecTypeInfo pspec_info = {
1450 sizeof (GParamSpecParam), /* instance_size */
1451 16, /* n_preallocs */
1452 param_param_init, /* instance_init */
1453 G_TYPE_PARAM, /* value_type */
1454 NULL, /* finalize */
1455 param_param_set_default, /* value_set_default */
1456 param_param_validate, /* value_validate */
1457 param_pointer_values_cmp, /* values_cmp */
1459 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1460 *spec_types++ = type;
1461 g_assert (type == G_TYPE_PARAM_PARAM);
1464 /* G_TYPE_PARAM_BOXED
1467 static const GParamSpecTypeInfo pspec_info = {
1468 sizeof (GParamSpecBoxed), /* instance_size */
1469 4, /* n_preallocs */
1470 param_boxed_init, /* instance_init */
1471 G_TYPE_BOXED, /* value_type */
1472 NULL, /* finalize */
1473 param_boxed_set_default, /* value_set_default */
1474 param_boxed_validate, /* value_validate */
1475 param_boxed_values_cmp, /* values_cmp */
1477 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1478 *spec_types++ = type;
1479 g_assert (type == G_TYPE_PARAM_BOXED);
1482 /* G_TYPE_PARAM_POINTER
1485 static const GParamSpecTypeInfo pspec_info = {
1486 sizeof (GParamSpecPointer), /* instance_size */
1487 0, /* n_preallocs */
1488 param_pointer_init, /* instance_init */
1489 G_TYPE_POINTER, /* value_type */
1490 NULL, /* finalize */
1491 param_pointer_set_default, /* value_set_default */
1492 param_pointer_validate, /* value_validate */
1493 param_pointer_values_cmp, /* values_cmp */
1495 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1496 *spec_types++ = type;
1497 g_assert (type == G_TYPE_PARAM_POINTER);
1500 /* G_TYPE_PARAM_VALUE_ARRAY
1503 static /* const */ GParamSpecTypeInfo pspec_info = {
1504 sizeof (GParamSpecValueArray), /* instance_size */
1505 0, /* n_preallocs */
1506 param_value_array_init, /* instance_init */
1507 0xdeadbeef, /* value_type, assigned further down */
1508 param_value_array_finalize, /* finalize */
1509 param_value_array_set_default, /* value_set_default */
1510 param_value_array_validate, /* value_validate */
1511 param_value_array_values_cmp, /* values_cmp */
1513 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1514 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1515 *spec_types++ = type;
1516 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1519 /* G_TYPE_PARAM_OBJECT
1522 static const GParamSpecTypeInfo pspec_info = {
1523 sizeof (GParamSpecObject), /* instance_size */
1524 16, /* n_preallocs */
1525 param_object_init, /* instance_init */
1526 G_TYPE_OBJECT, /* value_type */
1527 NULL, /* finalize */
1528 param_object_set_default, /* value_set_default */
1529 param_object_validate, /* value_validate */
1530 param_object_values_cmp, /* values_cmp */
1532 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1533 *spec_types++ = type;
1534 g_assert (type == G_TYPE_PARAM_OBJECT);
1537 /* G_TYPE_PARAM_OVERRIDE
1540 static const GParamSpecTypeInfo pspec_info = {
1541 sizeof (GParamSpecOverride), /* instance_size */
1542 16, /* n_preallocs */
1543 param_override_init, /* instance_init */
1544 G_TYPE_NONE, /* value_type */
1545 param_override_finalize, /* finalize */
1546 param_override_set_default, /* value_set_default */
1547 param_override_validate, /* value_validate */
1548 param_override_values_cmp, /* values_cmp */
1550 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1551 *spec_types++ = type;
1552 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1555 /* G_TYPE_PARAM_GTYPE
1558 GParamSpecTypeInfo pspec_info = {
1559 sizeof (GParamSpecGType), /* instance_size */
1560 0, /* n_preallocs */
1561 param_gtype_init, /* instance_init */
1562 0xdeadbeef, /* value_type, assigned further down */
1563 NULL, /* finalize */
1564 param_gtype_set_default, /* value_set_default */
1565 param_gtype_validate, /* value_validate */
1566 param_gtype_values_cmp, /* values_cmp */
1568 pspec_info.value_type = G_TYPE_GTYPE;
1569 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1570 *spec_types++ = type;
1571 g_assert (type == G_TYPE_PARAM_GTYPE);
1574 /* G_TYPE_PARAM_VARIANT
1577 const GParamSpecTypeInfo pspec_info = {
1578 sizeof (GParamSpecVariant), /* instance_size */
1579 0, /* n_preallocs */
1580 param_variant_init, /* instance_init */
1581 G_TYPE_VARIANT, /* value_type */
1582 param_variant_finalize, /* finalize */
1583 param_variant_set_default, /* value_set_default */
1584 param_variant_validate, /* value_validate */
1585 param_variant_values_cmp, /* values_cmp */
1587 type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1588 *spec_types++ = type;
1589 g_assert (type == G_TYPE_PARAM_VARIANT);
1592 g_assert (spec_types == spec_types_bound);
1595 /* --- GParamSpec initialization --- */
1598 * g_param_spec_char:
1599 * @name: canonical name of the property specified
1600 * @nick: nick name for the property specified
1601 * @blurb: description of the property specified
1602 * @minimum: minimum value for the property specified
1603 * @maximum: maximum value for the property specified
1604 * @default_value: default value for the property specified
1605 * @flags: flags for the property specified
1607 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1609 * Returns: (transfer full): a newly created parameter specification
1612 g_param_spec_char (const gchar *name,
1617 gint8 default_value,
1620 GParamSpecChar *cspec;
1622 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1624 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1632 cspec->minimum = minimum;
1633 cspec->maximum = maximum;
1634 cspec->default_value = default_value;
1636 return G_PARAM_SPEC (cspec);
1640 * g_param_spec_uchar:
1641 * @name: canonical name of the property specified
1642 * @nick: nick name for the property specified
1643 * @blurb: description of the property specified
1644 * @minimum: minimum value for the property specified
1645 * @maximum: maximum value for the property specified
1646 * @default_value: default value for the property specified
1647 * @flags: flags for the property specified
1649 * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1651 * Returns: (transfer full): a newly created parameter specification
1654 g_param_spec_uchar (const gchar *name,
1659 guint8 default_value,
1662 GParamSpecUChar *uspec;
1664 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1666 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1674 uspec->minimum = minimum;
1675 uspec->maximum = maximum;
1676 uspec->default_value = default_value;
1678 return G_PARAM_SPEC (uspec);
1682 * g_param_spec_boolean:
1683 * @name: canonical name of the property specified
1684 * @nick: nick name for the property specified
1685 * @blurb: description of the property specified
1686 * @default_value: default value for the property specified
1687 * @flags: flags for the property specified
1689 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1692 * See g_param_spec_internal() for details on property names.
1694 * Returns: (transfer full): a newly created parameter specification
1697 g_param_spec_boolean (const gchar *name,
1700 gboolean default_value,
1703 GParamSpecBoolean *bspec;
1705 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1707 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1715 bspec->default_value = default_value;
1717 return G_PARAM_SPEC (bspec);
1722 * @name: canonical name of the property specified
1723 * @nick: nick name for the property specified
1724 * @blurb: description of the property specified
1725 * @minimum: minimum value for the property specified
1726 * @maximum: maximum value for the property specified
1727 * @default_value: default value for the property specified
1728 * @flags: flags for the property specified
1730 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1732 * See g_param_spec_internal() for details on property names.
1734 * Returns: (transfer full): a newly created parameter specification
1737 g_param_spec_int (const gchar *name,
1745 GParamSpecInt *ispec;
1747 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1749 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1757 ispec->minimum = minimum;
1758 ispec->maximum = maximum;
1759 ispec->default_value = default_value;
1761 return G_PARAM_SPEC (ispec);
1765 * g_param_spec_uint:
1766 * @name: canonical name of the property specified
1767 * @nick: nick name for the property specified
1768 * @blurb: description of the property specified
1769 * @minimum: minimum value for the property specified
1770 * @maximum: maximum value for the property specified
1771 * @default_value: default value for the property specified
1772 * @flags: flags for the property specified
1774 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1776 * See g_param_spec_internal() for details on property names.
1778 * Returns: (transfer full): a newly created parameter specification
1781 g_param_spec_uint (const gchar *name,
1786 guint default_value,
1789 GParamSpecUInt *uspec;
1791 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1793 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1801 uspec->minimum = minimum;
1802 uspec->maximum = maximum;
1803 uspec->default_value = default_value;
1805 return G_PARAM_SPEC (uspec);
1809 * g_param_spec_long:
1810 * @name: canonical name of the property specified
1811 * @nick: nick name for the property specified
1812 * @blurb: description of the property specified
1813 * @minimum: minimum value for the property specified
1814 * @maximum: maximum value for the property specified
1815 * @default_value: default value for the property specified
1816 * @flags: flags for the property specified
1818 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1820 * See g_param_spec_internal() for details on property names.
1822 * Returns: (transfer full): a newly created parameter specification
1825 g_param_spec_long (const gchar *name,
1830 glong default_value,
1833 GParamSpecLong *lspec;
1835 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1837 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1845 lspec->minimum = minimum;
1846 lspec->maximum = maximum;
1847 lspec->default_value = default_value;
1849 return G_PARAM_SPEC (lspec);
1853 * g_param_spec_ulong:
1854 * @name: canonical name of the property specified
1855 * @nick: nick name for the property specified
1856 * @blurb: description of the property specified
1857 * @minimum: minimum value for the property specified
1858 * @maximum: maximum value for the property specified
1859 * @default_value: default value for the property specified
1860 * @flags: flags for the property specified
1862 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
1865 * See g_param_spec_internal() for details on property names.
1867 * Returns: (transfer full): a newly created parameter specification
1870 g_param_spec_ulong (const gchar *name,
1875 gulong default_value,
1878 GParamSpecULong *uspec;
1880 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1882 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1890 uspec->minimum = minimum;
1891 uspec->maximum = maximum;
1892 uspec->default_value = default_value;
1894 return G_PARAM_SPEC (uspec);
1898 * g_param_spec_int64:
1899 * @name: canonical name of the property specified
1900 * @nick: nick name for the property specified
1901 * @blurb: description of the property specified
1902 * @minimum: minimum value for the property specified
1903 * @maximum: maximum value for the property specified
1904 * @default_value: default value for the property specified
1905 * @flags: flags for the property specified
1907 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1909 * See g_param_spec_internal() for details on property names.
1911 * Returns: (transfer full): a newly created parameter specification
1914 g_param_spec_int64 (const gchar *name,
1919 gint64 default_value,
1922 GParamSpecInt64 *lspec;
1924 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1926 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1934 lspec->minimum = minimum;
1935 lspec->maximum = maximum;
1936 lspec->default_value = default_value;
1938 return G_PARAM_SPEC (lspec);
1942 * g_param_spec_uint64:
1943 * @name: canonical name of the property specified
1944 * @nick: nick name for the property specified
1945 * @blurb: description of the property specified
1946 * @minimum: minimum value for the property specified
1947 * @maximum: maximum value for the property specified
1948 * @default_value: default value for the property specified
1949 * @flags: flags for the property specified
1951 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1954 * See g_param_spec_internal() for details on property names.
1956 * Returns: (transfer full): a newly created parameter specification
1959 g_param_spec_uint64 (const gchar *name,
1964 guint64 default_value,
1967 GParamSpecUInt64 *uspec;
1969 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1971 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1979 uspec->minimum = minimum;
1980 uspec->maximum = maximum;
1981 uspec->default_value = default_value;
1983 return G_PARAM_SPEC (uspec);
1987 * g_param_spec_unichar:
1988 * @name: canonical name of the property specified
1989 * @nick: nick name for the property specified
1990 * @blurb: description of the property specified
1991 * @default_value: default value for the property specified
1992 * @flags: flags for the property specified
1994 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1995 * property. #GValue structures for this property can be accessed with
1996 * g_value_set_uint() and g_value_get_uint().
1998 * See g_param_spec_internal() for details on property names.
2000 * Returns: (transfer full): a newly created parameter specification
2003 g_param_spec_unichar (const gchar *name,
2006 gunichar default_value,
2009 GParamSpecUnichar *uspec;
2011 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
2019 uspec->default_value = default_value;
2021 return G_PARAM_SPEC (uspec);
2025 * g_param_spec_enum:
2026 * @name: canonical name of the property specified
2027 * @nick: nick name for the property specified
2028 * @blurb: description of the property specified
2029 * @enum_type: a #GType derived from %G_TYPE_ENUM
2030 * @default_value: default value for the property specified
2031 * @flags: flags for the property specified
2033 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2036 * See g_param_spec_internal() for details on property names.
2038 * Returns: (transfer full): a newly created parameter specification
2041 g_param_spec_enum (const gchar *name,
2048 GParamSpecEnum *espec;
2049 GEnumClass *enum_class;
2051 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2053 enum_class = g_type_class_ref (enum_type);
2055 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2057 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2065 espec->enum_class = enum_class;
2066 espec->default_value = default_value;
2067 G_PARAM_SPEC (espec)->value_type = enum_type;
2069 return G_PARAM_SPEC (espec);
2073 * g_param_spec_flags:
2074 * @name: canonical name of the property specified
2075 * @nick: nick name for the property specified
2076 * @blurb: description of the property specified
2077 * @flags_type: a #GType derived from %G_TYPE_FLAGS
2078 * @default_value: default value for the property specified
2079 * @flags: flags for the property specified
2081 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2084 * See g_param_spec_internal() for details on property names.
2086 * Returns: (transfer full): a newly created parameter specification
2089 g_param_spec_flags (const gchar *name,
2093 guint default_value,
2096 GParamSpecFlags *fspec;
2097 GFlagsClass *flags_class;
2099 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2101 flags_class = g_type_class_ref (flags_type);
2103 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2105 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2113 fspec->flags_class = flags_class;
2114 fspec->default_value = default_value;
2115 G_PARAM_SPEC (fspec)->value_type = flags_type;
2117 return G_PARAM_SPEC (fspec);
2121 * g_param_spec_float:
2122 * @name: canonical name of the property specified
2123 * @nick: nick name for the property specified
2124 * @blurb: description of the property specified
2125 * @minimum: minimum value for the property specified
2126 * @maximum: maximum value for the property specified
2127 * @default_value: default value for the property specified
2128 * @flags: flags for the property specified
2130 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2132 * See g_param_spec_internal() for details on property names.
2134 * Returns: (transfer full): a newly created parameter specification
2137 g_param_spec_float (const gchar *name,
2142 gfloat default_value,
2145 GParamSpecFloat *fspec;
2147 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2149 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2157 fspec->minimum = minimum;
2158 fspec->maximum = maximum;
2159 fspec->default_value = default_value;
2161 return G_PARAM_SPEC (fspec);
2165 * g_param_spec_double:
2166 * @name: canonical name of the property specified
2167 * @nick: nick name for the property specified
2168 * @blurb: description of the property specified
2169 * @minimum: minimum value for the property specified
2170 * @maximum: maximum value for the property specified
2171 * @default_value: default value for the property specified
2172 * @flags: flags for the property specified
2174 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2177 * See g_param_spec_internal() for details on property names.
2179 * Returns: (transfer full): a newly created parameter specification
2182 g_param_spec_double (const gchar *name,
2187 gdouble default_value,
2190 GParamSpecDouble *dspec;
2192 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2194 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2202 dspec->minimum = minimum;
2203 dspec->maximum = maximum;
2204 dspec->default_value = default_value;
2206 return G_PARAM_SPEC (dspec);
2210 * g_param_spec_string:
2211 * @name: canonical name of the property specified
2212 * @nick: nick name for the property specified
2213 * @blurb: description of the property specified
2214 * @default_value: default value for the property specified
2215 * @flags: flags for the property specified
2217 * Creates a new #GParamSpecString instance.
2219 * See g_param_spec_internal() for details on property names.
2221 * Returns: (transfer full): a newly created parameter specification
2224 g_param_spec_string (const gchar *name,
2227 const gchar *default_value,
2230 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2238 g_free (sspec->default_value);
2239 sspec->default_value = g_strdup (default_value);
2241 return G_PARAM_SPEC (sspec);
2245 * g_param_spec_param:
2246 * @name: canonical name of the property specified
2247 * @nick: nick name for the property specified
2248 * @blurb: description of the property specified
2249 * @param_type: a #GType derived from %G_TYPE_PARAM
2250 * @flags: flags for the property specified
2252 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2255 * See g_param_spec_internal() for details on property names.
2257 * Returns: (transfer full): a newly created parameter specification
2260 g_param_spec_param (const gchar *name,
2266 GParamSpecParam *pspec;
2268 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2270 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2278 G_PARAM_SPEC (pspec)->value_type = param_type;
2280 return G_PARAM_SPEC (pspec);
2284 * g_param_spec_boxed:
2285 * @name: canonical name of the property specified
2286 * @nick: nick name for the property specified
2287 * @blurb: description of the property specified
2288 * @boxed_type: %G_TYPE_BOXED derived type of this property
2289 * @flags: flags for the property specified
2291 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2294 * See g_param_spec_internal() for details on property names.
2296 * Returns: (transfer full): a newly created parameter specification
2299 g_param_spec_boxed (const gchar *name,
2305 GParamSpecBoxed *bspec;
2307 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2308 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2310 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2318 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2320 return G_PARAM_SPEC (bspec);
2324 * g_param_spec_pointer:
2325 * @name: canonical name of the property specified
2326 * @nick: nick name for the property specified
2327 * @blurb: description of the property specified
2328 * @flags: flags for the property specified
2330 * Creates a new #GParamSpecPointer instance specifying a pointer property.
2332 * See g_param_spec_internal() for details on property names.
2334 * Returns: (transfer full): a newly created parameter specification
2337 g_param_spec_pointer (const gchar *name,
2342 GParamSpecPointer *pspec;
2344 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2352 return G_PARAM_SPEC (pspec);
2356 * g_param_spec_gtype:
2357 * @name: canonical name of the property specified
2358 * @nick: nick name for the property specified
2359 * @blurb: description of the property specified
2360 * @is_a_type: a #GType whose subtypes are allowed as values
2361 * of the property (use %G_TYPE_NONE for any type)
2362 * @flags: flags for the property specified
2364 * Creates a new #GParamSpecGType instance specifying a
2365 * %G_TYPE_GTYPE property.
2367 * See g_param_spec_internal() for details on property names.
2371 * Returns: (transfer full): a newly created parameter specification
2374 g_param_spec_gtype (const gchar *name,
2380 GParamSpecGType *tspec;
2382 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2390 tspec->is_a_type = is_a_type;
2392 return G_PARAM_SPEC (tspec);
2396 * g_param_spec_value_array: (skip)
2397 * @name: canonical name of the property specified
2398 * @nick: nick name for the property specified
2399 * @blurb: description of the property specified
2400 * @element_spec: a #GParamSpec describing the elements contained in
2401 * arrays of this property, may be %NULL
2402 * @flags: flags for the property specified
2404 * Creates a new #GParamSpecValueArray instance specifying a
2405 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2406 * %G_TYPE_BOXED type, as such, #GValue structures for this property
2407 * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2409 * See g_param_spec_internal() for details on property names.
2411 * Returns: a newly created parameter specification
2414 g_param_spec_value_array (const gchar *name,
2417 GParamSpec *element_spec,
2420 GParamSpecValueArray *aspec;
2423 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2425 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2435 aspec->element_spec = g_param_spec_ref (element_spec);
2436 g_param_spec_sink (element_spec);
2439 return G_PARAM_SPEC (aspec);
2443 * g_param_spec_object:
2444 * @name: canonical name of the property specified
2445 * @nick: nick name for the property specified
2446 * @blurb: description of the property specified
2447 * @object_type: %G_TYPE_OBJECT derived type of this property
2448 * @flags: flags for the property specified
2450 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2453 * See g_param_spec_internal() for details on property names.
2455 * Returns: (transfer full): a newly created parameter specification
2458 g_param_spec_object (const gchar *name,
2464 GParamSpecObject *ospec;
2466 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2468 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2476 G_PARAM_SPEC (ospec)->value_type = object_type;
2478 return G_PARAM_SPEC (ospec);
2482 * g_param_spec_override: (skip)
2483 * @name: the name of the property.
2484 * @overridden: The property that is being overridden
2486 * Creates a new property of type #GParamSpecOverride. This is used
2487 * to direct operations to another paramspec, and will not be directly
2488 * useful unless you are implementing a new base type similar to GObject.
2492 * Returns: the newly created #GParamSpec
2495 g_param_spec_override (const gchar *name,
2496 GParamSpec *overridden)
2500 g_return_val_if_fail (name != NULL, NULL);
2501 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2503 /* Dereference further redirections for property that was passed in
2507 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2509 overridden = indirect;
2514 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2520 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2521 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2527 * g_param_spec_variant:
2528 * @name: canonical name of the property specified
2529 * @nick: nick name for the property specified
2530 * @blurb: description of the property specified
2531 * @type: a #GVariantType
2532 * @default_value: (allow-none) (transfer full): a #GVariant of type @type to
2533 * use as the default value, or %NULL
2534 * @flags: flags for the property specified
2536 * Creates a new #GParamSpecVariant instance specifying a #GVariant
2539 * If @default_value is floating, it is consumed.
2541 * See g_param_spec_internal() for details on property names.
2543 * Returns: (transfer full): the newly created #GParamSpec
2548 g_param_spec_variant (const gchar *name,
2551 const GVariantType *type,
2552 GVariant *default_value,
2555 GParamSpecVariant *vspec;
2557 g_return_val_if_fail (type != NULL, NULL);
2558 g_return_val_if_fail (default_value == NULL ||
2559 g_variant_is_of_type (default_value, type), NULL);
2561 vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2569 vspec->type = g_variant_type_copy (type);
2571 vspec->default_value = g_variant_ref_sink (default_value);
2573 return G_PARAM_SPEC (vspec);