1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
20 * SECTION:param_value_types
21 * @Short_description: Standard Parameter and Value Types
22 * @See_also:#GParamSpec, #GValue, g_object_class_install_property().
23 * @Title: Parameters and Values
25 * #GValue provides an abstract container structure which can be copied,
26 * transformed and compared while holding a value of any (derived) type, which
27 * is registered as a #GType with a #GTypeValueTable in its #GTypeInfo structure.
28 * Parameter specifications for most value types can be created as
29 * #GParamSpec derived instances, to implement e.g. #GObject properties which
30 * operate on #GValue containers.
32 * Parameter names need to start with a letter (a-z or A-Z). Subsequent
33 * characters can be letters, numbers or a '-'.
34 * All other characters are replaced by a '-' during construction.
40 #include "../config.h"
42 #include "gparamspecs.h"
44 #include "gvaluecollector.h"
45 #include "gvaluearray.h"
46 #include "gobjectalias.h"
49 #define G_FLOAT_EPSILON (1e-30)
50 #define G_DOUBLE_EPSILON (1e-90)
53 /* --- param spec functions --- */
55 param_char_init (GParamSpec *pspec)
57 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
59 cspec->minimum = 0x7f;
60 cspec->maximum = 0x80;
61 cspec->default_value = 0;
65 param_char_set_default (GParamSpec *pspec,
68 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
72 param_char_validate (GParamSpec *pspec,
75 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
76 gint oval = value->data[0].v_int;
78 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
80 return value->data[0].v_int != oval;
84 param_uchar_init (GParamSpec *pspec)
86 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
89 uspec->maximum = 0xff;
90 uspec->default_value = 0;
94 param_uchar_set_default (GParamSpec *pspec,
97 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
101 param_uchar_validate (GParamSpec *pspec,
104 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
105 guint oval = value->data[0].v_uint;
107 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
109 return value->data[0].v_uint != oval;
113 param_boolean_set_default (GParamSpec *pspec,
116 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
120 param_boolean_validate (GParamSpec *pspec,
123 gint oval = value->data[0].v_int;
125 value->data[0].v_int = value->data[0].v_int != FALSE;
127 return value->data[0].v_int != oval;
131 param_int_init (GParamSpec *pspec)
133 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
135 ispec->minimum = 0x7fffffff;
136 ispec->maximum = 0x80000000;
137 ispec->default_value = 0;
141 param_int_set_default (GParamSpec *pspec,
144 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
148 param_int_validate (GParamSpec *pspec,
151 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
152 gint oval = value->data[0].v_int;
154 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
156 return value->data[0].v_int != oval;
160 param_int_values_cmp (GParamSpec *pspec,
161 const GValue *value1,
162 const GValue *value2)
164 if (value1->data[0].v_int < value2->data[0].v_int)
167 return value1->data[0].v_int > value2->data[0].v_int;
171 param_uint_init (GParamSpec *pspec)
173 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
176 uspec->maximum = 0xffffffff;
177 uspec->default_value = 0;
181 param_uint_set_default (GParamSpec *pspec,
184 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
188 param_uint_validate (GParamSpec *pspec,
191 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
192 guint oval = value->data[0].v_uint;
194 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
196 return value->data[0].v_uint != oval;
200 param_uint_values_cmp (GParamSpec *pspec,
201 const GValue *value1,
202 const GValue *value2)
204 if (value1->data[0].v_uint < value2->data[0].v_uint)
207 return value1->data[0].v_uint > value2->data[0].v_uint;
211 param_long_init (GParamSpec *pspec)
213 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
216 lspec->minimum = 0x7fffffff;
217 lspec->maximum = 0x80000000;
218 #else /* SIZEOF_LONG != 4 (8) */
219 lspec->minimum = 0x7fffffffffffffff;
220 lspec->maximum = 0x8000000000000000;
222 lspec->default_value = 0;
226 param_long_set_default (GParamSpec *pspec,
229 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
233 param_long_validate (GParamSpec *pspec,
236 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
237 glong oval = value->data[0].v_long;
239 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
241 return value->data[0].v_long != oval;
245 param_long_values_cmp (GParamSpec *pspec,
246 const GValue *value1,
247 const GValue *value2)
249 if (value1->data[0].v_long < value2->data[0].v_long)
252 return value1->data[0].v_long > value2->data[0].v_long;
256 param_ulong_init (GParamSpec *pspec)
258 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
262 uspec->maximum = 0xffffffff;
263 #else /* SIZEOF_LONG != 4 (8) */
264 uspec->maximum = 0xffffffffffffffff;
266 uspec->default_value = 0;
270 param_ulong_set_default (GParamSpec *pspec,
273 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
277 param_ulong_validate (GParamSpec *pspec,
280 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
281 gulong oval = value->data[0].v_ulong;
283 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
285 return value->data[0].v_ulong != oval;
289 param_ulong_values_cmp (GParamSpec *pspec,
290 const GValue *value1,
291 const GValue *value2)
293 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
296 return value1->data[0].v_ulong > value2->data[0].v_ulong;
300 param_int64_init (GParamSpec *pspec)
302 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
304 lspec->minimum = G_MININT64;
305 lspec->maximum = G_MAXINT64;
306 lspec->default_value = 0;
310 param_int64_set_default (GParamSpec *pspec,
313 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
317 param_int64_validate (GParamSpec *pspec,
320 GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
321 gint64 oval = value->data[0].v_int64;
323 value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
325 return value->data[0].v_int64 != oval;
329 param_int64_values_cmp (GParamSpec *pspec,
330 const GValue *value1,
331 const GValue *value2)
333 if (value1->data[0].v_int64 < value2->data[0].v_int64)
336 return value1->data[0].v_int64 > value2->data[0].v_int64;
340 param_uint64_init (GParamSpec *pspec)
342 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
345 uspec->maximum = G_MAXUINT64;
346 uspec->default_value = 0;
350 param_uint64_set_default (GParamSpec *pspec,
353 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
357 param_uint64_validate (GParamSpec *pspec,
360 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
361 guint64 oval = value->data[0].v_uint64;
363 value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
365 return value->data[0].v_uint64 != oval;
369 param_uint64_values_cmp (GParamSpec *pspec,
370 const GValue *value1,
371 const GValue *value2)
373 if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
376 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
380 param_unichar_init (GParamSpec *pspec)
382 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
384 uspec->default_value = 0;
388 param_unichar_set_default (GParamSpec *pspec,
391 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
395 param_unichar_validate (GParamSpec *pspec,
398 gunichar oval = value->data[0].v_uint;
399 gboolean changed = FALSE;
401 if (!g_unichar_validate (oval))
403 value->data[0].v_uint = 0;
411 param_unichar_values_cmp (GParamSpec *pspec,
412 const GValue *value1,
413 const GValue *value2)
415 if (value1->data[0].v_uint < value2->data[0].v_uint)
418 return value1->data[0].v_uint > value2->data[0].v_uint;
422 param_enum_init (GParamSpec *pspec)
424 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
426 espec->enum_class = NULL;
427 espec->default_value = 0;
431 param_enum_finalize (GParamSpec *pspec)
433 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
434 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
436 if (espec->enum_class)
438 g_type_class_unref (espec->enum_class);
439 espec->enum_class = NULL;
442 parent_class->finalize (pspec);
446 param_enum_set_default (GParamSpec *pspec,
449 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
453 param_enum_validate (GParamSpec *pspec,
456 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
457 glong oval = value->data[0].v_long;
459 if (!espec->enum_class ||
460 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
461 value->data[0].v_long = espec->default_value;
463 return value->data[0].v_long != oval;
467 param_flags_init (GParamSpec *pspec)
469 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
471 fspec->flags_class = NULL;
472 fspec->default_value = 0;
476 param_flags_finalize (GParamSpec *pspec)
478 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
479 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
481 if (fspec->flags_class)
483 g_type_class_unref (fspec->flags_class);
484 fspec->flags_class = NULL;
487 parent_class->finalize (pspec);
491 param_flags_set_default (GParamSpec *pspec,
494 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
498 param_flags_validate (GParamSpec *pspec,
501 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
502 gulong oval = value->data[0].v_ulong;
504 if (fspec->flags_class)
505 value->data[0].v_ulong &= fspec->flags_class->mask;
507 value->data[0].v_ulong = fspec->default_value;
509 return value->data[0].v_ulong != oval;
513 param_float_init (GParamSpec *pspec)
515 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
517 fspec->minimum = -G_MAXFLOAT;
518 fspec->maximum = G_MAXFLOAT;
519 fspec->default_value = 0;
520 fspec->epsilon = G_FLOAT_EPSILON;
524 param_float_set_default (GParamSpec *pspec,
527 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
531 param_float_validate (GParamSpec *pspec,
534 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
535 gfloat oval = value->data[0].v_float;
537 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
539 return value->data[0].v_float != oval;
543 param_float_values_cmp (GParamSpec *pspec,
544 const GValue *value1,
545 const GValue *value2)
547 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
549 if (value1->data[0].v_float < value2->data[0].v_float)
550 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
552 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
556 param_double_init (GParamSpec *pspec)
558 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
560 dspec->minimum = -G_MAXDOUBLE;
561 dspec->maximum = G_MAXDOUBLE;
562 dspec->default_value = 0;
563 dspec->epsilon = G_DOUBLE_EPSILON;
567 param_double_set_default (GParamSpec *pspec,
570 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
574 param_double_validate (GParamSpec *pspec,
577 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
578 gdouble oval = value->data[0].v_double;
580 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
582 return value->data[0].v_double != oval;
586 param_double_values_cmp (GParamSpec *pspec,
587 const GValue *value1,
588 const GValue *value2)
590 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
592 if (value1->data[0].v_double < value2->data[0].v_double)
593 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
595 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
599 param_string_init (GParamSpec *pspec)
601 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
603 sspec->default_value = NULL;
604 sspec->cset_first = NULL;
605 sspec->cset_nth = NULL;
606 sspec->substitutor = '_';
607 sspec->null_fold_if_empty = FALSE;
608 sspec->ensure_non_null = FALSE;
612 param_string_finalize (GParamSpec *pspec)
614 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
615 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
617 g_free (sspec->default_value);
618 g_free (sspec->cset_first);
619 g_free (sspec->cset_nth);
620 sspec->default_value = NULL;
621 sspec->cset_first = NULL;
622 sspec->cset_nth = NULL;
624 parent_class->finalize (pspec);
628 param_string_set_default (GParamSpec *pspec,
631 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
635 param_string_validate (GParamSpec *pspec,
638 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
639 gchar *string = value->data[0].v_pointer;
642 if (string && string[0])
646 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
648 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
650 value->data[0].v_pointer = g_strdup (string);
651 string = value->data[0].v_pointer;
652 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
654 string[0] = sspec->substitutor;
658 for (s = string + 1; *s; s++)
659 if (!strchr (sspec->cset_nth, *s))
661 if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
663 value->data[0].v_pointer = g_strdup (string);
664 s = (gchar*) value->data[0].v_pointer + (s - string);
665 string = value->data[0].v_pointer;
666 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
668 *s = sspec->substitutor;
672 if (sspec->null_fold_if_empty && string && string[0] == 0)
674 if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
675 g_free (value->data[0].v_pointer);
677 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
678 value->data[0].v_pointer = NULL;
680 string = value->data[0].v_pointer;
682 if (sspec->ensure_non_null && !string)
684 value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
685 value->data[0].v_pointer = g_strdup ("");
687 string = value->data[0].v_pointer;
694 param_string_values_cmp (GParamSpec *pspec,
695 const GValue *value1,
696 const GValue *value2)
698 if (!value1->data[0].v_pointer)
699 return value2->data[0].v_pointer != NULL ? -1 : 0;
700 else if (!value2->data[0].v_pointer)
701 return value1->data[0].v_pointer != NULL;
703 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
707 param_param_init (GParamSpec *pspec)
709 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
713 param_param_set_default (GParamSpec *pspec,
716 value->data[0].v_pointer = NULL;
720 param_param_validate (GParamSpec *pspec,
723 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
724 GParamSpec *param = value->data[0].v_pointer;
727 if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
729 g_param_spec_unref (param);
730 value->data[0].v_pointer = NULL;
738 param_boxed_init (GParamSpec *pspec)
740 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
744 param_boxed_set_default (GParamSpec *pspec,
747 value->data[0].v_pointer = NULL;
751 param_boxed_validate (GParamSpec *pspec,
754 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
757 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
763 param_boxed_values_cmp (GParamSpec *pspec,
764 const GValue *value1,
765 const GValue *value2)
767 guint8 *p1 = value1->data[0].v_pointer;
768 guint8 *p2 = value2->data[0].v_pointer;
770 /* not much to compare here, try to at least provide stable lesser/greater result */
772 return p1 < p2 ? -1 : p1 > p2;
776 param_pointer_init (GParamSpec *pspec)
778 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
782 param_pointer_set_default (GParamSpec *pspec,
785 value->data[0].v_pointer = NULL;
789 param_pointer_validate (GParamSpec *pspec,
792 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
799 param_pointer_values_cmp (GParamSpec *pspec,
800 const GValue *value1,
801 const GValue *value2)
803 guint8 *p1 = value1->data[0].v_pointer;
804 guint8 *p2 = value2->data[0].v_pointer;
806 /* not much to compare here, try to at least provide stable lesser/greater result */
808 return p1 < p2 ? -1 : p1 > p2;
812 param_value_array_init (GParamSpec *pspec)
814 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
816 aspec->element_spec = NULL;
817 aspec->fixed_n_elements = 0; /* disable */
821 value_array_ensure_size (GValueArray *value_array,
822 guint fixed_n_elements)
826 if (fixed_n_elements)
828 while (value_array->n_values < fixed_n_elements)
830 g_value_array_append (value_array, NULL);
833 while (value_array->n_values > fixed_n_elements)
835 g_value_array_remove (value_array, value_array->n_values - 1);
843 param_value_array_finalize (GParamSpec *pspec)
845 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
846 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY));
848 if (aspec->element_spec)
850 g_param_spec_unref (aspec->element_spec);
851 aspec->element_spec = NULL;
854 parent_class->finalize (pspec);
858 param_value_array_set_default (GParamSpec *pspec,
861 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
863 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
864 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
866 if (value->data[0].v_pointer)
868 /* g_value_reset (value); already done */
869 value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
874 param_value_array_validate (GParamSpec *pspec,
877 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
878 GValueArray *value_array = value->data[0].v_pointer;
881 if (!value->data[0].v_pointer && aspec->fixed_n_elements)
882 value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
884 if (value->data[0].v_pointer)
886 /* ensure array size validity */
887 changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
889 /* ensure array values validity against a present element spec */
890 if (aspec->element_spec)
892 GParamSpec *element_spec = aspec->element_spec;
895 for (i = 0; i < value_array->n_values; i++)
897 GValue *element = value_array->values + i;
899 /* need to fixup value type, or ensure that the array value is initialized at all */
900 if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec)))
902 if (G_VALUE_TYPE (element) != 0)
903 g_value_unset (element);
904 g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
905 g_param_value_set_default (element_spec, element);
908 /* validate array value against element_spec */
909 changed += g_param_value_validate (element_spec, element);
918 param_value_array_values_cmp (GParamSpec *pspec,
919 const GValue *value1,
920 const GValue *value2)
922 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
923 GValueArray *value_array1 = value1->data[0].v_pointer;
924 GValueArray *value_array2 = value2->data[0].v_pointer;
926 if (!value_array1 || !value_array2)
927 return value_array2 ? -1 : value_array1 != value_array2;
929 if (value_array1->n_values != value_array2->n_values)
930 return value_array1->n_values < value_array2->n_values ? -1 : 1;
931 else if (!aspec->element_spec)
933 /* we need an element specification for comparisons, so there's not much
934 * to compare here, try to at least provide stable lesser/greater result
936 return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values;
938 else /* value_array1->n_values == value_array2->n_values */
942 for (i = 0; i < value_array1->n_values; i++)
944 GValue *element1 = value_array1->values + i;
945 GValue *element2 = value_array2->values + i;
948 /* need corresponding element types, provide stable result otherwise */
949 if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2))
950 return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1;
951 cmp = g_param_values_cmp (aspec->element_spec, element1, element2);
960 param_object_init (GParamSpec *pspec)
962 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
966 param_object_set_default (GParamSpec *pspec,
969 value->data[0].v_pointer = NULL;
973 param_object_validate (GParamSpec *pspec,
976 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
977 GObject *object = value->data[0].v_pointer;
980 if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
982 g_object_unref (object);
983 value->data[0].v_pointer = NULL;
991 param_object_values_cmp (GParamSpec *pspec,
992 const GValue *value1,
993 const GValue *value2)
995 guint8 *p1 = value1->data[0].v_pointer;
996 guint8 *p2 = value2->data[0].v_pointer;
998 /* not much to compare here, try to at least provide stable lesser/greater result */
1000 return p1 < p2 ? -1 : p1 > p2;
1004 param_override_init (GParamSpec *pspec)
1006 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1010 param_override_finalize (GParamSpec *pspec)
1012 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1013 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1015 if (ospec->overridden)
1017 g_param_spec_unref (ospec->overridden);
1018 ospec->overridden = NULL;
1021 parent_class->finalize (pspec);
1025 param_override_set_default (GParamSpec *pspec,
1028 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1030 g_param_value_set_default (ospec->overridden, value);
1034 param_override_validate (GParamSpec *pspec,
1037 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1039 return g_param_value_validate (ospec->overridden, value);
1043 param_override_values_cmp (GParamSpec *pspec,
1044 const GValue *value1,
1045 const GValue *value2)
1047 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1049 return g_param_values_cmp (ospec->overridden, value1, value2);
1053 param_gtype_init (GParamSpec *pspec)
1058 param_gtype_set_default (GParamSpec *pspec,
1061 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1063 value->data[0].v_long = tspec->is_a_type;
1067 param_gtype_validate (GParamSpec *pspec,
1070 GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1071 GType gtype = value->data[0].v_long;
1074 if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1076 value->data[0].v_long = tspec->is_a_type;
1084 param_gtype_values_cmp (GParamSpec *pspec,
1085 const GValue *value1,
1086 const GValue *value2)
1088 GType p1 = value1->data[0].v_long;
1089 GType p2 = value2->data[0].v_long;
1091 /* not much to compare here, try to at least provide stable lesser/greater result */
1093 return p1 < p2 ? -1 : p1 > p2;
1096 /* --- type initialization --- */
1097 GType *g_param_spec_types = NULL;
1100 g_param_spec_types_init (void)
1102 const guint n_types = 22;
1103 GType type, *spec_types, *spec_types_bound;
1105 g_param_spec_types = g_new0 (GType, n_types);
1106 spec_types = g_param_spec_types;
1107 spec_types_bound = g_param_spec_types + n_types;
1109 /* G_TYPE_PARAM_CHAR
1112 static const GParamSpecTypeInfo pspec_info = {
1113 sizeof (GParamSpecChar), /* instance_size */
1114 16, /* n_preallocs */
1115 param_char_init, /* instance_init */
1116 G_TYPE_CHAR, /* value_type */
1117 NULL, /* finalize */
1118 param_char_set_default, /* value_set_default */
1119 param_char_validate, /* value_validate */
1120 param_int_values_cmp, /* values_cmp */
1122 type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1123 *spec_types++ = type;
1124 g_assert (type == G_TYPE_PARAM_CHAR);
1127 /* G_TYPE_PARAM_UCHAR
1130 static const GParamSpecTypeInfo pspec_info = {
1131 sizeof (GParamSpecUChar), /* instance_size */
1132 16, /* n_preallocs */
1133 param_uchar_init, /* instance_init */
1134 G_TYPE_UCHAR, /* value_type */
1135 NULL, /* finalize */
1136 param_uchar_set_default, /* value_set_default */
1137 param_uchar_validate, /* value_validate */
1138 param_uint_values_cmp, /* values_cmp */
1140 type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1141 *spec_types++ = type;
1142 g_assert (type == G_TYPE_PARAM_UCHAR);
1145 /* G_TYPE_PARAM_BOOLEAN
1148 static const GParamSpecTypeInfo pspec_info = {
1149 sizeof (GParamSpecBoolean), /* instance_size */
1150 16, /* n_preallocs */
1151 NULL, /* instance_init */
1152 G_TYPE_BOOLEAN, /* value_type */
1153 NULL, /* finalize */
1154 param_boolean_set_default, /* value_set_default */
1155 param_boolean_validate, /* value_validate */
1156 param_int_values_cmp, /* values_cmp */
1158 type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1159 *spec_types++ = type;
1160 g_assert (type == G_TYPE_PARAM_BOOLEAN);
1166 static const GParamSpecTypeInfo pspec_info = {
1167 sizeof (GParamSpecInt), /* instance_size */
1168 16, /* n_preallocs */
1169 param_int_init, /* instance_init */
1170 G_TYPE_INT, /* value_type */
1171 NULL, /* finalize */
1172 param_int_set_default, /* value_set_default */
1173 param_int_validate, /* value_validate */
1174 param_int_values_cmp, /* values_cmp */
1176 type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1177 *spec_types++ = type;
1178 g_assert (type == G_TYPE_PARAM_INT);
1181 /* G_TYPE_PARAM_UINT
1184 static const GParamSpecTypeInfo pspec_info = {
1185 sizeof (GParamSpecUInt), /* instance_size */
1186 16, /* n_preallocs */
1187 param_uint_init, /* instance_init */
1188 G_TYPE_UINT, /* value_type */
1189 NULL, /* finalize */
1190 param_uint_set_default, /* value_set_default */
1191 param_uint_validate, /* value_validate */
1192 param_uint_values_cmp, /* values_cmp */
1194 type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1195 *spec_types++ = type;
1196 g_assert (type == G_TYPE_PARAM_UINT);
1199 /* G_TYPE_PARAM_LONG
1202 static const GParamSpecTypeInfo pspec_info = {
1203 sizeof (GParamSpecLong), /* instance_size */
1204 16, /* n_preallocs */
1205 param_long_init, /* instance_init */
1206 G_TYPE_LONG, /* value_type */
1207 NULL, /* finalize */
1208 param_long_set_default, /* value_set_default */
1209 param_long_validate, /* value_validate */
1210 param_long_values_cmp, /* values_cmp */
1212 type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1213 *spec_types++ = type;
1214 g_assert (type == G_TYPE_PARAM_LONG);
1217 /* G_TYPE_PARAM_ULONG
1220 static const GParamSpecTypeInfo pspec_info = {
1221 sizeof (GParamSpecULong), /* instance_size */
1222 16, /* n_preallocs */
1223 param_ulong_init, /* instance_init */
1224 G_TYPE_ULONG, /* value_type */
1225 NULL, /* finalize */
1226 param_ulong_set_default, /* value_set_default */
1227 param_ulong_validate, /* value_validate */
1228 param_ulong_values_cmp, /* values_cmp */
1230 type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1231 *spec_types++ = type;
1232 g_assert (type == G_TYPE_PARAM_ULONG);
1235 /* G_TYPE_PARAM_INT64
1238 static const GParamSpecTypeInfo pspec_info = {
1239 sizeof (GParamSpecInt64), /* instance_size */
1240 16, /* n_preallocs */
1241 param_int64_init, /* instance_init */
1242 G_TYPE_INT64, /* value_type */
1243 NULL, /* finalize */
1244 param_int64_set_default, /* value_set_default */
1245 param_int64_validate, /* value_validate */
1246 param_int64_values_cmp, /* values_cmp */
1248 type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1249 *spec_types++ = type;
1250 g_assert (type == G_TYPE_PARAM_INT64);
1253 /* G_TYPE_PARAM_UINT64
1256 static const GParamSpecTypeInfo pspec_info = {
1257 sizeof (GParamSpecUInt64), /* instance_size */
1258 16, /* n_preallocs */
1259 param_uint64_init, /* instance_init */
1260 G_TYPE_UINT64, /* value_type */
1261 NULL, /* finalize */
1262 param_uint64_set_default, /* value_set_default */
1263 param_uint64_validate, /* value_validate */
1264 param_uint64_values_cmp, /* values_cmp */
1266 type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1267 *spec_types++ = type;
1268 g_assert (type == G_TYPE_PARAM_UINT64);
1271 /* G_TYPE_PARAM_UNICHAR
1274 static const GParamSpecTypeInfo pspec_info = {
1275 sizeof (GParamSpecUnichar), /* instance_size */
1276 16, /* n_preallocs */
1277 param_unichar_init, /* instance_init */
1278 G_TYPE_UINT, /* value_type */
1279 NULL, /* finalize */
1280 param_unichar_set_default, /* value_set_default */
1281 param_unichar_validate, /* value_validate */
1282 param_unichar_values_cmp, /* values_cmp */
1284 type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1285 *spec_types++ = type;
1286 g_assert (type == G_TYPE_PARAM_UNICHAR);
1289 /* G_TYPE_PARAM_ENUM
1292 static const GParamSpecTypeInfo pspec_info = {
1293 sizeof (GParamSpecEnum), /* instance_size */
1294 16, /* n_preallocs */
1295 param_enum_init, /* instance_init */
1296 G_TYPE_ENUM, /* value_type */
1297 param_enum_finalize, /* finalize */
1298 param_enum_set_default, /* value_set_default */
1299 param_enum_validate, /* value_validate */
1300 param_long_values_cmp, /* values_cmp */
1302 type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1303 *spec_types++ = type;
1304 g_assert (type == G_TYPE_PARAM_ENUM);
1307 /* G_TYPE_PARAM_FLAGS
1310 static const GParamSpecTypeInfo pspec_info = {
1311 sizeof (GParamSpecFlags), /* instance_size */
1312 16, /* n_preallocs */
1313 param_flags_init, /* instance_init */
1314 G_TYPE_FLAGS, /* value_type */
1315 param_flags_finalize, /* finalize */
1316 param_flags_set_default, /* value_set_default */
1317 param_flags_validate, /* value_validate */
1318 param_ulong_values_cmp, /* values_cmp */
1320 type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1321 *spec_types++ = type;
1322 g_assert (type == G_TYPE_PARAM_FLAGS);
1325 /* G_TYPE_PARAM_FLOAT
1328 static const GParamSpecTypeInfo pspec_info = {
1329 sizeof (GParamSpecFloat), /* instance_size */
1330 16, /* n_preallocs */
1331 param_float_init, /* instance_init */
1332 G_TYPE_FLOAT, /* value_type */
1333 NULL, /* finalize */
1334 param_float_set_default, /* value_set_default */
1335 param_float_validate, /* value_validate */
1336 param_float_values_cmp, /* values_cmp */
1338 type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1339 *spec_types++ = type;
1340 g_assert (type == G_TYPE_PARAM_FLOAT);
1343 /* G_TYPE_PARAM_DOUBLE
1346 static const GParamSpecTypeInfo pspec_info = {
1347 sizeof (GParamSpecDouble), /* instance_size */
1348 16, /* n_preallocs */
1349 param_double_init, /* instance_init */
1350 G_TYPE_DOUBLE, /* value_type */
1351 NULL, /* finalize */
1352 param_double_set_default, /* value_set_default */
1353 param_double_validate, /* value_validate */
1354 param_double_values_cmp, /* values_cmp */
1356 type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1357 *spec_types++ = type;
1358 g_assert (type == G_TYPE_PARAM_DOUBLE);
1361 /* G_TYPE_PARAM_STRING
1364 static const GParamSpecTypeInfo pspec_info = {
1365 sizeof (GParamSpecString), /* instance_size */
1366 16, /* n_preallocs */
1367 param_string_init, /* instance_init */
1368 G_TYPE_STRING, /* value_type */
1369 param_string_finalize, /* finalize */
1370 param_string_set_default, /* value_set_default */
1371 param_string_validate, /* value_validate */
1372 param_string_values_cmp, /* values_cmp */
1374 type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1375 *spec_types++ = type;
1376 g_assert (type == G_TYPE_PARAM_STRING);
1379 /* G_TYPE_PARAM_PARAM
1382 static const GParamSpecTypeInfo pspec_info = {
1383 sizeof (GParamSpecParam), /* instance_size */
1384 16, /* n_preallocs */
1385 param_param_init, /* instance_init */
1386 G_TYPE_PARAM, /* value_type */
1387 NULL, /* finalize */
1388 param_param_set_default, /* value_set_default */
1389 param_param_validate, /* value_validate */
1390 param_pointer_values_cmp, /* values_cmp */
1392 type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1393 *spec_types++ = type;
1394 g_assert (type == G_TYPE_PARAM_PARAM);
1397 /* G_TYPE_PARAM_BOXED
1400 static const GParamSpecTypeInfo pspec_info = {
1401 sizeof (GParamSpecBoxed), /* instance_size */
1402 4, /* n_preallocs */
1403 param_boxed_init, /* instance_init */
1404 G_TYPE_BOXED, /* value_type */
1405 NULL, /* finalize */
1406 param_boxed_set_default, /* value_set_default */
1407 param_boxed_validate, /* value_validate */
1408 param_boxed_values_cmp, /* values_cmp */
1410 type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1411 *spec_types++ = type;
1412 g_assert (type == G_TYPE_PARAM_BOXED);
1415 /* G_TYPE_PARAM_POINTER
1418 static const GParamSpecTypeInfo pspec_info = {
1419 sizeof (GParamSpecPointer), /* instance_size */
1420 0, /* n_preallocs */
1421 param_pointer_init, /* instance_init */
1422 G_TYPE_POINTER, /* value_type */
1423 NULL, /* finalize */
1424 param_pointer_set_default, /* value_set_default */
1425 param_pointer_validate, /* value_validate */
1426 param_pointer_values_cmp, /* values_cmp */
1428 type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1429 *spec_types++ = type;
1430 g_assert (type == G_TYPE_PARAM_POINTER);
1433 /* G_TYPE_PARAM_VALUE_ARRAY
1436 static /* const */ GParamSpecTypeInfo pspec_info = {
1437 sizeof (GParamSpecValueArray), /* instance_size */
1438 0, /* n_preallocs */
1439 param_value_array_init, /* instance_init */
1440 0xdeadbeef, /* value_type, assigned further down */
1441 param_value_array_finalize, /* finalize */
1442 param_value_array_set_default, /* value_set_default */
1443 param_value_array_validate, /* value_validate */
1444 param_value_array_values_cmp, /* values_cmp */
1446 pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1447 type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1448 *spec_types++ = type;
1449 g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1452 /* G_TYPE_PARAM_OBJECT
1455 static const GParamSpecTypeInfo pspec_info = {
1456 sizeof (GParamSpecObject), /* instance_size */
1457 16, /* n_preallocs */
1458 param_object_init, /* instance_init */
1459 G_TYPE_OBJECT, /* value_type */
1460 NULL, /* finalize */
1461 param_object_set_default, /* value_set_default */
1462 param_object_validate, /* value_validate */
1463 param_object_values_cmp, /* values_cmp */
1465 type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1466 *spec_types++ = type;
1467 g_assert (type == G_TYPE_PARAM_OBJECT);
1470 /* G_TYPE_PARAM_OVERRIDE
1473 static const GParamSpecTypeInfo pspec_info = {
1474 sizeof (GParamSpecOverride), /* instance_size */
1475 16, /* n_preallocs */
1476 param_override_init, /* instance_init */
1477 G_TYPE_NONE, /* value_type */
1478 param_override_finalize, /* finalize */
1479 param_override_set_default, /* value_set_default */
1480 param_override_validate, /* value_validate */
1481 param_override_values_cmp, /* values_cmp */
1483 type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1484 *spec_types++ = type;
1485 g_assert (type == G_TYPE_PARAM_OVERRIDE);
1488 /* G_TYPE_PARAM_GTYPE
1491 GParamSpecTypeInfo pspec_info = {
1492 sizeof (GParamSpecGType), /* instance_size */
1493 0, /* n_preallocs */
1494 param_gtype_init, /* instance_init */
1495 0xdeadbeef, /* value_type, assigned further down */
1496 NULL, /* finalize */
1497 param_gtype_set_default, /* value_set_default */
1498 param_gtype_validate, /* value_validate */
1499 param_gtype_values_cmp, /* values_cmp */
1501 pspec_info.value_type = G_TYPE_GTYPE;
1502 type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1503 *spec_types++ = type;
1504 g_assert (type == G_TYPE_PARAM_GTYPE);
1507 g_assert (spec_types == spec_types_bound);
1510 /* --- GParamSpec initialization --- */
1513 * g_param_spec_char:
1514 * @name: canonical name of the property specified
1515 * @nick: nick name for the property specified
1516 * @blurb: description of the property specified
1517 * @minimum: minimum value for the property specified
1518 * @maximum: maximum value for the property specified
1519 * @default_value: default value for the property specified
1520 * @flags: flags for the property specified
1522 * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property.
1524 * Returns: a newly created parameter specification
1527 g_param_spec_char (const gchar *name,
1532 gint8 default_value,
1535 GParamSpecChar *cspec;
1537 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1539 cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1545 cspec->minimum = minimum;
1546 cspec->maximum = maximum;
1547 cspec->default_value = default_value;
1549 return G_PARAM_SPEC (cspec);
1553 * g_param_spec_uchar:
1554 * @name: canonical name of the property specified
1555 * @nick: nick name for the property specified
1556 * @blurb: description of the property specified
1557 * @minimum: minimum value for the property specified
1558 * @maximum: maximum value for the property specified
1559 * @default_value: default value for the property specified
1560 * @flags: flags for the property specified
1562 * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property.
1564 * Returns: a newly created parameter specification
1567 g_param_spec_uchar (const gchar *name,
1572 guint8 default_value,
1575 GParamSpecUChar *uspec;
1577 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1579 uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1585 uspec->minimum = minimum;
1586 uspec->maximum = maximum;
1587 uspec->default_value = default_value;
1589 return G_PARAM_SPEC (uspec);
1593 * g_param_spec_boolean:
1594 * @name: canonical name of the property specified
1595 * @nick: nick name for the property specified
1596 * @blurb: description of the property specified
1597 * @default_value: default value for the property specified
1598 * @flags: flags for the property specified
1600 * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN
1603 * See g_param_spec_internal() for details on property names.
1605 * Returns: a newly created parameter specification
1608 g_param_spec_boolean (const gchar *name,
1611 gboolean default_value,
1614 GParamSpecBoolean *bspec;
1616 g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1618 bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1624 bspec->default_value = default_value;
1626 return G_PARAM_SPEC (bspec);
1631 * @name: canonical name of the property specified
1632 * @nick: nick name for the property specified
1633 * @blurb: description of the property specified
1634 * @minimum: minimum value for the property specified
1635 * @maximum: maximum value for the property specified
1636 * @default_value: default value for the property specified
1637 * @flags: flags for the property specified
1639 * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property.
1641 * See g_param_spec_internal() for details on property names.
1643 * Returns: a newly created parameter specification
1646 g_param_spec_int (const gchar *name,
1654 GParamSpecInt *ispec;
1656 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1658 ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1664 ispec->minimum = minimum;
1665 ispec->maximum = maximum;
1666 ispec->default_value = default_value;
1668 return G_PARAM_SPEC (ispec);
1672 * g_param_spec_uint:
1673 * @name: canonical name of the property specified
1674 * @nick: nick name for the property specified
1675 * @blurb: description of the property specified
1676 * @minimum: minimum value for the property specified
1677 * @maximum: maximum value for the property specified
1678 * @default_value: default value for the property specified
1679 * @flags: flags for the property specified
1681 * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property.
1683 * See g_param_spec_internal() for details on property names.
1685 * Returns: a newly created parameter specification
1688 g_param_spec_uint (const gchar *name,
1693 guint default_value,
1696 GParamSpecUInt *uspec;
1698 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1700 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1706 uspec->minimum = minimum;
1707 uspec->maximum = maximum;
1708 uspec->default_value = default_value;
1710 return G_PARAM_SPEC (uspec);
1714 * g_param_spec_long:
1715 * @name: canonical name of the property specified
1716 * @nick: nick name for the property specified
1717 * @blurb: description of the property specified
1718 * @minimum: minimum value for the property specified
1719 * @maximum: maximum value for the property specified
1720 * @default_value: default value for the property specified
1721 * @flags: flags for the property specified
1723 * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property.
1725 * See g_param_spec_internal() for details on property names.
1727 * Returns: a newly created parameter specification
1730 g_param_spec_long (const gchar *name,
1735 glong default_value,
1738 GParamSpecLong *lspec;
1740 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1742 lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1748 lspec->minimum = minimum;
1749 lspec->maximum = maximum;
1750 lspec->default_value = default_value;
1752 return G_PARAM_SPEC (lspec);
1756 * g_param_spec_ulong:
1757 * @name: canonical name of the property specified
1758 * @nick: nick name for the property specified
1759 * @blurb: description of the property specified
1760 * @minimum: minimum value for the property specified
1761 * @maximum: maximum value for the property specified
1762 * @default_value: default value for the property specified
1763 * @flags: flags for the property specified
1765 * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG property.
1767 * See g_param_spec_internal() for details on property names.
1769 * Returns: a newly created parameter specification
1772 g_param_spec_ulong (const gchar *name,
1777 gulong default_value,
1780 GParamSpecULong *uspec;
1782 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1784 uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1790 uspec->minimum = minimum;
1791 uspec->maximum = maximum;
1792 uspec->default_value = default_value;
1794 return G_PARAM_SPEC (uspec);
1798 * g_param_spec_int64:
1799 * @name: canonical name of the property specified
1800 * @nick: nick name for the property specified
1801 * @blurb: description of the property specified
1802 * @minimum: minimum value for the property specified
1803 * @maximum: maximum value for the property specified
1804 * @default_value: default value for the property specified
1805 * @flags: flags for the property specified
1807 * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property.
1809 * See g_param_spec_internal() for details on property names.
1811 * Returns: a newly created parameter specification
1814 g_param_spec_int64 (const gchar *name,
1819 gint64 default_value,
1822 GParamSpecInt64 *lspec;
1824 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1826 lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
1832 lspec->minimum = minimum;
1833 lspec->maximum = maximum;
1834 lspec->default_value = default_value;
1836 return G_PARAM_SPEC (lspec);
1840 * g_param_spec_uint64:
1841 * @name: canonical name of the property specified
1842 * @nick: nick name for the property specified
1843 * @blurb: description of the property specified
1844 * @minimum: minimum value for the property specified
1845 * @maximum: maximum value for the property specified
1846 * @default_value: default value for the property specified
1847 * @flags: flags for the property specified
1849 * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64
1852 * See g_param_spec_internal() for details on property names.
1854 * Returns: a newly created parameter specification
1857 g_param_spec_uint64 (const gchar *name,
1862 guint64 default_value,
1865 GParamSpecUInt64 *uspec;
1867 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1869 uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
1875 uspec->minimum = minimum;
1876 uspec->maximum = maximum;
1877 uspec->default_value = default_value;
1879 return G_PARAM_SPEC (uspec);
1883 * g_param_spec_unichar:
1884 * @name: canonical name of the property specified
1885 * @nick: nick name for the property specified
1886 * @blurb: description of the property specified
1887 * @default_value: default value for the property specified
1888 * @flags: flags for the property specified
1890 * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT
1891 * property. #GValue structures for this property can be accessed with
1892 * g_value_set_uint() and g_value_get_uint().
1894 * See g_param_spec_internal() for details on property names.
1896 * Returns: a newly created parameter specification
1899 g_param_spec_unichar (const gchar *name,
1902 gunichar default_value,
1905 GParamSpecUnichar *uspec;
1907 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1913 uspec->default_value = default_value;
1915 return G_PARAM_SPEC (uspec);
1919 * g_param_spec_enum:
1920 * @name: canonical name of the property specified
1921 * @nick: nick name for the property specified
1922 * @blurb: description of the property specified
1923 * @enum_type: a #GType derived from %G_TYPE_ENUM
1924 * @default_value: default value for the property specified
1925 * @flags: flags for the property specified
1927 * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM
1930 * See g_param_spec_internal() for details on property names.
1932 * Returns: a newly created parameter specification
1935 g_param_spec_enum (const gchar *name,
1942 GParamSpecEnum *espec;
1943 GEnumClass *enum_class;
1945 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
1947 enum_class = g_type_class_ref (enum_type);
1949 g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
1951 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
1957 espec->enum_class = enum_class;
1958 espec->default_value = default_value;
1959 G_PARAM_SPEC (espec)->value_type = enum_type;
1961 return G_PARAM_SPEC (espec);
1965 * g_param_spec_flags:
1966 * @name: canonical name of the property specified
1967 * @nick: nick name for the property specified
1968 * @blurb: description of the property specified
1969 * @flags_type: a #GType derived from %G_TYPE_FLAGS
1970 * @default_value: default value for the property specified
1971 * @flags: flags for the property specified
1973 * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS
1976 * See g_param_spec_internal() for details on property names.
1978 * Returns: a newly created parameter specification
1981 g_param_spec_flags (const gchar *name,
1985 guint default_value,
1988 GParamSpecFlags *fspec;
1989 GFlagsClass *flags_class;
1991 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
1993 flags_class = g_type_class_ref (flags_type);
1995 g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
1997 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2003 fspec->flags_class = flags_class;
2004 fspec->default_value = default_value;
2005 G_PARAM_SPEC (fspec)->value_type = flags_type;
2007 return G_PARAM_SPEC (fspec);
2011 * g_param_spec_float:
2012 * @name: canonical name of the property specified
2013 * @nick: nick name for the property specified
2014 * @blurb: description of the property specified
2015 * @minimum: minimum value for the property specified
2016 * @maximum: maximum value for the property specified
2017 * @default_value: default value for the property specified
2018 * @flags: flags for the property specified
2020 * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property.
2022 * See g_param_spec_internal() for details on property names.
2024 * Returns: a newly created parameter specification
2027 g_param_spec_float (const gchar *name,
2032 gfloat default_value,
2035 GParamSpecFloat *fspec;
2037 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2039 fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2045 fspec->minimum = minimum;
2046 fspec->maximum = maximum;
2047 fspec->default_value = default_value;
2049 return G_PARAM_SPEC (fspec);
2053 * g_param_spec_double:
2054 * @name: canonical name of the property specified
2055 * @nick: nick name for the property specified
2056 * @blurb: description of the property specified
2057 * @minimum: minimum value for the property specified
2058 * @maximum: maximum value for the property specified
2059 * @default_value: default value for the property specified
2060 * @flags: flags for the property specified
2062 * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE
2065 * See g_param_spec_internal() for details on property names.
2067 * Returns: a newly created parameter specification
2070 g_param_spec_double (const gchar *name,
2075 gdouble default_value,
2078 GParamSpecDouble *dspec;
2080 g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2082 dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2088 dspec->minimum = minimum;
2089 dspec->maximum = maximum;
2090 dspec->default_value = default_value;
2092 return G_PARAM_SPEC (dspec);
2096 * g_param_spec_string:
2097 * @name: canonical name of the property specified
2098 * @nick: nick name for the property specified
2099 * @blurb: description of the property specified
2100 * @default_value: default value for the property specified
2101 * @flags: flags for the property specified
2103 * Creates a new #GParamSpecString instance.
2105 * See g_param_spec_internal() for details on property names.
2107 * Returns: a newly created parameter specification
2110 g_param_spec_string (const gchar *name,
2113 const gchar *default_value,
2116 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2121 g_free (sspec->default_value);
2122 sspec->default_value = g_strdup (default_value);
2124 return G_PARAM_SPEC (sspec);
2128 * g_param_spec_param:
2129 * @name: canonical name of the property specified
2130 * @nick: nick name for the property specified
2131 * @blurb: description of the property specified
2132 * @param_type: a #GType derived from %G_TYPE_PARAM
2133 * @flags: flags for the property specified
2135 * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM
2138 * See g_param_spec_internal() for details on property names.
2140 * Returns: a newly created parameter specification
2143 g_param_spec_param (const gchar *name,
2149 GParamSpecParam *pspec;
2151 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2153 pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2158 G_PARAM_SPEC (pspec)->value_type = param_type;
2160 return G_PARAM_SPEC (pspec);
2164 * g_param_spec_boxed:
2165 * @name: canonical name of the property specified
2166 * @nick: nick name for the property specified
2167 * @blurb: description of the property specified
2168 * @boxed_type: %G_TYPE_BOXED derived type of this property
2169 * @flags: flags for the property specified
2171 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED
2174 * See g_param_spec_internal() for details on property names.
2176 * Returns: a newly created parameter specification
2179 g_param_spec_boxed (const gchar *name,
2185 GParamSpecBoxed *bspec;
2187 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2188 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2190 bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2195 G_PARAM_SPEC (bspec)->value_type = boxed_type;
2197 return G_PARAM_SPEC (bspec);
2201 * g_param_spec_pointer:
2202 * @name: canonical name of the property specified
2203 * @nick: nick name for the property specified
2204 * @blurb: description of the property specified
2205 * @flags: flags for the property specified
2207 * Creates a new #GParamSpecPoiner instance specifying a pointer property.
2209 * See g_param_spec_internal() for details on property names.
2211 * Returns: a newly created parameter specification
2214 g_param_spec_pointer (const gchar *name,
2219 GParamSpecPointer *pspec;
2221 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2226 return G_PARAM_SPEC (pspec);
2230 * g_param_spec_gtype:
2231 * @name: canonical name of the property specified
2232 * @nick: nick name for the property specified
2233 * @blurb: description of the property specified
2234 * @is_a_type: a #GType whose subtypes are allowed as values
2235 * of the property (use %G_TYPE_NONE for any type)
2236 * @flags: flags for the property specified
2238 * Creates a new #GParamSpecGType instance specifying a
2239 * %G_TYPE_GTYPE property.
2241 * See g_param_spec_internal() for details on property names.
2244 * Returns: a newly created parameter specification
2247 g_param_spec_gtype (const gchar *name,
2253 GParamSpecGType *tspec;
2255 tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2261 tspec->is_a_type = is_a_type;
2263 return G_PARAM_SPEC (tspec);
2267 * g_param_spec_value_array:
2268 * @name: canonical name of the property specified
2269 * @nick: nick name for the property specified
2270 * @blurb: description of the property specified
2271 * @element_spec: a #GParamSpec describing the elements contained in
2272 * arrays of this property, may be %NULL
2273 * @flags: flags for the property specified
2275 * Creates a new #GParamSpecValueArray instance specifying a
2276 * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a %G_TYPE_BOXED
2277 * type, as such, #GValue structures for this property can be accessed
2278 * with g_value_set_boxed() and g_value_get_boxed().
2280 * See g_param_spec_internal() for details on property names.
2282 * Returns: a newly created parameter specification
2285 g_param_spec_value_array (const gchar *name,
2288 GParamSpec *element_spec,
2291 GParamSpecValueArray *aspec;
2294 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
2296 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
2303 aspec->element_spec = g_param_spec_ref (element_spec);
2304 g_param_spec_sink (element_spec);
2307 return G_PARAM_SPEC (aspec);
2311 * g_param_spec_object:
2312 * @name: canonical name of the property specified
2313 * @nick: nick name for the property specified
2314 * @blurb: description of the property specified
2315 * @object_type: %G_TYPE_OBJECT derived type of this property
2316 * @flags: flags for the property specified
2318 * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT
2321 * See g_param_spec_internal() for details on property names.
2323 * Returns: a newly created parameter specification
2326 g_param_spec_object (const gchar *name,
2332 GParamSpecObject *ospec;
2334 g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2336 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2341 G_PARAM_SPEC (ospec)->value_type = object_type;
2343 return G_PARAM_SPEC (ospec);
2347 * g_param_spec_override:
2348 * @name: the name of the property.
2349 * @overridden: The property that is being overridden
2351 * Creates a new property of type #GParamSpecOverride. This is used
2352 * to direct operations to another paramspec, and will not be directly
2353 * useful unless you are implementing a new base type similar to GObject.
2356 * Returns: the newly created #GParamSpec
2359 g_param_spec_override (const gchar *name,
2360 GParamSpec *overridden)
2364 g_return_val_if_fail (name != NULL, NULL);
2365 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2367 /* Dereference further redirections for property that was passed in
2371 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2373 overridden = indirect;
2378 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2382 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2383 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2388 #define __G_PARAMSPECS_C__
2389 #include "gobjectaliasdef.c"