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.
24 #include "../config.h"
26 #include "gparamspecs.h"
28 #include "gvaluecollector.h"
29 #include "gvaluearray.h"
32 #define G_FLOAT_EPSILON (1e-30)
33 #define G_DOUBLE_EPSILON (1e-90)
36 /* --- param spec functions --- */
38 param_char_init (GParamSpec
*pspec
)
40 GParamSpecChar
*cspec
= G_PARAM_SPEC_CHAR (pspec
);
42 cspec
->minimum
= 0x7f;
43 cspec
->maximum
= 0x80;
44 cspec
->default_value
= 0;
48 param_char_set_default (GParamSpec
*pspec
,
51 value
->data
[0].v_int
= G_PARAM_SPEC_CHAR (pspec
)->default_value
;
55 param_char_validate (GParamSpec
*pspec
,
58 GParamSpecChar
*cspec
= G_PARAM_SPEC_CHAR (pspec
);
59 gint oval
= value
->data
[0].v_int
;
61 value
->data
[0].v_int
= CLAMP (value
->data
[0].v_int
, cspec
->minimum
, cspec
->maximum
);
63 return value
->data
[0].v_int
!= oval
;
67 param_uchar_init (GParamSpec
*pspec
)
69 GParamSpecUChar
*uspec
= G_PARAM_SPEC_UCHAR (pspec
);
72 uspec
->maximum
= 0xff;
73 uspec
->default_value
= 0;
77 param_uchar_set_default (GParamSpec
*pspec
,
80 value
->data
[0].v_uint
= G_PARAM_SPEC_UCHAR (pspec
)->default_value
;
84 param_uchar_validate (GParamSpec
*pspec
,
87 GParamSpecUChar
*uspec
= G_PARAM_SPEC_UCHAR (pspec
);
88 guint oval
= value
->data
[0].v_uint
;
90 value
->data
[0].v_uint
= CLAMP (value
->data
[0].v_uint
, uspec
->minimum
, uspec
->maximum
);
92 return value
->data
[0].v_uint
!= oval
;
96 param_boolean_set_default (GParamSpec
*pspec
,
99 value
->data
[0].v_int
= G_PARAM_SPEC_BOOLEAN (pspec
)->default_value
;
103 param_boolean_validate (GParamSpec
*pspec
,
106 gint oval
= value
->data
[0].v_int
;
108 value
->data
[0].v_int
= value
->data
[0].v_int
!= FALSE
;
110 return value
->data
[0].v_int
!= oval
;
114 param_int_init (GParamSpec
*pspec
)
116 GParamSpecInt
*ispec
= G_PARAM_SPEC_INT (pspec
);
118 ispec
->minimum
= 0x7fffffff;
119 ispec
->maximum
= 0x80000000;
120 ispec
->default_value
= 0;
124 param_int_set_default (GParamSpec
*pspec
,
127 value
->data
[0].v_int
= G_PARAM_SPEC_INT (pspec
)->default_value
;
131 param_int_validate (GParamSpec
*pspec
,
134 GParamSpecInt
*ispec
= G_PARAM_SPEC_INT (pspec
);
135 gint oval
= value
->data
[0].v_int
;
137 value
->data
[0].v_int
= CLAMP (value
->data
[0].v_int
, ispec
->minimum
, ispec
->maximum
);
139 return value
->data
[0].v_int
!= oval
;
143 param_int_values_cmp (GParamSpec
*pspec
,
144 const GValue
*value1
,
145 const GValue
*value2
)
147 if (value1
->data
[0].v_int
< value2
->data
[0].v_int
)
150 return value1
->data
[0].v_int
> value2
->data
[0].v_int
;
154 param_uint_init (GParamSpec
*pspec
)
156 GParamSpecUInt
*uspec
= G_PARAM_SPEC_UINT (pspec
);
159 uspec
->maximum
= 0xffffffff;
160 uspec
->default_value
= 0;
164 param_uint_set_default (GParamSpec
*pspec
,
167 value
->data
[0].v_uint
= G_PARAM_SPEC_UINT (pspec
)->default_value
;
171 param_uint_validate (GParamSpec
*pspec
,
174 GParamSpecUInt
*uspec
= G_PARAM_SPEC_UINT (pspec
);
175 guint oval
= value
->data
[0].v_uint
;
177 value
->data
[0].v_uint
= CLAMP (value
->data
[0].v_uint
, uspec
->minimum
, uspec
->maximum
);
179 return value
->data
[0].v_uint
!= oval
;
183 param_uint_values_cmp (GParamSpec
*pspec
,
184 const GValue
*value1
,
185 const GValue
*value2
)
187 if (value1
->data
[0].v_uint
< value2
->data
[0].v_uint
)
190 return value1
->data
[0].v_uint
> value2
->data
[0].v_uint
;
194 param_long_init (GParamSpec
*pspec
)
196 GParamSpecLong
*lspec
= G_PARAM_SPEC_LONG (pspec
);
199 lspec
->minimum
= 0x7fffffff;
200 lspec
->maximum
= 0x80000000;
201 #else /* SIZEOF_LONG != 4 (8) */
202 lspec
->minimum
= 0x7fffffffffffffff;
203 lspec
->maximum
= 0x8000000000000000;
205 lspec
->default_value
= 0;
209 param_long_set_default (GParamSpec
*pspec
,
212 value
->data
[0].v_long
= G_PARAM_SPEC_LONG (pspec
)->default_value
;
216 param_long_validate (GParamSpec
*pspec
,
219 GParamSpecLong
*lspec
= G_PARAM_SPEC_LONG (pspec
);
220 glong oval
= value
->data
[0].v_long
;
222 value
->data
[0].v_long
= CLAMP (value
->data
[0].v_long
, lspec
->minimum
, lspec
->maximum
);
224 return value
->data
[0].v_long
!= oval
;
228 param_long_values_cmp (GParamSpec
*pspec
,
229 const GValue
*value1
,
230 const GValue
*value2
)
232 if (value1
->data
[0].v_long
< value2
->data
[0].v_long
)
235 return value1
->data
[0].v_long
> value2
->data
[0].v_long
;
239 param_ulong_init (GParamSpec
*pspec
)
241 GParamSpecULong
*uspec
= G_PARAM_SPEC_ULONG (pspec
);
245 uspec
->maximum
= 0xffffffff;
246 #else /* SIZEOF_LONG != 4 (8) */
247 uspec
->maximum
= 0xffffffffffffffff;
249 uspec
->default_value
= 0;
253 param_ulong_set_default (GParamSpec
*pspec
,
256 value
->data
[0].v_ulong
= G_PARAM_SPEC_ULONG (pspec
)->default_value
;
260 param_ulong_validate (GParamSpec
*pspec
,
263 GParamSpecULong
*uspec
= G_PARAM_SPEC_ULONG (pspec
);
264 gulong oval
= value
->data
[0].v_ulong
;
266 value
->data
[0].v_ulong
= CLAMP (value
->data
[0].v_ulong
, uspec
->minimum
, uspec
->maximum
);
268 return value
->data
[0].v_ulong
!= oval
;
272 param_ulong_values_cmp (GParamSpec
*pspec
,
273 const GValue
*value1
,
274 const GValue
*value2
)
276 if (value1
->data
[0].v_ulong
< value2
->data
[0].v_ulong
)
279 return value1
->data
[0].v_ulong
> value2
->data
[0].v_ulong
;
283 param_int64_init (GParamSpec
*pspec
)
285 GParamSpecInt64
*lspec
= G_PARAM_SPEC_INT64 (pspec
);
287 lspec
->minimum
= G_MININT64
;
288 lspec
->maximum
= G_MAXINT64
;
289 lspec
->default_value
= 0;
293 param_int64_set_default (GParamSpec
*pspec
,
296 value
->data
[0].v_int64
= G_PARAM_SPEC_INT64 (pspec
)->default_value
;
300 param_int64_validate (GParamSpec
*pspec
,
303 GParamSpecInt64
*lspec
= G_PARAM_SPEC_INT64 (pspec
);
304 gint64 oval
= value
->data
[0].v_int64
;
306 value
->data
[0].v_int64
= CLAMP (value
->data
[0].v_int64
, lspec
->minimum
, lspec
->maximum
);
308 return value
->data
[0].v_int64
!= oval
;
312 param_int64_values_cmp (GParamSpec
*pspec
,
313 const GValue
*value1
,
314 const GValue
*value2
)
316 if (value1
->data
[0].v_int64
< value2
->data
[0].v_int64
)
319 return value1
->data
[0].v_int64
> value2
->data
[0].v_int64
;
323 param_uint64_init (GParamSpec
*pspec
)
325 GParamSpecUInt64
*uspec
= G_PARAM_SPEC_UINT64 (pspec
);
328 uspec
->maximum
= G_MAXUINT64
;
329 uspec
->default_value
= 0;
333 param_uint64_set_default (GParamSpec
*pspec
,
336 value
->data
[0].v_uint64
= G_PARAM_SPEC_UINT64 (pspec
)->default_value
;
340 param_uint64_validate (GParamSpec
*pspec
,
343 GParamSpecUInt64
*uspec
= G_PARAM_SPEC_UINT64 (pspec
);
344 guint64 oval
= value
->data
[0].v_uint64
;
346 value
->data
[0].v_uint64
= CLAMP (value
->data
[0].v_uint64
, uspec
->minimum
, uspec
->maximum
);
348 return value
->data
[0].v_uint64
!= oval
;
352 param_uint64_values_cmp (GParamSpec
*pspec
,
353 const GValue
*value1
,
354 const GValue
*value2
)
356 if (value1
->data
[0].v_uint64
< value2
->data
[0].v_uint64
)
359 return value1
->data
[0].v_uint64
> value2
->data
[0].v_uint64
;
363 param_unichar_init (GParamSpec
*pspec
)
365 GParamSpecUnichar
*uspec
= G_PARAM_SPEC_UNICHAR (pspec
);
367 uspec
->default_value
= 0;
371 param_unichar_set_default (GParamSpec
*pspec
,
374 value
->data
[0].v_uint
= G_PARAM_SPEC_UNICHAR (pspec
)->default_value
;
378 param_unichar_validate (GParamSpec
*pspec
,
381 gunichar oval
= value
->data
[0].v_uint
;
382 gboolean changed
= FALSE
;
384 if (!g_unichar_validate (oval
))
386 value
->data
[0].v_uint
= 0;
394 param_unichar_values_cmp (GParamSpec
*pspec
,
395 const GValue
*value1
,
396 const GValue
*value2
)
398 if (value1
->data
[0].v_uint
< value2
->data
[0].v_uint
)
401 return value1
->data
[0].v_uint
> value2
->data
[0].v_uint
;
405 param_enum_init (GParamSpec
*pspec
)
407 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
409 espec
->enum_class
= NULL
;
410 espec
->default_value
= 0;
414 param_enum_finalize (GParamSpec
*pspec
)
416 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
417 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM
));
419 if (espec
->enum_class
)
421 g_type_class_unref (espec
->enum_class
);
422 espec
->enum_class
= NULL
;
425 parent_class
->finalize (pspec
);
429 param_enum_set_default (GParamSpec
*pspec
,
432 value
->data
[0].v_long
= G_PARAM_SPEC_ENUM (pspec
)->default_value
;
436 param_enum_validate (GParamSpec
*pspec
,
439 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
440 glong oval
= value
->data
[0].v_long
;
442 if (!espec
->enum_class
||
443 !g_enum_get_value (espec
->enum_class
, value
->data
[0].v_long
))
444 value
->data
[0].v_long
= espec
->default_value
;
446 return value
->data
[0].v_long
!= oval
;
450 param_flags_init (GParamSpec
*pspec
)
452 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
454 fspec
->flags_class
= NULL
;
455 fspec
->default_value
= 0;
459 param_flags_finalize (GParamSpec
*pspec
)
461 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
462 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS
));
464 if (fspec
->flags_class
)
466 g_type_class_unref (fspec
->flags_class
);
467 fspec
->flags_class
= NULL
;
470 parent_class
->finalize (pspec
);
474 param_flags_set_default (GParamSpec
*pspec
,
477 value
->data
[0].v_ulong
= G_PARAM_SPEC_FLAGS (pspec
)->default_value
;
481 param_flags_validate (GParamSpec
*pspec
,
484 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
485 gulong oval
= value
->data
[0].v_ulong
;
487 if (fspec
->flags_class
)
488 value
->data
[0].v_ulong
&= fspec
->flags_class
->mask
;
490 value
->data
[0].v_ulong
= fspec
->default_value
;
492 return value
->data
[0].v_ulong
!= oval
;
496 param_float_init (GParamSpec
*pspec
)
498 GParamSpecFloat
*fspec
= G_PARAM_SPEC_FLOAT (pspec
);
500 fspec
->minimum
= G_MINFLOAT
;
501 fspec
->maximum
= G_MAXFLOAT
;
502 fspec
->default_value
= 0;
503 fspec
->epsilon
= G_FLOAT_EPSILON
;
507 param_float_set_default (GParamSpec
*pspec
,
510 value
->data
[0].v_float
= G_PARAM_SPEC_FLOAT (pspec
)->default_value
;
514 param_float_validate (GParamSpec
*pspec
,
517 GParamSpecFloat
*fspec
= G_PARAM_SPEC_FLOAT (pspec
);
518 gfloat oval
= value
->data
[0].v_float
;
520 value
->data
[0].v_float
= CLAMP (value
->data
[0].v_float
, fspec
->minimum
, fspec
->maximum
);
522 return value
->data
[0].v_float
!= oval
;
526 param_float_values_cmp (GParamSpec
*pspec
,
527 const GValue
*value1
,
528 const GValue
*value2
)
530 gfloat epsilon
= G_PARAM_SPEC_FLOAT (pspec
)->epsilon
;
532 if (value1
->data
[0].v_float
< value2
->data
[0].v_float
)
533 return - (value2
->data
[0].v_float
- value1
->data
[0].v_float
> epsilon
);
535 return value1
->data
[0].v_float
- value2
->data
[0].v_float
> epsilon
;
539 param_double_init (GParamSpec
*pspec
)
541 GParamSpecDouble
*dspec
= G_PARAM_SPEC_DOUBLE (pspec
);
543 dspec
->minimum
= G_MINDOUBLE
;
544 dspec
->maximum
= G_MAXDOUBLE
;
545 dspec
->default_value
= 0;
546 dspec
->epsilon
= G_DOUBLE_EPSILON
;
550 param_double_set_default (GParamSpec
*pspec
,
553 value
->data
[0].v_double
= G_PARAM_SPEC_DOUBLE (pspec
)->default_value
;
557 param_double_validate (GParamSpec
*pspec
,
560 GParamSpecDouble
*dspec
= G_PARAM_SPEC_DOUBLE (pspec
);
561 gdouble oval
= value
->data
[0].v_double
;
563 value
->data
[0].v_double
= CLAMP (value
->data
[0].v_double
, dspec
->minimum
, dspec
->maximum
);
565 return value
->data
[0].v_double
!= oval
;
569 param_double_values_cmp (GParamSpec
*pspec
,
570 const GValue
*value1
,
571 const GValue
*value2
)
573 gdouble epsilon
= G_PARAM_SPEC_DOUBLE (pspec
)->epsilon
;
575 if (value1
->data
[0].v_double
< value2
->data
[0].v_double
)
576 return - (value2
->data
[0].v_double
- value1
->data
[0].v_double
> epsilon
);
578 return value1
->data
[0].v_double
- value2
->data
[0].v_double
> epsilon
;
582 param_string_init (GParamSpec
*pspec
)
584 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
586 sspec
->default_value
= NULL
;
587 sspec
->cset_first
= NULL
;
588 sspec
->cset_nth
= NULL
;
589 sspec
->substitutor
= '_';
590 sspec
->null_fold_if_empty
= FALSE
;
591 sspec
->ensure_non_null
= FALSE
;
595 param_string_finalize (GParamSpec
*pspec
)
597 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
598 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING
));
600 g_free (sspec
->default_value
);
601 g_free (sspec
->cset_first
);
602 g_free (sspec
->cset_nth
);
603 sspec
->default_value
= NULL
;
604 sspec
->cset_first
= NULL
;
605 sspec
->cset_nth
= NULL
;
607 parent_class
->finalize (pspec
);
611 param_string_set_default (GParamSpec
*pspec
,
614 value
->data
[0].v_pointer
= g_strdup (G_PARAM_SPEC_STRING (pspec
)->default_value
);
618 param_string_validate (GParamSpec
*pspec
,
621 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
622 gchar
*string
= value
->data
[0].v_pointer
;
625 if (string
&& string
[0])
629 if (sspec
->cset_first
&& !strchr (sspec
->cset_first
, string
[0]))
631 string
[0] = sspec
->substitutor
;
635 for (s
= string
+ 1; *s
; s
++)
636 if (!strchr (sspec
->cset_nth
, *s
))
638 *s
= sspec
->substitutor
;
642 if (sspec
->null_fold_if_empty
&& string
&& string
[0] == 0)
644 g_free (value
->data
[0].v_pointer
);
645 value
->data
[0].v_pointer
= NULL
;
647 string
= value
->data
[0].v_pointer
;
649 if (sspec
->ensure_non_null
&& !string
)
651 value
->data
[0].v_pointer
= g_strdup ("");
653 string
= value
->data
[0].v_pointer
;
660 param_string_values_cmp (GParamSpec
*pspec
,
661 const GValue
*value1
,
662 const GValue
*value2
)
664 if (!value1
->data
[0].v_pointer
)
665 return value2
->data
[0].v_pointer
!= NULL
? -1 : 0;
666 else if (!value2
->data
[0].v_pointer
)
667 return value1
->data
[0].v_pointer
!= NULL
;
669 return strcmp (value1
->data
[0].v_pointer
, value2
->data
[0].v_pointer
);
673 param_param_init (GParamSpec
*pspec
)
675 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
679 param_param_set_default (GParamSpec
*pspec
,
682 value
->data
[0].v_pointer
= NULL
;
686 param_param_validate (GParamSpec
*pspec
,
689 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
690 GParamSpec
*param
= value
->data
[0].v_pointer
;
693 if (param
&& !g_value_type_compatible (G_PARAM_SPEC_TYPE (param
), G_PARAM_SPEC_VALUE_TYPE (pspec
)))
695 g_param_spec_unref (param
);
696 value
->data
[0].v_pointer
= NULL
;
704 param_boxed_init (GParamSpec
*pspec
)
706 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
710 param_boxed_set_default (GParamSpec
*pspec
,
713 value
->data
[0].v_pointer
= NULL
;
717 param_boxed_validate (GParamSpec
*pspec
,
720 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
723 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
729 param_boxed_values_cmp (GParamSpec
*pspec
,
730 const GValue
*value1
,
731 const GValue
*value2
)
733 guint8
*p1
= value1
->data
[0].v_pointer
;
734 guint8
*p2
= value2
->data
[0].v_pointer
;
736 /* not much to compare here, try to at least provide stable lesser/greater result */
738 return p1
< p2
? -1 : p1
> p2
;
742 param_pointer_init (GParamSpec
*pspec
)
744 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
748 param_pointer_set_default (GParamSpec
*pspec
,
751 value
->data
[0].v_pointer
= NULL
;
755 param_pointer_validate (GParamSpec
*pspec
,
758 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
765 param_pointer_values_cmp (GParamSpec
*pspec
,
766 const GValue
*value1
,
767 const GValue
*value2
)
769 guint8
*p1
= value1
->data
[0].v_pointer
;
770 guint8
*p2
= value2
->data
[0].v_pointer
;
772 /* not much to compare here, try to at least provide stable lesser/greater result */
774 return p1
< p2
? -1 : p1
> p2
;
778 param_value_array_init (GParamSpec
*pspec
)
780 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
782 aspec
->element_spec
= NULL
;
783 aspec
->fixed_n_elements
= 0; /* disable */
787 value_array_ensure_size (GValueArray
*value_array
,
788 guint fixed_n_elements
)
792 if (fixed_n_elements
)
794 while (value_array
->n_values
< fixed_n_elements
)
796 g_value_array_append (value_array
, NULL
);
799 while (value_array
->n_values
> fixed_n_elements
)
801 g_value_array_remove (value_array
, value_array
->n_values
- 1);
809 param_value_array_finalize (GParamSpec
*pspec
)
811 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
812 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY
));
814 if (aspec
->element_spec
)
816 g_param_spec_unref (aspec
->element_spec
);
817 aspec
->element_spec
= NULL
;
820 parent_class
->finalize (pspec
);
824 param_value_array_set_default (GParamSpec
*pspec
,
827 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
829 if (!value
->data
[0].v_pointer
&& aspec
->fixed_n_elements
)
830 value
->data
[0].v_pointer
= g_value_array_new (aspec
->fixed_n_elements
);
832 if (value
->data
[0].v_pointer
)
834 /* g_value_reset (value); already done */
835 value_array_ensure_size (value
->data
[0].v_pointer
, aspec
->fixed_n_elements
);
840 param_value_array_validate (GParamSpec
*pspec
,
843 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
844 GValueArray
*value_array
= value
->data
[0].v_pointer
;
847 if (!value
->data
[0].v_pointer
&& aspec
->fixed_n_elements
)
848 value
->data
[0].v_pointer
= g_value_array_new (aspec
->fixed_n_elements
);
850 if (value
->data
[0].v_pointer
)
852 /* ensure array size validity */
853 changed
+= value_array_ensure_size (value_array
, aspec
->fixed_n_elements
);
855 /* ensure array values validity against a present element spec */
856 if (aspec
->element_spec
)
858 GParamSpec
*element_spec
= aspec
->element_spec
;
861 for (i
= 0; i
< value_array
->n_values
; i
++)
863 GValue
*element
= value_array
->values
+ i
;
865 /* need to fixup value type, or ensure that the array value is initialized at all */
866 if (!g_value_type_compatible (G_VALUE_TYPE (element
), G_PARAM_SPEC_VALUE_TYPE (element_spec
)))
868 if (G_VALUE_TYPE (element
) != 0)
869 g_value_unset (element
);
870 g_value_init (element
, G_PARAM_SPEC_VALUE_TYPE (element_spec
));
871 g_param_value_set_default (element_spec
, element
);
874 /* validate array value against element_spec */
875 changed
+= g_param_value_validate (element_spec
, element
);
884 param_value_array_values_cmp (GParamSpec
*pspec
,
885 const GValue
*value1
,
886 const GValue
*value2
)
888 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
889 GValueArray
*value_array1
= value1
->data
[0].v_pointer
;
890 GValueArray
*value_array2
= value2
->data
[0].v_pointer
;
892 if (!value_array1
|| !value_array2
)
893 return value_array2
? -1 : value_array1
!= value_array2
;
895 if (value_array1
->n_values
!= value_array2
->n_values
)
896 return value_array1
->n_values
< value_array2
->n_values
? -1 : 1;
897 else if (!aspec
->element_spec
)
899 /* we need an element specification for comparisons, so there's not much
900 * to compare here, try to at least provide stable lesser/greater result
902 return value_array1
->n_values
< value_array2
->n_values
? -1 : value_array1
->n_values
> value_array2
->n_values
;
904 else /* value_array1->n_values == value_array2->n_values */
908 for (i
= 0; i
< value_array1
->n_values
; i
++)
910 GValue
*element1
= value_array1
->values
+ i
;
911 GValue
*element2
= value_array2
->values
+ i
;
914 /* need corresponding element types, provide stable result otherwise */
915 if (G_VALUE_TYPE (element1
) != G_VALUE_TYPE (element2
))
916 return G_VALUE_TYPE (element1
) < G_VALUE_TYPE (element2
) ? -1 : 1;
917 cmp
= g_param_values_cmp (aspec
->element_spec
, element1
, element2
);
926 param_object_init (GParamSpec
*pspec
)
928 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
932 param_object_set_default (GParamSpec
*pspec
,
935 value
->data
[0].v_pointer
= NULL
;
939 param_object_validate (GParamSpec
*pspec
,
942 GParamSpecObject
*ospec
= G_PARAM_SPEC_OBJECT (pspec
);
943 GObject
*object
= value
->data
[0].v_pointer
;
946 if (object
&& !g_value_type_compatible (G_OBJECT_TYPE (object
), G_PARAM_SPEC_VALUE_TYPE (ospec
)))
948 g_object_unref (object
);
949 value
->data
[0].v_pointer
= NULL
;
957 param_object_values_cmp (GParamSpec
*pspec
,
958 const GValue
*value1
,
959 const GValue
*value2
)
961 guint8
*p1
= value1
->data
[0].v_pointer
;
962 guint8
*p2
= value2
->data
[0].v_pointer
;
964 /* not much to compare here, try to at least provide stable lesser/greater result */
966 return p1
< p2
? -1 : p1
> p2
;
970 param_override_init (GParamSpec
*pspec
)
972 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
976 param_override_finalize (GParamSpec
*pspec
)
978 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
979 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE
));
981 if (ospec
->overridden
)
983 g_param_spec_unref (ospec
->overridden
);
984 ospec
->overridden
= NULL
;
987 parent_class
->finalize (pspec
);
991 param_override_set_default (GParamSpec
*pspec
,
994 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
996 g_param_value_set_default (ospec
->overridden
, value
);
1000 param_override_validate (GParamSpec
*pspec
,
1003 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
1005 return g_param_value_validate (ospec
->overridden
, value
);
1009 param_override_values_cmp (GParamSpec
*pspec
,
1010 const GValue
*value1
,
1011 const GValue
*value2
)
1013 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
1015 return g_param_values_cmp (ospec
->overridden
, value1
, value2
);
1018 /* --- type initialization --- */
1019 GType
*g_param_spec_types
= NULL
;
1022 g_param_spec_types_init (void) /* sync with gtype.c */
1024 const guint n_types
= 21;
1025 GType type
, *spec_types
, *spec_types_bound
;
1027 g_param_spec_types
= g_new0 (GType
, n_types
);
1028 spec_types
= g_param_spec_types
;
1029 spec_types_bound
= g_param_spec_types
+ n_types
;
1031 /* G_TYPE_PARAM_CHAR
1034 static const GParamSpecTypeInfo pspec_info
= {
1035 sizeof (GParamSpecChar
), /* instance_size */
1036 16, /* n_preallocs */
1037 param_char_init
, /* instance_init */
1038 G_TYPE_CHAR
, /* value_type */
1039 NULL
, /* finalize */
1040 param_char_set_default
, /* value_set_default */
1041 param_char_validate
, /* value_validate */
1042 param_int_values_cmp
, /* values_cmp */
1044 type
= g_param_type_register_static ("GParamChar", &pspec_info
);
1045 *spec_types
++ = type
;
1046 g_assert (type
== G_TYPE_PARAM_CHAR
);
1049 /* G_TYPE_PARAM_UCHAR
1052 static const GParamSpecTypeInfo pspec_info
= {
1053 sizeof (GParamSpecUChar
), /* instance_size */
1054 16, /* n_preallocs */
1055 param_uchar_init
, /* instance_init */
1056 G_TYPE_UCHAR
, /* value_type */
1057 NULL
, /* finalize */
1058 param_uchar_set_default
, /* value_set_default */
1059 param_uchar_validate
, /* value_validate */
1060 param_uint_values_cmp
, /* values_cmp */
1062 type
= g_param_type_register_static ("GParamUChar", &pspec_info
);
1063 *spec_types
++ = type
;
1064 g_assert (type
== G_TYPE_PARAM_UCHAR
);
1067 /* G_TYPE_PARAM_BOOLEAN
1070 static const GParamSpecTypeInfo pspec_info
= {
1071 sizeof (GParamSpecBoolean
), /* instance_size */
1072 16, /* n_preallocs */
1073 NULL
, /* instance_init */
1074 G_TYPE_BOOLEAN
, /* value_type */
1075 NULL
, /* finalize */
1076 param_boolean_set_default
, /* value_set_default */
1077 param_boolean_validate
, /* value_validate */
1078 param_int_values_cmp
, /* values_cmp */
1080 type
= g_param_type_register_static ("GParamBoolean", &pspec_info
);
1081 *spec_types
++ = type
;
1082 g_assert (type
== G_TYPE_PARAM_BOOLEAN
);
1088 static const GParamSpecTypeInfo pspec_info
= {
1089 sizeof (GParamSpecInt
), /* instance_size */
1090 16, /* n_preallocs */
1091 param_int_init
, /* instance_init */
1092 G_TYPE_INT
, /* value_type */
1093 NULL
, /* finalize */
1094 param_int_set_default
, /* value_set_default */
1095 param_int_validate
, /* value_validate */
1096 param_int_values_cmp
, /* values_cmp */
1098 type
= g_param_type_register_static ("GParamInt", &pspec_info
);
1099 *spec_types
++ = type
;
1100 g_assert (type
== G_TYPE_PARAM_INT
);
1103 /* G_TYPE_PARAM_UINT
1106 static const GParamSpecTypeInfo pspec_info
= {
1107 sizeof (GParamSpecUInt
), /* instance_size */
1108 16, /* n_preallocs */
1109 param_uint_init
, /* instance_init */
1110 G_TYPE_UINT
, /* value_type */
1111 NULL
, /* finalize */
1112 param_uint_set_default
, /* value_set_default */
1113 param_uint_validate
, /* value_validate */
1114 param_uint_values_cmp
, /* values_cmp */
1116 type
= g_param_type_register_static ("GParamUInt", &pspec_info
);
1117 *spec_types
++ = type
;
1118 g_assert (type
== G_TYPE_PARAM_UINT
);
1121 /* G_TYPE_PARAM_LONG
1124 static const GParamSpecTypeInfo pspec_info
= {
1125 sizeof (GParamSpecLong
), /* instance_size */
1126 16, /* n_preallocs */
1127 param_long_init
, /* instance_init */
1128 G_TYPE_LONG
, /* value_type */
1129 NULL
, /* finalize */
1130 param_long_set_default
, /* value_set_default */
1131 param_long_validate
, /* value_validate */
1132 param_long_values_cmp
, /* values_cmp */
1134 type
= g_param_type_register_static ("GParamLong", &pspec_info
);
1135 *spec_types
++ = type
;
1136 g_assert (type
== G_TYPE_PARAM_LONG
);
1139 /* G_TYPE_PARAM_ULONG
1142 static const GParamSpecTypeInfo pspec_info
= {
1143 sizeof (GParamSpecULong
), /* instance_size */
1144 16, /* n_preallocs */
1145 param_ulong_init
, /* instance_init */
1146 G_TYPE_ULONG
, /* value_type */
1147 NULL
, /* finalize */
1148 param_ulong_set_default
, /* value_set_default */
1149 param_ulong_validate
, /* value_validate */
1150 param_ulong_values_cmp
, /* values_cmp */
1152 type
= g_param_type_register_static ("GParamULong", &pspec_info
);
1153 *spec_types
++ = type
;
1154 g_assert (type
== G_TYPE_PARAM_ULONG
);
1157 /* G_TYPE_PARAM_INT64
1160 static const GParamSpecTypeInfo pspec_info
= {
1161 sizeof (GParamSpecInt64
), /* instance_size */
1162 16, /* n_preallocs */
1163 param_int64_init
, /* instance_init */
1164 G_TYPE_INT64
, /* value_type */
1165 NULL
, /* finalize */
1166 param_int64_set_default
, /* value_set_default */
1167 param_int64_validate
, /* value_validate */
1168 param_int64_values_cmp
, /* values_cmp */
1170 type
= g_param_type_register_static ("GParamInt64", &pspec_info
);
1171 *spec_types
++ = type
;
1172 g_assert (type
== G_TYPE_PARAM_INT64
);
1175 /* G_TYPE_PARAM_UINT64
1178 static const GParamSpecTypeInfo pspec_info
= {
1179 sizeof (GParamSpecUInt64
), /* instance_size */
1180 16, /* n_preallocs */
1181 param_uint64_init
, /* instance_init */
1182 G_TYPE_UINT64
, /* value_type */
1183 NULL
, /* finalize */
1184 param_uint64_set_default
, /* value_set_default */
1185 param_uint64_validate
, /* value_validate */
1186 param_uint64_values_cmp
, /* values_cmp */
1188 type
= g_param_type_register_static ("GParamUInt64", &pspec_info
);
1189 *spec_types
++ = type
;
1190 g_assert (type
== G_TYPE_PARAM_UINT64
);
1193 /* G_TYPE_PARAM_UNICHAR
1196 static const GParamSpecTypeInfo pspec_info
= {
1197 sizeof (GParamSpecUnichar
), /* instance_size */
1198 16, /* n_preallocs */
1199 param_unichar_init
, /* instance_init */
1200 G_TYPE_UINT
, /* value_type */
1201 NULL
, /* finalize */
1202 param_unichar_set_default
, /* value_set_default */
1203 param_unichar_validate
, /* value_validate */
1204 param_unichar_values_cmp
, /* values_cmp */
1206 type
= g_param_type_register_static ("GParamUnichar", &pspec_info
);
1207 *spec_types
++ = type
;
1208 g_assert (type
== G_TYPE_PARAM_UNICHAR
);
1211 /* G_TYPE_PARAM_ENUM
1214 static const GParamSpecTypeInfo pspec_info
= {
1215 sizeof (GParamSpecEnum
), /* instance_size */
1216 16, /* n_preallocs */
1217 param_enum_init
, /* instance_init */
1218 G_TYPE_ENUM
, /* value_type */
1219 param_enum_finalize
, /* finalize */
1220 param_enum_set_default
, /* value_set_default */
1221 param_enum_validate
, /* value_validate */
1222 param_long_values_cmp
, /* values_cmp */
1224 type
= g_param_type_register_static ("GParamEnum", &pspec_info
);
1225 *spec_types
++ = type
;
1226 g_assert (type
== G_TYPE_PARAM_ENUM
);
1229 /* G_TYPE_PARAM_FLAGS
1232 static const GParamSpecTypeInfo pspec_info
= {
1233 sizeof (GParamSpecFlags
), /* instance_size */
1234 16, /* n_preallocs */
1235 param_flags_init
, /* instance_init */
1236 G_TYPE_FLAGS
, /* value_type */
1237 param_flags_finalize
, /* finalize */
1238 param_flags_set_default
, /* value_set_default */
1239 param_flags_validate
, /* value_validate */
1240 param_ulong_values_cmp
, /* values_cmp */
1242 type
= g_param_type_register_static ("GParamFlags", &pspec_info
);
1243 *spec_types
++ = type
;
1244 g_assert (type
== G_TYPE_PARAM_FLAGS
);
1247 /* G_TYPE_PARAM_FLOAT
1250 static const GParamSpecTypeInfo pspec_info
= {
1251 sizeof (GParamSpecFloat
), /* instance_size */
1252 16, /* n_preallocs */
1253 param_float_init
, /* instance_init */
1254 G_TYPE_FLOAT
, /* value_type */
1255 NULL
, /* finalize */
1256 param_float_set_default
, /* value_set_default */
1257 param_float_validate
, /* value_validate */
1258 param_float_values_cmp
, /* values_cmp */
1260 type
= g_param_type_register_static ("GParamFloat", &pspec_info
);
1261 *spec_types
++ = type
;
1262 g_assert (type
== G_TYPE_PARAM_FLOAT
);
1265 /* G_TYPE_PARAM_DOUBLE
1268 static const GParamSpecTypeInfo pspec_info
= {
1269 sizeof (GParamSpecDouble
), /* instance_size */
1270 16, /* n_preallocs */
1271 param_double_init
, /* instance_init */
1272 G_TYPE_DOUBLE
, /* value_type */
1273 NULL
, /* finalize */
1274 param_double_set_default
, /* value_set_default */
1275 param_double_validate
, /* value_validate */
1276 param_double_values_cmp
, /* values_cmp */
1278 type
= g_param_type_register_static ("GParamDouble", &pspec_info
);
1279 *spec_types
++ = type
;
1280 g_assert (type
== G_TYPE_PARAM_DOUBLE
);
1283 /* G_TYPE_PARAM_STRING
1286 static const GParamSpecTypeInfo pspec_info
= {
1287 sizeof (GParamSpecString
), /* instance_size */
1288 16, /* n_preallocs */
1289 param_string_init
, /* instance_init */
1290 G_TYPE_STRING
, /* value_type */
1291 param_string_finalize
, /* finalize */
1292 param_string_set_default
, /* value_set_default */
1293 param_string_validate
, /* value_validate */
1294 param_string_values_cmp
, /* values_cmp */
1296 type
= g_param_type_register_static ("GParamString", &pspec_info
);
1297 *spec_types
++ = type
;
1298 g_assert (type
== G_TYPE_PARAM_STRING
);
1301 /* G_TYPE_PARAM_PARAM
1304 static const GParamSpecTypeInfo pspec_info
= {
1305 sizeof (GParamSpecParam
), /* instance_size */
1306 16, /* n_preallocs */
1307 param_param_init
, /* instance_init */
1308 G_TYPE_PARAM
, /* value_type */
1309 NULL
, /* finalize */
1310 param_param_set_default
, /* value_set_default */
1311 param_param_validate
, /* value_validate */
1312 param_pointer_values_cmp
, /* values_cmp */
1314 type
= g_param_type_register_static ("GParamParam", &pspec_info
);
1315 *spec_types
++ = type
;
1316 g_assert (type
== G_TYPE_PARAM_PARAM
);
1319 /* G_TYPE_PARAM_BOXED
1322 static const GParamSpecTypeInfo pspec_info
= {
1323 sizeof (GParamSpecBoxed
), /* instance_size */
1324 4, /* n_preallocs */
1325 param_boxed_init
, /* instance_init */
1326 G_TYPE_BOXED
, /* value_type */
1327 NULL
, /* finalize */
1328 param_boxed_set_default
, /* value_set_default */
1329 param_boxed_validate
, /* value_validate */
1330 param_boxed_values_cmp
, /* values_cmp */
1332 type
= g_param_type_register_static ("GParamBoxed", &pspec_info
);
1333 *spec_types
++ = type
;
1334 g_assert (type
== G_TYPE_PARAM_BOXED
);
1337 /* G_TYPE_PARAM_POINTER
1340 static const GParamSpecTypeInfo pspec_info
= {
1341 sizeof (GParamSpecPointer
), /* instance_size */
1342 0, /* n_preallocs */
1343 param_pointer_init
, /* instance_init */
1344 G_TYPE_POINTER
, /* value_type */
1345 NULL
, /* finalize */
1346 param_pointer_set_default
, /* value_set_default */
1347 param_pointer_validate
, /* value_validate */
1348 param_pointer_values_cmp
, /* values_cmp */
1350 type
= g_param_type_register_static ("GParamPointer", &pspec_info
);
1351 *spec_types
++ = type
;
1352 g_assert (type
== G_TYPE_PARAM_POINTER
);
1355 /* G_TYPE_PARAM_VALUE_ARRAY
1358 static /* const */ GParamSpecTypeInfo pspec_info
= {
1359 sizeof (GParamSpecValueArray
), /* instance_size */
1360 0, /* n_preallocs */
1361 param_value_array_init
, /* instance_init */
1362 0xdeadbeef, /* value_type, assigned further down */
1363 param_value_array_finalize
, /* finalize */
1364 param_value_array_set_default
, /* value_set_default */
1365 param_value_array_validate
, /* value_validate */
1366 param_value_array_values_cmp
, /* values_cmp */
1368 pspec_info
.value_type
= G_TYPE_VALUE_ARRAY
;
1369 type
= g_param_type_register_static ("GParamValueArray", &pspec_info
);
1370 *spec_types
++ = type
;
1371 g_assert (type
== G_TYPE_PARAM_VALUE_ARRAY
);
1374 /* G_TYPE_PARAM_OBJECT
1377 static const GParamSpecTypeInfo pspec_info
= {
1378 sizeof (GParamSpecObject
), /* instance_size */
1379 16, /* n_preallocs */
1380 param_object_init
, /* instance_init */
1381 G_TYPE_OBJECT
, /* value_type */
1382 NULL
, /* finalize */
1383 param_object_set_default
, /* value_set_default */
1384 param_object_validate
, /* value_validate */
1385 param_object_values_cmp
, /* values_cmp */
1387 type
= g_param_type_register_static ("GParamObject", &pspec_info
);
1388 *spec_types
++ = type
;
1389 g_assert (type
== G_TYPE_PARAM_OBJECT
);
1392 /* G_TYPE_PARAM_OVERRIDE
1395 static const GParamSpecTypeInfo pspec_info
= {
1396 sizeof (GParamSpecOverride
), /* instance_size */
1397 16, /* n_preallocs */
1398 param_override_init
, /* instance_init */
1399 G_TYPE_NONE
, /* value_type */
1400 param_override_finalize
, /* finalize */
1401 param_override_set_default
, /* value_set_default */
1402 param_override_validate
, /* value_validate */
1403 param_override_values_cmp
, /* values_cmp */
1405 type
= g_param_type_register_static ("GParamOverride", &pspec_info
);
1406 *spec_types
++ = type
;
1407 g_assert (type
== G_TYPE_PARAM_OVERRIDE
);
1410 g_assert (spec_types
== spec_types_bound
);
1413 /* --- GParamSpec initialization --- */
1416 g_param_spec_char (const gchar
*name
,
1421 gint8 default_value
,
1424 GParamSpecChar
*cspec
;
1426 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1428 cspec
= g_param_spec_internal (G_TYPE_PARAM_CHAR
,
1434 cspec
->minimum
= minimum
;
1435 cspec
->maximum
= maximum
;
1436 cspec
->default_value
= default_value
;
1438 return G_PARAM_SPEC (cspec
);
1442 g_param_spec_uchar (const gchar
*name
,
1447 guint8 default_value
,
1450 GParamSpecUChar
*uspec
;
1452 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1454 uspec
= g_param_spec_internal (G_TYPE_PARAM_UCHAR
,
1460 uspec
->minimum
= minimum
;
1461 uspec
->maximum
= maximum
;
1462 uspec
->default_value
= default_value
;
1464 return G_PARAM_SPEC (uspec
);
1468 g_param_spec_boolean (const gchar
*name
,
1471 gboolean default_value
,
1474 GParamSpecBoolean
*bspec
;
1476 g_return_val_if_fail (default_value
== TRUE
|| default_value
== FALSE
, NULL
);
1478 bspec
= g_param_spec_internal (G_TYPE_PARAM_BOOLEAN
,
1484 bspec
->default_value
= default_value
;
1486 return G_PARAM_SPEC (bspec
);
1490 g_param_spec_int (const gchar
*name
,
1498 GParamSpecInt
*ispec
;
1500 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1502 ispec
= g_param_spec_internal (G_TYPE_PARAM_INT
,
1508 ispec
->minimum
= minimum
;
1509 ispec
->maximum
= maximum
;
1510 ispec
->default_value
= default_value
;
1512 return G_PARAM_SPEC (ispec
);
1516 g_param_spec_uint (const gchar
*name
,
1521 guint default_value
,
1524 GParamSpecUInt
*uspec
;
1526 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1528 uspec
= g_param_spec_internal (G_TYPE_PARAM_UINT
,
1534 uspec
->minimum
= minimum
;
1535 uspec
->maximum
= maximum
;
1536 uspec
->default_value
= default_value
;
1538 return G_PARAM_SPEC (uspec
);
1542 g_param_spec_long (const gchar
*name
,
1547 glong default_value
,
1550 GParamSpecLong
*lspec
;
1552 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1554 lspec
= g_param_spec_internal (G_TYPE_PARAM_LONG
,
1560 lspec
->minimum
= minimum
;
1561 lspec
->maximum
= maximum
;
1562 lspec
->default_value
= default_value
;
1564 return G_PARAM_SPEC (lspec
);
1568 g_param_spec_ulong (const gchar
*name
,
1573 gulong default_value
,
1576 GParamSpecULong
*uspec
;
1578 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1580 uspec
= g_param_spec_internal (G_TYPE_PARAM_ULONG
,
1586 uspec
->minimum
= minimum
;
1587 uspec
->maximum
= maximum
;
1588 uspec
->default_value
= default_value
;
1590 return G_PARAM_SPEC (uspec
);
1594 g_param_spec_int64 (const gchar
*name
,
1599 gint64 default_value
,
1602 GParamSpecInt64
*lspec
;
1604 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1606 lspec
= g_param_spec_internal (G_TYPE_PARAM_INT64
,
1612 lspec
->minimum
= minimum
;
1613 lspec
->maximum
= maximum
;
1614 lspec
->default_value
= default_value
;
1616 return G_PARAM_SPEC (lspec
);
1620 g_param_spec_uint64 (const gchar
*name
,
1625 guint64 default_value
,
1628 GParamSpecUInt64
*uspec
;
1630 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1632 uspec
= g_param_spec_internal (G_TYPE_PARAM_UINT64
,
1638 uspec
->minimum
= minimum
;
1639 uspec
->maximum
= maximum
;
1640 uspec
->default_value
= default_value
;
1642 return G_PARAM_SPEC (uspec
);
1646 g_param_spec_unichar (const gchar
*name
,
1649 gunichar default_value
,
1652 GParamSpecUnichar
*uspec
;
1654 uspec
= g_param_spec_internal (G_TYPE_PARAM_UNICHAR
,
1660 uspec
->default_value
= default_value
;
1662 return G_PARAM_SPEC (uspec
);
1666 g_param_spec_enum (const gchar
*name
,
1673 GParamSpecEnum
*espec
;
1674 GEnumClass
*enum_class
;
1676 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type
), NULL
);
1678 enum_class
= g_type_class_ref (enum_type
);
1680 g_return_val_if_fail (g_enum_get_value (enum_class
, default_value
) != NULL
, NULL
);
1682 espec
= g_param_spec_internal (G_TYPE_PARAM_ENUM
,
1688 espec
->enum_class
= enum_class
;
1689 espec
->default_value
= default_value
;
1690 G_PARAM_SPEC (espec
)->value_type
= enum_type
;
1692 return G_PARAM_SPEC (espec
);
1696 g_param_spec_flags (const gchar
*name
,
1700 guint default_value
,
1703 GParamSpecFlags
*fspec
;
1704 GFlagsClass
*flags_class
;
1706 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type
), NULL
);
1708 flags_class
= g_type_class_ref (flags_type
);
1710 g_return_val_if_fail ((default_value
& flags_class
->mask
) == default_value
, NULL
);
1712 fspec
= g_param_spec_internal (G_TYPE_PARAM_FLAGS
,
1718 fspec
->flags_class
= flags_class
;
1719 fspec
->default_value
= default_value
;
1720 G_PARAM_SPEC (fspec
)->value_type
= flags_type
;
1722 return G_PARAM_SPEC (fspec
);
1726 g_param_spec_float (const gchar
*name
,
1731 gfloat default_value
,
1734 GParamSpecFloat
*fspec
;
1736 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1738 fspec
= g_param_spec_internal (G_TYPE_PARAM_FLOAT
,
1744 fspec
->minimum
= minimum
;
1745 fspec
->maximum
= maximum
;
1746 fspec
->default_value
= default_value
;
1748 return G_PARAM_SPEC (fspec
);
1752 g_param_spec_double (const gchar
*name
,
1757 gdouble default_value
,
1760 GParamSpecDouble
*dspec
;
1762 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1764 dspec
= g_param_spec_internal (G_TYPE_PARAM_DOUBLE
,
1770 dspec
->minimum
= minimum
;
1771 dspec
->maximum
= maximum
;
1772 dspec
->default_value
= default_value
;
1774 return G_PARAM_SPEC (dspec
);
1778 g_param_spec_string (const gchar
*name
,
1781 const gchar
*default_value
,
1784 GParamSpecString
*sspec
= g_param_spec_internal (G_TYPE_PARAM_STRING
,
1789 g_free (sspec
->default_value
);
1790 sspec
->default_value
= g_strdup (default_value
);
1792 return G_PARAM_SPEC (sspec
);
1796 g_param_spec_param (const gchar
*name
,
1802 GParamSpecParam
*pspec
;
1804 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type
), NULL
);
1806 pspec
= g_param_spec_internal (G_TYPE_PARAM_PARAM
,
1811 G_PARAM_SPEC (pspec
)->value_type
= param_type
;
1813 return G_PARAM_SPEC (pspec
);
1817 g_param_spec_boxed (const gchar
*name
,
1823 GParamSpecBoxed
*bspec
;
1825 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type
), NULL
);
1826 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type
), NULL
);
1828 bspec
= g_param_spec_internal (G_TYPE_PARAM_BOXED
,
1833 G_PARAM_SPEC (bspec
)->value_type
= boxed_type
;
1835 return G_PARAM_SPEC (bspec
);
1839 g_param_spec_pointer (const gchar
*name
,
1844 GParamSpecPointer
*pspec
;
1846 pspec
= g_param_spec_internal (G_TYPE_PARAM_POINTER
,
1851 return G_PARAM_SPEC (pspec
);
1855 g_param_spec_value_array (const gchar
*name
,
1858 GParamSpec
*element_spec
,
1861 GParamSpecValueArray
*aspec
;
1864 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec
), NULL
);
1866 aspec
= g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY
,
1873 aspec
->element_spec
= g_param_spec_ref (element_spec
);
1874 g_param_spec_sink (element_spec
);
1877 return G_PARAM_SPEC (aspec
);
1881 g_param_spec_object (const gchar
*name
,
1887 GParamSpecObject
*ospec
;
1889 g_return_val_if_fail (g_type_is_a (object_type
, G_TYPE_OBJECT
), NULL
);
1891 ospec
= g_param_spec_internal (G_TYPE_PARAM_OBJECT
,
1896 G_PARAM_SPEC (ospec
)->value_type
= object_type
;
1898 return G_PARAM_SPEC (ospec
);
1902 g_param_spec_override (const gchar
*name
,
1903 GParamSpec
*overridden
)
1907 g_return_val_if_fail (name
!= NULL
, NULL
);
1908 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden
), NULL
);
1910 /* Dereference further redirections for property that was passed in
1914 GParamSpec
*indirect
= g_param_spec_get_redirect_target (overridden
);
1916 overridden
= indirect
;
1921 pspec
= g_param_spec_internal (G_TYPE_PARAM_OVERRIDE
,
1925 pspec
->value_type
= G_PARAM_SPEC_VALUE_TYPE (overridden
);
1926 G_PARAM_SPEC_OVERRIDE (pspec
)->overridden
= g_param_spec_ref (overridden
);