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 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS
30 #define GLIB_DISABLE_DEPRECATION_WARNINGS
33 #include "gparamspecs.h"
34 #include "gtype-private.h"
35 #include "gvaluecollector.h"
37 #include "gvaluearray.h"
41 * SECTION:param_value_types
42 * @short_description: Standard Parameter and Value Types
43 * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
44 * @title: Parameters and Values
46 * #GValue provides an abstract container structure which can be
47 * copied, transformed and compared while holding a value of any
48 * (derived) type, which is registered as a #GType with a
49 * #GTypeValueTable in its #GTypeInfo structure. Parameter
50 * specifications for most value types can be created as #GParamSpec
51 * derived instances, to implement e.g. #GObject properties which
52 * operate on #GValue containers.
54 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
55 * characters can be letters, numbers or a '-'.
56 * All other characters are replaced by a '-' during construction.
58 * See also #GValue for more information.
63 #define G_FLOAT_EPSILON (1e-30)
64 #define G_DOUBLE_EPSILON (1e-90)
67 /* --- param spec functions --- */
69 param_char_init (GParamSpec *pspec)
71 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
73 cspec->minimum = 0x7f;
74 cspec->maximum = 0x80;
75 cspec->default_value = 0;
79 param_char_set_default (GParamSpec *pspec,
82 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
86 param_char_is_valid (GParamSpec *pspec,
89 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
90 gint oval = value->data[0].v_int;
92 return cspec->minimum <= oval && oval <= cspec->maximum;
96 param_char_validate (GParamSpec *pspec,
99 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
100 gint oval = value->data[0].v_int;
102 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
104 return value->data[0].v_int != oval;
108 param_uchar_init (GParamSpec *pspec)
110 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
113 uspec->maximum = 0xff;
114 uspec->default_value = 0;
118 param_uchar_set_default (GParamSpec *pspec,
121 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
125 param_uchar_is_valid (GParamSpec *pspec,
128 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
129 guint oval = value->data[0].v_uint;
131 return uspec->minimum <= oval && oval <= uspec->maximum;
135 param_uchar_validate (GParamSpec *pspec,
138 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
139 guint oval = value->data[0].v_uint;
141 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
143 return value->data[0].v_uint != oval;
147 param_boolean_set_default (GParamSpec *pspec,
150 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
154 param_boolean_is_valid (GParamSpec *pspec,
157 int oval = value->data[0].v_int;
159 return oval == FALSE || oval == TRUE;
163 param_boolean_validate (GParamSpec *pspec,
166 gint oval = value->data[0].v_int;
168 value->data[0].v_int = value->data[0].v_int != FALSE;
170 return value->data[0].v_int != oval;
174 param_int_init (GParamSpec *pspec)
176 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
178 ispec->minimum = 0x7fffffff;
179 ispec->maximum = 0x80000000;
180 ispec->default_value = 0;
184 param_int_set_default (GParamSpec *pspec,
187 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
191 param_int_is_valid (GParamSpec *pspec,
194 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
195 int oval = value->data[0].v_int;
197 return ispec->minimum <= oval && oval <= ispec->maximum;
201 param_int_validate (GParamSpec *pspec,
204 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
205 gint oval = value->data[0].v_int;
207 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
209 return value->data[0].v_int != oval;
213 param_int_values_cmp (GParamSpec *pspec,
214 const GValue *value1,
215 const GValue *value2)
217 if (value1->data[0].v_int < value2->data[0].v_int)
220 return value1->data[0].v_int > value2->data[0].v_int;
224 param_uint_init (GParamSpec *pspec)
226 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
229 uspec->maximum = 0xffffffff;
230 uspec->default_value = 0;
234 param_uint_set_default (GParamSpec *pspec,
237 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
241 param_uint_is_valid (GParamSpec *pspec,
244 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
245 guint oval = value->data[0].v_uint;
247 return uspec->minimum <= oval && oval <= uspec->maximum;
251 param_uint_validate (GParamSpec *pspec,
254 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
255 guint oval = value->data[0].v_uint;
257 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
259 return value->data[0].v_uint != oval;
263 param_uint_values_cmp (GParamSpec *pspec,
264 const GValue *value1,
265 const GValue *value2)
267 if (value1->data[0].v_uint < value2->data[0].v_uint)
270 return value1->data[0].v_uint > value2->data[0].v_uint;
274 param_long_init (GParamSpec *pspec)
276 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
279 lspec->minimum = 0x7fffffff;
280 lspec->maximum = 0x80000000;
281 #else /* SIZEOF_LONG != 4 (8) */
282 lspec->minimum = 0x7fffffffffffffff;
283 lspec->maximum = 0x8000000000000000;
285 lspec->default_value = 0;
289 param_long_set_default (GParamSpec *pspec,
292 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
296 param_long_is_valid (GParamSpec *pspec,
299 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
300 glong oval = value->data[0].v_long;
302 return lspec->minimum <= oval && oval <= lspec->maximum;
306 param_long_validate (GParamSpec *pspec,
309 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
310 glong oval = value->data[0].v_long;
312 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
314 return value->data[0].v_long != oval;
318 param_long_values_cmp (GParamSpec *pspec,
319 const GValue *value1,
320 const GValue *value2)
322 if (value1->data[0].v_long < value2->data[0].v_long)
325 return value1->data[0].v_long > value2->data[0].v_long;
329 param_ulong_init (GParamSpec *pspec)
331 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
335 uspec->maximum = 0xffffffff;
336 #else /* SIZEOF_LONG != 4 (8) */
337 uspec->maximum = 0xffffffffffffffff;
339 uspec->default_value = 0;
343 param_ulong_set_default (GParamSpec *pspec,
346 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
350 param_ulong_is_valid (GParamSpec *pspec,
353 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
354 gulong oval = value->data[0].v_ulong;
356 return uspec->minimum <= oval && oval <= uspec->maximum;
360 param_ulong_validate (GParamSpec *pspec,
363 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
364 gulong oval = value->data[0].v_ulong;
366 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
368 return value->data[0].v_ulong != oval;
372 param_ulong_values_cmp (GParamSpec *pspec,
373 const GValue *value1,
374 const GValue *value2)
376 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
379 return value1->data[0].v_ulong > value2->data[0].v_ulong;
383 param_int64_init (GParamSpec *pspec)
385 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
387 lspec->minimum = G_MININT64;
388 lspec->maximum = G_MAXINT64;
389 lspec->default_value = 0;
393 param_int64_set_default (GParamSpec *pspec,
396 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
400 param_int64_is_valid (GParamSpec *pspec,
403 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
404 gint64 oval = value->data[0].v_int64;
406 return lspec->minimum <= oval && oval <= lspec->maximum;
410 param_int64_validate (GParamSpec *pspec,
413 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
414 gint64 oval = value->data[0].v_int64;
416 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
418 return value->data[0].v_int64 != oval;
422 param_int64_values_cmp (GParamSpec *pspec,
423 const GValue *value1,
424 const GValue *value2)
426 if (value1->data[0].v_int64 < value2->data[0].v_int64)
429 return value1->data[0].v_int64 > value2->data[0].v_int64;
433 param_uint64_init (GParamSpec *pspec)
435 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
438 uspec->maximum = G_MAXUINT64;
439 uspec->default_value = 0;
443 param_uint64_set_default (GParamSpec *pspec,
446 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
450 param_uint64_is_valid (GParamSpec *pspec,
453 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
454 guint64 oval = value->data[0].v_uint64;
456 return uspec->minimum <= oval && oval <= uspec->maximum;
460 param_uint64_validate (GParamSpec *pspec,
463 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
464 guint64 oval = value->data[0].v_uint64;
466 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
468 return value->data[0].v_uint64 != oval;
472 param_uint64_values_cmp (GParamSpec *pspec,
473 const GValue *value1,
474 const GValue *value2)
476 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
479 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
483 param_unichar_init (GParamSpec *pspec)
485 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
487 uspec->default_value = 0;
491 param_unichar_set_default (GParamSpec *pspec,
494 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
498 param_unichar_is_valid (GParamSpec *pspec,
501 return g_unichar_validate (value->data[0].v_uint);
505 param_unichar_validate (GParamSpec *pspec,
508 gunichar oval = value->data[0].v_uint;
509 gboolean changed = FALSE;
511 if (!g_unichar_validate (oval))
513 value->data[0].v_uint = 0;
521 param_unichar_values_cmp (GParamSpec *pspec,
522 const GValue *value1,
523 const GValue *value2)
525 if (value1->data[0].v_uint < value2->data[0].v_uint)
528 return value1->data[0].v_uint > value2->data[0].v_uint;
532 param_enum_init (GParamSpec *pspec)
534 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
536 espec->enum_class = NULL;
537 espec->default_value = 0;
541 param_enum_finalize (GParamSpec *pspec)
543 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
544 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
546 if (espec->enum_class)
548 g_type_class_unref (espec->enum_class);
549 espec->enum_class = NULL;
552 parent_class->finalize (pspec);
556 param_enum_set_default (GParamSpec *pspec,
559 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
563 param_enum_is_valid (GParamSpec *pspec,
566 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
567 glong oval = value->data[0].v_long;
569 return g_enum_get_value (espec->enum_class, oval) != NULL;
573 param_enum_validate (GParamSpec *pspec,
576 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
577 glong oval = value->data[0].v_long;
579 if (!espec->enum_class ||
580 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
581 value->data[0].v_long = espec->default_value;
583 return value->data[0].v_long != oval;
587 param_flags_init (GParamSpec *pspec)
589 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
591 fspec->flags_class = NULL;
592 fspec->default_value = 0;
596 param_flags_finalize (GParamSpec *pspec)
598 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
599 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
601 if (fspec->flags_class)
603 g_type_class_unref (fspec->flags_class);
604 fspec->flags_class = NULL;
607 parent_class->finalize (pspec);
611 param_flags_set_default (GParamSpec *pspec,
614 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
618 param_flags_is_valid (GParamSpec *pspec,
621 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
622 gulong oval = value->data[0].v_ulong;
624 return (oval & ~fspec->flags_class->mask) == 0;
627 param_flags_validate (GParamSpec *pspec,
630 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
631 gulong oval = value->data[0].v_ulong;
633 if (fspec->flags_class)
634 value->data[0].v_ulong &= fspec->flags_class->mask;
636 value->data[0].v_ulong = fspec->default_value;
638 return value->data[0].v_ulong != oval;
642 param_float_init (GParamSpec *pspec)
644 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
646 fspec->minimum = -G_MAXFLOAT;
647 fspec->maximum = G_MAXFLOAT;
648 fspec->default_value = 0;
649 fspec->epsilon = G_FLOAT_EPSILON;
653 param_float_set_default (GParamSpec *pspec,
656 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
660 param_float_is_valid (GParamSpec *pspec,
663 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
664 gfloat oval = value->data[0].v_float;
666 return fspec->minimum <= oval && oval <= fspec->maximum;
670 param_float_validate (GParamSpec *pspec,
673 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
674 gfloat oval = value->data[0].v_float;
676 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
678 return value->data[0].v_float != oval;
682 param_float_values_cmp (GParamSpec *pspec,
683 const GValue *value1,
684 const GValue *value2)
686 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
688 if (value1->data[0].v_float < value2->data[0].v_float)
689 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
691 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
695 param_double_init (GParamSpec *pspec)
697 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
699 dspec->minimum = -G_MAXDOUBLE;
700 dspec->maximum = G_MAXDOUBLE;
701 dspec->default_value = 0;
702 dspec->epsilon = G_DOUBLE_EPSILON;
706 param_double_set_default (GParamSpec *pspec,
709 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
713 param_double_is_valid (GParamSpec *pspec,
716 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
717 gfloat oval = value->data[0].v_double;
719 return dspec->minimum <= oval && oval <= dspec->maximum;
723 param_double_validate (GParamSpec *pspec,
726 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
727 gdouble oval = value->data[0].v_double;
729 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
731 return value->data[0].v_double != oval;
735 param_double_values_cmp (GParamSpec *pspec,
736 const GValue *value1,
737 const GValue *value2)
739 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
741 if (value1->data[0].v_double < value2->data[0].v_double)
742 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
744 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
748 param_string_init (GParamSpec *pspec)
750 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
752 sspec->default_value = NULL;
753 sspec->cset_first = NULL;
754 sspec->cset_nth = NULL;
755 sspec->substitutor = '_';
756 sspec->null_fold_if_empty = FALSE;
757 sspec->ensure_non_null = FALSE;
761 param_string_finalize (GParamSpec *pspec)
763 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
764 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
766 g_free (sspec->default_value);
767 g_free (sspec->cset_first);
768 g_free (sspec->cset_nth);
769 sspec->default_value = NULL;
770 sspec->cset_first = NULL;
771 sspec->cset_nth = NULL;
773 parent_class->finalize (pspec);
777 param_string_set_default (GParamSpec *pspec,
780 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
784 param_string_validate (GParamSpec *pspec,
787 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
788 gchar *string = value->data[0].v_pointer;
791 if (string && string[0])
795 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
797 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
799 value->data[0].v_pointer = g_strdup (string);
800 string = value->data[0].v_pointer;
801 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
803 string[0] = sspec->substitutor;
807 for (s = string + 1; *s; s++)
808 if (!strchr (sspec->cset_nth, *s))
810 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
812 value->data[0].v_pointer = g_strdup (string);
813 s = (gchar*) value->data[0].v_pointer + (s - string);
814 string = value->data[0].v_pointer;
815 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
817 *s = sspec->substitutor;
821 if (sspec->null_fold_if_empty && string && string[0] == 0)
823 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
824 g_free (value->data[0].v_pointer);
826 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
827 value->data[0].v_pointer = NULL;
829 string = value->data[0].v_pointer;
831 if (sspec->ensure_non_null && !string)
833 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
834 value->data[0].v_pointer = g_strdup ("");
836 string = value->data[0].v_pointer;
843 param_string_is_valid (GParamSpec *pspec,
846 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
849 if (sspec->cset_first != NULL || sspec->cset_nth != NULL ||
850 sspec->ensure_non_null || sspec->null_fold_if_empty)
852 GValue tmp_value = G_VALUE_INIT;
854 g_value_init (&tmp_value, G_VALUE_TYPE (value));
855 g_value_copy (value, &tmp_value);
857 ret = !param_string_validate (pspec, &tmp_value);
859 g_value_unset (&tmp_value);
866 param_string_values_cmp (GParamSpec *pspec,
867 const GValue *value1,
868 const GValue *value2)
870 if (!value1->data[0].v_pointer)
871 return value2->data[0].v_pointer != NULL ? -1 : 0;
872 else if (!value2->data[0].v_pointer)
873 return value1->data[0].v_pointer != NULL;
875 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
879 param_param_init (GParamSpec *pspec)
881 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
885 param_param_set_default (GParamSpec *pspec,
888 value->data[0].v_pointer = NULL;
892 param_param_is_valid (GParamSpec *pspec,
895 GParamSpec *param = value->data[0].v_pointer;
900 return g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec));
904 param_param_validate (GParamSpec *pspec,
907 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
908 GParamSpec *param = value->data[0].v_pointer;
911 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
913 g_param_spec_unref (param);
914 value->data[0].v_pointer = NULL;
922 param_boxed_init (GParamSpec *pspec)
924 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
928 param_boxed_set_default (GParamSpec *pspec,
931 value->data[0].v_pointer = NULL;
935 param_boxed_values_cmp (GParamSpec *pspec,
936 const GValue *value1,
937 const GValue *value2)
939 guint8 *p1 = value1->data[0].v_pointer;
940 guint8 *p2 = value2->data[0].v_pointer;
942 /* not much to compare here, try to at least provide stable lesser/greater result */
944 return p1 < p2 ? -1 : p1 > p2;
948 param_pointer_init (GParamSpec *pspec)
950 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
954 param_pointer_set_default (GParamSpec *pspec,
957 value->data[0].v_pointer = NULL;
961 param_pointer_values_cmp (GParamSpec *pspec,
962 const GValue *value1,
963 const GValue *value2)
965 guint8 *p1 = value1->data[0].v_pointer;
966 guint8 *p2 = value2->data[0].v_pointer;
968 /* not much to compare here, try to at least provide stable lesser/greater result */
970 return p1 < p2 ? -1 : p1 > p2;
974 param_value_array_init (GParamSpec *pspec)
976 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
978 aspec->element_spec = NULL;
979 aspec->fixed_n_elements = 0; /* disable */
983 value_array_ensure_size (GValueArray *value_array,
984 guint fixed_n_elements)
988 if (fixed_n_elements)
990 while (value_array->n_values < fixed_n_elements)
992 g_value_array_append (value_array, NULL);
995 while (value_array->n_values > fixed_n_elements)
997 g_value_array_remove (value_array, value_array->n_values - 1);
1005 param_value_array_finalize (GParamSpec *pspec)
1007 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
1008 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
1010 if (aspec->element_spec)
1012 g_param_spec_unref (aspec->element_spec);
1013 aspec->element_spec = NULL;
1016 parent_class->finalize (pspec);
1020 param_value_array_set_default (GParamSpec *pspec,
1023 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
1025 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
1026 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
1028 if (value->data[0].v_pointer)
1030 /* g_value_reset (value); already done */
1031 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
1036 param_value_array_validate (GParamSpec *pspec,
1039 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
1040 GValueArray *value_array = value->data[0].v_pointer;
1043 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
1044 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
1046 if (value->data[0].v_pointer)
1048 /* ensure array size validity */
1049 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
1051 /* ensure array values validity against a present element spec */
1052 if (aspec->element_spec)
1054 GParamSpec *element_spec = aspec->element_spec;
1057 for (i = 0; i < value_array->n_values; i++)
1059 GValue *element = value_array->values + i;
1061 /* need to fixup value type, or ensure that the array value is initialized at all */
1062 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
1064 if (G_VALUE_TYPE (element) != 0)
1065 g_value_unset (element);
1066 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
1067 g_param_value_set_default (element_spec, element);
1072 /* validate array value against element_spec */
1073 changed += g_param_value_validate (element_spec, element);
1083 param_value_array_values_cmp (GParamSpec *pspec,
1084 const GValue *value1,
1085 const GValue *value2)
1087 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
1088 GValueArray *value_array1 = value1->data[0].v_pointer;
1089 GValueArray *value_array2 = value2->data[0].v_pointer;
1091 if (!value_array1 || !value_array2)
1092 return value_array2 ? -1 : value_array1 != value_array2;
1094 if (value_array1->n_values != value_array2->n_values)
1095 return value_array1->n_values < value_array2->n_values ? -1 : 1;
1096 else if (!aspec->element_spec)
1098 /* we need an element specification for comparisons, so there's not much
1099 * to compare here, try to at least provide stable lesser/greater result
1101 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
1103 else /* value_array1->n_values == value_array2->n_values */
1107 for (i = 0; i < value_array1->n_values; i++)
1109 GValue *element1 = value_array1->values + i;
1110 GValue *element2 = value_array2->values + i;
1113 /* need corresponding element types, provide stable result otherwise */
1114 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
1115 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
1116 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
1125 param_object_init (GParamSpec *pspec)
1127 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
1131 param_object_set_default (GParamSpec *pspec,
1134 value->data[0].v_pointer = NULL;
1138 param_object_is_valid (GParamSpec *pspec,
1139 const GValue *value)
1141 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
1142 GObject *object = value->data[0].v_pointer;
1145 g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec));
1149 param_object_validate (GParamSpec *pspec,
1152 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
1153 GObject *object = value->data[0].v_pointer;
1156 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
1158 g_object_unref (object);
1159 value->data[0].v_pointer = NULL;
1167 param_object_values_cmp (GParamSpec *pspec,
1168 const GValue *value1,
1169 const GValue *value2)
1171 guint8 *p1 = value1->data[0].v_pointer;
1172 guint8 *p2 = value2->data[0].v_pointer;
1174 /* not much to compare here, try to at least provide stable lesser/greater result */
1176 return p1 < p2 ? -1 : p1 > p2;
1180 param_override_init (GParamSpec *pspec)
1182 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1186 param_override_finalize (GParamSpec *pspec)
1188 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1189 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1191 if (ospec->overridden)
1193 g_param_spec_unref (ospec->overridden);
1194 ospec->overridden = NULL;
1197 parent_class->finalize (pspec);
1201 param_override_set_default (GParamSpec *pspec,
1204 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1206 g_param_value_set_default (ospec->overridden, value);
1210 param_override_is_valid (GParamSpec *pspec,
1211 const GValue *value)
1213 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1215 return g_param_value_is_valid (ospec->overridden, value);
1219 param_override_validate (GParamSpec *pspec,
1222 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1224 return g_param_value_validate (ospec->overridden, value);
1228 param_override_values_cmp (GParamSpec *pspec,
1229 const GValue *value1,
1230 const GValue *value2)
1232 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1234 return g_param_values_cmp (ospec->overridden, value1, value2);
1238 param_gtype_init (GParamSpec *pspec)
1243 param_gtype_set_default (GParamSpec *pspec,
1246 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1248 value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type);
1252 param_gtype_is_valid (GParamSpec *pspec,
1253 const GValue *value)
1255 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1256 GType gtype = GPOINTER_TO_SIZE (value->data[0].v_pointer);
1258 return tspec->is_a_type == G_TYPE_NONE ||
1259 g_type_is_a (gtype, tspec->is_a_type);
1263 param_gtype_validate (GParamSpec *pspec,
1266 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1267 GType gtype = GPOINTER_TO_SIZE (value->data[0].v_pointer);
1270 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1272 value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type);
1280 param_gtype_values_cmp (GParamSpec *pspec,
1281 const GValue *value1,
1282 const GValue *value2)
1284 GType p1 = GPOINTER_TO_SIZE (value1->data[0].v_pointer);
1285 GType p2 = GPOINTER_TO_SIZE (value2->data[0].v_pointer);
1287 /* not much to compare here, try to at least provide stable lesser/greater result */
1289 return p1 < p2 ? -1 : p1 > p2;
1293 param_variant_init (GParamSpec *pspec)
1295 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1298 vspec->default_value = NULL;
1302 param_variant_finalize (GParamSpec *pspec)
1304 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1305 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1307 if (vspec->default_value)
1308 g_variant_unref (vspec->default_value);
1309 g_variant_type_free (vspec->type);
1311 parent_class->finalize (pspec);
1315 param_variant_set_default (GParamSpec *pspec,
1318 value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1319 value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1323 param_variant_is_valid (GParamSpec *pspec,
1324 const GValue *value)
1326 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1327 GVariant *variant = value->data[0].v_pointer;
1329 if (variant == NULL)
1330 return vspec->default_value == NULL;
1332 return g_variant_is_of_type (variant, vspec->type);
1336 param_variant_validate (GParamSpec *pspec,
1339 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1340 GVariant *variant = value->data[0].v_pointer;
1342 if ((variant == NULL && vspec->default_value != NULL) ||
1343 (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1345 g_param_value_set_default (pspec, value);
1352 /* g_variant_compare() can only be used with scalar types. */
1354 variant_is_incomparable (GVariant *v)
1356 GVariantClass v_class = g_variant_classify (v);
1358 return (v_class == G_VARIANT_CLASS_HANDLE ||
1359 v_class == G_VARIANT_CLASS_VARIANT ||
1360 v_class == G_VARIANT_CLASS_MAYBE||
1361 v_class == G_VARIANT_CLASS_ARRAY ||
1362 v_class == G_VARIANT_CLASS_TUPLE ||
1363 v_class == G_VARIANT_CLASS_DICT_ENTRY);
1367 param_variant_values_cmp (GParamSpec *pspec,
1368 const GValue *value1,
1369 const GValue *value2)
1371 GVariant *v1 = value1->data[0].v_pointer;
1372 GVariant *v2 = value2->data[0].v_pointer;
1374 if (v1 == NULL && v2 == NULL)
1376 else if (v1 == NULL && v2 != NULL)
1378 else if (v1 != NULL && v2 == NULL)
1381 if (!g_variant_type_equal (g_variant_get_type (v1), g_variant_get_type (v2)) ||
1382 variant_is_incomparable (v1) ||
1383 variant_is_incomparable (v2))
1384 return g_variant_equal (v1, v2) ? 0 : (v1 < v2 ? -1 : 1);
1386 return g_variant_compare (v1, v2);
1389 /* --- type initialization --- */
1391 #define set_is_valid_vfunc(type,func) { \
1392 GParamSpecClass *class = g_type_class_ref (type); \
1393 class->value_is_valid = func; \
1394 g_type_class_unref (class); \
1397 GType *g_param_spec_types = NULL;
1400 _g_param_spec_types_init (void)
1402 const guint n_types = 23;
1403 GType type, *spec_types;
1404 #ifndef G_DISABLE_ASSERT
1405 GType *spec_types_bound;
1408 g_param_spec_types = g_new0 (GType, n_types);
1409 spec_types = g_param_spec_types;
1410 #ifndef G_DISABLE_ASSERT
1411 spec_types_bound = g_param_spec_types + n_types;
1414 /* G_TYPE_PARAM_CHAR
1417 const GParamSpecTypeInfo pspec_info = {
1418 sizeof (GParamSpecChar), /* instance_size */
1419 16, /* n_preallocs */
1420 param_char_init, /* instance_init */
1421 G_TYPE_CHAR, /* value_type */
1422 NULL, /* finalize */
1423 param_char_set_default, /* value_set_default */
1424 param_char_validate, /* value_validate */
1425 param_int_values_cmp, /* values_cmp */
1427 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1428 set_is_valid_vfunc (type, param_char_is_valid);
1429 *spec_types++ = type;
1430 g_assert (type == G_TYPE_PARAM_CHAR);
1433 /* G_TYPE_PARAM_UCHAR
1436 const GParamSpecTypeInfo pspec_info = {
1437 sizeof (GParamSpecUChar), /* instance_size */
1438 16, /* n_preallocs */
1439 param_uchar_init, /* instance_init */
1440 G_TYPE_UCHAR, /* value_type */
1441 NULL, /* finalize */
1442 param_uchar_set_default, /* value_set_default */
1443 param_uchar_validate, /* value_validate */
1444 param_uint_values_cmp, /* values_cmp */
1446 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1447 set_is_valid_vfunc (type, param_uchar_is_valid);
1448 *spec_types++ = type;
1449 g_assert (type == G_TYPE_PARAM_UCHAR);
1452 /* G_TYPE_PARAM_BOOLEAN
1455 const GParamSpecTypeInfo pspec_info = {
1456 sizeof (GParamSpecBoolean), /* instance_size */
1457 16, /* n_preallocs */
1458 NULL, /* instance_init */
1459 G_TYPE_BOOLEAN, /* value_type */
1460 NULL, /* finalize */
1461 param_boolean_set_default, /* value_set_default */
1462 param_boolean_validate, /* value_validate */
1463 param_int_values_cmp, /* values_cmp */
1465 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1466 set_is_valid_vfunc (type, param_boolean_is_valid);
1467 *spec_types++ = type;
1468 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1474 const GParamSpecTypeInfo pspec_info = {
1475 sizeof (GParamSpecInt), /* instance_size */
1476 16, /* n_preallocs */
1477 param_int_init, /* instance_init */
1478 G_TYPE_INT, /* value_type */
1479 NULL, /* finalize */
1480 param_int_set_default, /* value_set_default */
1481 param_int_validate, /* value_validate */
1482 param_int_values_cmp, /* values_cmp */
1484 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1485 set_is_valid_vfunc (type, param_int_is_valid);
1486 *spec_types++ = type;
1487 g_assert (type == G_TYPE_PARAM_INT);
1490 /* G_TYPE_PARAM_UINT
1493 const GParamSpecTypeInfo pspec_info = {
1494 sizeof (GParamSpecUInt), /* instance_size */
1495 16, /* n_preallocs */
1496 param_uint_init, /* instance_init */
1497 G_TYPE_UINT, /* value_type */
1498 NULL, /* finalize */
1499 param_uint_set_default, /* value_set_default */
1500 param_uint_validate, /* value_validate */
1501 param_uint_values_cmp, /* values_cmp */
1503 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1504 set_is_valid_vfunc (type, param_uint_is_valid);
1505 *spec_types++ = type;
1506 g_assert (type == G_TYPE_PARAM_UINT);
1509 /* G_TYPE_PARAM_LONG
1512 const GParamSpecTypeInfo pspec_info = {
1513 sizeof (GParamSpecLong), /* instance_size */
1514 16, /* n_preallocs */
1515 param_long_init, /* instance_init */
1516 G_TYPE_LONG, /* value_type */
1517 NULL, /* finalize */
1518 param_long_set_default, /* value_set_default */
1519 param_long_validate, /* value_validate */
1520 param_long_values_cmp, /* values_cmp */
1522 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1523 set_is_valid_vfunc (type, param_long_is_valid);
1524 *spec_types++ = type;
1525 g_assert (type == G_TYPE_PARAM_LONG);
1528 /* G_TYPE_PARAM_ULONG
1531 const GParamSpecTypeInfo pspec_info = {
1532 sizeof (GParamSpecULong), /* instance_size */
1533 16, /* n_preallocs */
1534 param_ulong_init, /* instance_init */
1535 G_TYPE_ULONG, /* value_type */
1536 NULL, /* finalize */
1537 param_ulong_set_default, /* value_set_default */
1538 param_ulong_validate, /* value_validate */
1539 param_ulong_values_cmp, /* values_cmp */
1541 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1542 set_is_valid_vfunc (type, param_ulong_is_valid);
1543 *spec_types++ = type;
1544 g_assert (type == G_TYPE_PARAM_ULONG);
1547 /* G_TYPE_PARAM_INT64
1550 const GParamSpecTypeInfo pspec_info = {
1551 sizeof (GParamSpecInt64), /* instance_size */
1552 16, /* n_preallocs */
1553 param_int64_init, /* instance_init */
1554 G_TYPE_INT64, /* value_type */
1555 NULL, /* finalize */
1556 param_int64_set_default, /* value_set_default */
1557 param_int64_validate, /* value_validate */
1558 param_int64_values_cmp, /* values_cmp */
1560 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1561 set_is_valid_vfunc (type, param_int64_is_valid);
1562 *spec_types++ = type;
1563 g_assert (type == G_TYPE_PARAM_INT64);
1566 /* G_TYPE_PARAM_UINT64
1569 const GParamSpecTypeInfo pspec_info = {
1570 sizeof (GParamSpecUInt64), /* instance_size */
1571 16, /* n_preallocs */
1572 param_uint64_init, /* instance_init */
1573 G_TYPE_UINT64, /* value_type */
1574 NULL, /* finalize */
1575 param_uint64_set_default, /* value_set_default */
1576 param_uint64_validate, /* value_validate */
1577 param_uint64_values_cmp, /* values_cmp */
1579 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1580 set_is_valid_vfunc (type, param_uint64_is_valid);
1581 *spec_types++ = type;
1582 g_assert (type == G_TYPE_PARAM_UINT64);
1585 /* G_TYPE_PARAM_UNICHAR
1588 const GParamSpecTypeInfo pspec_info = {
1589 sizeof (GParamSpecUnichar), /* instance_size */
1590 16, /* n_preallocs */
1591 param_unichar_init, /* instance_init */
1592 G_TYPE_UINT, /* value_type */
1593 NULL, /* finalize */
1594 param_unichar_set_default, /* value_set_default */
1595 param_unichar_validate, /* value_validate */
1596 param_unichar_values_cmp, /* values_cmp */
1598 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1599 set_is_valid_vfunc (type, param_unichar_is_valid);
1600 *spec_types++ = type;
1601 g_assert (type == G_TYPE_PARAM_UNICHAR);
1604 /* G_TYPE_PARAM_ENUM
1607 const GParamSpecTypeInfo pspec_info = {
1608 sizeof (GParamSpecEnum), /* instance_size */
1609 16, /* n_preallocs */
1610 param_enum_init, /* instance_init */
1611 G_TYPE_ENUM, /* value_type */
1612 param_enum_finalize, /* finalize */
1613 param_enum_set_default, /* value_set_default */
1614 param_enum_validate, /* value_validate */
1615 param_long_values_cmp, /* values_cmp */
1617 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1618 set_is_valid_vfunc (type, param_enum_is_valid);
1619 *spec_types++ = type;
1620 g_assert (type == G_TYPE_PARAM_ENUM);
1623 /* G_TYPE_PARAM_FLAGS
1626 const GParamSpecTypeInfo pspec_info = {
1627 sizeof (GParamSpecFlags), /* instance_size */
1628 16, /* n_preallocs */
1629 param_flags_init, /* instance_init */
1630 G_TYPE_FLAGS, /* value_type */
1631 param_flags_finalize, /* finalize */
1632 param_flags_set_default, /* value_set_default */
1633 param_flags_validate, /* value_validate */
1634 param_ulong_values_cmp, /* values_cmp */
1636 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1637 set_is_valid_vfunc (type, param_flags_is_valid);
1638 *spec_types++ = type;
1639 g_assert (type == G_TYPE_PARAM_FLAGS);
1642 /* G_TYPE_PARAM_FLOAT
1645 const GParamSpecTypeInfo pspec_info = {
1646 sizeof (GParamSpecFloat), /* instance_size */
1647 16, /* n_preallocs */
1648 param_float_init, /* instance_init */
1649 G_TYPE_FLOAT, /* value_type */
1650 NULL, /* finalize */
1651 param_float_set_default, /* value_set_default */
1652 param_float_validate, /* value_validate */
1653 param_float_values_cmp, /* values_cmp */
1655 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1656 set_is_valid_vfunc (type, param_float_is_valid);
1657 *spec_types++ = type;
1658 g_assert (type == G_TYPE_PARAM_FLOAT);
1661 /* G_TYPE_PARAM_DOUBLE
1664 const GParamSpecTypeInfo pspec_info = {
1665 sizeof (GParamSpecDouble), /* instance_size */
1666 16, /* n_preallocs */
1667 param_double_init, /* instance_init */
1668 G_TYPE_DOUBLE, /* value_type */
1669 NULL, /* finalize */
1670 param_double_set_default, /* value_set_default */
1671 param_double_validate, /* value_validate */
1672 param_double_values_cmp, /* values_cmp */
1674 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1675 set_is_valid_vfunc (type, param_double_is_valid);
1676 *spec_types++ = type;
1677 g_assert (type == G_TYPE_PARAM_DOUBLE);
1680 /* G_TYPE_PARAM_STRING
1683 const GParamSpecTypeInfo pspec_info = {
1684 sizeof (GParamSpecString), /* instance_size */
1685 16, /* n_preallocs */
1686 param_string_init, /* instance_init */
1687 G_TYPE_STRING, /* value_type */
1688 param_string_finalize, /* finalize */
1689 param_string_set_default, /* value_set_default */
1690 param_string_validate, /* value_validate */
1691 param_string_values_cmp, /* values_cmp */
1693 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1694 set_is_valid_vfunc (type, param_string_is_valid);
1695 *spec_types++ = type;
1696 g_assert (type == G_TYPE_PARAM_STRING);
1699 /* G_TYPE_PARAM_PARAM
1702 const GParamSpecTypeInfo pspec_info = {
1703 sizeof (GParamSpecParam), /* instance_size */
1704 16, /* n_preallocs */
1705 param_param_init, /* instance_init */
1706 G_TYPE_PARAM, /* value_type */
1707 NULL, /* finalize */
1708 param_param_set_default, /* value_set_default */
1709 param_param_validate, /* value_validate */
1710 param_pointer_values_cmp, /* values_cmp */
1712 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1713 set_is_valid_vfunc (type, param_param_is_valid);
1714 *spec_types++ = type;
1715 g_assert (type == G_TYPE_PARAM_PARAM);
1718 /* G_TYPE_PARAM_BOXED
1721 const GParamSpecTypeInfo pspec_info = {
1722 sizeof (GParamSpecBoxed), /* instance_size */
1723 4, /* n_preallocs */
1724 param_boxed_init, /* instance_init */
1725 G_TYPE_BOXED, /* value_type */
1726 NULL, /* finalize */
1727 param_boxed_set_default, /* value_set_default */
1728 NULL, /* value_validate */
1729 param_boxed_values_cmp, /* values_cmp */
1731 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1732 *spec_types++ = type;
1733 g_assert (type == G_TYPE_PARAM_BOXED);
1736 /* G_TYPE_PARAM_POINTER
1739 const GParamSpecTypeInfo pspec_info = {
1740 sizeof (GParamSpecPointer), /* instance_size */
1741 0, /* n_preallocs */
1742 param_pointer_init, /* instance_init */
1743 G_TYPE_POINTER, /* value_type */
1744 NULL, /* finalize */
1745 param_pointer_set_default, /* value_set_default */
1747 param_pointer_values_cmp, /* values_cmp */
1749 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1750 *spec_types++ = type;
1751 g_assert (type == G_TYPE_PARAM_POINTER);
1754 /* G_TYPE_PARAM_VALUE_ARRAY
1757 /* const */ GParamSpecTypeInfo pspec_info = {
1758 sizeof (GParamSpecValueArray), /* instance_size */
1759 0, /* n_preallocs */
1760 param_value_array_init, /* instance_init */
1761 0xdeadbeef, /* value_type, assigned further down */
1762 param_value_array_finalize, /* finalize */
1763 param_value_array_set_default, /* value_set_default */
1764 param_value_array_validate, /* value_validate */
1765 param_value_array_values_cmp, /* values_cmp */
1767 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1768 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1769 *spec_types++ = type;
1770 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1773 /* G_TYPE_PARAM_OBJECT
1776 const GParamSpecTypeInfo pspec_info = {
1777 sizeof (GParamSpecObject), /* instance_size */
1778 16, /* n_preallocs */
1779 param_object_init, /* instance_init */
1780 G_TYPE_OBJECT, /* value_type */
1781 NULL, /* finalize */
1782 param_object_set_default, /* value_set_default */
1783 param_object_validate, /* value_validate */
1784 param_object_values_cmp, /* values_cmp */
1786 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1787 set_is_valid_vfunc (type, param_object_is_valid);
1788 *spec_types++ = type;
1789 g_assert (type == G_TYPE_PARAM_OBJECT);
1792 /* G_TYPE_PARAM_OVERRIDE
1795 const GParamSpecTypeInfo pspec_info = {
1796 sizeof (GParamSpecOverride), /* instance_size */
1797 16, /* n_preallocs */
1798 param_override_init, /* instance_init */
1799 G_TYPE_NONE, /* value_type */
1800 param_override_finalize, /* finalize */
1801 param_override_set_default, /* value_set_default */
1802 param_override_validate, /* value_validate */
1803 param_override_values_cmp, /* values_cmp */
1805 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1806 set_is_valid_vfunc (type, param_override_is_valid);
1807 *spec_types++ = type;
1808 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1811 /* G_TYPE_PARAM_GTYPE
1814 GParamSpecTypeInfo pspec_info = {
1815 sizeof (GParamSpecGType), /* instance_size */
1816 0, /* n_preallocs */
1817 param_gtype_init, /* instance_init */
1818 0xdeadbeef, /* value_type, assigned further down */
1819 NULL, /* finalize */
1820 param_gtype_set_default, /* value_set_default */
1821 param_gtype_validate, /* value_validate */
1822 param_gtype_values_cmp, /* values_cmp */
1824 pspec_info.value_type = G_TYPE_GTYPE;
1825 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1826 set_is_valid_vfunc (type, param_gtype_is_valid);
1827 *spec_types++ = type;
1828 g_assert (type == G_TYPE_PARAM_GTYPE);
1831 /* G_TYPE_PARAM_VARIANT
1834 const GParamSpecTypeInfo pspec_info = {
1835 sizeof (GParamSpecVariant), /* instance_size */
1836 0, /* n_preallocs */
1837 param_variant_init, /* instance_init */
1838 G_TYPE_VARIANT, /* value_type */
1839 param_variant_finalize, /* finalize */
1840 param_variant_set_default, /* value_set_default */
1841 param_variant_validate, /* value_validate */
1842 param_variant_values_cmp, /* values_cmp */
1844 type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1845 set_is_valid_vfunc (type, param_variant_is_valid);
1846 *spec_types++ = type;
1847 g_assert (type == G_TYPE_PARAM_VARIANT);
1850 g_assert (spec_types == spec_types_bound);
1853 /* --- GParamSpec initialization --- */
1856 * g_param_spec_char:
1857 * @name: canonical name of the property specified
1858 * @nick: (nullable): nick name for the property specified
1859 * @blurb: (nullable): description of the property specified
1860 * @minimum: minimum value for the property specified
1861 * @maximum: maximum value for the property specified
1862 * @default_value: default value for the property specified
1863 * @flags: flags for the property specified
1865 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1867 * Returns: (transfer full): a newly created parameter specification
1870 g_param_spec_char (const gchar *name,
1875 gint8 default_value,
1878 GParamSpecChar *cspec;
1880 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1882 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1890 cspec->minimum = minimum;
1891 cspec->maximum = maximum;
1892 cspec->default_value = default_value;
1894 return G_PARAM_SPEC (cspec);
1898 * g_param_spec_uchar:
1899 * @name: canonical name of the property specified
1900 * @nick: (nullable): nick name for the property specified
1901 * @blurb: (nullable): 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 #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1909 * Returns: (transfer full): a newly created parameter specification
1912 g_param_spec_uchar (const gchar *name,
1917 guint8 default_value,
1920 GParamSpecUChar *uspec;
1922 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1924 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1932 uspec->minimum = minimum;
1933 uspec->maximum = maximum;
1934 uspec->default_value = default_value;
1936 return G_PARAM_SPEC (uspec);
1940 * g_param_spec_boolean:
1941 * @name: canonical name of the property specified
1942 * @nick: (nullable): nick name for the property specified
1943 * @blurb: (nullable): description of the property specified
1944 * @default_value: default value for the property specified
1945 * @flags: flags for the property specified
1947 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1948 * property. In many cases, it may be more appropriate to use an enum with
1949 * g_param_spec_enum(), both to improve code clarity by using explicitly named
1950 * values, and to allow for more values to be added in future without breaking
1953 * See g_param_spec_internal() for details on property names.
1955 * Returns: (transfer full): a newly created parameter specification
1958 g_param_spec_boolean (const gchar *name,
1961 gboolean default_value,
1964 GParamSpecBoolean *bspec;
1966 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1968 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1976 bspec->default_value = default_value;
1978 return G_PARAM_SPEC (bspec);
1983 * @name: canonical name of the property specified
1984 * @nick: (nullable): nick name for the property specified
1985 * @blurb: (nullable): description of the property specified
1986 * @minimum: minimum value for the property specified
1987 * @maximum: maximum value for the property specified
1988 * @default_value: default value for the property specified
1989 * @flags: flags for the property specified
1991 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1993 * See g_param_spec_internal() for details on property names.
1995 * Returns: (transfer full): a newly created parameter specification
1998 g_param_spec_int (const gchar *name,
2006 GParamSpecInt *ispec;
2008 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2010 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
2018 ispec->minimum = minimum;
2019 ispec->maximum = maximum;
2020 ispec->default_value = default_value;
2022 return G_PARAM_SPEC (ispec);
2026 * g_param_spec_uint:
2027 * @name: canonical name of the property specified
2028 * @nick: (nullable): nick name for the property specified
2029 * @blurb: (nullable): description of the property specified
2030 * @minimum: minimum value for the property specified
2031 * @maximum: maximum value for the property specified
2032 * @default_value: default value for the property specified
2033 * @flags: flags for the property specified
2035 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
2037 * See g_param_spec_internal() for details on property names.
2039 * Returns: (transfer full): a newly created parameter specification
2042 g_param_spec_uint (const gchar *name,
2047 guint default_value,
2050 GParamSpecUInt *uspec;
2052 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2054 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
2062 uspec->minimum = minimum;
2063 uspec->maximum = maximum;
2064 uspec->default_value = default_value;
2066 return G_PARAM_SPEC (uspec);
2070 * g_param_spec_long:
2071 * @name: canonical name of the property specified
2072 * @nick: (nullable): nick name for the property specified
2073 * @blurb: (nullable): description of the property specified
2074 * @minimum: minimum value for the property specified
2075 * @maximum: maximum value for the property specified
2076 * @default_value: default value for the property specified
2077 * @flags: flags for the property specified
2079 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
2081 * See g_param_spec_internal() for details on property names.
2083 * Returns: (transfer full): a newly created parameter specification
2086 g_param_spec_long (const gchar *name,
2091 glong default_value,
2094 GParamSpecLong *lspec;
2096 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2098 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
2106 lspec->minimum = minimum;
2107 lspec->maximum = maximum;
2108 lspec->default_value = default_value;
2110 return G_PARAM_SPEC (lspec);
2114 * g_param_spec_ulong:
2115 * @name: canonical name of the property specified
2116 * @nick: (nullable): nick name for the property specified
2117 * @blurb: (nullable): description of the property specified
2118 * @minimum: minimum value for the property specified
2119 * @maximum: maximum value for the property specified
2120 * @default_value: default value for the property specified
2121 * @flags: flags for the property specified
2123 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
2126 * See g_param_spec_internal() for details on property names.
2128 * Returns: (transfer full): a newly created parameter specification
2131 g_param_spec_ulong (const gchar *name,
2136 gulong default_value,
2139 GParamSpecULong *uspec;
2141 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2143 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
2151 uspec->minimum = minimum;
2152 uspec->maximum = maximum;
2153 uspec->default_value = default_value;
2155 return G_PARAM_SPEC (uspec);
2159 * g_param_spec_int64:
2160 * @name: canonical name of the property specified
2161 * @nick: (nullable): nick name for the property specified
2162 * @blurb: (nullable): description of the property specified
2163 * @minimum: minimum value for the property specified
2164 * @maximum: maximum value for the property specified
2165 * @default_value: default value for the property specified
2166 * @flags: flags for the property specified
2168 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
2170 * See g_param_spec_internal() for details on property names.
2172 * Returns: (transfer full): a newly created parameter specification
2175 g_param_spec_int64 (const gchar *name,
2180 gint64 default_value,
2183 GParamSpecInt64 *lspec;
2185 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2187 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
2195 lspec->minimum = minimum;
2196 lspec->maximum = maximum;
2197 lspec->default_value = default_value;
2199 return G_PARAM_SPEC (lspec);
2203 * g_param_spec_uint64:
2204 * @name: canonical name of the property specified
2205 * @nick: (nullable): nick name for the property specified
2206 * @blurb: (nullable): description of the property specified
2207 * @minimum: minimum value for the property specified
2208 * @maximum: maximum value for the property specified
2209 * @default_value: default value for the property specified
2210 * @flags: flags for the property specified
2212 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
2215 * See g_param_spec_internal() for details on property names.
2217 * Returns: (transfer full): a newly created parameter specification
2220 g_param_spec_uint64 (const gchar *name,
2225 guint64 default_value,
2228 GParamSpecUInt64 *uspec;
2230 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2232 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
2240 uspec->minimum = minimum;
2241 uspec->maximum = maximum;
2242 uspec->default_value = default_value;
2244 return G_PARAM_SPEC (uspec);
2248 * g_param_spec_unichar:
2249 * @name: canonical name of the property specified
2250 * @nick: (nullable): nick name for the property specified
2251 * @blurb: (nullable): description of the property specified
2252 * @default_value: default value for the property specified
2253 * @flags: flags for the property specified
2255 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
2256 * property. #GValue structures for this property can be accessed with
2257 * g_value_set_uint() and g_value_get_uint().
2259 * See g_param_spec_internal() for details on property names.
2261 * Returns: (transfer full): a newly created parameter specification
2264 g_param_spec_unichar (const gchar *name,
2267 gunichar default_value,
2270 GParamSpecUnichar *uspec;
2272 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
2280 uspec->default_value = default_value;
2282 return G_PARAM_SPEC (uspec);
2286 * g_param_spec_enum:
2287 * @name: canonical name of the property specified
2288 * @nick: (nullable): nick name for the property specified
2289 * @blurb: (nullable): description of the property specified
2290 * @enum_type: a #GType derived from %G_TYPE_ENUM
2291 * @default_value: default value for the property specified
2292 * @flags: flags for the property specified
2294 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2297 * See g_param_spec_internal() for details on property names.
2299 * Returns: (transfer full): a newly created parameter specification
2302 g_param_spec_enum (const gchar *name,
2309 GParamSpecEnum *espec;
2310 GEnumClass *enum_class;
2312 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2314 enum_class = g_type_class_ref (enum_type);
2316 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2318 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2326 espec->enum_class = enum_class;
2327 espec->default_value = default_value;
2328 G_PARAM_SPEC (espec)->value_type = enum_type;
2330 return G_PARAM_SPEC (espec);
2334 * g_param_spec_flags:
2335 * @name: canonical name of the property specified
2336 * @nick: (nullable): nick name for the property specified
2337 * @blurb: (nullable): description of the property specified
2338 * @flags_type: a #GType derived from %G_TYPE_FLAGS
2339 * @default_value: default value for the property specified
2340 * @flags: flags for the property specified
2342 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2345 * See g_param_spec_internal() for details on property names.
2347 * Returns: (transfer full): a newly created parameter specification
2350 g_param_spec_flags (const gchar *name,
2354 guint default_value,
2357 GParamSpecFlags *fspec;
2358 GFlagsClass *flags_class;
2360 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2362 flags_class = g_type_class_ref (flags_type);
2364 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2366 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2374 fspec->flags_class = flags_class;
2375 fspec->default_value = default_value;
2376 G_PARAM_SPEC (fspec)->value_type = flags_type;
2378 return G_PARAM_SPEC (fspec);
2382 * g_param_spec_float:
2383 * @name: canonical name of the property specified
2384 * @nick: (nullable): nick name for the property specified
2385 * @blurb: (nullable): description of the property specified
2386 * @minimum: minimum value for the property specified
2387 * @maximum: maximum value for the property specified
2388 * @default_value: default value for the property specified
2389 * @flags: flags for the property specified
2391 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2393 * See g_param_spec_internal() for details on property names.
2395 * Returns: (transfer full): a newly created parameter specification
2398 g_param_spec_float (const gchar *name,
2403 gfloat default_value,
2406 GParamSpecFloat *fspec;
2408 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2410 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2418 fspec->minimum = minimum;
2419 fspec->maximum = maximum;
2420 fspec->default_value = default_value;
2422 return G_PARAM_SPEC (fspec);
2426 * g_param_spec_double:
2427 * @name: canonical name of the property specified
2428 * @nick: (nullable): nick name for the property specified
2429 * @blurb: (nullable): description of the property specified
2430 * @minimum: minimum value for the property specified
2431 * @maximum: maximum value for the property specified
2432 * @default_value: default value for the property specified
2433 * @flags: flags for the property specified
2435 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2438 * See g_param_spec_internal() for details on property names.
2440 * Returns: (transfer full): a newly created parameter specification
2443 g_param_spec_double (const gchar *name,
2448 gdouble default_value,
2451 GParamSpecDouble *dspec;
2453 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2455 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2463 dspec->minimum = minimum;
2464 dspec->maximum = maximum;
2465 dspec->default_value = default_value;
2467 return G_PARAM_SPEC (dspec);
2471 * g_param_spec_string:
2472 * @name: canonical name of the property specified
2473 * @nick: (nullable): nick name for the property specified
2474 * @blurb: (nullable): description of the property specified
2475 * @default_value: (nullable): default value for the property specified
2476 * @flags: flags for the property specified
2478 * Creates a new #GParamSpecString instance.
2480 * See g_param_spec_internal() for details on property names.
2482 * Returns: (transfer full): a newly created parameter specification
2485 g_param_spec_string (const gchar *name,
2488 const gchar *default_value,
2491 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2499 g_free (sspec->default_value);
2500 sspec->default_value = g_strdup (default_value);
2502 return G_PARAM_SPEC (sspec);
2506 * g_param_spec_param:
2507 * @name: canonical name of the property specified
2508 * @nick: (nullable): nick name for the property specified
2509 * @blurb: (nullable): description of the property specified
2510 * @param_type: a #GType derived from %G_TYPE_PARAM
2511 * @flags: flags for the property specified
2513 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2516 * See g_param_spec_internal() for details on property names.
2518 * Returns: (transfer full): a newly created parameter specification
2521 g_param_spec_param (const gchar *name,
2527 GParamSpecParam *pspec;
2529 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2531 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2539 G_PARAM_SPEC (pspec)->value_type = param_type;
2541 return G_PARAM_SPEC (pspec);
2545 * g_param_spec_boxed:
2546 * @name: canonical name of the property specified
2547 * @nick: (nullable): nick name for the property specified
2548 * @blurb: (nullable): description of the property specified
2549 * @boxed_type: %G_TYPE_BOXED derived type of this property
2550 * @flags: flags for the property specified
2552 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2555 * See g_param_spec_internal() for details on property names.
2557 * Returns: (transfer full): a newly created parameter specification
2560 g_param_spec_boxed (const gchar *name,
2566 GParamSpecBoxed *bspec;
2568 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2569 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2571 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2579 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2581 return G_PARAM_SPEC (bspec);
2585 * g_param_spec_pointer:
2586 * @name: canonical name of the property specified
2587 * @nick: (nullable): nick name for the property specified
2588 * @blurb: (nullable): description of the property specified
2589 * @flags: flags for the property specified
2591 * Creates a new #GParamSpecPointer instance specifying a pointer property.
2592 * Where possible, it is better to use g_param_spec_object() or
2593 * g_param_spec_boxed() to expose memory management information.
2595 * See g_param_spec_internal() for details on property names.
2597 * Returns: (transfer full): a newly created parameter specification
2600 g_param_spec_pointer (const gchar *name,
2605 GParamSpecPointer *pspec;
2607 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2615 return G_PARAM_SPEC (pspec);
2619 * g_param_spec_gtype:
2620 * @name: canonical name of the property specified
2621 * @nick: (nullable): nick name for the property specified
2622 * @blurb: (nullable): description of the property specified
2623 * @is_a_type: a #GType whose subtypes are allowed as values
2624 * of the property (use %G_TYPE_NONE for any type)
2625 * @flags: flags for the property specified
2627 * Creates a new #GParamSpecGType instance specifying a
2628 * %G_TYPE_GTYPE property.
2630 * See g_param_spec_internal() for details on property names.
2634 * Returns: (transfer full): a newly created parameter specification
2637 g_param_spec_gtype (const gchar *name,
2643 GParamSpecGType *tspec;
2645 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2653 tspec->is_a_type = is_a_type;
2655 return G_PARAM_SPEC (tspec);
2659 * g_param_spec_value_array: (skip)
2660 * @name: canonical name of the property specified
2661 * @nick: (nullable): nick name for the property specified
2662 * @blurb: (nullable): description of the property specified
2663 * @element_spec: a #GParamSpec describing the elements contained in
2664 * arrays of this property, may be %NULL
2665 * @flags: flags for the property specified
2667 * Creates a new #GParamSpecValueArray instance specifying a
2668 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2669 * %G_TYPE_BOXED type, as such, #GValue structures for this property
2670 * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2672 * See g_param_spec_internal() for details on property names.
2674 * Returns: a newly created parameter specification
2677 g_param_spec_value_array (const gchar *name,
2680 GParamSpec *element_spec,
2683 GParamSpecValueArray *aspec;
2685 g_return_val_if_fail (element_spec == NULL || G_IS_PARAM_SPEC (element_spec), NULL);
2687 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2697 aspec->element_spec = g_param_spec_ref (element_spec);
2698 g_param_spec_sink (element_spec);
2701 return G_PARAM_SPEC (aspec);
2705 * g_param_spec_object:
2706 * @name: canonical name of the property specified
2707 * @nick: (nullable): nick name for the property specified
2708 * @blurb: (nullable): description of the property specified
2709 * @object_type: %G_TYPE_OBJECT derived type of this property
2710 * @flags: flags for the property specified
2712 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2715 * See g_param_spec_internal() for details on property names.
2717 * Returns: (transfer full): a newly created parameter specification
2720 g_param_spec_object (const gchar *name,
2726 GParamSpecObject *ospec;
2728 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2730 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2738 G_PARAM_SPEC (ospec)->value_type = object_type;
2740 return G_PARAM_SPEC (ospec);
2744 * g_param_spec_override: (skip)
2745 * @name: the name of the property.
2746 * @overridden: The property that is being overridden
2748 * Creates a new property of type #GParamSpecOverride. This is used
2749 * to direct operations to another paramspec, and will not be directly
2750 * useful unless you are implementing a new base type similar to GObject.
2754 * Returns: the newly created #GParamSpec
2757 g_param_spec_override (const gchar *name,
2758 GParamSpec *overridden)
2762 g_return_val_if_fail (name != NULL, NULL);
2763 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2765 /* Dereference further redirections for property that was passed in
2769 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2771 overridden = indirect;
2776 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2782 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2783 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2789 * g_param_spec_variant:
2790 * @name: canonical name of the property specified
2791 * @nick: (nullable): nick name for the property specified
2792 * @blurb: (nullable): description of the property specified
2793 * @type: a #GVariantType
2794 * @default_value: (nullable) (transfer full): a #GVariant of type @type to
2795 * use as the default value, or %NULL
2796 * @flags: flags for the property specified
2798 * Creates a new #GParamSpecVariant instance specifying a #GVariant
2801 * If @default_value is floating, it is consumed.
2803 * See g_param_spec_internal() for details on property names.
2805 * Returns: (transfer full): the newly created #GParamSpec
2810 g_param_spec_variant (const gchar *name,
2813 const GVariantType *type,
2814 GVariant *default_value,
2817 GParamSpecVariant *vspec;
2819 g_return_val_if_fail (type != NULL, NULL);
2820 g_return_val_if_fail (default_value == NULL ||
2821 g_variant_is_of_type (default_value, type), NULL);
2823 vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2831 vspec->type = g_variant_type_copy (type);
2833 vspec->default_value = g_variant_ref_sink (default_value);
2835 return G_PARAM_SPEC (vspec);