regex: Add PARTIAL_HARD match option
[glib.git] / gobject / gparamspecs.c
blob0043cace0b0794c48b22c7a8be38b49682a4dec2
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 * Copyright (C) 2010 Christian Persch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * MT safe
25 #include "config.h"
27 #include <string.h>
29 #define GLIB_DISABLE_DEPRECATION_WARNINGS
31 #include "gparamspecs.h"
32 #include "gtype-private.h"
33 #include "gvaluecollector.h"
35 #include "gvaluearray.h"
38 /**
39 * SECTION:param_value_types
40 * @short_description: Standard Parameter and Value Types
41 * @see_also: #GParamSpec, #GValue, g_object_class_install_property().
42 * @title: Parameters and Values
44 * #GValue provides an abstract container structure which can be
45 * copied, transformed and compared while holding a value of any
46 * (derived) type, which is registered as a #GType with a
47 * #GTypeValueTable in its #GTypeInfo structure. Parameter
48 * specifications for most value types can be created as #GParamSpec
49 * derived instances, to implement e.g. #GObject properties which
50 * operate on #GValue containers.
52 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
53 * characters can be letters, numbers or a '-'.
54 * All other characters are replaced by a '-' during construction.
58 #define G_FLOAT_EPSILON (1e-30)
59 #define G_DOUBLE_EPSILON (1e-90)
62 /* --- param spec functions --- */
63 static void
64 param_char_init (GParamSpec *pspec)
66 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
68 cspec->minimum = 0x7f;
69 cspec->maximum = 0x80;
70 cspec->default_value = 0;
73 static void
74 param_char_set_default (GParamSpec *pspec,
75 GValue *value)
77 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
80 static gboolean
81 param_char_validate (GParamSpec *pspec,
82 GValue *value)
84 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
85 gint oval = value->data[0].v_int;
87 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
89 return value->data[0].v_int != oval;
92 static void
93 param_uchar_init (GParamSpec *pspec)
95 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
97 uspec->minimum = 0;
98 uspec->maximum = 0xff;
99 uspec->default_value = 0;
102 static void
103 param_uchar_set_default (GParamSpec *pspec,
104 GValue *value)
106 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
109 static gboolean
110 param_uchar_validate (GParamSpec *pspec,
111 GValue *value)
113 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
114 guint oval = value->data[0].v_uint;
116 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
118 return value->data[0].v_uint != oval;
121 static void
122 param_boolean_set_default (GParamSpec *pspec,
123 GValue *value)
125 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
128 static gboolean
129 param_boolean_validate (GParamSpec *pspec,
130 GValue *value)
132 gint oval = value->data[0].v_int;
134 value->data[0].v_int = value->data[0].v_int != FALSE;
136 return value->data[0].v_int != oval;
139 static void
140 param_int_init (GParamSpec *pspec)
142 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
144 ispec->minimum = 0x7fffffff;
145 ispec->maximum = 0x80000000;
146 ispec->default_value = 0;
149 static void
150 param_int_set_default (GParamSpec *pspec,
151 GValue *value)
153 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
156 static gboolean
157 param_int_validate (GParamSpec *pspec,
158 GValue *value)
160 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
161 gint oval = value->data[0].v_int;
163 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
165 return value->data[0].v_int != oval;
168 static gint
169 param_int_values_cmp (GParamSpec *pspec,
170 const GValue *value1,
171 const GValue *value2)
173 if (value1->data[0].v_int < value2->data[0].v_int)
174 return -1;
175 else
176 return value1->data[0].v_int > value2->data[0].v_int;
179 static void
180 param_uint_init (GParamSpec *pspec)
182 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
184 uspec->minimum = 0;
185 uspec->maximum = 0xffffffff;
186 uspec->default_value = 0;
189 static void
190 param_uint_set_default (GParamSpec *pspec,
191 GValue *value)
193 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
196 static gboolean
197 param_uint_validate (GParamSpec *pspec,
198 GValue *value)
200 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
201 guint oval = value->data[0].v_uint;
203 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
205 return value->data[0].v_uint != oval;
208 static gint
209 param_uint_values_cmp (GParamSpec *pspec,
210 const GValue *value1,
211 const GValue *value2)
213 if (value1->data[0].v_uint < value2->data[0].v_uint)
214 return -1;
215 else
216 return value1->data[0].v_uint > value2->data[0].v_uint;
219 static void
220 param_long_init (GParamSpec *pspec)
222 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
224 #if SIZEOF_LONG == 4
225 lspec->minimum = 0x7fffffff;
226 lspec->maximum = 0x80000000;
227 #else /* SIZEOF_LONG != 4 (8) */
228 lspec->minimum = 0x7fffffffffffffff;
229 lspec->maximum = 0x8000000000000000;
230 #endif
231 lspec->default_value = 0;
234 static void
235 param_long_set_default (GParamSpec *pspec,
236 GValue *value)
238 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
241 static gboolean
242 param_long_validate (GParamSpec *pspec,
243 GValue *value)
245 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
246 glong oval = value->data[0].v_long;
248 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
250 return value->data[0].v_long != oval;
253 static gint
254 param_long_values_cmp (GParamSpec *pspec,
255 const GValue *value1,
256 const GValue *value2)
258 if (value1->data[0].v_long < value2->data[0].v_long)
259 return -1;
260 else
261 return value1->data[0].v_long > value2->data[0].v_long;
264 static void
265 param_ulong_init (GParamSpec *pspec)
267 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
269 uspec->minimum = 0;
270 #if SIZEOF_LONG == 4
271 uspec->maximum = 0xffffffff;
272 #else /* SIZEOF_LONG != 4 (8) */
273 uspec->maximum = 0xffffffffffffffff;
274 #endif
275 uspec->default_value = 0;
278 static void
279 param_ulong_set_default (GParamSpec *pspec,
280 GValue *value)
282 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
285 static gboolean
286 param_ulong_validate (GParamSpec *pspec,
287 GValue *value)
289 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
290 gulong oval = value->data[0].v_ulong;
292 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
294 return value->data[0].v_ulong != oval;
297 static gint
298 param_ulong_values_cmp (GParamSpec *pspec,
299 const GValue *value1,
300 const GValue *value2)
302 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
303 return -1;
304 else
305 return value1->data[0].v_ulong > value2->data[0].v_ulong;
308 static void
309 param_int64_init (GParamSpec *pspec)
311 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
313 lspec->minimum = G_MININT64;
314 lspec->maximum = G_MAXINT64;
315 lspec->default_value = 0;
318 static void
319 param_int64_set_default (GParamSpec *pspec,
320 GValue *value)
322 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
325 static gboolean
326 param_int64_validate (GParamSpec *pspec,
327 GValue *value)
329 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
330 gint64 oval = value->data[0].v_int64;
332 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
334 return value->data[0].v_int64 != oval;
337 static gint
338 param_int64_values_cmp (GParamSpec *pspec,
339 const GValue *value1,
340 const GValue *value2)
342 if (value1->data[0].v_int64 < value2->data[0].v_int64)
343 return -1;
344 else
345 return value1->data[0].v_int64 > value2->data[0].v_int64;
348 static void
349 param_uint64_init (GParamSpec *pspec)
351 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
353 uspec->minimum = 0;
354 uspec->maximum = G_MAXUINT64;
355 uspec->default_value = 0;
358 static void
359 param_uint64_set_default (GParamSpec *pspec,
360 GValue *value)
362 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
365 static gboolean
366 param_uint64_validate (GParamSpec *pspec,
367 GValue *value)
369 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
370 guint64 oval = value->data[0].v_uint64;
372 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
374 return value->data[0].v_uint64 != oval;
377 static gint
378 param_uint64_values_cmp (GParamSpec *pspec,
379 const GValue *value1,
380 const GValue *value2)
382 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
383 return -1;
384 else
385 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
388 static void
389 param_unichar_init (GParamSpec *pspec)
391 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
393 uspec->default_value = 0;
396 static void
397 param_unichar_set_default (GParamSpec *pspec,
398 GValue *value)
400 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
403 static gboolean
404 param_unichar_validate (GParamSpec *pspec,
405 GValue *value)
407 gunichar oval = value->data[0].v_uint;
408 gboolean changed = FALSE;
410 if (!g_unichar_validate (oval))
412 value->data[0].v_uint = 0;
413 changed = TRUE;
416 return changed;
419 static gint
420 param_unichar_values_cmp (GParamSpec *pspec,
421 const GValue *value1,
422 const GValue *value2)
424 if (value1->data[0].v_uint < value2->data[0].v_uint)
425 return -1;
426 else
427 return value1->data[0].v_uint > value2->data[0].v_uint;
430 static void
431 param_enum_init (GParamSpec *pspec)
433 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
435 espec->enum_class = NULL;
436 espec->default_value = 0;
439 static void
440 param_enum_finalize (GParamSpec *pspec)
442 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
443 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
445 if (espec->enum_class)
447 g_type_class_unref (espec->enum_class);
448 espec->enum_class = NULL;
451 parent_class->finalize (pspec);
454 static void
455 param_enum_set_default (GParamSpec *pspec,
456 GValue *value)
458 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
461 static gboolean
462 param_enum_validate (GParamSpec *pspec,
463 GValue *value)
465 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
466 glong oval = value->data[0].v_long;
468 if (!espec->enum_class ||
469 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
470 value->data[0].v_long = espec->default_value;
472 return value->data[0].v_long != oval;
475 static void
476 param_flags_init (GParamSpec *pspec)
478 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
480 fspec->flags_class = NULL;
481 fspec->default_value = 0;
484 static void
485 param_flags_finalize (GParamSpec *pspec)
487 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
488 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
490 if (fspec->flags_class)
492 g_type_class_unref (fspec->flags_class);
493 fspec->flags_class = NULL;
496 parent_class->finalize (pspec);
499 static void
500 param_flags_set_default (GParamSpec *pspec,
501 GValue *value)
503 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
506 static gboolean
507 param_flags_validate (GParamSpec *pspec,
508 GValue *value)
510 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
511 gulong oval = value->data[0].v_ulong;
513 if (fspec->flags_class)
514 value->data[0].v_ulong &= fspec->flags_class->mask;
515 else
516 value->data[0].v_ulong = fspec->default_value;
518 return value->data[0].v_ulong != oval;
521 static void
522 param_float_init (GParamSpec *pspec)
524 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
526 fspec->minimum = -G_MAXFLOAT;
527 fspec->maximum = G_MAXFLOAT;
528 fspec->default_value = 0;
529 fspec->epsilon = G_FLOAT_EPSILON;
532 static void
533 param_float_set_default (GParamSpec *pspec,
534 GValue *value)
536 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
539 static gboolean
540 param_float_validate (GParamSpec *pspec,
541 GValue *value)
543 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
544 gfloat oval = value->data[0].v_float;
546 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
548 return value->data[0].v_float != oval;
551 static gint
552 param_float_values_cmp (GParamSpec *pspec,
553 const GValue *value1,
554 const GValue *value2)
556 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
558 if (value1->data[0].v_float < value2->data[0].v_float)
559 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
560 else
561 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
564 static void
565 param_double_init (GParamSpec *pspec)
567 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
569 dspec->minimum = -G_MAXDOUBLE;
570 dspec->maximum = G_MAXDOUBLE;
571 dspec->default_value = 0;
572 dspec->epsilon = G_DOUBLE_EPSILON;
575 static void
576 param_double_set_default (GParamSpec *pspec,
577 GValue *value)
579 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
582 static gboolean
583 param_double_validate (GParamSpec *pspec,
584 GValue *value)
586 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
587 gdouble oval = value->data[0].v_double;
589 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
591 return value->data[0].v_double != oval;
594 static gint
595 param_double_values_cmp (GParamSpec *pspec,
596 const GValue *value1,
597 const GValue *value2)
599 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
601 if (value1->data[0].v_double < value2->data[0].v_double)
602 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
603 else
604 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
607 static void
608 param_string_init (GParamSpec *pspec)
610 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
612 sspec->default_value = NULL;
613 sspec->cset_first = NULL;
614 sspec->cset_nth = NULL;
615 sspec->substitutor = '_';
616 sspec->null_fold_if_empty = FALSE;
617 sspec->ensure_non_null = FALSE;
620 static void
621 param_string_finalize (GParamSpec *pspec)
623 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
624 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
626 g_free (sspec->default_value);
627 g_free (sspec->cset_first);
628 g_free (sspec->cset_nth);
629 sspec->default_value = NULL;
630 sspec->cset_first = NULL;
631 sspec->cset_nth = NULL;
633 parent_class->finalize (pspec);
636 static void
637 param_string_set_default (GParamSpec *pspec,
638 GValue *value)
640 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
643 static gboolean
644 param_string_validate (GParamSpec *pspec,
645 GValue *value)
647 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
648 gchar *string = value->data[0].v_pointer;
649 guint changed = 0;
651 if (string && string[0])
653 gchar *s;
655 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
657 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
659 value->data[0].v_pointer = g_strdup (string);
660 string = value->data[0].v_pointer;
661 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
663 string[0] = sspec->substitutor;
664 changed++;
666 if (sspec->cset_nth)
667 for (s = string + 1; *s; s++)
668 if (!strchr (sspec->cset_nth, *s))
670 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
672 value->data[0].v_pointer = g_strdup (string);
673 s = (gchar*) value->data[0].v_pointer + (s - string);
674 string = value->data[0].v_pointer;
675 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
677 *s = sspec->substitutor;
678 changed++;
681 if (sspec->null_fold_if_empty && string && string[0] == 0)
683 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
684 g_free (value->data[0].v_pointer);
685 else
686 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
687 value->data[0].v_pointer = NULL;
688 changed++;
689 string = value->data[0].v_pointer;
691 if (sspec->ensure_non_null && !string)
693 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
694 value->data[0].v_pointer = g_strdup ("");
695 changed++;
696 string = value->data[0].v_pointer;
699 return changed;
702 static gint
703 param_string_values_cmp (GParamSpec *pspec,
704 const GValue *value1,
705 const GValue *value2)
707 if (!value1->data[0].v_pointer)
708 return value2->data[0].v_pointer != NULL ? -1 : 0;
709 else if (!value2->data[0].v_pointer)
710 return value1->data[0].v_pointer != NULL;
711 else
712 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
715 static void
716 param_param_init (GParamSpec *pspec)
718 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
721 static void
722 param_param_set_default (GParamSpec *pspec,
723 GValue *value)
725 value->data[0].v_pointer = NULL;
728 static gboolean
729 param_param_validate (GParamSpec *pspec,
730 GValue *value)
732 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
733 GParamSpec *param = value->data[0].v_pointer;
734 guint changed = 0;
736 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
738 g_param_spec_unref (param);
739 value->data[0].v_pointer = NULL;
740 changed++;
743 return changed;
746 static void
747 param_boxed_init (GParamSpec *pspec)
749 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
752 static void
753 param_boxed_set_default (GParamSpec *pspec,
754 GValue *value)
756 value->data[0].v_pointer = NULL;
759 static gboolean
760 param_boxed_validate (GParamSpec *pspec,
761 GValue *value)
763 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
764 guint changed = 0;
766 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
768 return changed;
771 static gint
772 param_boxed_values_cmp (GParamSpec *pspec,
773 const GValue *value1,
774 const GValue *value2)
776 guint8 *p1 = value1->data[0].v_pointer;
777 guint8 *p2 = value2->data[0].v_pointer;
779 /* not much to compare here, try to at least provide stable lesser/greater result */
781 return p1 < p2 ? -1 : p1 > p2;
784 static void
785 param_pointer_init (GParamSpec *pspec)
787 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
790 static void
791 param_pointer_set_default (GParamSpec *pspec,
792 GValue *value)
794 value->data[0].v_pointer = NULL;
797 static gboolean
798 param_pointer_validate (GParamSpec *pspec,
799 GValue *value)
801 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
802 guint changed = 0;
804 return changed;
807 static gint
808 param_pointer_values_cmp (GParamSpec *pspec,
809 const GValue *value1,
810 const GValue *value2)
812 guint8 *p1 = value1->data[0].v_pointer;
813 guint8 *p2 = value2->data[0].v_pointer;
815 /* not much to compare here, try to at least provide stable lesser/greater result */
817 return p1 < p2 ? -1 : p1 > p2;
820 static void
821 param_value_array_init (GParamSpec *pspec)
823 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
825 aspec->element_spec = NULL;
826 aspec->fixed_n_elements = 0; /* disable */
829 static inline guint
830 value_array_ensure_size (GValueArray *value_array,
831 guint fixed_n_elements)
833 guint changed = 0;
835 if (fixed_n_elements)
837 while (value_array->n_values < fixed_n_elements)
839 g_value_array_append (value_array, NULL);
840 changed++;
842 while (value_array->n_values > fixed_n_elements)
844 g_value_array_remove (value_array, value_array->n_values - 1);
845 changed++;
848 return changed;
851 static void
852 param_value_array_finalize (GParamSpec *pspec)
854 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
855 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
857 if (aspec->element_spec)
859 g_param_spec_unref (aspec->element_spec);
860 aspec->element_spec = NULL;
863 parent_class->finalize (pspec);
866 static void
867 param_value_array_set_default (GParamSpec *pspec,
868 GValue *value)
870 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
872 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
873 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
875 if (value->data[0].v_pointer)
877 /* g_value_reset (value); already done */
878 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
882 static gboolean
883 param_value_array_validate (GParamSpec *pspec,
884 GValue *value)
886 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
887 GValueArray *value_array = value->data[0].v_pointer;
888 guint changed = 0;
890 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
891 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
893 if (value->data[0].v_pointer)
895 /* ensure array size validity */
896 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
898 /* ensure array values validity against a present element spec */
899 if (aspec->element_spec)
901 GParamSpec *element_spec = aspec->element_spec;
902 guint i;
904 for (i = 0; i < value_array->n_values; i++)
906 GValue *element = value_array->values + i;
908 /* need to fixup value type, or ensure that the array value is initialized at all */
909 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
911 if (G_VALUE_TYPE (element) != 0)
912 g_value_unset (element);
913 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
914 g_param_value_set_default (element_spec, element);
915 changed++;
917 /* validate array value against element_spec */
918 changed += g_param_value_validate (element_spec, element);
923 return changed;
926 static gint
927 param_value_array_values_cmp (GParamSpec *pspec,
928 const GValue *value1,
929 const GValue *value2)
931 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
932 GValueArray *value_array1 = value1->data[0].v_pointer;
933 GValueArray *value_array2 = value2->data[0].v_pointer;
935 if (!value_array1 || !value_array2)
936 return value_array2 ? -1 : value_array1 != value_array2;
938 if (value_array1->n_values != value_array2->n_values)
939 return value_array1->n_values < value_array2->n_values ? -1 : 1;
940 else if (!aspec->element_spec)
942 /* we need an element specification for comparisons, so there's not much
943 * to compare here, try to at least provide stable lesser/greater result
945 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
947 else /* value_array1->n_values == value_array2->n_values */
949 guint i;
951 for (i = 0; i < value_array1->n_values; i++)
953 GValue *element1 = value_array1->values + i;
954 GValue *element2 = value_array2->values + i;
955 gint cmp;
957 /* need corresponding element types, provide stable result otherwise */
958 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
959 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
960 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
961 if (cmp)
962 return cmp;
964 return 0;
968 static void
969 param_object_init (GParamSpec *pspec)
971 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
974 static void
975 param_object_set_default (GParamSpec *pspec,
976 GValue *value)
978 value->data[0].v_pointer = NULL;
981 static gboolean
982 param_object_validate (GParamSpec *pspec,
983 GValue *value)
985 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
986 GObject *object = value->data[0].v_pointer;
987 guint changed = 0;
989 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
991 g_object_unref (object);
992 value->data[0].v_pointer = NULL;
993 changed++;
996 return changed;
999 static gint
1000 param_object_values_cmp (GParamSpec *pspec,
1001 const GValue *value1,
1002 const GValue *value2)
1004 guint8 *p1 = value1->data[0].v_pointer;
1005 guint8 *p2 = value2->data[0].v_pointer;
1007 /* not much to compare here, try to at least provide stable lesser/greater result */
1009 return p1 < p2 ? -1 : p1 > p2;
1012 static void
1013 param_override_init (GParamSpec *pspec)
1015 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1018 static void
1019 param_override_finalize (GParamSpec *pspec)
1021 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1022 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1024 if (ospec->overridden)
1026 g_param_spec_unref (ospec->overridden);
1027 ospec->overridden = NULL;
1030 parent_class->finalize (pspec);
1033 static void
1034 param_override_set_default (GParamSpec *pspec,
1035 GValue *value)
1037 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1039 g_param_value_set_default (ospec->overridden, value);
1042 static gboolean
1043 param_override_validate (GParamSpec *pspec,
1044 GValue *value)
1046 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1048 return g_param_value_validate (ospec->overridden, value);
1051 static gint
1052 param_override_values_cmp (GParamSpec *pspec,
1053 const GValue *value1,
1054 const GValue *value2)
1056 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1058 return g_param_values_cmp (ospec->overridden, value1, value2);
1061 static void
1062 param_gtype_init (GParamSpec *pspec)
1066 static void
1067 param_gtype_set_default (GParamSpec *pspec,
1068 GValue *value)
1070 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1072 value->data[0].v_long = tspec->is_a_type;
1075 static gboolean
1076 param_gtype_validate (GParamSpec *pspec,
1077 GValue *value)
1079 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1080 GType gtype = value->data[0].v_long;
1081 guint changed = 0;
1083 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1085 value->data[0].v_long = tspec->is_a_type;
1086 changed++;
1089 return changed;
1092 static gint
1093 param_gtype_values_cmp (GParamSpec *pspec,
1094 const GValue *value1,
1095 const GValue *value2)
1097 GType p1 = value1->data[0].v_long;
1098 GType p2 = value2->data[0].v_long;
1100 /* not much to compare here, try to at least provide stable lesser/greater result */
1102 return p1 < p2 ? -1 : p1 > p2;
1105 static void
1106 param_variant_init (GParamSpec *pspec)
1108 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1110 vspec->type = NULL;
1111 vspec->default_value = NULL;
1114 static void
1115 param_variant_finalize (GParamSpec *pspec)
1117 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1118 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1120 if (vspec->default_value)
1121 g_variant_unref (vspec->default_value);
1122 g_variant_type_free (vspec->type);
1124 parent_class->finalize (pspec);
1127 static void
1128 param_variant_set_default (GParamSpec *pspec,
1129 GValue *value)
1131 value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1132 value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1135 static gboolean
1136 param_variant_validate (GParamSpec *pspec,
1137 GValue *value)
1139 GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1140 GVariant *variant = value->data[0].v_pointer;
1142 if ((variant == NULL && vspec->default_value != NULL) ||
1143 (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1145 g_param_value_set_default (pspec, value);
1146 return TRUE;
1149 return FALSE;
1152 static gint
1153 param_variant_values_cmp (GParamSpec *pspec,
1154 const GValue *value1,
1155 const GValue *value2)
1157 GVariant *v1 = value1->data[0].v_pointer;
1158 GVariant *v2 = value2->data[0].v_pointer;
1160 return v1 < v2 ? -1 : v2 > v1;
1163 /* --- type initialization --- */
1164 GType *g_param_spec_types = NULL;
1166 void
1167 _g_param_spec_types_init (void)
1169 const guint n_types = 23;
1170 GType type, *spec_types, *spec_types_bound;
1172 g_param_spec_types = g_new0 (GType, n_types);
1173 spec_types = g_param_spec_types;
1174 spec_types_bound = g_param_spec_types + n_types;
1176 /* G_TYPE_PARAM_CHAR
1179 static const GParamSpecTypeInfo pspec_info = {
1180 sizeof (GParamSpecChar), /* instance_size */
1181 16, /* n_preallocs */
1182 param_char_init, /* instance_init */
1183 G_TYPE_CHAR, /* value_type */
1184 NULL, /* finalize */
1185 param_char_set_default, /* value_set_default */
1186 param_char_validate, /* value_validate */
1187 param_int_values_cmp, /* values_cmp */
1189 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1190 *spec_types++ = type;
1191 g_assert (type == G_TYPE_PARAM_CHAR);
1194 /* G_TYPE_PARAM_UCHAR
1197 static const GParamSpecTypeInfo pspec_info = {
1198 sizeof (GParamSpecUChar), /* instance_size */
1199 16, /* n_preallocs */
1200 param_uchar_init, /* instance_init */
1201 G_TYPE_UCHAR, /* value_type */
1202 NULL, /* finalize */
1203 param_uchar_set_default, /* value_set_default */
1204 param_uchar_validate, /* value_validate */
1205 param_uint_values_cmp, /* values_cmp */
1207 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1208 *spec_types++ = type;
1209 g_assert (type == G_TYPE_PARAM_UCHAR);
1212 /* G_TYPE_PARAM_BOOLEAN
1215 static const GParamSpecTypeInfo pspec_info = {
1216 sizeof (GParamSpecBoolean), /* instance_size */
1217 16, /* n_preallocs */
1218 NULL, /* instance_init */
1219 G_TYPE_BOOLEAN, /* value_type */
1220 NULL, /* finalize */
1221 param_boolean_set_default, /* value_set_default */
1222 param_boolean_validate, /* value_validate */
1223 param_int_values_cmp, /* values_cmp */
1225 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1226 *spec_types++ = type;
1227 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1230 /* G_TYPE_PARAM_INT
1233 static const GParamSpecTypeInfo pspec_info = {
1234 sizeof (GParamSpecInt), /* instance_size */
1235 16, /* n_preallocs */
1236 param_int_init, /* instance_init */
1237 G_TYPE_INT, /* value_type */
1238 NULL, /* finalize */
1239 param_int_set_default, /* value_set_default */
1240 param_int_validate, /* value_validate */
1241 param_int_values_cmp, /* values_cmp */
1243 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1244 *spec_types++ = type;
1245 g_assert (type == G_TYPE_PARAM_INT);
1248 /* G_TYPE_PARAM_UINT
1251 static const GParamSpecTypeInfo pspec_info = {
1252 sizeof (GParamSpecUInt), /* instance_size */
1253 16, /* n_preallocs */
1254 param_uint_init, /* instance_init */
1255 G_TYPE_UINT, /* value_type */
1256 NULL, /* finalize */
1257 param_uint_set_default, /* value_set_default */
1258 param_uint_validate, /* value_validate */
1259 param_uint_values_cmp, /* values_cmp */
1261 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1262 *spec_types++ = type;
1263 g_assert (type == G_TYPE_PARAM_UINT);
1266 /* G_TYPE_PARAM_LONG
1269 static const GParamSpecTypeInfo pspec_info = {
1270 sizeof (GParamSpecLong), /* instance_size */
1271 16, /* n_preallocs */
1272 param_long_init, /* instance_init */
1273 G_TYPE_LONG, /* value_type */
1274 NULL, /* finalize */
1275 param_long_set_default, /* value_set_default */
1276 param_long_validate, /* value_validate */
1277 param_long_values_cmp, /* values_cmp */
1279 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1280 *spec_types++ = type;
1281 g_assert (type == G_TYPE_PARAM_LONG);
1284 /* G_TYPE_PARAM_ULONG
1287 static const GParamSpecTypeInfo pspec_info = {
1288 sizeof (GParamSpecULong), /* instance_size */
1289 16, /* n_preallocs */
1290 param_ulong_init, /* instance_init */
1291 G_TYPE_ULONG, /* value_type */
1292 NULL, /* finalize */
1293 param_ulong_set_default, /* value_set_default */
1294 param_ulong_validate, /* value_validate */
1295 param_ulong_values_cmp, /* values_cmp */
1297 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1298 *spec_types++ = type;
1299 g_assert (type == G_TYPE_PARAM_ULONG);
1302 /* G_TYPE_PARAM_INT64
1305 static const GParamSpecTypeInfo pspec_info = {
1306 sizeof (GParamSpecInt64), /* instance_size */
1307 16, /* n_preallocs */
1308 param_int64_init, /* instance_init */
1309 G_TYPE_INT64, /* value_type */
1310 NULL, /* finalize */
1311 param_int64_set_default, /* value_set_default */
1312 param_int64_validate, /* value_validate */
1313 param_int64_values_cmp, /* values_cmp */
1315 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1316 *spec_types++ = type;
1317 g_assert (type == G_TYPE_PARAM_INT64);
1320 /* G_TYPE_PARAM_UINT64
1323 static const GParamSpecTypeInfo pspec_info = {
1324 sizeof (GParamSpecUInt64), /* instance_size */
1325 16, /* n_preallocs */
1326 param_uint64_init, /* instance_init */
1327 G_TYPE_UINT64, /* value_type */
1328 NULL, /* finalize */
1329 param_uint64_set_default, /* value_set_default */
1330 param_uint64_validate, /* value_validate */
1331 param_uint64_values_cmp, /* values_cmp */
1333 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1334 *spec_types++ = type;
1335 g_assert (type == G_TYPE_PARAM_UINT64);
1338 /* G_TYPE_PARAM_UNICHAR
1341 static const GParamSpecTypeInfo pspec_info = {
1342 sizeof (GParamSpecUnichar), /* instance_size */
1343 16, /* n_preallocs */
1344 param_unichar_init, /* instance_init */
1345 G_TYPE_UINT, /* value_type */
1346 NULL, /* finalize */
1347 param_unichar_set_default, /* value_set_default */
1348 param_unichar_validate, /* value_validate */
1349 param_unichar_values_cmp, /* values_cmp */
1351 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1352 *spec_types++ = type;
1353 g_assert (type == G_TYPE_PARAM_UNICHAR);
1356 /* G_TYPE_PARAM_ENUM
1359 static const GParamSpecTypeInfo pspec_info = {
1360 sizeof (GParamSpecEnum), /* instance_size */
1361 16, /* n_preallocs */
1362 param_enum_init, /* instance_init */
1363 G_TYPE_ENUM, /* value_type */
1364 param_enum_finalize, /* finalize */
1365 param_enum_set_default, /* value_set_default */
1366 param_enum_validate, /* value_validate */
1367 param_long_values_cmp, /* values_cmp */
1369 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1370 *spec_types++ = type;
1371 g_assert (type == G_TYPE_PARAM_ENUM);
1374 /* G_TYPE_PARAM_FLAGS
1377 static const GParamSpecTypeInfo pspec_info = {
1378 sizeof (GParamSpecFlags), /* instance_size */
1379 16, /* n_preallocs */
1380 param_flags_init, /* instance_init */
1381 G_TYPE_FLAGS, /* value_type */
1382 param_flags_finalize, /* finalize */
1383 param_flags_set_default, /* value_set_default */
1384 param_flags_validate, /* value_validate */
1385 param_ulong_values_cmp, /* values_cmp */
1387 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1388 *spec_types++ = type;
1389 g_assert (type == G_TYPE_PARAM_FLAGS);
1392 /* G_TYPE_PARAM_FLOAT
1395 static const GParamSpecTypeInfo pspec_info = {
1396 sizeof (GParamSpecFloat), /* instance_size */
1397 16, /* n_preallocs */
1398 param_float_init, /* instance_init */
1399 G_TYPE_FLOAT, /* value_type */
1400 NULL, /* finalize */
1401 param_float_set_default, /* value_set_default */
1402 param_float_validate, /* value_validate */
1403 param_float_values_cmp, /* values_cmp */
1405 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1406 *spec_types++ = type;
1407 g_assert (type == G_TYPE_PARAM_FLOAT);
1410 /* G_TYPE_PARAM_DOUBLE
1413 static const GParamSpecTypeInfo pspec_info = {
1414 sizeof (GParamSpecDouble), /* instance_size */
1415 16, /* n_preallocs */
1416 param_double_init, /* instance_init */
1417 G_TYPE_DOUBLE, /* value_type */
1418 NULL, /* finalize */
1419 param_double_set_default, /* value_set_default */
1420 param_double_validate, /* value_validate */
1421 param_double_values_cmp, /* values_cmp */
1423 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1424 *spec_types++ = type;
1425 g_assert (type == G_TYPE_PARAM_DOUBLE);
1428 /* G_TYPE_PARAM_STRING
1431 static const GParamSpecTypeInfo pspec_info = {
1432 sizeof (GParamSpecString), /* instance_size */
1433 16, /* n_preallocs */
1434 param_string_init, /* instance_init */
1435 G_TYPE_STRING, /* value_type */
1436 param_string_finalize, /* finalize */
1437 param_string_set_default, /* value_set_default */
1438 param_string_validate, /* value_validate */
1439 param_string_values_cmp, /* values_cmp */
1441 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1442 *spec_types++ = type;
1443 g_assert (type == G_TYPE_PARAM_STRING);
1446 /* G_TYPE_PARAM_PARAM
1449 static const GParamSpecTypeInfo pspec_info = {
1450 sizeof (GParamSpecParam), /* instance_size */
1451 16, /* n_preallocs */
1452 param_param_init, /* instance_init */
1453 G_TYPE_PARAM, /* value_type */
1454 NULL, /* finalize */
1455 param_param_set_default, /* value_set_default */
1456 param_param_validate, /* value_validate */
1457 param_pointer_values_cmp, /* values_cmp */
1459 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1460 *spec_types++ = type;
1461 g_assert (type == G_TYPE_PARAM_PARAM);
1464 /* G_TYPE_PARAM_BOXED
1467 static const GParamSpecTypeInfo pspec_info = {
1468 sizeof (GParamSpecBoxed), /* instance_size */
1469 4, /* n_preallocs */
1470 param_boxed_init, /* instance_init */
1471 G_TYPE_BOXED, /* value_type */
1472 NULL, /* finalize */
1473 param_boxed_set_default, /* value_set_default */
1474 param_boxed_validate, /* value_validate */
1475 param_boxed_values_cmp, /* values_cmp */
1477 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1478 *spec_types++ = type;
1479 g_assert (type == G_TYPE_PARAM_BOXED);
1482 /* G_TYPE_PARAM_POINTER
1485 static const GParamSpecTypeInfo pspec_info = {
1486 sizeof (GParamSpecPointer), /* instance_size */
1487 0, /* n_preallocs */
1488 param_pointer_init, /* instance_init */
1489 G_TYPE_POINTER, /* value_type */
1490 NULL, /* finalize */
1491 param_pointer_set_default, /* value_set_default */
1492 param_pointer_validate, /* value_validate */
1493 param_pointer_values_cmp, /* values_cmp */
1495 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1496 *spec_types++ = type;
1497 g_assert (type == G_TYPE_PARAM_POINTER);
1500 /* G_TYPE_PARAM_VALUE_ARRAY
1503 static /* const */ GParamSpecTypeInfo pspec_info = {
1504 sizeof (GParamSpecValueArray), /* instance_size */
1505 0, /* n_preallocs */
1506 param_value_array_init, /* instance_init */
1507 0xdeadbeef, /* value_type, assigned further down */
1508 param_value_array_finalize, /* finalize */
1509 param_value_array_set_default, /* value_set_default */
1510 param_value_array_validate, /* value_validate */
1511 param_value_array_values_cmp, /* values_cmp */
1513 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1514 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1515 *spec_types++ = type;
1516 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1519 /* G_TYPE_PARAM_OBJECT
1522 static const GParamSpecTypeInfo pspec_info = {
1523 sizeof (GParamSpecObject), /* instance_size */
1524 16, /* n_preallocs */
1525 param_object_init, /* instance_init */
1526 G_TYPE_OBJECT, /* value_type */
1527 NULL, /* finalize */
1528 param_object_set_default, /* value_set_default */
1529 param_object_validate, /* value_validate */
1530 param_object_values_cmp, /* values_cmp */
1532 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1533 *spec_types++ = type;
1534 g_assert (type == G_TYPE_PARAM_OBJECT);
1537 /* G_TYPE_PARAM_OVERRIDE
1540 static const GParamSpecTypeInfo pspec_info = {
1541 sizeof (GParamSpecOverride), /* instance_size */
1542 16, /* n_preallocs */
1543 param_override_init, /* instance_init */
1544 G_TYPE_NONE, /* value_type */
1545 param_override_finalize, /* finalize */
1546 param_override_set_default, /* value_set_default */
1547 param_override_validate, /* value_validate */
1548 param_override_values_cmp, /* values_cmp */
1550 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1551 *spec_types++ = type;
1552 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1555 /* G_TYPE_PARAM_GTYPE
1558 GParamSpecTypeInfo pspec_info = {
1559 sizeof (GParamSpecGType), /* instance_size */
1560 0, /* n_preallocs */
1561 param_gtype_init, /* instance_init */
1562 0xdeadbeef, /* value_type, assigned further down */
1563 NULL, /* finalize */
1564 param_gtype_set_default, /* value_set_default */
1565 param_gtype_validate, /* value_validate */
1566 param_gtype_values_cmp, /* values_cmp */
1568 pspec_info.value_type = G_TYPE_GTYPE;
1569 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1570 *spec_types++ = type;
1571 g_assert (type == G_TYPE_PARAM_GTYPE);
1574 /* G_TYPE_PARAM_VARIANT
1577 const GParamSpecTypeInfo pspec_info = {
1578 sizeof (GParamSpecVariant), /* instance_size */
1579 0, /* n_preallocs */
1580 param_variant_init, /* instance_init */
1581 G_TYPE_VARIANT, /* value_type */
1582 param_variant_finalize, /* finalize */
1583 param_variant_set_default, /* value_set_default */
1584 param_variant_validate, /* value_validate */
1585 param_variant_values_cmp, /* values_cmp */
1587 type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1588 *spec_types++ = type;
1589 g_assert (type == G_TYPE_PARAM_VARIANT);
1592 g_assert (spec_types == spec_types_bound);
1595 /* --- GParamSpec initialization --- */
1598 * g_param_spec_char: (skip)
1599 * @name: canonical name of the property specified
1600 * @nick: nick name for the property specified
1601 * @blurb: description of the property specified
1602 * @minimum: minimum value for the property specified
1603 * @maximum: maximum value for the property specified
1604 * @default_value: default value for the property specified
1605 * @flags: flags for the property specified
1607 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1609 * Returns: a newly created parameter specification
1611 GParamSpec*
1612 g_param_spec_char (const gchar *name,
1613 const gchar *nick,
1614 const gchar *blurb,
1615 gint8 minimum,
1616 gint8 maximum,
1617 gint8 default_value,
1618 GParamFlags flags)
1620 GParamSpecChar *cspec;
1622 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1624 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1625 name,
1626 nick,
1627 blurb,
1628 flags);
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: (skip)
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: 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);
1670 uspec->minimum = minimum;
1671 uspec->maximum = maximum;
1672 uspec->default_value = default_value;
1674 return G_PARAM_SPEC (uspec);
1678 * g_param_spec_boolean: (skip)
1679 * @name: canonical name of the property specified
1680 * @nick: nick name for the property specified
1681 * @blurb: description of the property specified
1682 * @default_value: default value for the property specified
1683 * @flags: flags for the property specified
1685 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1686 * property.
1688 * See g_param_spec_internal() for details on property names.
1690 * Returns: a newly created parameter specification
1692 GParamSpec*
1693 g_param_spec_boolean (const gchar *name,
1694 const gchar *nick,
1695 const gchar *blurb,
1696 gboolean default_value,
1697 GParamFlags flags)
1699 GParamSpecBoolean *bspec;
1701 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1703 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1704 name,
1705 nick,
1706 blurb,
1707 flags);
1709 bspec->default_value = default_value;
1711 return G_PARAM_SPEC (bspec);
1715 * g_param_spec_int: (skip)
1716 * @name: canonical name of the property specified
1717 * @nick: nick name for the property specified
1718 * @blurb: description of the property specified
1719 * @minimum: minimum value for the property specified
1720 * @maximum: maximum value for the property specified
1721 * @default_value: default value for the property specified
1722 * @flags: flags for the property specified
1724 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1726 * See g_param_spec_internal() for details on property names.
1728 * Returns: a newly created parameter specification
1730 GParamSpec*
1731 g_param_spec_int (const gchar *name,
1732 const gchar *nick,
1733 const gchar *blurb,
1734 gint minimum,
1735 gint maximum,
1736 gint default_value,
1737 GParamFlags flags)
1739 GParamSpecInt *ispec;
1741 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1743 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1744 name,
1745 nick,
1746 blurb,
1747 flags);
1749 ispec->minimum = minimum;
1750 ispec->maximum = maximum;
1751 ispec->default_value = default_value;
1753 return G_PARAM_SPEC (ispec);
1757 * g_param_spec_uint: (skip)
1758 * @name: canonical name of the property specified
1759 * @nick: nick name for the property specified
1760 * @blurb: description of the property specified
1761 * @minimum: minimum value for the property specified
1762 * @maximum: maximum value for the property specified
1763 * @default_value: default value for the property specified
1764 * @flags: flags for the property specified
1766 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1768 * See g_param_spec_internal() for details on property names.
1770 * Returns: a newly created parameter specification
1772 GParamSpec*
1773 g_param_spec_uint (const gchar *name,
1774 const gchar *nick,
1775 const gchar *blurb,
1776 guint minimum,
1777 guint maximum,
1778 guint default_value,
1779 GParamFlags flags)
1781 GParamSpecUInt *uspec;
1783 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1785 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1786 name,
1787 nick,
1788 blurb,
1789 flags);
1791 uspec->minimum = minimum;
1792 uspec->maximum = maximum;
1793 uspec->default_value = default_value;
1795 return G_PARAM_SPEC (uspec);
1799 * g_param_spec_long: (skip)
1800 * @name: canonical name of the property specified
1801 * @nick: nick name for the property specified
1802 * @blurb: description of the property specified
1803 * @minimum: minimum value for the property specified
1804 * @maximum: maximum value for the property specified
1805 * @default_value: default value for the property specified
1806 * @flags: flags for the property specified
1808 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1810 * See g_param_spec_internal() for details on property names.
1812 * Returns: a newly created parameter specification
1814 GParamSpec*
1815 g_param_spec_long (const gchar *name,
1816 const gchar *nick,
1817 const gchar *blurb,
1818 glong minimum,
1819 glong maximum,
1820 glong default_value,
1821 GParamFlags flags)
1823 GParamSpecLong *lspec;
1825 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1827 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1828 name,
1829 nick,
1830 blurb,
1831 flags);
1833 lspec->minimum = minimum;
1834 lspec->maximum = maximum;
1835 lspec->default_value = default_value;
1837 return G_PARAM_SPEC (lspec);
1841 * g_param_spec_ulong: (skip)
1842 * @name: canonical name of the property specified
1843 * @nick: nick name for the property specified
1844 * @blurb: description of the property specified
1845 * @minimum: minimum value for the property specified
1846 * @maximum: maximum value for the property specified
1847 * @default_value: default value for the property specified
1848 * @flags: flags for the property specified
1850 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG
1851 * property.
1853 * See g_param_spec_internal() for details on property names.
1855 * Returns: a newly created parameter specification
1857 GParamSpec*
1858 g_param_spec_ulong (const gchar *name,
1859 const gchar *nick,
1860 const gchar *blurb,
1861 gulong minimum,
1862 gulong maximum,
1863 gulong default_value,
1864 GParamFlags flags)
1866 GParamSpecULong *uspec;
1868 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1870 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1871 name,
1872 nick,
1873 blurb,
1874 flags);
1876 uspec->minimum = minimum;
1877 uspec->maximum = maximum;
1878 uspec->default_value = default_value;
1880 return G_PARAM_SPEC (uspec);
1884 * g_param_spec_int64: (skip)
1885 * @name: canonical name of the property specified
1886 * @nick: nick name for the property specified
1887 * @blurb: description of the property specified
1888 * @minimum: minimum value for the property specified
1889 * @maximum: maximum value for the property specified
1890 * @default_value: default value for the property specified
1891 * @flags: flags for the property specified
1893 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1895 * See g_param_spec_internal() for details on property names.
1897 * Returns: a newly created parameter specification
1899 GParamSpec*
1900 g_param_spec_int64 (const gchar *name,
1901 const gchar *nick,
1902 const gchar *blurb,
1903 gint64 minimum,
1904 gint64 maximum,
1905 gint64 default_value,
1906 GParamFlags flags)
1908 GParamSpecInt64 *lspec;
1910 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1912 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1913 name,
1914 nick,
1915 blurb,
1916 flags);
1918 lspec->minimum = minimum;
1919 lspec->maximum = maximum;
1920 lspec->default_value = default_value;
1922 return G_PARAM_SPEC (lspec);
1926 * g_param_spec_uint64: (skip)
1927 * @name: canonical name of the property specified
1928 * @nick: nick name for the property specified
1929 * @blurb: description of the property specified
1930 * @minimum: minimum value for the property specified
1931 * @maximum: maximum value for the property specified
1932 * @default_value: default value for the property specified
1933 * @flags: flags for the property specified
1935 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1936 * property.
1938 * See g_param_spec_internal() for details on property names.
1940 * Returns: a newly created parameter specification
1942 GParamSpec*
1943 g_param_spec_uint64 (const gchar *name,
1944 const gchar *nick,
1945 const gchar *blurb,
1946 guint64 minimum,
1947 guint64 maximum,
1948 guint64 default_value,
1949 GParamFlags flags)
1951 GParamSpecUInt64 *uspec;
1953 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1955 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1956 name,
1957 nick,
1958 blurb,
1959 flags);
1961 uspec->minimum = minimum;
1962 uspec->maximum = maximum;
1963 uspec->default_value = default_value;
1965 return G_PARAM_SPEC (uspec);
1969 * g_param_spec_unichar: (skip)
1970 * @name: canonical name of the property specified
1971 * @nick: nick name for the property specified
1972 * @blurb: description of the property specified
1973 * @default_value: default value for the property specified
1974 * @flags: flags for the property specified
1976 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1977 * property. #GValue structures for this property can be accessed with
1978 * g_value_set_uint() and g_value_get_uint().
1980 * See g_param_spec_internal() for details on property names.
1982 * Returns: a newly created parameter specification
1984 GParamSpec*
1985 g_param_spec_unichar (const gchar *name,
1986 const gchar *nick,
1987 const gchar *blurb,
1988 gunichar default_value,
1989 GParamFlags flags)
1991 GParamSpecUnichar *uspec;
1993 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1994 name,
1995 nick,
1996 blurb,
1997 flags);
1999 uspec->default_value = default_value;
2001 return G_PARAM_SPEC (uspec);
2005 * g_param_spec_enum: (skip)
2006 * @name: canonical name of the property specified
2007 * @nick: nick name for the property specified
2008 * @blurb: description of the property specified
2009 * @enum_type: a #GType derived from %G_TYPE_ENUM
2010 * @default_value: default value for the property specified
2011 * @flags: flags for the property specified
2013 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
2014 * property.
2016 * See g_param_spec_internal() for details on property names.
2018 * Returns: a newly created parameter specification
2020 GParamSpec*
2021 g_param_spec_enum (const gchar *name,
2022 const gchar *nick,
2023 const gchar *blurb,
2024 GType enum_type,
2025 gint default_value,
2026 GParamFlags flags)
2028 GParamSpecEnum *espec;
2029 GEnumClass *enum_class;
2031 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2033 enum_class = g_type_class_ref (enum_type);
2035 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2037 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2038 name,
2039 nick,
2040 blurb,
2041 flags);
2043 espec->enum_class = enum_class;
2044 espec->default_value = default_value;
2045 G_PARAM_SPEC (espec)->value_type = enum_type;
2047 return G_PARAM_SPEC (espec);
2051 * g_param_spec_flags: (skip)
2052 * @name: canonical name of the property specified
2053 * @nick: nick name for the property specified
2054 * @blurb: description of the property specified
2055 * @flags_type: a #GType derived from %G_TYPE_FLAGS
2056 * @default_value: default value for the property specified
2057 * @flags: flags for the property specified
2059 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
2060 * property.
2062 * See g_param_spec_internal() for details on property names.
2064 * Returns: a newly created parameter specification
2066 GParamSpec*
2067 g_param_spec_flags (const gchar *name,
2068 const gchar *nick,
2069 const gchar *blurb,
2070 GType flags_type,
2071 guint default_value,
2072 GParamFlags flags)
2074 GParamSpecFlags *fspec;
2075 GFlagsClass *flags_class;
2077 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2079 flags_class = g_type_class_ref (flags_type);
2081 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2083 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2084 name,
2085 nick,
2086 blurb,
2087 flags);
2089 fspec->flags_class = flags_class;
2090 fspec->default_value = default_value;
2091 G_PARAM_SPEC (fspec)->value_type = flags_type;
2093 return G_PARAM_SPEC (fspec);
2097 * g_param_spec_float: (skip)
2098 * @name: canonical name of the property specified
2099 * @nick: nick name for the property specified
2100 * @blurb: description of the property specified
2101 * @minimum: minimum value for the property specified
2102 * @maximum: maximum value for the property specified
2103 * @default_value: default value for the property specified
2104 * @flags: flags for the property specified
2106 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2108 * See g_param_spec_internal() for details on property names.
2110 * Returns: a newly created parameter specification
2112 GParamSpec*
2113 g_param_spec_float (const gchar *name,
2114 const gchar *nick,
2115 const gchar *blurb,
2116 gfloat minimum,
2117 gfloat maximum,
2118 gfloat default_value,
2119 GParamFlags flags)
2121 GParamSpecFloat *fspec;
2123 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2125 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2126 name,
2127 nick,
2128 blurb,
2129 flags);
2131 fspec->minimum = minimum;
2132 fspec->maximum = maximum;
2133 fspec->default_value = default_value;
2135 return G_PARAM_SPEC (fspec);
2139 * g_param_spec_double: (skip)
2140 * @name: canonical name of the property specified
2141 * @nick: nick name for the property specified
2142 * @blurb: description of the property specified
2143 * @minimum: minimum value for the property specified
2144 * @maximum: maximum value for the property specified
2145 * @default_value: default value for the property specified
2146 * @flags: flags for the property specified
2148 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2149 * property.
2151 * See g_param_spec_internal() for details on property names.
2153 * Returns: a newly created parameter specification
2155 GParamSpec*
2156 g_param_spec_double (const gchar *name,
2157 const gchar *nick,
2158 const gchar *blurb,
2159 gdouble minimum,
2160 gdouble maximum,
2161 gdouble default_value,
2162 GParamFlags flags)
2164 GParamSpecDouble *dspec;
2166 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2168 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2169 name,
2170 nick,
2171 blurb,
2172 flags);
2174 dspec->minimum = minimum;
2175 dspec->maximum = maximum;
2176 dspec->default_value = default_value;
2178 return G_PARAM_SPEC (dspec);
2182 * g_param_spec_string: (skip)
2183 * @name: canonical name of the property specified
2184 * @nick: nick name for the property specified
2185 * @blurb: description of the property specified
2186 * @default_value: default value for the property specified
2187 * @flags: flags for the property specified
2189 * Creates a new #GParamSpecString instance.
2191 * See g_param_spec_internal() for details on property names.
2193 * Returns: a newly created parameter specification
2195 GParamSpec*
2196 g_param_spec_string (const gchar *name,
2197 const gchar *nick,
2198 const gchar *blurb,
2199 const gchar *default_value,
2200 GParamFlags flags)
2202 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2203 name,
2204 nick,
2205 blurb,
2206 flags);
2207 g_free (sspec->default_value);
2208 sspec->default_value = g_strdup (default_value);
2210 return G_PARAM_SPEC (sspec);
2214 * g_param_spec_param: (skip)
2215 * @name: canonical name of the property specified
2216 * @nick: nick name for the property specified
2217 * @blurb: description of the property specified
2218 * @param_type: a #GType derived from %G_TYPE_PARAM
2219 * @flags: flags for the property specified
2221 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2222 * property.
2224 * See g_param_spec_internal() for details on property names.
2226 * Returns: a newly created parameter specification
2228 GParamSpec*
2229 g_param_spec_param (const gchar *name,
2230 const gchar *nick,
2231 const gchar *blurb,
2232 GType param_type,
2233 GParamFlags flags)
2235 GParamSpecParam *pspec;
2237 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2239 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2240 name,
2241 nick,
2242 blurb,
2243 flags);
2244 G_PARAM_SPEC (pspec)->value_type = param_type;
2246 return G_PARAM_SPEC (pspec);
2250 * g_param_spec_boxed: (skip)
2251 * @name: canonical name of the property specified
2252 * @nick: nick name for the property specified
2253 * @blurb: description of the property specified
2254 * @boxed_type: %G_TYPE_BOXED derived type of this property
2255 * @flags: flags for the property specified
2257 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2258 * derived property.
2260 * See g_param_spec_internal() for details on property names.
2262 * Returns: a newly created parameter specification
2264 GParamSpec*
2265 g_param_spec_boxed (const gchar *name,
2266 const gchar *nick,
2267 const gchar *blurb,
2268 GType boxed_type,
2269 GParamFlags flags)
2271 GParamSpecBoxed *bspec;
2273 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2274 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2276 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2277 name,
2278 nick,
2279 blurb,
2280 flags);
2281 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2283 return G_PARAM_SPEC (bspec);
2287 * g_param_spec_pointer: (skip)
2288 * @name: canonical name of the property specified
2289 * @nick: nick name for the property specified
2290 * @blurb: description of the property specified
2291 * @flags: flags for the property specified
2293 * Creates a new #GParamSpecPointer instance specifying a pointer property.
2295 * See g_param_spec_internal() for details on property names.
2297 * Returns: a newly created parameter specification
2299 GParamSpec*
2300 g_param_spec_pointer (const gchar *name,
2301 const gchar *nick,
2302 const gchar *blurb,
2303 GParamFlags flags)
2305 GParamSpecPointer *pspec;
2307 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2308 name,
2309 nick,
2310 blurb,
2311 flags);
2312 return G_PARAM_SPEC (pspec);
2316 * g_param_spec_gtype: (skip)
2317 * @name: canonical name of the property specified
2318 * @nick: nick name for the property specified
2319 * @blurb: description of the property specified
2320 * @is_a_type: a #GType whose subtypes are allowed as values
2321 * of the property (use %G_TYPE_NONE for any type)
2322 * @flags: flags for the property specified
2324 * Creates a new #GParamSpecGType instance specifying a
2325 * %G_TYPE_GTYPE property.
2327 * See g_param_spec_internal() for details on property names.
2329 * Since: 2.10
2331 * Returns: a newly created parameter specification
2333 GParamSpec*
2334 g_param_spec_gtype (const gchar *name,
2335 const gchar *nick,
2336 const gchar *blurb,
2337 GType is_a_type,
2338 GParamFlags flags)
2340 GParamSpecGType *tspec;
2342 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2343 name,
2344 nick,
2345 blurb,
2346 flags);
2348 tspec->is_a_type = is_a_type;
2350 return G_PARAM_SPEC (tspec);
2354 * g_param_spec_value_array: (skip)
2355 * @name: canonical name of the property specified
2356 * @nick: nick name for the property specified
2357 * @blurb: description of the property specified
2358 * @element_spec: a #GParamSpec describing the elements contained in
2359 * arrays of this property, may be %NULL
2360 * @flags: flags for the property specified
2362 * Creates a new #GParamSpecValueArray instance specifying a
2363 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a
2364 * %G_TYPE_BOXED type, as such, #GValue structures for this property
2365 * can be accessed with g_value_set_boxed() and g_value_get_boxed().
2367 * See g_param_spec_internal() for details on property names.
2369 * Returns: a newly created parameter specification
2371 GParamSpec*
2372 g_param_spec_value_array (const gchar *name,
2373 const gchar *nick,
2374 const gchar *blurb,
2375 GParamSpec *element_spec,
2376 GParamFlags flags)
2378 GParamSpecValueArray *aspec;
2380 if (element_spec)
2381 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2383 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2384 name,
2385 nick,
2386 blurb,
2387 flags);
2388 if (element_spec)
2390 aspec->element_spec = g_param_spec_ref (element_spec);
2391 g_param_spec_sink (element_spec);
2394 return G_PARAM_SPEC (aspec);
2398 * g_param_spec_object: (skip)
2399 * @name: canonical name of the property specified
2400 * @nick: nick name for the property specified
2401 * @blurb: description of the property specified
2402 * @object_type: %G_TYPE_OBJECT derived type of this property
2403 * @flags: flags for the property specified
2405 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2406 * derived property.
2408 * See g_param_spec_internal() for details on property names.
2410 * Returns: a newly created parameter specification
2412 GParamSpec*
2413 g_param_spec_object (const gchar *name,
2414 const gchar *nick,
2415 const gchar *blurb,
2416 GType object_type,
2417 GParamFlags flags)
2419 GParamSpecObject *ospec;
2421 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2423 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2424 name,
2425 nick,
2426 blurb,
2427 flags);
2428 G_PARAM_SPEC (ospec)->value_type = object_type;
2430 return G_PARAM_SPEC (ospec);
2434 * g_param_spec_override: (skip)
2435 * @name: the name of the property.
2436 * @overridden: The property that is being overridden
2438 * Creates a new property of type #GParamSpecOverride. This is used
2439 * to direct operations to another paramspec, and will not be directly
2440 * useful unless you are implementing a new base type similar to GObject.
2442 * Since: 2.4
2444 * Returns: the newly created #GParamSpec
2446 GParamSpec*
2447 g_param_spec_override (const gchar *name,
2448 GParamSpec *overridden)
2450 GParamSpec *pspec;
2452 g_return_val_if_fail (name != NULL, NULL);
2453 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2455 /* Dereference further redirections for property that was passed in
2457 while (TRUE)
2459 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2460 if (indirect)
2461 overridden = indirect;
2462 else
2463 break;
2466 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2467 name, NULL, NULL,
2468 overridden->flags);
2470 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2471 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2473 return pspec;
2477 * g_param_spec_variant: (skip)
2478 * @name: canonical name of the property specified
2479 * @nick: nick name for the property specified
2480 * @blurb: description of the property specified
2481 * @type: a #GVariantType
2482 * @default_value: (allow-none): a #GVariant of type @type to use as the
2483 * default value, or %NULL
2484 * @flags: flags for the property specified
2486 * Creates a new #GParamSpecVariant instance specifying a #GVariant
2487 * property.
2489 * If @default_value is floating, it is consumed.
2491 * See g_param_spec_internal() for details on property names.
2493 * Returns: the newly created #GParamSpec
2495 * Since: 2.26
2497 GParamSpec*
2498 g_param_spec_variant (const gchar *name,
2499 const gchar *nick,
2500 const gchar *blurb,
2501 const GVariantType *type,
2502 GVariant *default_value,
2503 GParamFlags flags)
2505 GParamSpecVariant *vspec;
2507 g_return_val_if_fail (type != NULL, NULL);
2508 g_return_val_if_fail (default_value == NULL ||
2509 g_variant_is_of_type (default_value, type), NULL);
2511 vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2512 name,
2513 nick,
2514 blurb,
2515 flags);
2517 vspec->type = g_variant_type_copy (type);
2518 if (default_value)
2519 vspec->default_value = g_variant_ref_sink (default_value);
2521 return G_PARAM_SPEC (vspec);