Update German translation
[glib.git] / gobject / gparamspecs.c
blob9685ef4469a7f5a37b66ff17ad955051ae6e87d0
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, see <http://www.gnu.org/licenses/>.
20 * MT safe
23 #include "config.h"
25 #include <string.h>
27 #define GLIB_DISABLE_DEPRECATION_WARNINGS
29 #include "gparamspecs.h"
30 #include "gtype-private.h"
31 #include "gvaluecollector.h"
33 #include "gvaluearray.h"
36 /**
37 * SECTION:param_value_types
38 * @short_description: Standard Parameter and Value Types
39 * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
40 * @title: Parameters and Values
42 * #GValue provides an abstract container structure which can be
43 * copied, transformed and compared while holding a value of any
44 * (derived) type, which is registered as a #GType with a
45 * #GTypeValueTable in its #GTypeInfo structure. Parameter
46 * specifications for most value types can be created as #GParamSpec
47 * derived instances, to implement e.g. #GObject properties which
48 * operate on #GValue containers.
50 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
51 * characters can be letters, numbers or a '-'.
52 * All other characters are replaced by a '-' during construction.
56 #define G_FLOAT_EPSILON (1e-30)
57 #define G_DOUBLE_EPSILON (1e-90)
60 /* --- param spec functions --- */
61 static void
62 param_char_init (GParamSpec *pspec)
64 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
66 cspec->minimum = 0x7f;
67 cspec->maximum = 0x80;
68 cspec->default_value = 0;
71 static void
72 param_char_set_default (GParamSpec *pspec,
73 GValue *value)
75 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
78 static gboolean
79 param_char_validate (GParamSpec *pspec,
80 GValue *value)
82 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
83 gint oval = value->data[0].v_int;
85 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
87 return value->data[0].v_int != oval;
90 static void
91 param_uchar_init (GParamSpec *pspec)
93 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
95 uspec->minimum = 0;
96 uspec->maximum = 0xff;
97 uspec->default_value = 0;
100 static void
101 param_uchar_set_default (GParamSpec *pspec,
102 GValue *value)
104 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
107 static gboolean
108 param_uchar_validate (GParamSpec *pspec,
109 GValue *value)
111 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
112 guint oval = value->data[0].v_uint;
114 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
116 return value->data[0].v_uint != oval;
119 static void
120 param_boolean_set_default (GParamSpec *pspec,
121 GValue *value)
123 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
126 static gboolean
127 param_boolean_validate (GParamSpec *pspec,
128 GValue *value)
130 gint oval = value->data[0].v_int;
132 value->data[0].v_int = value->data[0].v_int != FALSE;
134 return value->data[0].v_int != oval;
137 static void
138 param_int_init (GParamSpec *pspec)
140 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
142 ispec->minimum = 0x7fffffff;
143 ispec->maximum = 0x80000000;
144 ispec->default_value = 0;
147 static void
148 param_int_set_default (GParamSpec *pspec,
149 GValue *value)
151 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
154 static gboolean
155 param_int_validate (GParamSpec *pspec,
156 GValue *value)
158 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
159 gint oval = value->data[0].v_int;
161 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
163 return value->data[0].v_int != oval;
166 static gint
167 param_int_values_cmp (GParamSpec *pspec,
168 const GValue *value1,
169 const GValue *value2)
171 if (value1->data[0].v_int < value2->data[0].v_int)
172 return -1;
173 else
174 return value1->data[0].v_int > value2->data[0].v_int;
177 static void
178 param_uint_init (GParamSpec *pspec)
180 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
182 uspec->minimum = 0;
183 uspec->maximum = 0xffffffff;
184 uspec->default_value = 0;
187 static void
188 param_uint_set_default (GParamSpec *pspec,
189 GValue *value)
191 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
194 static gboolean
195 param_uint_validate (GParamSpec *pspec,
196 GValue *value)
198 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
199 guint oval = value->data[0].v_uint;
201 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
203 return value->data[0].v_uint != oval;
206 static gint
207 param_uint_values_cmp (GParamSpec *pspec,
208 const GValue *value1,
209 const GValue *value2)
211 if (value1->data[0].v_uint < value2->data[0].v_uint)
212 return -1;
213 else
214 return value1->data[0].v_uint > value2->data[0].v_uint;
217 static void
218 param_long_init (GParamSpec *pspec)
220 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
222 #if SIZEOF_LONG == 4
223 lspec->minimum = 0x7fffffff;
224 lspec->maximum = 0x80000000;
225 #else /* SIZEOF_LONG != 4 (8) */
226 lspec->minimum = 0x7fffffffffffffff;
227 lspec->maximum = 0x8000000000000000;
228 #endif
229 lspec->default_value = 0;
232 static void
233 param_long_set_default (GParamSpec *pspec,
234 GValue *value)
236 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
239 static gboolean
240 param_long_validate (GParamSpec *pspec,
241 GValue *value)
243 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
244 glong oval = value->data[0].v_long;
246 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
248 return value->data[0].v_long != oval;
251 static gint
252 param_long_values_cmp (GParamSpec *pspec,
253 const GValue *value1,
254 const GValue *value2)
256 if (value1->data[0].v_long < value2->data[0].v_long)
257 return -1;
258 else
259 return value1->data[0].v_long > value2->data[0].v_long;
262 static void
263 param_ulong_init (GParamSpec *pspec)
265 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
267 uspec->minimum = 0;
268 #if SIZEOF_LONG == 4
269 uspec->maximum = 0xffffffff;
270 #else /* SIZEOF_LONG != 4 (8) */
271 uspec->maximum = 0xffffffffffffffff;
272 #endif
273 uspec->default_value = 0;
276 static void
277 param_ulong_set_default (GParamSpec *pspec,
278 GValue *value)
280 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
283 static gboolean
284 param_ulong_validate (GParamSpec *pspec,
285 GValue *value)
287 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
288 gulong oval = value->data[0].v_ulong;
290 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
292 return value->data[0].v_ulong != oval;
295 static gint
296 param_ulong_values_cmp (GParamSpec *pspec,
297 const GValue *value1,
298 const GValue *value2)
300 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
301 return -1;
302 else
303 return value1->data[0].v_ulong > value2->data[0].v_ulong;
306 static void
307 param_int64_init (GParamSpec *pspec)
309 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
311 lspec->minimum = G_MININT64;
312 lspec->maximum = G_MAXINT64;
313 lspec->default_value = 0;
316 static void
317 param_int64_set_default (GParamSpec *pspec,
318 GValue *value)
320 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
323 static gboolean
324 param_int64_validate (GParamSpec *pspec,
325 GValue *value)
327 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
328 gint64 oval = value->data[0].v_int64;
330 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
332 return value->data[0].v_int64 != oval;
335 static gint
336 param_int64_values_cmp (GParamSpec *pspec,
337 const GValue *value1,
338 const GValue *value2)
340 if (value1->data[0].v_int64 < value2->data[0].v_int64)
341 return -1;
342 else
343 return value1->data[0].v_int64 > value2->data[0].v_int64;
346 static void
347 param_uint64_init (GParamSpec *pspec)
349 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
351 uspec->minimum = 0;
352 uspec->maximum = G_MAXUINT64;
353 uspec->default_value = 0;
356 static void
357 param_uint64_set_default (GParamSpec *pspec,
358 GValue *value)
360 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
363 static gboolean
364 param_uint64_validate (GParamSpec *pspec,
365 GValue *value)
367 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
368 guint64 oval = value->data[0].v_uint64;
370 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
372 return value->data[0].v_uint64 != oval;
375 static gint
376 param_uint64_values_cmp (GParamSpec *pspec,
377 const GValue *value1,
378 const GValue *value2)
380 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
381 return -1;
382 else
383 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
386 static void
387 param_unichar_init (GParamSpec *pspec)
389 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
391 uspec->default_value = 0;
394 static void
395 param_unichar_set_default (GParamSpec *pspec,
396 GValue *value)
398 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
401 static gboolean
402 param_unichar_validate (GParamSpec *pspec,
403 GValue *value)
405 gunichar oval = value->data[0].v_uint;
406 gboolean changed = FALSE;
408 if (!g_unichar_validate (oval))
410 value->data[0].v_uint = 0;
411 changed = TRUE;
414 return changed;
417 static gint
418 param_unichar_values_cmp (GParamSpec *pspec,
419 const GValue *value1,
420 const GValue *value2)
422 if (value1->data[0].v_uint < value2->data[0].v_uint)
423 return -1;
424 else
425 return value1->data[0].v_uint > value2->data[0].v_uint;
428 static void
429 param_enum_init (GParamSpec *pspec)
431 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
433 espec->enum_class = NULL;
434 espec->default_value = 0;
437 static void
438 param_enum_finalize (GParamSpec *pspec)
440 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
441 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
443 if (espec->enum_class)
445 g_type_class_unref (espec->enum_class);
446 espec->enum_class = NULL;
449 parent_class->finalize (pspec);
452 static void
453 param_enum_set_default (GParamSpec *pspec,
454 GValue *value)
456 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
459 static gboolean
460 param_enum_validate (GParamSpec *pspec,
461 GValue *value)
463 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
464 glong oval = value->data[0].v_long;
466 if (!espec->enum_class ||
467 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
468 value->data[0].v_long = espec->default_value;
470 return value->data[0].v_long != oval;
473 static void
474 param_flags_init (GParamSpec *pspec)
476 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
478 fspec->flags_class = NULL;
479 fspec->default_value = 0;
482 static void
483 param_flags_finalize (GParamSpec *pspec)
485 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
486 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
488 if (fspec->flags_class)
490 g_type_class_unref (fspec->flags_class);
491 fspec->flags_class = NULL;
494 parent_class->finalize (pspec);
497 static void
498 param_flags_set_default (GParamSpec *pspec,
499 GValue *value)
501 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
504 static gboolean
505 param_flags_validate (GParamSpec *pspec,
506 GValue *value)
508 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
509 gulong oval = value->data[0].v_ulong;
511 if (fspec->flags_class)
512 value->data[0].v_ulong &= fspec->flags_class->mask;
513 else
514 value->data[0].v_ulong = fspec->default_value;
516 return value->data[0].v_ulong != oval;
519 static void
520 param_float_init (GParamSpec *pspec)
522 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
524 fspec->minimum = -G_MAXFLOAT;
525 fspec->maximum = G_MAXFLOAT;
526 fspec->default_value = 0;
527 fspec->epsilon = G_FLOAT_EPSILON;
530 static void
531 param_float_set_default (GParamSpec *pspec,
532 GValue *value)
534 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
537 static gboolean
538 param_float_validate (GParamSpec *pspec,
539 GValue *value)
541 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
542 gfloat oval = value->data[0].v_float;
544 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
546 return value->data[0].v_float != oval;
549 static gint
550 param_float_values_cmp (GParamSpec *pspec,
551 const GValue *value1,
552 const GValue *value2)
554 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
556 if (value1->data[0].v_float < value2->data[0].v_float)
557 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
558 else
559 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
562 static void
563 param_double_init (GParamSpec *pspec)
565 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
567 dspec->minimum = -G_MAXDOUBLE;
568 dspec->maximum = G_MAXDOUBLE;
569 dspec->default_value = 0;
570 dspec->epsilon = G_DOUBLE_EPSILON;
573 static void
574 param_double_set_default (GParamSpec *pspec,
575 GValue *value)
577 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
580 static gboolean
581 param_double_validate (GParamSpec *pspec,
582 GValue *value)
584 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
585 gdouble oval = value->data[0].v_double;
587 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
589 return value->data[0].v_double != oval;
592 static gint
593 param_double_values_cmp (GParamSpec *pspec,
594 const GValue *value1,
595 const GValue *value2)
597 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
599 if (value1->data[0].v_double < value2->data[0].v_double)
600 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
601 else
602 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
605 static void
606 param_string_init (GParamSpec *pspec)
608 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
610 sspec->default_value = NULL;
611 sspec->cset_first = NULL;
612 sspec->cset_nth = NULL;
613 sspec->substitutor = '_';
614 sspec->null_fold_if_empty = FALSE;
615 sspec->ensure_non_null = FALSE;
618 static void
619 param_string_finalize (GParamSpec *pspec)
621 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
622 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
624 g_free (sspec->default_value);
625 g_free (sspec->cset_first);
626 g_free (sspec->cset_nth);
627 sspec->default_value = NULL;
628 sspec->cset_first = NULL;
629 sspec->cset_nth = NULL;
631 parent_class->finalize (pspec);
634 static void
635 param_string_set_default (GParamSpec *pspec,
636 GValue *value)
638 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
641 static gboolean
642 param_string_validate (GParamSpec *pspec,
643 GValue *value)
645 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
646 gchar *string = value->data[0].v_pointer;
647 guint changed = 0;
649 if (string && string[0])
651 gchar *s;
653 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
655 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
657 value->data[0].v_pointer = g_strdup (string);
658 string = value->data[0].v_pointer;
659 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
661 string[0] = sspec->substitutor;
662 changed++;
664 if (sspec->cset_nth)
665 for (s = string + 1; *s; s++)
666 if (!strchr (sspec->cset_nth, *s))
668 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
670 value->data[0].v_pointer = g_strdup (string);
671 s = (gchar*) value->data[0].v_pointer + (s - string);
672 string = value->data[0].v_pointer;
673 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
675 *s = sspec->substitutor;
676 changed++;
679 if (sspec->null_fold_if_empty && string && string[0] == 0)
681 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
682 g_free (value->data[0].v_pointer);
683 else
684 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
685 value->data[0].v_pointer = NULL;
686 changed++;
687 string = value->data[0].v_pointer;
689 if (sspec->ensure_non_null && !string)
691 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
692 value->data[0].v_pointer = g_strdup ("");
693 changed++;
694 string = value->data[0].v_pointer;
697 return changed;
700 static gint
701 param_string_values_cmp (GParamSpec *pspec,
702 const GValue *value1,
703 const GValue *value2)
705 if (!value1->data[0].v_pointer)
706 return value2->data[0].v_pointer != NULL ? -1 : 0;
707 else if (!value2->data[0].v_pointer)
708 return value1->data[0].v_pointer != NULL;
709 else
710 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
713 static void
714 param_param_init (GParamSpec *pspec)
716 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
719 static void
720 param_param_set_default (GParamSpec *pspec,
721 GValue *value)
723 value->data[0].v_pointer = NULL;
726 static gboolean
727 param_param_validate (GParamSpec *pspec,
728 GValue *value)
730 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
731 GParamSpec *param = value->data[0].v_pointer;
732 guint changed = 0;
734 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
736 g_param_spec_unref (param);
737 value->data[0].v_pointer = NULL;
738 changed++;
741 return changed;
744 static void
745 param_boxed_init (GParamSpec *pspec)
747 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
750 static void
751 param_boxed_set_default (GParamSpec *pspec,
752 GValue *value)
754 value->data[0].v_pointer = NULL;
757 static gboolean
758 param_boxed_validate (GParamSpec *pspec,
759 GValue *value)
761 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
762 guint changed = 0;
764 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
766 return changed;
769 static gint
770 param_boxed_values_cmp (GParamSpec *pspec,
771 const GValue *value1,
772 const GValue *value2)
774 guint8 *p1 = value1->data[0].v_pointer;
775 guint8 *p2 = value2->data[0].v_pointer;
777 /* not much to compare here, try to at least provide stable lesser/greater result */
779 return p1 < p2 ? -1 : p1 > p2;
782 static void
783 param_pointer_init (GParamSpec *pspec)
785 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
788 static void
789 param_pointer_set_default (GParamSpec *pspec,
790 GValue *value)
792 value->data[0].v_pointer = NULL;
795 static gboolean
796 param_pointer_validate (GParamSpec *pspec,
797 GValue *value)
799 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
800 guint changed = 0;
802 return changed;
805 static gint
806 param_pointer_values_cmp (GParamSpec *pspec,
807 const GValue *value1,
808 const GValue *value2)
810 guint8 *p1 = value1->data[0].v_pointer;
811 guint8 *p2 = value2->data[0].v_pointer;
813 /* not much to compare here, try to at least provide stable lesser/greater result */
815 return p1 < p2 ? -1 : p1 > p2;
818 static void
819 param_value_array_init (GParamSpec *pspec)
821 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
823 aspec->element_spec = NULL;
824 aspec->fixed_n_elements = 0; /* disable */
827 static inline guint
828 value_array_ensure_size (GValueArray *value_array,
829 guint fixed_n_elements)
831 guint changed = 0;
833 if (fixed_n_elements)
835 while (value_array->n_values < fixed_n_elements)
837 g_value_array_append (value_array, NULL);
838 changed++;
840 while (value_array->n_values > fixed_n_elements)
842 g_value_array_remove (value_array, value_array->n_values - 1);
843 changed++;
846 return changed;
849 static void
850 param_value_array_finalize (GParamSpec *pspec)
852 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
853 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
855 if (aspec->element_spec)
857 g_param_spec_unref (aspec->element_spec);
858 aspec->element_spec = NULL;
861 parent_class->finalize (pspec);
864 static void
865 param_value_array_set_default (GParamSpec *pspec,
866 GValue *value)
868 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
870 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
871 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
873 if (value->data[0].v_pointer)
875 /* g_value_reset (value); already done */
876 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
880 static gboolean
881 param_value_array_validate (GParamSpec *pspec,
882 GValue *value)
884 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
885 GValueArray *value_array = value->data[0].v_pointer;
886 guint changed = 0;
888 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
889 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
891 if (value->data[0].v_pointer)
893 /* ensure array size validity */
894 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
896 /* ensure array values validity against a present element spec */
897 if (aspec->element_spec)
899 GParamSpec *element_spec = aspec->element_spec;
900 guint i;
902 for (i = 0; i < value_array->n_values; i++)
904 GValue *element = value_array->values + i;
906 /* need to fixup value type, or ensure that the array value is initialized at all */
907 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
909 if (G_VALUE_TYPE (element) != 0)
910 g_value_unset (element);
911 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
912 g_param_value_set_default (element_spec, element);
913 changed++;
915 /* validate array value against element_spec */
916 changed += g_param_value_validate (element_spec, element);
921 return changed;
924 static gint
925 param_value_array_values_cmp (GParamSpec *pspec,
926 const GValue *value1,
927 const GValue *value2)
929 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
930 GValueArray *value_array1 = value1->data[0].v_pointer;
931 GValueArray *value_array2 = value2->data[0].v_pointer;
933 if (!value_array1 || !value_array2)
934 return value_array2 ? -1 : value_array1 != value_array2;
936 if (value_array1->n_values != value_array2->n_values)
937 return value_array1->n_values < value_array2->n_values ? -1 : 1;
938 else if (!aspec->element_spec)
940 /* we need an element specification for comparisons, so there's not much
941 * to compare here, try to at least provide stable lesser/greater result
943 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
945 else /* value_array1->n_values == value_array2->n_values */
947 guint i;
949 for (i = 0; i < value_array1->n_values; i++)
951 GValue *element1 = value_array1->values + i;
952 GValue *element2 = value_array2->values + i;
953 gint cmp;
955 /* need corresponding element types, provide stable result otherwise */
956 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
957 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
958 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
959 if (cmp)
960 return cmp;
962 return 0;
966 static void
967 param_object_init (GParamSpec *pspec)
969 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
972 static void
973 param_object_set_default (GParamSpec *pspec,
974 GValue *value)
976 value->data[0].v_pointer = NULL;
979 static gboolean
980 param_object_validate (GParamSpec *pspec,
981 GValue *value)
983 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
984 GObject *object = value->data[0].v_pointer;
985 guint changed = 0;
987 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
989 g_object_unref (object);
990 value->data[0].v_pointer = NULL;
991 changed++;
994 return changed;
997 static gint
998 param_object_values_cmp (GParamSpec *pspec,
999 const GValue *value1,
1000 const GValue *value2)
1002 guint8 *p1 = value1->data[0].v_pointer;
1003 guint8 *p2 = value2->data[0].v_pointer;
1005 /* not much to compare here, try to at least provide stable lesser/greater result */
1007 return p1 < p2 ? -1 : p1 > p2;
1010 static void
1011 param_override_init (GParamSpec *pspec)
1013 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1016 static void
1017 param_override_finalize (GParamSpec *pspec)
1019 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1020 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1022 if (ospec->overridden)
1024 g_param_spec_unref (ospec->overridden);
1025 ospec->overridden = NULL;
1028 parent_class->finalize (pspec);
1031 static void
1032 param_override_set_default (GParamSpec *pspec,
1033 GValue *value)
1035 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1037 g_param_value_set_default (ospec->overridden, value);
1040 static gboolean
1041 param_override_validate (GParamSpec *pspec,
1042 GValue *value)
1044 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1046 return g_param_value_validate (ospec->overridden, value);
1049 static gint
1050 param_override_values_cmp (GParamSpec *pspec,
1051 const GValue *value1,
1052 const GValue *value2)
1054 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1056 return g_param_values_cmp (ospec->overridden, value1, value2);
1059 static void
1060 param_gtype_init (GParamSpec *pspec)
1064 static void
1065 param_gtype_set_default (GParamSpec *pspec,
1066 GValue *value)
1068 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1070 value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type);
1073 static gboolean
1074 param_gtype_validate (GParamSpec *pspec,
1075 GValue *value)
1077 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1078 GType gtype = GPOINTER_TO_SIZE (value->data[0].v_pointer);
1079 guint changed = 0;
1081 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1083 value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type);
1084 changed++;
1087 return changed;
1090 static gint
1091 param_gtype_values_cmp (GParamSpec *pspec,
1092 const GValue *value1,
1093 const GValue *value2)
1095 GType p1 = GPOINTER_TO_SIZE (value1->data[0].v_pointer);
1096 GType p2 = GPOINTER_TO_SIZE (value2->data[0].v_pointer);
1098 /* not much to compare here, try to at least provide stable lesser/greater result */
1100 return p1 < p2 ? -1 : p1 > p2;
1103 static void
1104 param_variant_init (GParamSpec *pspec)
1106 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1108 vspec->type = NULL;
1109 vspec->default_value = NULL;
1112 static void
1113 param_variant_finalize (GParamSpec *pspec)
1115 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1116 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1118 if (vspec->default_value)
1119 g_variant_unref (vspec->default_value);
1120 g_variant_type_free (vspec->type);
1122 parent_class->finalize (pspec);
1125 static void
1126 param_variant_set_default (GParamSpec *pspec,
1127 GValue *value)
1129 value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1130 value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1133 static gboolean
1134 param_variant_validate (GParamSpec *pspec,
1135 GValue *value)
1137 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1138 GVariant *variant = value->data[0].v_pointer;
1140 if ((variant == NULL && vspec->default_value != NULL) ||
1141 (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1143 g_param_value_set_default (pspec, value);
1144 return TRUE;
1147 return FALSE;
1150 static gint
1151 param_variant_values_cmp (GParamSpec *pspec,
1152 const GValue *value1,
1153 const GValue *value2)
1155 GVariant *v1 = value1->data[0].v_pointer;
1156 GVariant *v2 = value2->data[0].v_pointer;
1158 return v1 < v2 ? -1 : v2 > v1;
1161 /* --- type initialization --- */
1162 GType *g_param_spec_types = NULL;
1164 void
1165 _g_param_spec_types_init (void)
1167 const guint n_types = 23;
1168 GType type, *spec_types, *spec_types_bound;
1170 g_param_spec_types = g_new0 (GType, n_types);
1171 spec_types = g_param_spec_types;
1172 spec_types_bound = g_param_spec_types + n_types;
1174 /* G_TYPE_PARAM_CHAR
1177 const GParamSpecTypeInfo pspec_info = {
1178 sizeof (GParamSpecChar), /* instance_size */
1179 16, /* n_preallocs */
1180 param_char_init, /* instance_init */
1181 G_TYPE_CHAR, /* value_type */
1182 NULL, /* finalize */
1183 param_char_set_default, /* value_set_default */
1184 param_char_validate, /* value_validate */
1185 param_int_values_cmp, /* values_cmp */
1187 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1188 *spec_types++ = type;
1189 g_assert (type == G_TYPE_PARAM_CHAR);
1192 /* G_TYPE_PARAM_UCHAR
1195 const GParamSpecTypeInfo pspec_info = {
1196 sizeof (GParamSpecUChar), /* instance_size */
1197 16, /* n_preallocs */
1198 param_uchar_init, /* instance_init */
1199 G_TYPE_UCHAR, /* value_type */
1200 NULL, /* finalize */
1201 param_uchar_set_default, /* value_set_default */
1202 param_uchar_validate, /* value_validate */
1203 param_uint_values_cmp, /* values_cmp */
1205 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1206 *spec_types++ = type;
1207 g_assert (type == G_TYPE_PARAM_UCHAR);
1210 /* G_TYPE_PARAM_BOOLEAN
1213 const GParamSpecTypeInfo pspec_info = {
1214 sizeof (GParamSpecBoolean), /* instance_size */
1215 16, /* n_preallocs */
1216 NULL, /* instance_init */
1217 G_TYPE_BOOLEAN, /* value_type */
1218 NULL, /* finalize */
1219 param_boolean_set_default, /* value_set_default */
1220 param_boolean_validate, /* value_validate */
1221 param_int_values_cmp, /* values_cmp */
1223 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1224 *spec_types++ = type;
1225 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1228 /* G_TYPE_PARAM_INT
1231 const GParamSpecTypeInfo pspec_info = {
1232 sizeof (GParamSpecInt), /* instance_size */
1233 16, /* n_preallocs */
1234 param_int_init, /* instance_init */
1235 G_TYPE_INT, /* value_type */
1236 NULL, /* finalize */
1237 param_int_set_default, /* value_set_default */
1238 param_int_validate, /* value_validate */
1239 param_int_values_cmp, /* values_cmp */
1241 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1242 *spec_types++ = type;
1243 g_assert (type == G_TYPE_PARAM_INT);
1246 /* G_TYPE_PARAM_UINT
1249 const GParamSpecTypeInfo pspec_info = {
1250 sizeof (GParamSpecUInt), /* instance_size */
1251 16, /* n_preallocs */
1252 param_uint_init, /* instance_init */
1253 G_TYPE_UINT, /* value_type */
1254 NULL, /* finalize */
1255 param_uint_set_default, /* value_set_default */
1256 param_uint_validate, /* value_validate */
1257 param_uint_values_cmp, /* values_cmp */
1259 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1260 *spec_types++ = type;
1261 g_assert (type == G_TYPE_PARAM_UINT);
1264 /* G_TYPE_PARAM_LONG
1267 const GParamSpecTypeInfo pspec_info = {
1268 sizeof (GParamSpecLong), /* instance_size */
1269 16, /* n_preallocs */
1270 param_long_init, /* instance_init */
1271 G_TYPE_LONG, /* value_type */
1272 NULL, /* finalize */
1273 param_long_set_default, /* value_set_default */
1274 param_long_validate, /* value_validate */
1275 param_long_values_cmp, /* values_cmp */
1277 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1278 *spec_types++ = type;
1279 g_assert (type == G_TYPE_PARAM_LONG);
1282 /* G_TYPE_PARAM_ULONG
1285 const GParamSpecTypeInfo pspec_info = {
1286 sizeof (GParamSpecULong), /* instance_size */
1287 16, /* n_preallocs */
1288 param_ulong_init, /* instance_init */
1289 G_TYPE_ULONG, /* value_type */
1290 NULL, /* finalize */
1291 param_ulong_set_default, /* value_set_default */
1292 param_ulong_validate, /* value_validate */
1293 param_ulong_values_cmp, /* values_cmp */
1295 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1296 *spec_types++ = type;
1297 g_assert (type == G_TYPE_PARAM_ULONG);
1300 /* G_TYPE_PARAM_INT64
1303 const GParamSpecTypeInfo pspec_info = {
1304 sizeof (GParamSpecInt64), /* instance_size */
1305 16, /* n_preallocs */
1306 param_int64_init, /* instance_init */
1307 G_TYPE_INT64, /* value_type */
1308 NULL, /* finalize */
1309 param_int64_set_default, /* value_set_default */
1310 param_int64_validate, /* value_validate */
1311 param_int64_values_cmp, /* values_cmp */
1313 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1314 *spec_types++ = type;
1315 g_assert (type == G_TYPE_PARAM_INT64);
1318 /* G_TYPE_PARAM_UINT64
1321 const GParamSpecTypeInfo pspec_info = {
1322 sizeof (GParamSpecUInt64), /* instance_size */
1323 16, /* n_preallocs */
1324 param_uint64_init, /* instance_init */
1325 G_TYPE_UINT64, /* value_type */
1326 NULL, /* finalize */
1327 param_uint64_set_default, /* value_set_default */
1328 param_uint64_validate, /* value_validate */
1329 param_uint64_values_cmp, /* values_cmp */
1331 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1332 *spec_types++ = type;
1333 g_assert (type == G_TYPE_PARAM_UINT64);
1336 /* G_TYPE_PARAM_UNICHAR
1339 const GParamSpecTypeInfo pspec_info = {
1340 sizeof (GParamSpecUnichar), /* instance_size */
1341 16, /* n_preallocs */
1342 param_unichar_init, /* instance_init */
1343 G_TYPE_UINT, /* value_type */
1344 NULL, /* finalize */
1345 param_unichar_set_default, /* value_set_default */
1346 param_unichar_validate, /* value_validate */
1347 param_unichar_values_cmp, /* values_cmp */
1349 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1350 *spec_types++ = type;
1351 g_assert (type == G_TYPE_PARAM_UNICHAR);
1354 /* G_TYPE_PARAM_ENUM
1357 const GParamSpecTypeInfo pspec_info = {
1358 sizeof (GParamSpecEnum), /* instance_size */
1359 16, /* n_preallocs */
1360 param_enum_init, /* instance_init */
1361 G_TYPE_ENUM, /* value_type */
1362 param_enum_finalize, /* finalize */
1363 param_enum_set_default, /* value_set_default */
1364 param_enum_validate, /* value_validate */
1365 param_long_values_cmp, /* values_cmp */
1367 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1368 *spec_types++ = type;
1369 g_assert (type == G_TYPE_PARAM_ENUM);
1372 /* G_TYPE_PARAM_FLAGS
1375 const GParamSpecTypeInfo pspec_info = {
1376 sizeof (GParamSpecFlags), /* instance_size */
1377 16, /* n_preallocs */
1378 param_flags_init, /* instance_init */
1379 G_TYPE_FLAGS, /* value_type */
1380 param_flags_finalize, /* finalize */
1381 param_flags_set_default, /* value_set_default */
1382 param_flags_validate, /* value_validate */
1383 param_ulong_values_cmp, /* values_cmp */
1385 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1386 *spec_types++ = type;
1387 g_assert (type == G_TYPE_PARAM_FLAGS);
1390 /* G_TYPE_PARAM_FLOAT
1393 const GParamSpecTypeInfo pspec_info = {
1394 sizeof (GParamSpecFloat), /* instance_size */
1395 16, /* n_preallocs */
1396 param_float_init, /* instance_init */
1397 G_TYPE_FLOAT, /* value_type */
1398 NULL, /* finalize */
1399 param_float_set_default, /* value_set_default */
1400 param_float_validate, /* value_validate */
1401 param_float_values_cmp, /* values_cmp */
1403 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1404 *spec_types++ = type;
1405 g_assert (type == G_TYPE_PARAM_FLOAT);
1408 /* G_TYPE_PARAM_DOUBLE
1411 const GParamSpecTypeInfo pspec_info = {
1412 sizeof (GParamSpecDouble), /* instance_size */
1413 16, /* n_preallocs */
1414 param_double_init, /* instance_init */
1415 G_TYPE_DOUBLE, /* value_type */
1416 NULL, /* finalize */
1417 param_double_set_default, /* value_set_default */
1418 param_double_validate, /* value_validate */
1419 param_double_values_cmp, /* values_cmp */
1421 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1422 *spec_types++ = type;
1423 g_assert (type == G_TYPE_PARAM_DOUBLE);
1426 /* G_TYPE_PARAM_STRING
1429 const GParamSpecTypeInfo pspec_info = {
1430 sizeof (GParamSpecString), /* instance_size */
1431 16, /* n_preallocs */
1432 param_string_init, /* instance_init */
1433 G_TYPE_STRING, /* value_type */
1434 param_string_finalize, /* finalize */
1435 param_string_set_default, /* value_set_default */
1436 param_string_validate, /* value_validate */
1437 param_string_values_cmp, /* values_cmp */
1439 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1440 *spec_types++ = type;
1441 g_assert (type == G_TYPE_PARAM_STRING);
1444 /* G_TYPE_PARAM_PARAM
1447 const GParamSpecTypeInfo pspec_info = {
1448 sizeof (GParamSpecParam), /* instance_size */
1449 16, /* n_preallocs */
1450 param_param_init, /* instance_init */
1451 G_TYPE_PARAM, /* value_type */
1452 NULL, /* finalize */
1453 param_param_set_default, /* value_set_default */
1454 param_param_validate, /* value_validate */
1455 param_pointer_values_cmp, /* values_cmp */
1457 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1458 *spec_types++ = type;
1459 g_assert (type == G_TYPE_PARAM_PARAM);
1462 /* G_TYPE_PARAM_BOXED
1465 const GParamSpecTypeInfo pspec_info = {
1466 sizeof (GParamSpecBoxed), /* instance_size */
1467 4, /* n_preallocs */
1468 param_boxed_init, /* instance_init */
1469 G_TYPE_BOXED, /* value_type */
1470 NULL, /* finalize */
1471 param_boxed_set_default, /* value_set_default */
1472 param_boxed_validate, /* value_validate */
1473 param_boxed_values_cmp, /* values_cmp */
1475 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1476 *spec_types++ = type;
1477 g_assert (type == G_TYPE_PARAM_BOXED);
1480 /* G_TYPE_PARAM_POINTER
1483 const GParamSpecTypeInfo pspec_info = {
1484 sizeof (GParamSpecPointer), /* instance_size */
1485 0, /* n_preallocs */
1486 param_pointer_init, /* instance_init */
1487 G_TYPE_POINTER, /* value_type */
1488 NULL, /* finalize */
1489 param_pointer_set_default, /* value_set_default */
1490 param_pointer_validate, /* value_validate */
1491 param_pointer_values_cmp, /* values_cmp */
1493 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1494 *spec_types++ = type;
1495 g_assert (type == G_TYPE_PARAM_POINTER);
1498 /* G_TYPE_PARAM_VALUE_ARRAY
1501 /* const */ GParamSpecTypeInfo pspec_info = {
1502 sizeof (GParamSpecValueArray), /* instance_size */
1503 0, /* n_preallocs */
1504 param_value_array_init, /* instance_init */
1505 0xdeadbeef, /* value_type, assigned further down */
1506 param_value_array_finalize, /* finalize */
1507 param_value_array_set_default, /* value_set_default */
1508 param_value_array_validate, /* value_validate */
1509 param_value_array_values_cmp, /* values_cmp */
1511 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1512 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1513 *spec_types++ = type;
1514 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1517 /* G_TYPE_PARAM_OBJECT
1520 const GParamSpecTypeInfo pspec_info = {
1521 sizeof (GParamSpecObject), /* instance_size */
1522 16, /* n_preallocs */
1523 param_object_init, /* instance_init */
1524 G_TYPE_OBJECT, /* value_type */
1525 NULL, /* finalize */
1526 param_object_set_default, /* value_set_default */
1527 param_object_validate, /* value_validate */
1528 param_object_values_cmp, /* values_cmp */
1530 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1531 *spec_types++ = type;
1532 g_assert (type == G_TYPE_PARAM_OBJECT);
1535 /* G_TYPE_PARAM_OVERRIDE
1538 const GParamSpecTypeInfo pspec_info = {
1539 sizeof (GParamSpecOverride), /* instance_size */
1540 16, /* n_preallocs */
1541 param_override_init, /* instance_init */
1542 G_TYPE_NONE, /* value_type */
1543 param_override_finalize, /* finalize */
1544 param_override_set_default, /* value_set_default */
1545 param_override_validate, /* value_validate */
1546 param_override_values_cmp, /* values_cmp */
1548 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1549 *spec_types++ = type;
1550 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1553 /* G_TYPE_PARAM_GTYPE
1556 GParamSpecTypeInfo pspec_info = {
1557 sizeof (GParamSpecGType), /* instance_size */
1558 0, /* n_preallocs */
1559 param_gtype_init, /* instance_init */
1560 0xdeadbeef, /* value_type, assigned further down */
1561 NULL, /* finalize */
1562 param_gtype_set_default, /* value_set_default */
1563 param_gtype_validate, /* value_validate */
1564 param_gtype_values_cmp, /* values_cmp */
1566 pspec_info.value_type = G_TYPE_GTYPE;
1567 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1568 *spec_types++ = type;
1569 g_assert (type == G_TYPE_PARAM_GTYPE);
1572 /* G_TYPE_PARAM_VARIANT
1575 const GParamSpecTypeInfo pspec_info = {
1576 sizeof (GParamSpecVariant), /* instance_size */
1577 0, /* n_preallocs */
1578 param_variant_init, /* instance_init */
1579 G_TYPE_VARIANT, /* value_type */
1580 param_variant_finalize, /* finalize */
1581 param_variant_set_default, /* value_set_default */
1582 param_variant_validate, /* value_validate */
1583 param_variant_values_cmp, /* values_cmp */
1585 type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1586 *spec_types++ = type;
1587 g_assert (type == G_TYPE_PARAM_VARIANT);
1590 g_assert (spec_types == spec_types_bound);
1593 /* --- GParamSpec initialization --- */
1596 * g_param_spec_char:
1597 * @name: canonical name of the property specified
1598 * @nick: nick name for the property specified
1599 * @blurb: description of the property specified
1600 * @minimum: minimum value for the property specified
1601 * @maximum: maximum value for the property specified
1602 * @default_value: default value for the property specified
1603 * @flags: flags for the property specified
1605 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1607 * Returns: (transfer full): a newly created parameter specification
1609 GParamSpec*
1610 g_param_spec_char (const gchar *name,
1611 const gchar *nick,
1612 const gchar *blurb,
1613 gint8 minimum,
1614 gint8 maximum,
1615 gint8 default_value,
1616 GParamFlags flags)
1618 GParamSpecChar *cspec;
1620 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1622 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1623 name,
1624 nick,
1625 blurb,
1626 flags);
1627 if (cspec == NULL)
1628 return NULL;
1630 cspec->minimum = minimum;
1631 cspec->maximum = maximum;
1632 cspec->default_value = default_value;
1634 return G_PARAM_SPEC (cspec);
1638 * g_param_spec_uchar:
1639 * @name: canonical name of the property specified
1640 * @nick: nick name for the property specified
1641 * @blurb: description of the property specified
1642 * @minimum: minimum value for the property specified
1643 * @maximum: maximum value for the property specified
1644 * @default_value: default value for the property specified
1645 * @flags: flags for the property specified
1647 * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1649 * Returns: (transfer full): a newly created parameter specification
1651 GParamSpec*
1652 g_param_spec_uchar (const gchar *name,
1653 const gchar *nick,
1654 const gchar *blurb,
1655 guint8 minimum,
1656 guint8 maximum,
1657 guint8 default_value,
1658 GParamFlags flags)
1660 GParamSpecUChar *uspec;
1662 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1664 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1665 name,
1666 nick,
1667 blurb,
1668 flags);
1669 if (uspec == NULL)
1670 return NULL;
1672 uspec->minimum = minimum;
1673 uspec->maximum = maximum;
1674 uspec->default_value = default_value;
1676 return G_PARAM_SPEC (uspec);
1680 * g_param_spec_boolean:
1681 * @name: canonical name of the property specified
1682 * @nick: nick name for the property specified
1683 * @blurb: description of the property specified
1684 * @default_value: default value for the property specified
1685 * @flags: flags for the property specified
1687 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1688 * property. In many cases, it may be more appropriate to use an enum with
1689 * g_param_spec_enum(), both to improve code clarity by using explicitly named
1690 * values, and to allow for more values to be added in future without breaking
1691 * API.
1693 * See g_param_spec_internal() for details on property names.
1695 * Returns: (transfer full): a newly created parameter specification
1697 GParamSpec*
1698 g_param_spec_boolean (const gchar *name,
1699 const gchar *nick,
1700 const gchar *blurb,
1701 gboolean default_value,
1702 GParamFlags flags)
1704 GParamSpecBoolean *bspec;
1706 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1708 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1709 name,
1710 nick,
1711 blurb,
1712 flags);
1713 if (bspec == NULL)
1714 return NULL;
1716 bspec->default_value = default_value;
1718 return G_PARAM_SPEC (bspec);
1722 * g_param_spec_int:
1723 * @name: canonical name of the property specified
1724 * @nick: nick name for the property specified
1725 * @blurb: description of the property specified
1726 * @minimum: minimum value for the property specified
1727 * @maximum: maximum value for the property specified
1728 * @default_value: default value for the property specified
1729 * @flags: flags for the property specified
1731 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1733 * See g_param_spec_internal() for details on property names.
1735 * Returns: (transfer full): a newly created parameter specification
1737 GParamSpec*
1738 g_param_spec_int (const gchar *name,
1739 const gchar *nick,
1740 const gchar *blurb,
1741 gint minimum,
1742 gint maximum,
1743 gint default_value,
1744 GParamFlags flags)
1746 GParamSpecInt *ispec;
1748 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1750 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1751 name,
1752 nick,
1753 blurb,
1754 flags);
1755 if (ispec == NULL)
1756 return NULL;
1758 ispec->minimum = minimum;
1759 ispec->maximum = maximum;
1760 ispec->default_value = default_value;
1762 return G_PARAM_SPEC (ispec);
1766 * g_param_spec_uint:
1767 * @name: canonical name of the property specified
1768 * @nick: nick name for the property specified
1769 * @blurb: description of the property specified
1770 * @minimum: minimum value for the property specified
1771 * @maximum: maximum value for the property specified
1772 * @default_value: default value for the property specified
1773 * @flags: flags for the property specified
1775 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1777 * See g_param_spec_internal() for details on property names.
1779 * Returns: (transfer full): a newly created parameter specification
1781 GParamSpec*
1782 g_param_spec_uint (const gchar *name,
1783 const gchar *nick,
1784 const gchar *blurb,
1785 guint minimum,
1786 guint maximum,
1787 guint default_value,
1788 GParamFlags flags)
1790 GParamSpecUInt *uspec;
1792 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1794 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1795 name,
1796 nick,
1797 blurb,
1798 flags);
1799 if (uspec == NULL)
1800 return NULL;
1802 uspec->minimum = minimum;
1803 uspec->maximum = maximum;
1804 uspec->default_value = default_value;
1806 return G_PARAM_SPEC (uspec);
1810 * g_param_spec_long:
1811 * @name: canonical name of the property specified
1812 * @nick: nick name for the property specified
1813 * @blurb: description of the property specified
1814 * @minimum: minimum value for the property specified
1815 * @maximum: maximum value for the property specified
1816 * @default_value: default value for the property specified
1817 * @flags: flags for the property specified
1819 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1821 * See g_param_spec_internal() for details on property names.
1823 * Returns: (transfer full): a newly created parameter specification
1825 GParamSpec*
1826 g_param_spec_long (const gchar *name,
1827 const gchar *nick,
1828 const gchar *blurb,
1829 glong minimum,
1830 glong maximum,
1831 glong default_value,
1832 GParamFlags flags)
1834 GParamSpecLong *lspec;
1836 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1838 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1839 name,
1840 nick,
1841 blurb,
1842 flags);
1843 if (lspec == NULL)
1844 return NULL;
1846 lspec->minimum = minimum;
1847 lspec->maximum = maximum;
1848 lspec->default_value = default_value;
1850 return G_PARAM_SPEC (lspec);
1854 * g_param_spec_ulong:
1855 * @name: canonical name of the property specified
1856 * @nick: nick name for the property specified
1857 * @blurb: description of the property specified
1858 * @minimum: minimum value for the property specified
1859 * @maximum: maximum value for the property specified
1860 * @default_value: default value for the property specified
1861 * @flags: flags for the property specified
1863 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
1864 * property.
1866 * See g_param_spec_internal() for details on property names.
1868 * Returns: (transfer full): a newly created parameter specification
1870 GParamSpec*
1871 g_param_spec_ulong (const gchar *name,
1872 const gchar *nick,
1873 const gchar *blurb,
1874 gulong minimum,
1875 gulong maximum,
1876 gulong default_value,
1877 GParamFlags flags)
1879 GParamSpecULong *uspec;
1881 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1883 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1884 name,
1885 nick,
1886 blurb,
1887 flags);
1888 if (uspec == NULL)
1889 return NULL;
1891 uspec->minimum = minimum;
1892 uspec->maximum = maximum;
1893 uspec->default_value = default_value;
1895 return G_PARAM_SPEC (uspec);
1899 * g_param_spec_int64:
1900 * @name: canonical name of the property specified
1901 * @nick: nick name for the property specified
1902 * @blurb: description of the property specified
1903 * @minimum: minimum value for the property specified
1904 * @maximum: maximum value for the property specified
1905 * @default_value: default value for the property specified
1906 * @flags: flags for the property specified
1908 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1910 * See g_param_spec_internal() for details on property names.
1912 * Returns: (transfer full): a newly created parameter specification
1914 GParamSpec*
1915 g_param_spec_int64 (const gchar *name,
1916 const gchar *nick,
1917 const gchar *blurb,
1918 gint64 minimum,
1919 gint64 maximum,
1920 gint64 default_value,
1921 GParamFlags flags)
1923 GParamSpecInt64 *lspec;
1925 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1927 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1928 name,
1929 nick,
1930 blurb,
1931 flags);
1932 if (lspec == NULL)
1933 return NULL;
1935 lspec->minimum = minimum;
1936 lspec->maximum = maximum;
1937 lspec->default_value = default_value;
1939 return G_PARAM_SPEC (lspec);
1943 * g_param_spec_uint64:
1944 * @name: canonical name of the property specified
1945 * @nick: nick name for the property specified
1946 * @blurb: description of the property specified
1947 * @minimum: minimum value for the property specified
1948 * @maximum: maximum value for the property specified
1949 * @default_value: default value for the property specified
1950 * @flags: flags for the property specified
1952 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1953 * property.
1955 * See g_param_spec_internal() for details on property names.
1957 * Returns: (transfer full): a newly created parameter specification
1959 GParamSpec*
1960 g_param_spec_uint64 (const gchar *name,
1961 const gchar *nick,
1962 const gchar *blurb,
1963 guint64 minimum,
1964 guint64 maximum,
1965 guint64 default_value,
1966 GParamFlags flags)
1968 GParamSpecUInt64 *uspec;
1970 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1972 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1973 name,
1974 nick,
1975 blurb,
1976 flags);
1977 if (uspec == NULL)
1978 return NULL;
1980 uspec->minimum = minimum;
1981 uspec->maximum = maximum;
1982 uspec->default_value = default_value;
1984 return G_PARAM_SPEC (uspec);
1988 * g_param_spec_unichar:
1989 * @name: canonical name of the property specified
1990 * @nick: nick name for the property specified
1991 * @blurb: description of the property specified
1992 * @default_value: default value for the property specified
1993 * @flags: flags for the property specified
1995 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1996 * property. #GValue structures for this property can be accessed with
1997 * g_value_set_uint() and g_value_get_uint().
1999 * See g_param_spec_internal() for details on property names.
2001 * Returns: (transfer full): a newly created parameter specification
2003 GParamSpec*
2004 g_param_spec_unichar (const gchar *name,
2005 const gchar *nick,
2006 const gchar *blurb,
2007 gunichar default_value,
2008 GParamFlags flags)
2010 GParamSpecUnichar *uspec;
2012 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
2013 name,
2014 nick,
2015 blurb,
2016 flags);
2017 if (uspec == NULL)
2018 return NULL;
2020 uspec->default_value = default_value;
2022 return G_PARAM_SPEC (uspec);
2026 * g_param_spec_enum:
2027 * @name: canonical name of the property specified
2028 * @nick: nick name for the property specified
2029 * @blurb: description of the property specified
2030 * @enum_type: a #GType derived from %G_TYPE_ENUM
2031 * @default_value: default value for the property specified
2032 * @flags: flags for the property specified
2034 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2035 * property.
2037 * See g_param_spec_internal() for details on property names.
2039 * Returns: (transfer full): a newly created parameter specification
2041 GParamSpec*
2042 g_param_spec_enum (const gchar *name,
2043 const gchar *nick,
2044 const gchar *blurb,
2045 GType enum_type,
2046 gint default_value,
2047 GParamFlags flags)
2049 GParamSpecEnum *espec;
2050 GEnumClass *enum_class;
2052 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2054 enum_class = g_type_class_ref (enum_type);
2056 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2058 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2059 name,
2060 nick,
2061 blurb,
2062 flags);
2063 if (espec == NULL)
2064 return NULL;
2066 espec->enum_class = enum_class;
2067 espec->default_value = default_value;
2068 G_PARAM_SPEC (espec)->value_type = enum_type;
2070 return G_PARAM_SPEC (espec);
2074 * g_param_spec_flags:
2075 * @name: canonical name of the property specified
2076 * @nick: nick name for the property specified
2077 * @blurb: description of the property specified
2078 * @flags_type: a #GType derived from %G_TYPE_FLAGS
2079 * @default_value: default value for the property specified
2080 * @flags: flags for the property specified
2082 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2083 * property.
2085 * See g_param_spec_internal() for details on property names.
2087 * Returns: (transfer full): a newly created parameter specification
2089 GParamSpec*
2090 g_param_spec_flags (const gchar *name,
2091 const gchar *nick,
2092 const gchar *blurb,
2093 GType flags_type,
2094 guint default_value,
2095 GParamFlags flags)
2097 GParamSpecFlags *fspec;
2098 GFlagsClass *flags_class;
2100 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2102 flags_class = g_type_class_ref (flags_type);
2104 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2106 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2107 name,
2108 nick,
2109 blurb,
2110 flags);
2111 if (fspec == NULL)
2112 return NULL;
2114 fspec->flags_class = flags_class;
2115 fspec->default_value = default_value;
2116 G_PARAM_SPEC (fspec)->value_type = flags_type;
2118 return G_PARAM_SPEC (fspec);
2122 * g_param_spec_float:
2123 * @name: canonical name of the property specified
2124 * @nick: nick name for the property specified
2125 * @blurb: description of the property specified
2126 * @minimum: minimum value for the property specified
2127 * @maximum: maximum value for the property specified
2128 * @default_value: default value for the property specified
2129 * @flags: flags for the property specified
2131 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2133 * See g_param_spec_internal() for details on property names.
2135 * Returns: (transfer full): a newly created parameter specification
2137 GParamSpec*
2138 g_param_spec_float (const gchar *name,
2139 const gchar *nick,
2140 const gchar *blurb,
2141 gfloat minimum,
2142 gfloat maximum,
2143 gfloat default_value,
2144 GParamFlags flags)
2146 GParamSpecFloat *fspec;
2148 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2150 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2151 name,
2152 nick,
2153 blurb,
2154 flags);
2155 if (fspec == NULL)
2156 return NULL;
2158 fspec->minimum = minimum;
2159 fspec->maximum = maximum;
2160 fspec->default_value = default_value;
2162 return G_PARAM_SPEC (fspec);
2166 * g_param_spec_double:
2167 * @name: canonical name of the property specified
2168 * @nick: nick name for the property specified
2169 * @blurb: description of the property specified
2170 * @minimum: minimum value for the property specified
2171 * @maximum: maximum value for the property specified
2172 * @default_value: default value for the property specified
2173 * @flags: flags for the property specified
2175 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2176 * property.
2178 * See g_param_spec_internal() for details on property names.
2180 * Returns: (transfer full): a newly created parameter specification
2182 GParamSpec*
2183 g_param_spec_double (const gchar *name,
2184 const gchar *nick,
2185 const gchar *blurb,
2186 gdouble minimum,
2187 gdouble maximum,
2188 gdouble default_value,
2189 GParamFlags flags)
2191 GParamSpecDouble *dspec;
2193 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2195 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2196 name,
2197 nick,
2198 blurb,
2199 flags);
2200 if (dspec == NULL)
2201 return NULL;
2203 dspec->minimum = minimum;
2204 dspec->maximum = maximum;
2205 dspec->default_value = default_value;
2207 return G_PARAM_SPEC (dspec);
2211 * g_param_spec_string:
2212 * @name: canonical name of the property specified
2213 * @nick: nick name for the property specified
2214 * @blurb: description of the property specified
2215 * @default_value: (nullable): default value for the property specified
2216 * @flags: flags for the property specified
2218 * Creates a new #GParamSpecString instance.
2220 * See g_param_spec_internal() for details on property names.
2222 * Returns: (transfer full): a newly created parameter specification
2224 GParamSpec*
2225 g_param_spec_string (const gchar *name,
2226 const gchar *nick,
2227 const gchar *blurb,
2228 const gchar *default_value,
2229 GParamFlags flags)
2231 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2232 name,
2233 nick,
2234 blurb,
2235 flags);
2236 if (sspec == NULL)
2237 return NULL;
2239 g_free (sspec->default_value);
2240 sspec->default_value = g_strdup (default_value);
2242 return G_PARAM_SPEC (sspec);
2246 * g_param_spec_param:
2247 * @name: canonical name of the property specified
2248 * @nick: nick name for the property specified
2249 * @blurb: description of the property specified
2250 * @param_type: a #GType derived from %G_TYPE_PARAM
2251 * @flags: flags for the property specified
2253 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2254 * property.
2256 * See g_param_spec_internal() for details on property names.
2258 * Returns: (transfer full): a newly created parameter specification
2260 GParamSpec*
2261 g_param_spec_param (const gchar *name,
2262 const gchar *nick,
2263 const gchar *blurb,
2264 GType param_type,
2265 GParamFlags flags)
2267 GParamSpecParam *pspec;
2269 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2271 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2272 name,
2273 nick,
2274 blurb,
2275 flags);
2276 if (pspec == NULL)
2277 return NULL;
2279 G_PARAM_SPEC (pspec)->value_type = param_type;
2281 return G_PARAM_SPEC (pspec);
2285 * g_param_spec_boxed:
2286 * @name: canonical name of the property specified
2287 * @nick: nick name for the property specified
2288 * @blurb: description of the property specified
2289 * @boxed_type: %G_TYPE_BOXED derived type of this property
2290 * @flags: flags for the property specified
2292 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2293 * derived property.
2295 * See g_param_spec_internal() for details on property names.
2297 * Returns: (transfer full): a newly created parameter specification
2299 GParamSpec*
2300 g_param_spec_boxed (const gchar *name,
2301 const gchar *nick,
2302 const gchar *blurb,
2303 GType boxed_type,
2304 GParamFlags flags)
2306 GParamSpecBoxed *bspec;
2308 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2309 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2311 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2312 name,
2313 nick,
2314 blurb,
2315 flags);
2316 if (bspec == NULL)
2317 return NULL;
2319 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2321 return G_PARAM_SPEC (bspec);
2325 * g_param_spec_pointer:
2326 * @name: canonical name of the property specified
2327 * @nick: nick name for the property specified
2328 * @blurb: description of the property specified
2329 * @flags: flags for the property specified
2331 * Creates a new #GParamSpecPointer instance specifying a pointer property.
2332 * Where possible, it is better to use g_param_spec_object() or
2333 * g_param_spec_boxed() to expose memory management information.
2335 * See g_param_spec_internal() for details on property names.
2337 * Returns: (transfer full): a newly created parameter specification
2339 GParamSpec*
2340 g_param_spec_pointer (const gchar *name,
2341 const gchar *nick,
2342 const gchar *blurb,
2343 GParamFlags flags)
2345 GParamSpecPointer *pspec;
2347 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2348 name,
2349 nick,
2350 blurb,
2351 flags);
2352 if (pspec == NULL)
2353 return NULL;
2355 return G_PARAM_SPEC (pspec);
2359 * g_param_spec_gtype:
2360 * @name: canonical name of the property specified
2361 * @nick: nick name for the property specified
2362 * @blurb: description of the property specified
2363 * @is_a_type: a #GType whose subtypes are allowed as values
2364 * of the property (use %G_TYPE_NONE for any type)
2365 * @flags: flags for the property specified
2367 * Creates a new #GParamSpecGType instance specifying a
2368 * %G_TYPE_GTYPE property.
2370 * See g_param_spec_internal() for details on property names.
2372 * Since: 2.10
2374 * Returns: (transfer full): a newly created parameter specification
2376 GParamSpec*
2377 g_param_spec_gtype (const gchar *name,
2378 const gchar *nick,
2379 const gchar *blurb,
2380 GType is_a_type,
2381 GParamFlags flags)
2383 GParamSpecGType *tspec;
2385 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2386 name,
2387 nick,
2388 blurb,
2389 flags);
2390 if (tspec == NULL)
2391 return NULL;
2393 tspec->is_a_type = is_a_type;
2395 return G_PARAM_SPEC (tspec);
2399 * g_param_spec_value_array: (skip)
2400 * @name: canonical name of the property specified
2401 * @nick: nick name for the property specified
2402 * @blurb: description of the property specified
2403 * @element_spec: a #GParamSpec describing the elements contained in
2404 * arrays of this property, may be %NULL
2405 * @flags: flags for the property specified
2407 * Creates a new #GParamSpecValueArray instance specifying a
2408 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2409 * %G_TYPE_BOXED type, as such, #GValue structures for this property
2410 * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2412 * See g_param_spec_internal() for details on property names.
2414 * Returns: a newly created parameter specification
2416 GParamSpec*
2417 g_param_spec_value_array (const gchar *name,
2418 const gchar *nick,
2419 const gchar *blurb,
2420 GParamSpec *element_spec,
2421 GParamFlags flags)
2423 GParamSpecValueArray *aspec;
2425 if (element_spec)
2426 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2428 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2429 name,
2430 nick,
2431 blurb,
2432 flags);
2433 if (aspec == NULL)
2434 return NULL;
2436 if (element_spec)
2438 aspec->element_spec = g_param_spec_ref (element_spec);
2439 g_param_spec_sink (element_spec);
2442 return G_PARAM_SPEC (aspec);
2446 * g_param_spec_object:
2447 * @name: canonical name of the property specified
2448 * @nick: nick name for the property specified
2449 * @blurb: description of the property specified
2450 * @object_type: %G_TYPE_OBJECT derived type of this property
2451 * @flags: flags for the property specified
2453 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2454 * derived property.
2456 * See g_param_spec_internal() for details on property names.
2458 * Returns: (transfer full): a newly created parameter specification
2460 GParamSpec*
2461 g_param_spec_object (const gchar *name,
2462 const gchar *nick,
2463 const gchar *blurb,
2464 GType object_type,
2465 GParamFlags flags)
2467 GParamSpecObject *ospec;
2469 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2471 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2472 name,
2473 nick,
2474 blurb,
2475 flags);
2476 if (ospec == NULL)
2477 return NULL;
2479 G_PARAM_SPEC (ospec)->value_type = object_type;
2481 return G_PARAM_SPEC (ospec);
2485 * g_param_spec_override: (skip)
2486 * @name: the name of the property.
2487 * @overridden: The property that is being overridden
2489 * Creates a new property of type #GParamSpecOverride. This is used
2490 * to direct operations to another paramspec, and will not be directly
2491 * useful unless you are implementing a new base type similar to GObject.
2493 * Since: 2.4
2495 * Returns: the newly created #GParamSpec
2497 GParamSpec*
2498 g_param_spec_override (const gchar *name,
2499 GParamSpec *overridden)
2501 GParamSpec *pspec;
2503 g_return_val_if_fail (name != NULL, NULL);
2504 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2506 /* Dereference further redirections for property that was passed in
2508 while (TRUE)
2510 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2511 if (indirect)
2512 overridden = indirect;
2513 else
2514 break;
2517 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2518 name, NULL, NULL,
2519 overridden->flags);
2520 if (pspec == NULL)
2521 return NULL;
2523 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2524 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2526 return pspec;
2530 * g_param_spec_variant:
2531 * @name: canonical name of the property specified
2532 * @nick: nick name for the property specified
2533 * @blurb: description of the property specified
2534 * @type: a #GVariantType
2535 * @default_value: (nullable) (transfer full): a #GVariant of type @type to
2536 * use as the default value, or %NULL
2537 * @flags: flags for the property specified
2539 * Creates a new #GParamSpecVariant instance specifying a #GVariant
2540 * property.
2542 * If @default_value is floating, it is consumed.
2544 * See g_param_spec_internal() for details on property names.
2546 * Returns: (transfer full): the newly created #GParamSpec
2548 * Since: 2.26
2550 GParamSpec*
2551 g_param_spec_variant (const gchar *name,
2552 const gchar *nick,
2553 const gchar *blurb,
2554 const GVariantType *type,
2555 GVariant *default_value,
2556 GParamFlags flags)
2558 GParamSpecVariant *vspec;
2560 g_return_val_if_fail (type != NULL, NULL);
2561 g_return_val_if_fail (default_value == NULL ||
2562 g_variant_is_of_type (default_value, type), NULL);
2564 vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2565 name,
2566 nick,
2567 blurb,
2568 flags);
2569 if (vspec == NULL)
2570 return NULL;
2572 vspec->type = g_variant_type_copy (type);
2573 if (default_value)
2574 vspec->default_value = g_variant_ref_sink (default_value);
2576 return G_PARAM_SPEC (vspec);