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"
30 #include "gobjectalias.h"
33 #define G_FLOAT_EPSILON (1e-30)
34 #define G_DOUBLE_EPSILON (1e-90)
37 /* --- param spec functions --- */
39 param_char_init (GParamSpec
*pspec
)
41 GParamSpecChar
*cspec
= G_PARAM_SPEC_CHAR (pspec
);
43 cspec
->minimum
= 0x7f;
44 cspec
->maximum
= 0x80;
45 cspec
->default_value
= 0;
49 param_char_set_default (GParamSpec
*pspec
,
52 value
->data
[0].v_int
= G_PARAM_SPEC_CHAR (pspec
)->default_value
;
56 param_char_validate (GParamSpec
*pspec
,
59 GParamSpecChar
*cspec
= G_PARAM_SPEC_CHAR (pspec
);
60 gint oval
= value
->data
[0].v_int
;
62 value
->data
[0].v_int
= CLAMP (value
->data
[0].v_int
, cspec
->minimum
, cspec
->maximum
);
64 return value
->data
[0].v_int
!= oval
;
68 param_uchar_init (GParamSpec
*pspec
)
70 GParamSpecUChar
*uspec
= G_PARAM_SPEC_UCHAR (pspec
);
73 uspec
->maximum
= 0xff;
74 uspec
->default_value
= 0;
78 param_uchar_set_default (GParamSpec
*pspec
,
81 value
->data
[0].v_uint
= G_PARAM_SPEC_UCHAR (pspec
)->default_value
;
85 param_uchar_validate (GParamSpec
*pspec
,
88 GParamSpecUChar
*uspec
= G_PARAM_SPEC_UCHAR (pspec
);
89 guint oval
= value
->data
[0].v_uint
;
91 value
->data
[0].v_uint
= CLAMP (value
->data
[0].v_uint
, uspec
->minimum
, uspec
->maximum
);
93 return value
->data
[0].v_uint
!= oval
;
97 param_boolean_set_default (GParamSpec
*pspec
,
100 value
->data
[0].v_int
= G_PARAM_SPEC_BOOLEAN (pspec
)->default_value
;
104 param_boolean_validate (GParamSpec
*pspec
,
107 gint oval
= value
->data
[0].v_int
;
109 value
->data
[0].v_int
= value
->data
[0].v_int
!= FALSE
;
111 return value
->data
[0].v_int
!= oval
;
115 param_int_init (GParamSpec
*pspec
)
117 GParamSpecInt
*ispec
= G_PARAM_SPEC_INT (pspec
);
119 ispec
->minimum
= 0x7fffffff;
120 ispec
->maximum
= 0x80000000;
121 ispec
->default_value
= 0;
125 param_int_set_default (GParamSpec
*pspec
,
128 value
->data
[0].v_int
= G_PARAM_SPEC_INT (pspec
)->default_value
;
132 param_int_validate (GParamSpec
*pspec
,
135 GParamSpecInt
*ispec
= G_PARAM_SPEC_INT (pspec
);
136 gint oval
= value
->data
[0].v_int
;
138 value
->data
[0].v_int
= CLAMP (value
->data
[0].v_int
, ispec
->minimum
, ispec
->maximum
);
140 return value
->data
[0].v_int
!= oval
;
144 param_int_values_cmp (GParamSpec
*pspec
,
145 const GValue
*value1
,
146 const GValue
*value2
)
148 if (value1
->data
[0].v_int
< value2
->data
[0].v_int
)
151 return value1
->data
[0].v_int
> value2
->data
[0].v_int
;
155 param_uint_init (GParamSpec
*pspec
)
157 GParamSpecUInt
*uspec
= G_PARAM_SPEC_UINT (pspec
);
160 uspec
->maximum
= 0xffffffff;
161 uspec
->default_value
= 0;
165 param_uint_set_default (GParamSpec
*pspec
,
168 value
->data
[0].v_uint
= G_PARAM_SPEC_UINT (pspec
)->default_value
;
172 param_uint_validate (GParamSpec
*pspec
,
175 GParamSpecUInt
*uspec
= G_PARAM_SPEC_UINT (pspec
);
176 guint oval
= value
->data
[0].v_uint
;
178 value
->data
[0].v_uint
= CLAMP (value
->data
[0].v_uint
, uspec
->minimum
, uspec
->maximum
);
180 return value
->data
[0].v_uint
!= oval
;
184 param_uint_values_cmp (GParamSpec
*pspec
,
185 const GValue
*value1
,
186 const GValue
*value2
)
188 if (value1
->data
[0].v_uint
< value2
->data
[0].v_uint
)
191 return value1
->data
[0].v_uint
> value2
->data
[0].v_uint
;
195 param_long_init (GParamSpec
*pspec
)
197 GParamSpecLong
*lspec
= G_PARAM_SPEC_LONG (pspec
);
200 lspec
->minimum
= 0x7fffffff;
201 lspec
->maximum
= 0x80000000;
202 #else /* SIZEOF_LONG != 4 (8) */
203 lspec
->minimum
= 0x7fffffffffffffff;
204 lspec
->maximum
= 0x8000000000000000;
206 lspec
->default_value
= 0;
210 param_long_set_default (GParamSpec
*pspec
,
213 value
->data
[0].v_long
= G_PARAM_SPEC_LONG (pspec
)->default_value
;
217 param_long_validate (GParamSpec
*pspec
,
220 GParamSpecLong
*lspec
= G_PARAM_SPEC_LONG (pspec
);
221 glong oval
= value
->data
[0].v_long
;
223 value
->data
[0].v_long
= CLAMP (value
->data
[0].v_long
, lspec
->minimum
, lspec
->maximum
);
225 return value
->data
[0].v_long
!= oval
;
229 param_long_values_cmp (GParamSpec
*pspec
,
230 const GValue
*value1
,
231 const GValue
*value2
)
233 if (value1
->data
[0].v_long
< value2
->data
[0].v_long
)
236 return value1
->data
[0].v_long
> value2
->data
[0].v_long
;
240 param_ulong_init (GParamSpec
*pspec
)
242 GParamSpecULong
*uspec
= G_PARAM_SPEC_ULONG (pspec
);
246 uspec
->maximum
= 0xffffffff;
247 #else /* SIZEOF_LONG != 4 (8) */
248 uspec
->maximum
= 0xffffffffffffffff;
250 uspec
->default_value
= 0;
254 param_ulong_set_default (GParamSpec
*pspec
,
257 value
->data
[0].v_ulong
= G_PARAM_SPEC_ULONG (pspec
)->default_value
;
261 param_ulong_validate (GParamSpec
*pspec
,
264 GParamSpecULong
*uspec
= G_PARAM_SPEC_ULONG (pspec
);
265 gulong oval
= value
->data
[0].v_ulong
;
267 value
->data
[0].v_ulong
= CLAMP (value
->data
[0].v_ulong
, uspec
->minimum
, uspec
->maximum
);
269 return value
->data
[0].v_ulong
!= oval
;
273 param_ulong_values_cmp (GParamSpec
*pspec
,
274 const GValue
*value1
,
275 const GValue
*value2
)
277 if (value1
->data
[0].v_ulong
< value2
->data
[0].v_ulong
)
280 return value1
->data
[0].v_ulong
> value2
->data
[0].v_ulong
;
284 param_int64_init (GParamSpec
*pspec
)
286 GParamSpecInt64
*lspec
= G_PARAM_SPEC_INT64 (pspec
);
288 lspec
->minimum
= G_MININT64
;
289 lspec
->maximum
= G_MAXINT64
;
290 lspec
->default_value
= 0;
294 param_int64_set_default (GParamSpec
*pspec
,
297 value
->data
[0].v_int64
= G_PARAM_SPEC_INT64 (pspec
)->default_value
;
301 param_int64_validate (GParamSpec
*pspec
,
304 GParamSpecInt64
*lspec
= G_PARAM_SPEC_INT64 (pspec
);
305 gint64 oval
= value
->data
[0].v_int64
;
307 value
->data
[0].v_int64
= CLAMP (value
->data
[0].v_int64
, lspec
->minimum
, lspec
->maximum
);
309 return value
->data
[0].v_int64
!= oval
;
313 param_int64_values_cmp (GParamSpec
*pspec
,
314 const GValue
*value1
,
315 const GValue
*value2
)
317 if (value1
->data
[0].v_int64
< value2
->data
[0].v_int64
)
320 return value1
->data
[0].v_int64
> value2
->data
[0].v_int64
;
324 param_uint64_init (GParamSpec
*pspec
)
326 GParamSpecUInt64
*uspec
= G_PARAM_SPEC_UINT64 (pspec
);
329 uspec
->maximum
= G_MAXUINT64
;
330 uspec
->default_value
= 0;
334 param_uint64_set_default (GParamSpec
*pspec
,
337 value
->data
[0].v_uint64
= G_PARAM_SPEC_UINT64 (pspec
)->default_value
;
341 param_uint64_validate (GParamSpec
*pspec
,
344 GParamSpecUInt64
*uspec
= G_PARAM_SPEC_UINT64 (pspec
);
345 guint64 oval
= value
->data
[0].v_uint64
;
347 value
->data
[0].v_uint64
= CLAMP (value
->data
[0].v_uint64
, uspec
->minimum
, uspec
->maximum
);
349 return value
->data
[0].v_uint64
!= oval
;
353 param_uint64_values_cmp (GParamSpec
*pspec
,
354 const GValue
*value1
,
355 const GValue
*value2
)
357 if (value1
->data
[0].v_uint64
< value2
->data
[0].v_uint64
)
360 return value1
->data
[0].v_uint64
> value2
->data
[0].v_uint64
;
364 param_unichar_init (GParamSpec
*pspec
)
366 GParamSpecUnichar
*uspec
= G_PARAM_SPEC_UNICHAR (pspec
);
368 uspec
->default_value
= 0;
372 param_unichar_set_default (GParamSpec
*pspec
,
375 value
->data
[0].v_uint
= G_PARAM_SPEC_UNICHAR (pspec
)->default_value
;
379 param_unichar_validate (GParamSpec
*pspec
,
382 gunichar oval
= value
->data
[0].v_uint
;
383 gboolean changed
= FALSE
;
385 if (!g_unichar_validate (oval
))
387 value
->data
[0].v_uint
= 0;
395 param_unichar_values_cmp (GParamSpec
*pspec
,
396 const GValue
*value1
,
397 const GValue
*value2
)
399 if (value1
->data
[0].v_uint
< value2
->data
[0].v_uint
)
402 return value1
->data
[0].v_uint
> value2
->data
[0].v_uint
;
406 param_enum_init (GParamSpec
*pspec
)
408 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
410 espec
->enum_class
= NULL
;
411 espec
->default_value
= 0;
415 param_enum_finalize (GParamSpec
*pspec
)
417 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
418 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM
));
420 if (espec
->enum_class
)
422 g_type_class_unref (espec
->enum_class
);
423 espec
->enum_class
= NULL
;
426 parent_class
->finalize (pspec
);
430 param_enum_set_default (GParamSpec
*pspec
,
433 value
->data
[0].v_long
= G_PARAM_SPEC_ENUM (pspec
)->default_value
;
437 param_enum_validate (GParamSpec
*pspec
,
440 GParamSpecEnum
*espec
= G_PARAM_SPEC_ENUM (pspec
);
441 glong oval
= value
->data
[0].v_long
;
443 if (!espec
->enum_class
||
444 !g_enum_get_value (espec
->enum_class
, value
->data
[0].v_long
))
445 value
->data
[0].v_long
= espec
->default_value
;
447 return value
->data
[0].v_long
!= oval
;
451 param_flags_init (GParamSpec
*pspec
)
453 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
455 fspec
->flags_class
= NULL
;
456 fspec
->default_value
= 0;
460 param_flags_finalize (GParamSpec
*pspec
)
462 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
463 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS
));
465 if (fspec
->flags_class
)
467 g_type_class_unref (fspec
->flags_class
);
468 fspec
->flags_class
= NULL
;
471 parent_class
->finalize (pspec
);
475 param_flags_set_default (GParamSpec
*pspec
,
478 value
->data
[0].v_ulong
= G_PARAM_SPEC_FLAGS (pspec
)->default_value
;
482 param_flags_validate (GParamSpec
*pspec
,
485 GParamSpecFlags
*fspec
= G_PARAM_SPEC_FLAGS (pspec
);
486 gulong oval
= value
->data
[0].v_ulong
;
488 if (fspec
->flags_class
)
489 value
->data
[0].v_ulong
&= fspec
->flags_class
->mask
;
491 value
->data
[0].v_ulong
= fspec
->default_value
;
493 return value
->data
[0].v_ulong
!= oval
;
497 param_float_init (GParamSpec
*pspec
)
499 GParamSpecFloat
*fspec
= G_PARAM_SPEC_FLOAT (pspec
);
501 fspec
->minimum
= -G_MAXFLOAT
;
502 fspec
->maximum
= G_MAXFLOAT
;
503 fspec
->default_value
= 0;
504 fspec
->epsilon
= G_FLOAT_EPSILON
;
508 param_float_set_default (GParamSpec
*pspec
,
511 value
->data
[0].v_float
= G_PARAM_SPEC_FLOAT (pspec
)->default_value
;
515 param_float_validate (GParamSpec
*pspec
,
518 GParamSpecFloat
*fspec
= G_PARAM_SPEC_FLOAT (pspec
);
519 gfloat oval
= value
->data
[0].v_float
;
521 value
->data
[0].v_float
= CLAMP (value
->data
[0].v_float
, fspec
->minimum
, fspec
->maximum
);
523 return value
->data
[0].v_float
!= oval
;
527 param_float_values_cmp (GParamSpec
*pspec
,
528 const GValue
*value1
,
529 const GValue
*value2
)
531 gfloat epsilon
= G_PARAM_SPEC_FLOAT (pspec
)->epsilon
;
533 if (value1
->data
[0].v_float
< value2
->data
[0].v_float
)
534 return - (value2
->data
[0].v_float
- value1
->data
[0].v_float
> epsilon
);
536 return value1
->data
[0].v_float
- value2
->data
[0].v_float
> epsilon
;
540 param_double_init (GParamSpec
*pspec
)
542 GParamSpecDouble
*dspec
= G_PARAM_SPEC_DOUBLE (pspec
);
544 dspec
->minimum
= -G_MAXDOUBLE
;
545 dspec
->maximum
= G_MAXDOUBLE
;
546 dspec
->default_value
= 0;
547 dspec
->epsilon
= G_DOUBLE_EPSILON
;
551 param_double_set_default (GParamSpec
*pspec
,
554 value
->data
[0].v_double
= G_PARAM_SPEC_DOUBLE (pspec
)->default_value
;
558 param_double_validate (GParamSpec
*pspec
,
561 GParamSpecDouble
*dspec
= G_PARAM_SPEC_DOUBLE (pspec
);
562 gdouble oval
= value
->data
[0].v_double
;
564 value
->data
[0].v_double
= CLAMP (value
->data
[0].v_double
, dspec
->minimum
, dspec
->maximum
);
566 return value
->data
[0].v_double
!= oval
;
570 param_double_values_cmp (GParamSpec
*pspec
,
571 const GValue
*value1
,
572 const GValue
*value2
)
574 gdouble epsilon
= G_PARAM_SPEC_DOUBLE (pspec
)->epsilon
;
576 if (value1
->data
[0].v_double
< value2
->data
[0].v_double
)
577 return - (value2
->data
[0].v_double
- value1
->data
[0].v_double
> epsilon
);
579 return value1
->data
[0].v_double
- value2
->data
[0].v_double
> epsilon
;
583 param_string_init (GParamSpec
*pspec
)
585 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
587 sspec
->default_value
= NULL
;
588 sspec
->cset_first
= NULL
;
589 sspec
->cset_nth
= NULL
;
590 sspec
->substitutor
= '_';
591 sspec
->null_fold_if_empty
= FALSE
;
592 sspec
->ensure_non_null
= FALSE
;
596 param_string_finalize (GParamSpec
*pspec
)
598 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
599 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING
));
601 g_free (sspec
->default_value
);
602 g_free (sspec
->cset_first
);
603 g_free (sspec
->cset_nth
);
604 sspec
->default_value
= NULL
;
605 sspec
->cset_first
= NULL
;
606 sspec
->cset_nth
= NULL
;
608 parent_class
->finalize (pspec
);
612 param_string_set_default (GParamSpec
*pspec
,
615 value
->data
[0].v_pointer
= g_strdup (G_PARAM_SPEC_STRING (pspec
)->default_value
);
619 param_string_validate (GParamSpec
*pspec
,
622 GParamSpecString
*sspec
= G_PARAM_SPEC_STRING (pspec
);
623 gchar
*string
= value
->data
[0].v_pointer
;
626 if (string
&& string
[0])
630 if (sspec
->cset_first
&& !strchr (sspec
->cset_first
, string
[0]))
632 string
[0] = sspec
->substitutor
;
636 for (s
= string
+ 1; *s
; s
++)
637 if (!strchr (sspec
->cset_nth
, *s
))
639 *s
= sspec
->substitutor
;
643 if (sspec
->null_fold_if_empty
&& string
&& string
[0] == 0)
645 g_free (value
->data
[0].v_pointer
);
646 value
->data
[0].v_pointer
= NULL
;
648 string
= value
->data
[0].v_pointer
;
650 if (sspec
->ensure_non_null
&& !string
)
652 value
->data
[0].v_pointer
= g_strdup ("");
654 string
= value
->data
[0].v_pointer
;
661 param_string_values_cmp (GParamSpec
*pspec
,
662 const GValue
*value1
,
663 const GValue
*value2
)
665 if (!value1
->data
[0].v_pointer
)
666 return value2
->data
[0].v_pointer
!= NULL
? -1 : 0;
667 else if (!value2
->data
[0].v_pointer
)
668 return value1
->data
[0].v_pointer
!= NULL
;
670 return strcmp (value1
->data
[0].v_pointer
, value2
->data
[0].v_pointer
);
674 param_param_init (GParamSpec
*pspec
)
676 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
680 param_param_set_default (GParamSpec
*pspec
,
683 value
->data
[0].v_pointer
= NULL
;
687 param_param_validate (GParamSpec
*pspec
,
690 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
691 GParamSpec
*param
= value
->data
[0].v_pointer
;
694 if (param
&& !g_value_type_compatible (G_PARAM_SPEC_TYPE (param
), G_PARAM_SPEC_VALUE_TYPE (pspec
)))
696 g_param_spec_unref (param
);
697 value
->data
[0].v_pointer
= NULL
;
705 param_boxed_init (GParamSpec
*pspec
)
707 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
711 param_boxed_set_default (GParamSpec
*pspec
,
714 value
->data
[0].v_pointer
= NULL
;
718 param_boxed_validate (GParamSpec
*pspec
,
721 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
724 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
730 param_boxed_values_cmp (GParamSpec
*pspec
,
731 const GValue
*value1
,
732 const GValue
*value2
)
734 guint8
*p1
= value1
->data
[0].v_pointer
;
735 guint8
*p2
= value2
->data
[0].v_pointer
;
737 /* not much to compare here, try to at least provide stable lesser/greater result */
739 return p1
< p2
? -1 : p1
> p2
;
743 param_pointer_init (GParamSpec
*pspec
)
745 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
749 param_pointer_set_default (GParamSpec
*pspec
,
752 value
->data
[0].v_pointer
= NULL
;
756 param_pointer_validate (GParamSpec
*pspec
,
759 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
766 param_pointer_values_cmp (GParamSpec
*pspec
,
767 const GValue
*value1
,
768 const GValue
*value2
)
770 guint8
*p1
= value1
->data
[0].v_pointer
;
771 guint8
*p2
= value2
->data
[0].v_pointer
;
773 /* not much to compare here, try to at least provide stable lesser/greater result */
775 return p1
< p2
? -1 : p1
> p2
;
779 param_value_array_init (GParamSpec
*pspec
)
781 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
783 aspec
->element_spec
= NULL
;
784 aspec
->fixed_n_elements
= 0; /* disable */
788 value_array_ensure_size (GValueArray
*value_array
,
789 guint fixed_n_elements
)
793 if (fixed_n_elements
)
795 while (value_array
->n_values
< fixed_n_elements
)
797 g_value_array_append (value_array
, NULL
);
800 while (value_array
->n_values
> fixed_n_elements
)
802 g_value_array_remove (value_array
, value_array
->n_values
- 1);
810 param_value_array_finalize (GParamSpec
*pspec
)
812 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
813 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY
));
815 if (aspec
->element_spec
)
817 g_param_spec_unref (aspec
->element_spec
);
818 aspec
->element_spec
= NULL
;
821 parent_class
->finalize (pspec
);
825 param_value_array_set_default (GParamSpec
*pspec
,
828 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
830 if (!value
->data
[0].v_pointer
&& aspec
->fixed_n_elements
)
831 value
->data
[0].v_pointer
= g_value_array_new (aspec
->fixed_n_elements
);
833 if (value
->data
[0].v_pointer
)
835 /* g_value_reset (value); already done */
836 value_array_ensure_size (value
->data
[0].v_pointer
, aspec
->fixed_n_elements
);
841 param_value_array_validate (GParamSpec
*pspec
,
844 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
845 GValueArray
*value_array
= value
->data
[0].v_pointer
;
848 if (!value
->data
[0].v_pointer
&& aspec
->fixed_n_elements
)
849 value
->data
[0].v_pointer
= g_value_array_new (aspec
->fixed_n_elements
);
851 if (value
->data
[0].v_pointer
)
853 /* ensure array size validity */
854 changed
+= value_array_ensure_size (value_array
, aspec
->fixed_n_elements
);
856 /* ensure array values validity against a present element spec */
857 if (aspec
->element_spec
)
859 GParamSpec
*element_spec
= aspec
->element_spec
;
862 for (i
= 0; i
< value_array
->n_values
; i
++)
864 GValue
*element
= value_array
->values
+ i
;
866 /* need to fixup value type, or ensure that the array value is initialized at all */
867 if (!g_value_type_compatible (G_VALUE_TYPE (element
), G_PARAM_SPEC_VALUE_TYPE (element_spec
)))
869 if (G_VALUE_TYPE (element
) != 0)
870 g_value_unset (element
);
871 g_value_init (element
, G_PARAM_SPEC_VALUE_TYPE (element_spec
));
872 g_param_value_set_default (element_spec
, element
);
875 /* validate array value against element_spec */
876 changed
+= g_param_value_validate (element_spec
, element
);
885 param_value_array_values_cmp (GParamSpec
*pspec
,
886 const GValue
*value1
,
887 const GValue
*value2
)
889 GParamSpecValueArray
*aspec
= G_PARAM_SPEC_VALUE_ARRAY (pspec
);
890 GValueArray
*value_array1
= value1
->data
[0].v_pointer
;
891 GValueArray
*value_array2
= value2
->data
[0].v_pointer
;
893 if (!value_array1
|| !value_array2
)
894 return value_array2
? -1 : value_array1
!= value_array2
;
896 if (value_array1
->n_values
!= value_array2
->n_values
)
897 return value_array1
->n_values
< value_array2
->n_values
? -1 : 1;
898 else if (!aspec
->element_spec
)
900 /* we need an element specification for comparisons, so there's not much
901 * to compare here, try to at least provide stable lesser/greater result
903 return value_array1
->n_values
< value_array2
->n_values
? -1 : value_array1
->n_values
> value_array2
->n_values
;
905 else /* value_array1->n_values == value_array2->n_values */
909 for (i
= 0; i
< value_array1
->n_values
; i
++)
911 GValue
*element1
= value_array1
->values
+ i
;
912 GValue
*element2
= value_array2
->values
+ i
;
915 /* need corresponding element types, provide stable result otherwise */
916 if (G_VALUE_TYPE (element1
) != G_VALUE_TYPE (element2
))
917 return G_VALUE_TYPE (element1
) < G_VALUE_TYPE (element2
) ? -1 : 1;
918 cmp
= g_param_values_cmp (aspec
->element_spec
, element1
, element2
);
927 param_object_init (GParamSpec
*pspec
)
929 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
933 param_object_set_default (GParamSpec
*pspec
,
936 value
->data
[0].v_pointer
= NULL
;
940 param_object_validate (GParamSpec
*pspec
,
943 GParamSpecObject
*ospec
= G_PARAM_SPEC_OBJECT (pspec
);
944 GObject
*object
= value
->data
[0].v_pointer
;
947 if (object
&& !g_value_type_compatible (G_OBJECT_TYPE (object
), G_PARAM_SPEC_VALUE_TYPE (ospec
)))
949 g_object_unref (object
);
950 value
->data
[0].v_pointer
= NULL
;
958 param_object_values_cmp (GParamSpec
*pspec
,
959 const GValue
*value1
,
960 const GValue
*value2
)
962 guint8
*p1
= value1
->data
[0].v_pointer
;
963 guint8
*p2
= value2
->data
[0].v_pointer
;
965 /* not much to compare here, try to at least provide stable lesser/greater result */
967 return p1
< p2
? -1 : p1
> p2
;
971 param_override_init (GParamSpec
*pspec
)
973 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
977 param_override_finalize (GParamSpec
*pspec
)
979 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
980 GParamSpecClass
*parent_class
= g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE
));
982 if (ospec
->overridden
)
984 g_param_spec_unref (ospec
->overridden
);
985 ospec
->overridden
= NULL
;
988 parent_class
->finalize (pspec
);
992 param_override_set_default (GParamSpec
*pspec
,
995 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
997 g_param_value_set_default (ospec
->overridden
, value
);
1001 param_override_validate (GParamSpec
*pspec
,
1004 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
1006 return g_param_value_validate (ospec
->overridden
, value
);
1010 param_override_values_cmp (GParamSpec
*pspec
,
1011 const GValue
*value1
,
1012 const GValue
*value2
)
1014 GParamSpecOverride
*ospec
= G_PARAM_SPEC_OVERRIDE (pspec
);
1016 return g_param_values_cmp (ospec
->overridden
, value1
, value2
);
1020 param_gtype_init (GParamSpec
*pspec
)
1025 param_gtype_set_default (GParamSpec
*pspec
,
1028 value
->data
[0].v_long
= G_TYPE_NONE
;
1032 param_gtype_validate (GParamSpec
*pspec
,
1035 GParamSpecGType
*tspec
= G_PARAM_SPEC_GTYPE (pspec
);
1036 GType gtype
= value
->data
[0].v_long
;
1039 if (tspec
->is_a_type
!= G_TYPE_NONE
&& !g_type_is_a (gtype
, tspec
->is_a_type
))
1041 value
->data
[0].v_long
= G_TYPE_NONE
;
1049 param_gtype_values_cmp (GParamSpec
*pspec
,
1050 const GValue
*value1
,
1051 const GValue
*value2
)
1053 GType p1
= value1
->data
[0].v_long
;
1054 GType p2
= value2
->data
[0].v_long
;
1056 /* not much to compare here, try to at least provide stable lesser/greater result */
1058 return p1
< p2
? -1 : p1
> p2
;
1061 /* --- type initialization --- */
1062 GType
*g_param_spec_types
= NULL
;
1065 g_param_spec_types_init (void)
1067 const guint n_types
= 22;
1068 GType type
, *spec_types
, *spec_types_bound
;
1070 g_param_spec_types
= g_new0 (GType
, n_types
);
1071 spec_types
= g_param_spec_types
;
1072 spec_types_bound
= g_param_spec_types
+ n_types
;
1074 /* G_TYPE_PARAM_CHAR
1077 static const GParamSpecTypeInfo pspec_info
= {
1078 sizeof (GParamSpecChar
), /* instance_size */
1079 16, /* n_preallocs */
1080 param_char_init
, /* instance_init */
1081 G_TYPE_CHAR
, /* value_type */
1082 NULL
, /* finalize */
1083 param_char_set_default
, /* value_set_default */
1084 param_char_validate
, /* value_validate */
1085 param_int_values_cmp
, /* values_cmp */
1087 type
= g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info
);
1088 *spec_types
++ = type
;
1089 g_assert (type
== G_TYPE_PARAM_CHAR
);
1092 /* G_TYPE_PARAM_UCHAR
1095 static const GParamSpecTypeInfo pspec_info
= {
1096 sizeof (GParamSpecUChar
), /* instance_size */
1097 16, /* n_preallocs */
1098 param_uchar_init
, /* instance_init */
1099 G_TYPE_UCHAR
, /* value_type */
1100 NULL
, /* finalize */
1101 param_uchar_set_default
, /* value_set_default */
1102 param_uchar_validate
, /* value_validate */
1103 param_uint_values_cmp
, /* values_cmp */
1105 type
= g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info
);
1106 *spec_types
++ = type
;
1107 g_assert (type
== G_TYPE_PARAM_UCHAR
);
1110 /* G_TYPE_PARAM_BOOLEAN
1113 static const GParamSpecTypeInfo pspec_info
= {
1114 sizeof (GParamSpecBoolean
), /* instance_size */
1115 16, /* n_preallocs */
1116 NULL
, /* instance_init */
1117 G_TYPE_BOOLEAN
, /* value_type */
1118 NULL
, /* finalize */
1119 param_boolean_set_default
, /* value_set_default */
1120 param_boolean_validate
, /* value_validate */
1121 param_int_values_cmp
, /* values_cmp */
1123 type
= g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info
);
1124 *spec_types
++ = type
;
1125 g_assert (type
== G_TYPE_PARAM_BOOLEAN
);
1131 static const GParamSpecTypeInfo pspec_info
= {
1132 sizeof (GParamSpecInt
), /* instance_size */
1133 16, /* n_preallocs */
1134 param_int_init
, /* instance_init */
1135 G_TYPE_INT
, /* value_type */
1136 NULL
, /* finalize */
1137 param_int_set_default
, /* value_set_default */
1138 param_int_validate
, /* value_validate */
1139 param_int_values_cmp
, /* values_cmp */
1141 type
= g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info
);
1142 *spec_types
++ = type
;
1143 g_assert (type
== G_TYPE_PARAM_INT
);
1146 /* G_TYPE_PARAM_UINT
1149 static const GParamSpecTypeInfo pspec_info
= {
1150 sizeof (GParamSpecUInt
), /* instance_size */
1151 16, /* n_preallocs */
1152 param_uint_init
, /* instance_init */
1153 G_TYPE_UINT
, /* value_type */
1154 NULL
, /* finalize */
1155 param_uint_set_default
, /* value_set_default */
1156 param_uint_validate
, /* value_validate */
1157 param_uint_values_cmp
, /* values_cmp */
1159 type
= g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info
);
1160 *spec_types
++ = type
;
1161 g_assert (type
== G_TYPE_PARAM_UINT
);
1164 /* G_TYPE_PARAM_LONG
1167 static const GParamSpecTypeInfo pspec_info
= {
1168 sizeof (GParamSpecLong
), /* instance_size */
1169 16, /* n_preallocs */
1170 param_long_init
, /* instance_init */
1171 G_TYPE_LONG
, /* value_type */
1172 NULL
, /* finalize */
1173 param_long_set_default
, /* value_set_default */
1174 param_long_validate
, /* value_validate */
1175 param_long_values_cmp
, /* values_cmp */
1177 type
= g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info
);
1178 *spec_types
++ = type
;
1179 g_assert (type
== G_TYPE_PARAM_LONG
);
1182 /* G_TYPE_PARAM_ULONG
1185 static const GParamSpecTypeInfo pspec_info
= {
1186 sizeof (GParamSpecULong
), /* instance_size */
1187 16, /* n_preallocs */
1188 param_ulong_init
, /* instance_init */
1189 G_TYPE_ULONG
, /* value_type */
1190 NULL
, /* finalize */
1191 param_ulong_set_default
, /* value_set_default */
1192 param_ulong_validate
, /* value_validate */
1193 param_ulong_values_cmp
, /* values_cmp */
1195 type
= g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info
);
1196 *spec_types
++ = type
;
1197 g_assert (type
== G_TYPE_PARAM_ULONG
);
1200 /* G_TYPE_PARAM_INT64
1203 static const GParamSpecTypeInfo pspec_info
= {
1204 sizeof (GParamSpecInt64
), /* instance_size */
1205 16, /* n_preallocs */
1206 param_int64_init
, /* instance_init */
1207 G_TYPE_INT64
, /* value_type */
1208 NULL
, /* finalize */
1209 param_int64_set_default
, /* value_set_default */
1210 param_int64_validate
, /* value_validate */
1211 param_int64_values_cmp
, /* values_cmp */
1213 type
= g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info
);
1214 *spec_types
++ = type
;
1215 g_assert (type
== G_TYPE_PARAM_INT64
);
1218 /* G_TYPE_PARAM_UINT64
1221 static const GParamSpecTypeInfo pspec_info
= {
1222 sizeof (GParamSpecUInt64
), /* instance_size */
1223 16, /* n_preallocs */
1224 param_uint64_init
, /* instance_init */
1225 G_TYPE_UINT64
, /* value_type */
1226 NULL
, /* finalize */
1227 param_uint64_set_default
, /* value_set_default */
1228 param_uint64_validate
, /* value_validate */
1229 param_uint64_values_cmp
, /* values_cmp */
1231 type
= g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info
);
1232 *spec_types
++ = type
;
1233 g_assert (type
== G_TYPE_PARAM_UINT64
);
1236 /* G_TYPE_PARAM_UNICHAR
1239 static const GParamSpecTypeInfo pspec_info
= {
1240 sizeof (GParamSpecUnichar
), /* instance_size */
1241 16, /* n_preallocs */
1242 param_unichar_init
, /* instance_init */
1243 G_TYPE_UINT
, /* value_type */
1244 NULL
, /* finalize */
1245 param_unichar_set_default
, /* value_set_default */
1246 param_unichar_validate
, /* value_validate */
1247 param_unichar_values_cmp
, /* values_cmp */
1249 type
= g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info
);
1250 *spec_types
++ = type
;
1251 g_assert (type
== G_TYPE_PARAM_UNICHAR
);
1254 /* G_TYPE_PARAM_ENUM
1257 static const GParamSpecTypeInfo pspec_info
= {
1258 sizeof (GParamSpecEnum
), /* instance_size */
1259 16, /* n_preallocs */
1260 param_enum_init
, /* instance_init */
1261 G_TYPE_ENUM
, /* value_type */
1262 param_enum_finalize
, /* finalize */
1263 param_enum_set_default
, /* value_set_default */
1264 param_enum_validate
, /* value_validate */
1265 param_long_values_cmp
, /* values_cmp */
1267 type
= g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info
);
1268 *spec_types
++ = type
;
1269 g_assert (type
== G_TYPE_PARAM_ENUM
);
1272 /* G_TYPE_PARAM_FLAGS
1275 static const GParamSpecTypeInfo pspec_info
= {
1276 sizeof (GParamSpecFlags
), /* instance_size */
1277 16, /* n_preallocs */
1278 param_flags_init
, /* instance_init */
1279 G_TYPE_FLAGS
, /* value_type */
1280 param_flags_finalize
, /* finalize */
1281 param_flags_set_default
, /* value_set_default */
1282 param_flags_validate
, /* value_validate */
1283 param_ulong_values_cmp
, /* values_cmp */
1285 type
= g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info
);
1286 *spec_types
++ = type
;
1287 g_assert (type
== G_TYPE_PARAM_FLAGS
);
1290 /* G_TYPE_PARAM_FLOAT
1293 static const GParamSpecTypeInfo pspec_info
= {
1294 sizeof (GParamSpecFloat
), /* instance_size */
1295 16, /* n_preallocs */
1296 param_float_init
, /* instance_init */
1297 G_TYPE_FLOAT
, /* value_type */
1298 NULL
, /* finalize */
1299 param_float_set_default
, /* value_set_default */
1300 param_float_validate
, /* value_validate */
1301 param_float_values_cmp
, /* values_cmp */
1303 type
= g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info
);
1304 *spec_types
++ = type
;
1305 g_assert (type
== G_TYPE_PARAM_FLOAT
);
1308 /* G_TYPE_PARAM_DOUBLE
1311 static const GParamSpecTypeInfo pspec_info
= {
1312 sizeof (GParamSpecDouble
), /* instance_size */
1313 16, /* n_preallocs */
1314 param_double_init
, /* instance_init */
1315 G_TYPE_DOUBLE
, /* value_type */
1316 NULL
, /* finalize */
1317 param_double_set_default
, /* value_set_default */
1318 param_double_validate
, /* value_validate */
1319 param_double_values_cmp
, /* values_cmp */
1321 type
= g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info
);
1322 *spec_types
++ = type
;
1323 g_assert (type
== G_TYPE_PARAM_DOUBLE
);
1326 /* G_TYPE_PARAM_STRING
1329 static const GParamSpecTypeInfo pspec_info
= {
1330 sizeof (GParamSpecString
), /* instance_size */
1331 16, /* n_preallocs */
1332 param_string_init
, /* instance_init */
1333 G_TYPE_STRING
, /* value_type */
1334 param_string_finalize
, /* finalize */
1335 param_string_set_default
, /* value_set_default */
1336 param_string_validate
, /* value_validate */
1337 param_string_values_cmp
, /* values_cmp */
1339 type
= g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info
);
1340 *spec_types
++ = type
;
1341 g_assert (type
== G_TYPE_PARAM_STRING
);
1344 /* G_TYPE_PARAM_PARAM
1347 static const GParamSpecTypeInfo pspec_info
= {
1348 sizeof (GParamSpecParam
), /* instance_size */
1349 16, /* n_preallocs */
1350 param_param_init
, /* instance_init */
1351 G_TYPE_PARAM
, /* value_type */
1352 NULL
, /* finalize */
1353 param_param_set_default
, /* value_set_default */
1354 param_param_validate
, /* value_validate */
1355 param_pointer_values_cmp
, /* values_cmp */
1357 type
= g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info
);
1358 *spec_types
++ = type
;
1359 g_assert (type
== G_TYPE_PARAM_PARAM
);
1362 /* G_TYPE_PARAM_BOXED
1365 static const GParamSpecTypeInfo pspec_info
= {
1366 sizeof (GParamSpecBoxed
), /* instance_size */
1367 4, /* n_preallocs */
1368 param_boxed_init
, /* instance_init */
1369 G_TYPE_BOXED
, /* value_type */
1370 NULL
, /* finalize */
1371 param_boxed_set_default
, /* value_set_default */
1372 param_boxed_validate
, /* value_validate */
1373 param_boxed_values_cmp
, /* values_cmp */
1375 type
= g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info
);
1376 *spec_types
++ = type
;
1377 g_assert (type
== G_TYPE_PARAM_BOXED
);
1380 /* G_TYPE_PARAM_POINTER
1383 static const GParamSpecTypeInfo pspec_info
= {
1384 sizeof (GParamSpecPointer
), /* instance_size */
1385 0, /* n_preallocs */
1386 param_pointer_init
, /* instance_init */
1387 G_TYPE_POINTER
, /* value_type */
1388 NULL
, /* finalize */
1389 param_pointer_set_default
, /* value_set_default */
1390 param_pointer_validate
, /* value_validate */
1391 param_pointer_values_cmp
, /* values_cmp */
1393 type
= g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info
);
1394 *spec_types
++ = type
;
1395 g_assert (type
== G_TYPE_PARAM_POINTER
);
1398 /* G_TYPE_PARAM_VALUE_ARRAY
1401 static /* const */ GParamSpecTypeInfo pspec_info
= {
1402 sizeof (GParamSpecValueArray
), /* instance_size */
1403 0, /* n_preallocs */
1404 param_value_array_init
, /* instance_init */
1405 0xdeadbeef, /* value_type, assigned further down */
1406 param_value_array_finalize
, /* finalize */
1407 param_value_array_set_default
, /* value_set_default */
1408 param_value_array_validate
, /* value_validate */
1409 param_value_array_values_cmp
, /* values_cmp */
1411 pspec_info
.value_type
= G_TYPE_VALUE_ARRAY
;
1412 type
= g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info
);
1413 *spec_types
++ = type
;
1414 g_assert (type
== G_TYPE_PARAM_VALUE_ARRAY
);
1417 /* G_TYPE_PARAM_OBJECT
1420 static const GParamSpecTypeInfo pspec_info
= {
1421 sizeof (GParamSpecObject
), /* instance_size */
1422 16, /* n_preallocs */
1423 param_object_init
, /* instance_init */
1424 G_TYPE_OBJECT
, /* value_type */
1425 NULL
, /* finalize */
1426 param_object_set_default
, /* value_set_default */
1427 param_object_validate
, /* value_validate */
1428 param_object_values_cmp
, /* values_cmp */
1430 type
= g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info
);
1431 *spec_types
++ = type
;
1432 g_assert (type
== G_TYPE_PARAM_OBJECT
);
1435 /* G_TYPE_PARAM_OVERRIDE
1438 static const GParamSpecTypeInfo pspec_info
= {
1439 sizeof (GParamSpecOverride
), /* instance_size */
1440 16, /* n_preallocs */
1441 param_override_init
, /* instance_init */
1442 G_TYPE_NONE
, /* value_type */
1443 param_override_finalize
, /* finalize */
1444 param_override_set_default
, /* value_set_default */
1445 param_override_validate
, /* value_validate */
1446 param_override_values_cmp
, /* values_cmp */
1448 type
= g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info
);
1449 *spec_types
++ = type
;
1450 g_assert (type
== G_TYPE_PARAM_OVERRIDE
);
1453 /* G_TYPE_PARAM_GTYPE
1456 GType value_type
= G_TYPE_GTYPE
;
1457 GParamSpecTypeInfo pspec_info
= {
1458 sizeof (GParamSpecGType
), /* instance_size */
1459 0, /* n_preallocs */
1460 param_gtype_init
, /* instance_init */
1461 value_type
, /* value_type */
1462 NULL
, /* finalize */
1463 param_gtype_set_default
, /* value_set_default */
1464 param_gtype_validate
, /* value_validate */
1465 param_gtype_values_cmp
, /* values_cmp */
1467 type
= g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info
);
1468 *spec_types
++ = type
;
1469 g_assert (type
== G_TYPE_PARAM_GTYPE
);
1472 g_assert (spec_types
== spec_types_bound
);
1475 /* --- GParamSpec initialization --- */
1478 g_param_spec_char (const gchar
*name
,
1483 gint8 default_value
,
1486 GParamSpecChar
*cspec
;
1488 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1490 cspec
= g_param_spec_internal (G_TYPE_PARAM_CHAR
,
1496 cspec
->minimum
= minimum
;
1497 cspec
->maximum
= maximum
;
1498 cspec
->default_value
= default_value
;
1500 return G_PARAM_SPEC (cspec
);
1504 g_param_spec_uchar (const gchar
*name
,
1509 guint8 default_value
,
1512 GParamSpecUChar
*uspec
;
1514 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1516 uspec
= g_param_spec_internal (G_TYPE_PARAM_UCHAR
,
1522 uspec
->minimum
= minimum
;
1523 uspec
->maximum
= maximum
;
1524 uspec
->default_value
= default_value
;
1526 return G_PARAM_SPEC (uspec
);
1530 g_param_spec_boolean (const gchar
*name
,
1533 gboolean default_value
,
1536 GParamSpecBoolean
*bspec
;
1538 g_return_val_if_fail (default_value
== TRUE
|| default_value
== FALSE
, NULL
);
1540 bspec
= g_param_spec_internal (G_TYPE_PARAM_BOOLEAN
,
1546 bspec
->default_value
= default_value
;
1548 return G_PARAM_SPEC (bspec
);
1552 g_param_spec_int (const gchar
*name
,
1560 GParamSpecInt
*ispec
;
1562 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1564 ispec
= g_param_spec_internal (G_TYPE_PARAM_INT
,
1570 ispec
->minimum
= minimum
;
1571 ispec
->maximum
= maximum
;
1572 ispec
->default_value
= default_value
;
1574 return G_PARAM_SPEC (ispec
);
1578 g_param_spec_uint (const gchar
*name
,
1583 guint default_value
,
1586 GParamSpecUInt
*uspec
;
1588 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1590 uspec
= g_param_spec_internal (G_TYPE_PARAM_UINT
,
1596 uspec
->minimum
= minimum
;
1597 uspec
->maximum
= maximum
;
1598 uspec
->default_value
= default_value
;
1600 return G_PARAM_SPEC (uspec
);
1604 g_param_spec_long (const gchar
*name
,
1609 glong default_value
,
1612 GParamSpecLong
*lspec
;
1614 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1616 lspec
= g_param_spec_internal (G_TYPE_PARAM_LONG
,
1622 lspec
->minimum
= minimum
;
1623 lspec
->maximum
= maximum
;
1624 lspec
->default_value
= default_value
;
1626 return G_PARAM_SPEC (lspec
);
1630 g_param_spec_ulong (const gchar
*name
,
1635 gulong default_value
,
1638 GParamSpecULong
*uspec
;
1640 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1642 uspec
= g_param_spec_internal (G_TYPE_PARAM_ULONG
,
1648 uspec
->minimum
= minimum
;
1649 uspec
->maximum
= maximum
;
1650 uspec
->default_value
= default_value
;
1652 return G_PARAM_SPEC (uspec
);
1656 g_param_spec_int64 (const gchar
*name
,
1661 gint64 default_value
,
1664 GParamSpecInt64
*lspec
;
1666 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1668 lspec
= g_param_spec_internal (G_TYPE_PARAM_INT64
,
1674 lspec
->minimum
= minimum
;
1675 lspec
->maximum
= maximum
;
1676 lspec
->default_value
= default_value
;
1678 return G_PARAM_SPEC (lspec
);
1682 g_param_spec_uint64 (const gchar
*name
,
1687 guint64 default_value
,
1690 GParamSpecUInt64
*uspec
;
1692 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1694 uspec
= g_param_spec_internal (G_TYPE_PARAM_UINT64
,
1700 uspec
->minimum
= minimum
;
1701 uspec
->maximum
= maximum
;
1702 uspec
->default_value
= default_value
;
1704 return G_PARAM_SPEC (uspec
);
1708 g_param_spec_unichar (const gchar
*name
,
1711 gunichar default_value
,
1714 GParamSpecUnichar
*uspec
;
1716 uspec
= g_param_spec_internal (G_TYPE_PARAM_UNICHAR
,
1722 uspec
->default_value
= default_value
;
1724 return G_PARAM_SPEC (uspec
);
1728 g_param_spec_enum (const gchar
*name
,
1735 GParamSpecEnum
*espec
;
1736 GEnumClass
*enum_class
;
1738 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type
), NULL
);
1740 enum_class
= g_type_class_ref (enum_type
);
1742 g_return_val_if_fail (g_enum_get_value (enum_class
, default_value
) != NULL
, NULL
);
1744 espec
= g_param_spec_internal (G_TYPE_PARAM_ENUM
,
1750 espec
->enum_class
= enum_class
;
1751 espec
->default_value
= default_value
;
1752 G_PARAM_SPEC (espec
)->value_type
= enum_type
;
1754 return G_PARAM_SPEC (espec
);
1758 g_param_spec_flags (const gchar
*name
,
1762 guint default_value
,
1765 GParamSpecFlags
*fspec
;
1766 GFlagsClass
*flags_class
;
1768 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type
), NULL
);
1770 flags_class
= g_type_class_ref (flags_type
);
1772 g_return_val_if_fail ((default_value
& flags_class
->mask
) == default_value
, NULL
);
1774 fspec
= g_param_spec_internal (G_TYPE_PARAM_FLAGS
,
1780 fspec
->flags_class
= flags_class
;
1781 fspec
->default_value
= default_value
;
1782 G_PARAM_SPEC (fspec
)->value_type
= flags_type
;
1784 return G_PARAM_SPEC (fspec
);
1788 g_param_spec_float (const gchar
*name
,
1793 gfloat default_value
,
1796 GParamSpecFloat
*fspec
;
1798 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1800 fspec
= g_param_spec_internal (G_TYPE_PARAM_FLOAT
,
1806 fspec
->minimum
= minimum
;
1807 fspec
->maximum
= maximum
;
1808 fspec
->default_value
= default_value
;
1810 return G_PARAM_SPEC (fspec
);
1814 g_param_spec_double (const gchar
*name
,
1819 gdouble default_value
,
1822 GParamSpecDouble
*dspec
;
1824 g_return_val_if_fail (default_value
>= minimum
&& default_value
<= maximum
, NULL
);
1826 dspec
= g_param_spec_internal (G_TYPE_PARAM_DOUBLE
,
1832 dspec
->minimum
= minimum
;
1833 dspec
->maximum
= maximum
;
1834 dspec
->default_value
= default_value
;
1836 return G_PARAM_SPEC (dspec
);
1840 g_param_spec_string (const gchar
*name
,
1843 const gchar
*default_value
,
1846 GParamSpecString
*sspec
= g_param_spec_internal (G_TYPE_PARAM_STRING
,
1851 g_free (sspec
->default_value
);
1852 sspec
->default_value
= g_strdup (default_value
);
1854 return G_PARAM_SPEC (sspec
);
1858 g_param_spec_param (const gchar
*name
,
1864 GParamSpecParam
*pspec
;
1866 g_return_val_if_fail (G_TYPE_IS_PARAM (param_type
), NULL
);
1868 pspec
= g_param_spec_internal (G_TYPE_PARAM_PARAM
,
1873 G_PARAM_SPEC (pspec
)->value_type
= param_type
;
1875 return G_PARAM_SPEC (pspec
);
1879 g_param_spec_boxed (const gchar
*name
,
1885 GParamSpecBoxed
*bspec
;
1887 g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type
), NULL
);
1888 g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type
), NULL
);
1890 bspec
= g_param_spec_internal (G_TYPE_PARAM_BOXED
,
1895 G_PARAM_SPEC (bspec
)->value_type
= boxed_type
;
1897 return G_PARAM_SPEC (bspec
);
1901 g_param_spec_pointer (const gchar
*name
,
1906 GParamSpecPointer
*pspec
;
1908 pspec
= g_param_spec_internal (G_TYPE_PARAM_POINTER
,
1913 return G_PARAM_SPEC (pspec
);
1917 g_param_spec_gtype (const gchar
*name
,
1923 GParamSpecGType
*tspec
;
1925 tspec
= g_param_spec_internal (G_TYPE_PARAM_GTYPE
,
1931 tspec
->is_a_type
= is_a_type
;
1933 return G_PARAM_SPEC (tspec
);
1937 g_param_spec_value_array (const gchar
*name
,
1940 GParamSpec
*element_spec
,
1943 GParamSpecValueArray
*aspec
;
1946 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec
), NULL
);
1948 aspec
= g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY
,
1955 aspec
->element_spec
= g_param_spec_ref (element_spec
);
1956 g_param_spec_sink (element_spec
);
1959 return G_PARAM_SPEC (aspec
);
1963 g_param_spec_object (const gchar
*name
,
1969 GParamSpecObject
*ospec
;
1971 g_return_val_if_fail (g_type_is_a (object_type
, G_TYPE_OBJECT
), NULL
);
1973 ospec
= g_param_spec_internal (G_TYPE_PARAM_OBJECT
,
1978 G_PARAM_SPEC (ospec
)->value_type
= object_type
;
1980 return G_PARAM_SPEC (ospec
);
1984 g_param_spec_override (const gchar
*name
,
1985 GParamSpec
*overridden
)
1989 g_return_val_if_fail (name
!= NULL
, NULL
);
1990 g_return_val_if_fail (G_IS_PARAM_SPEC (overridden
), NULL
);
1992 /* Dereference further redirections for property that was passed in
1996 GParamSpec
*indirect
= g_param_spec_get_redirect_target (overridden
);
1998 overridden
= indirect
;
2003 pspec
= g_param_spec_internal (G_TYPE_PARAM_OVERRIDE
,
2007 pspec
->value_type
= G_PARAM_SPEC_VALUE_TYPE (overridden
);
2008 G_PARAM_SPEC_OVERRIDE (pspec
)->overridden
= g_param_spec_ref (overridden
);
2013 #define __G_PARAMSPECS_C__
2014 #include "gobjectaliasdef.c"