1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997, 1998, 1999, 2000 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.
19 #include "gparamspecs.h"
21 #include "gvaluecollector.h"
23 #include "../config.h" /* for SIZEOF_LONG */
25 #define G_FLOAT_EPSILON (1e-30)
26 #define G_DOUBLE_EPSILON (1e-90)
29 /* --- param spec functions --- */
31 param_spec_char_init (GParamSpec *pspec)
33 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
35 cspec->minimum = 0x7f;
36 cspec->maximum = 0x80;
37 cspec->default_value = 0;
41 param_char_set_default (GParamSpec *pspec,
44 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
48 param_char_validate (GParamSpec *pspec,
51 GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
52 gint oval = value->data[0].v_int;
54 value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
56 return value->data[0].v_int != oval;
60 param_spec_uchar_init (GParamSpec *pspec)
62 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
65 uspec->maximum = 0xff;
66 uspec->default_value = 0;
70 param_uchar_set_default (GParamSpec *pspec,
73 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
77 param_uchar_validate (GParamSpec *pspec,
80 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
81 guint oval = value->data[0].v_uint;
83 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
85 return value->data[0].v_uint != oval;
89 param_boolean_set_default (GParamSpec *pspec,
92 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
96 param_boolean_validate (GParamSpec *pspec,
99 gint oval = value->data[0].v_int;
101 value->data[0].v_int = value->data[0].v_int != FALSE;
103 return value->data[0].v_int != oval;
107 param_spec_int_init (GParamSpec *pspec)
109 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
111 ispec->minimum = 0x7fffffff;
112 ispec->maximum = 0x80000000;
113 ispec->default_value = 0;
117 param_int_set_default (GParamSpec *pspec,
120 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
124 param_int_validate (GParamSpec *pspec,
127 GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
128 gint oval = value->data[0].v_int;
130 value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
132 return value->data[0].v_int != oval;
136 param_int_values_cmp (GParamSpec *pspec,
137 const GValue *value1,
138 const GValue *value2)
140 if (value1->data[0].v_int < value2->data[0].v_int)
143 return value1->data[0].v_int > value2->data[0].v_int;
147 param_spec_uint_init (GParamSpec *pspec)
149 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
152 uspec->maximum = 0xffffffff;
153 uspec->default_value = 0;
157 param_uint_set_default (GParamSpec *pspec,
160 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
164 param_uint_validate (GParamSpec *pspec,
167 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
168 guint oval = value->data[0].v_uint;
170 value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
172 return value->data[0].v_uint != oval;
176 param_uint_values_cmp (GParamSpec *pspec,
177 const GValue *value1,
178 const GValue *value2)
180 if (value1->data[0].v_uint < value2->data[0].v_uint)
183 return value1->data[0].v_uint > value2->data[0].v_uint;
187 param_spec_long_init (GParamSpec *pspec)
189 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
192 lspec->minimum = 0x7fffffff;
193 lspec->maximum = 0x80000000;
194 #else /* SIZEOF_LONG != 4 (8) */
195 lspec->minimum = 0x7fffffffffffffff;
196 lspec->maximum = 0x8000000000000000;
198 lspec->default_value = 0;
202 param_long_set_default (GParamSpec *pspec,
205 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
209 param_long_validate (GParamSpec *pspec,
212 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
213 glong oval = value->data[0].v_long;
215 value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
217 return value->data[0].v_long != oval;
221 param_long_values_cmp (GParamSpec *pspec,
222 const GValue *value1,
223 const GValue *value2)
225 if (value1->data[0].v_long < value2->data[0].v_long)
228 return value1->data[0].v_long > value2->data[0].v_long;
232 param_spec_ulong_init (GParamSpec *pspec)
234 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
238 uspec->maximum = 0xffffffff;
239 #else /* SIZEOF_LONG != 4 (8) */
240 uspec->maximum = 0xffffffffffffffff;
242 uspec->default_value = 0;
246 param_ulong_set_default (GParamSpec *pspec,
249 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
253 param_ulong_validate (GParamSpec *pspec,
256 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
257 gulong oval = value->data[0].v_ulong;
259 value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
261 return value->data[0].v_ulong != oval;
265 param_ulong_values_cmp (GParamSpec *pspec,
266 const GValue *value1,
267 const GValue *value2)
269 if (value1->data[0].v_ulong < value2->data[0].v_ulong)
272 return value1->data[0].v_ulong > value2->data[0].v_ulong;
276 param_spec_enum_init (GParamSpec *pspec)
278 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
280 espec->enum_class = NULL;
281 espec->default_value = 0;
285 param_spec_enum_finalize (GParamSpec *pspec)
287 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
288 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM));
290 if (espec->enum_class)
292 g_type_class_unref (espec->enum_class);
293 espec->enum_class = NULL;
296 parent_class->finalize (pspec);
300 param_enum_set_default (GParamSpec *pspec,
303 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
307 param_enum_validate (GParamSpec *pspec,
310 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
311 glong oval = value->data[0].v_long;
313 if (!espec->enum_class ||
314 !g_enum_get_value (espec->enum_class, value->data[0].v_long))
315 value->data[0].v_long = espec->default_value;
317 return value->data[0].v_long != oval;
321 param_spec_flags_init (GParamSpec *pspec)
323 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
325 fspec->flags_class = NULL;
326 fspec->default_value = 0;
330 param_spec_flags_finalize (GParamSpec *pspec)
332 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
333 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS));
335 if (fspec->flags_class)
337 g_type_class_unref (fspec->flags_class);
338 fspec->flags_class = NULL;
341 parent_class->finalize (pspec);
345 param_flags_set_default (GParamSpec *pspec,
348 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
352 param_flags_validate (GParamSpec *pspec,
355 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
356 gulong oval = value->data[0].v_ulong;
358 if (fspec->flags_class)
359 value->data[0].v_ulong &= fspec->flags_class->mask;
361 value->data[0].v_ulong = fspec->default_value;
363 return value->data[0].v_ulong != oval;
367 param_spec_float_init (GParamSpec *pspec)
369 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
371 fspec->minimum = G_MINFLOAT;
372 fspec->maximum = G_MAXFLOAT;
373 fspec->default_value = 0;
374 fspec->epsilon = G_FLOAT_EPSILON;
378 param_float_set_default (GParamSpec *pspec,
381 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
385 param_float_validate (GParamSpec *pspec,
388 GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
389 gfloat oval = value->data[0].v_float;
391 value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
393 return value->data[0].v_float != oval;
397 param_float_values_cmp (GParamSpec *pspec,
398 const GValue *value1,
399 const GValue *value2)
401 gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
403 if (value1->data[0].v_float < value2->data[0].v_float)
404 return - (value2->data[0].v_float - value1->data[0].v_float > epsilon);
406 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
410 param_spec_double_init (GParamSpec *pspec)
412 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
414 dspec->minimum = G_MINDOUBLE;
415 dspec->maximum = G_MAXDOUBLE;
416 dspec->default_value = 0;
417 dspec->epsilon = G_DOUBLE_EPSILON;
421 param_double_set_default (GParamSpec *pspec,
424 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
428 param_double_validate (GParamSpec *pspec,
431 GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
432 gdouble oval = value->data[0].v_double;
434 value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
436 return value->data[0].v_double != oval;
440 param_double_values_cmp (GParamSpec *pspec,
441 const GValue *value1,
442 const GValue *value2)
444 gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
446 if (value1->data[0].v_double < value2->data[0].v_double)
447 return - (value2->data[0].v_double - value1->data[0].v_double > epsilon);
449 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
453 param_spec_string_init (GParamSpec *pspec)
455 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
457 sspec->default_value = NULL;
458 sspec->cset_first = NULL;
459 sspec->cset_nth = NULL;
460 sspec->substitutor = '_';
461 sspec->null_fold_if_empty = FALSE;
462 sspec->ensure_non_null = FALSE;
466 param_spec_string_finalize (GParamSpec *pspec)
468 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
469 GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
471 g_free (sspec->default_value);
472 g_free (sspec->cset_first);
473 g_free (sspec->cset_nth);
474 sspec->default_value = NULL;
475 sspec->cset_first = NULL;
476 sspec->cset_nth = NULL;
478 parent_class->finalize (pspec);
482 param_string_set_default (GParamSpec *pspec,
485 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
489 param_string_validate (GParamSpec *pspec,
492 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
493 gchar *string = value->data[0].v_pointer;
496 if (string && string[0])
500 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
502 string[0] = sspec->substitutor;
506 for (s = string + 1; *s; s++)
507 if (!strchr (sspec->cset_nth, *s))
509 *s = sspec->substitutor;
513 if (sspec->null_fold_if_empty && string && string[0] == 0)
515 g_free (value->data[0].v_pointer);
516 value->data[0].v_pointer = NULL;
518 string = value->data[0].v_pointer;
520 if (sspec->ensure_non_null && !string)
522 value->data[0].v_pointer = g_strdup ("");
524 string = value->data[0].v_pointer;
531 param_string_values_cmp (GParamSpec *pspec,
532 const GValue *value1,
533 const GValue *value2)
535 if (!value1->data[0].v_pointer)
536 return value2->data[0].v_pointer != NULL ? -1 : 0;
537 else if (!value2->data[0].v_pointer)
538 return value1->data[0].v_pointer != NULL;
540 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
544 param_spec_object_init (GParamSpec *pspec)
546 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
548 ospec->object_type = G_TYPE_OBJECT;
552 param_object_set_default (GParamSpec *pspec,
555 value->data[0].v_pointer = NULL;
559 param_object_validate (GParamSpec *pspec,
562 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
563 GObject *object = value->data[0].v_pointer;
566 if (object && !g_type_is_a (G_OBJECT_TYPE (object), ospec->object_type))
568 g_object_unref (object);
569 value->data[0].v_pointer = NULL;
577 param_object_values_cmp (GParamSpec *pspec,
578 const GValue *value1,
579 const GValue *value2)
581 return value1->data[0].v_pointer != value2->data[0].v_pointer;
585 value_exch_memcpy (GValue *value1,
589 memcpy (&tmp_value.data, &value1->data, sizeof (value1->data));
590 memcpy (&value1->data, &value2->data, sizeof (value1->data));
591 memcpy (&value2->data, &tmp_value.data, sizeof (value2->data));
595 value_exch_long_int (GValue *value1,
598 glong tmp = value1->data[0].v_long;
599 value1->data[0].v_long = value2->data[0].v_int;
600 value2->data[0].v_int = tmp;
604 value_exch_long_uint (GValue *value1,
607 glong tmp = value1->data[0].v_long;
608 value1->data[0].v_long = value2->data[0].v_uint;
609 value2->data[0].v_uint = tmp;
613 value_exch_ulong_int (GValue *value1,
616 gulong tmp = value1->data[0].v_ulong;
617 value1->data[0].v_ulong = value2->data[0].v_int;
618 value2->data[0].v_int = tmp;
622 value_exch_ulong_uint (GValue *value1,
625 gulong tmp = value1->data[0].v_ulong;
626 value1->data[0].v_ulong = value2->data[0].v_uint;
627 value2->data[0].v_uint = tmp;
631 value_exch_float_int (GValue *value1,
634 gfloat tmp = value1->data[0].v_float;
635 value1->data[0].v_float = value2->data[0].v_int;
636 value2->data[0].v_int = 0.5 + tmp;
640 value_exch_float_uint (GValue *value1,
643 gfloat tmp = value1->data[0].v_float;
644 value1->data[0].v_float = value2->data[0].v_uint;
645 value2->data[0].v_uint = 0.5 + tmp;
649 value_exch_float_long (GValue *value1,
652 gfloat tmp = value1->data[0].v_float;
653 value1->data[0].v_float = value2->data[0].v_long;
654 value2->data[0].v_long = 0.5 + tmp;
658 value_exch_float_ulong (GValue *value1,
661 gfloat tmp = value1->data[0].v_float;
662 value1->data[0].v_float = value2->data[0].v_ulong;
663 value2->data[0].v_ulong = 0.5 + tmp;
667 value_exch_double_int (GValue *value1,
670 gdouble tmp = value1->data[0].v_double;
671 value1->data[0].v_double = value2->data[0].v_int;
672 value2->data[0].v_int = 0.5 + tmp;
676 value_exch_double_uint (GValue *value1,
679 gdouble tmp = value1->data[0].v_double;
680 value1->data[0].v_double = value2->data[0].v_uint;
681 value2->data[0].v_uint = 0.5 + tmp;
685 value_exch_double_long (GValue *value1,
688 gdouble tmp = value1->data[0].v_double;
689 value1->data[0].v_double = value2->data[0].v_long;
690 value2->data[0].v_long = 0.5 + tmp;
694 value_exch_double_ulong (GValue *value1,
697 gdouble tmp = value1->data[0].v_double;
698 value1->data[0].v_double = value2->data[0].v_ulong;
699 value2->data[0].v_ulong = 0.5 + tmp;
703 value_exch_double_float (GValue *value1,
706 gdouble tmp = value1->data[0].v_double;
707 value1->data[0].v_double = value2->data[0].v_float;
708 value2->data[0].v_float = tmp;
712 /* --- type initialization --- */
714 g_param_spec_types_init (void) /* sync with gtype.c */
721 static const GParamSpecTypeInfo pspec_info = {
722 sizeof (GParamSpecChar), /* instance_size */
723 16, /* n_preallocs */
724 param_spec_char_init, /* instance_init */
725 G_TYPE_CHAR, /* value_type */
727 param_char_set_default, /* value_set_default */
728 param_char_validate, /* value_validate */
729 param_int_values_cmp, /* values_cmp */
731 type = g_param_type_register_static ("GParamChar", &pspec_info);
732 g_assert (type == G_TYPE_PARAM_CHAR);
735 /* G_TYPE_PARAM_UCHAR
738 static const GParamSpecTypeInfo pspec_info = {
739 sizeof (GParamSpecUChar), /* instance_size */
740 16, /* n_preallocs */
741 param_spec_uchar_init, /* instance_init */
742 G_TYPE_UCHAR, /* value_type */
744 param_uchar_set_default, /* value_set_default */
745 param_uchar_validate, /* value_validate */
746 param_uint_values_cmp, /* values_cmp */
748 type = g_param_type_register_static ("GParamUChar", &pspec_info);
749 g_assert (type == G_TYPE_PARAM_UCHAR);
752 /* G_TYPE_PARAM_BOOLEAN
755 static const GParamSpecTypeInfo pspec_info = {
756 sizeof (GParamSpecBoolean), /* instance_size */
757 16, /* n_preallocs */
758 NULL, /* instance_init */
759 G_TYPE_BOOLEAN, /* value_type */
761 param_boolean_set_default, /* value_set_default */
762 param_boolean_validate, /* value_validate */
763 param_int_values_cmp, /* values_cmp */
765 type = g_param_type_register_static ("GParamBoolean", &pspec_info);
766 g_assert (type == G_TYPE_PARAM_BOOLEAN);
772 static const GParamSpecTypeInfo pspec_info = {
773 sizeof (GParamSpecInt), /* instance_size */
774 16, /* n_preallocs */
775 param_spec_int_init, /* instance_init */
776 G_TYPE_INT, /* value_type */
778 param_int_set_default, /* value_set_default */
779 param_int_validate, /* value_validate */
780 param_int_values_cmp, /* values_cmp */
782 type = g_param_type_register_static ("GParamInt", &pspec_info);
783 g_assert (type == G_TYPE_PARAM_INT);
789 static const GParamSpecTypeInfo pspec_info = {
790 sizeof (GParamSpecUInt), /* instance_size */
791 16, /* n_preallocs */
792 param_spec_uint_init, /* instance_init */
793 G_TYPE_UINT, /* value_type */
795 param_uint_set_default, /* value_set_default */
796 param_uint_validate, /* value_validate */
797 param_uint_values_cmp, /* values_cmp */
799 type = g_param_type_register_static ("GParamUInt", &pspec_info);
800 g_assert (type == G_TYPE_PARAM_UINT);
806 static const GParamSpecTypeInfo pspec_info = {
807 sizeof (GParamSpecLong), /* instance_size */
808 16, /* n_preallocs */
809 param_spec_long_init, /* instance_init */
810 G_TYPE_LONG, /* value_type */
812 param_long_set_default, /* value_set_default */
813 param_long_validate, /* value_validate */
814 param_long_values_cmp, /* values_cmp */
816 type = g_param_type_register_static ("GParamLong", &pspec_info);
817 g_assert (type == G_TYPE_PARAM_LONG);
820 /* G_TYPE_PARAM_ULONG
823 static const GParamSpecTypeInfo pspec_info = {
824 sizeof (GParamSpecULong), /* instance_size */
825 16, /* n_preallocs */
826 param_spec_ulong_init, /* instance_init */
827 G_TYPE_ULONG, /* value_type */
829 param_ulong_set_default, /* value_set_default */
830 param_ulong_validate, /* value_validate */
831 param_ulong_values_cmp, /* values_cmp */
833 type = g_param_type_register_static ("GParamULong", &pspec_info);
834 g_assert (type == G_TYPE_PARAM_ULONG);
840 static const GParamSpecTypeInfo pspec_info = {
841 sizeof (GParamSpecEnum), /* instance_size */
842 16, /* n_preallocs */
843 param_spec_enum_init, /* instance_init */
844 G_TYPE_ENUM, /* value_type */
845 param_spec_enum_finalize, /* finalize */
846 param_enum_set_default, /* value_set_default */
847 param_enum_validate, /* value_validate */
848 param_long_values_cmp, /* values_cmp */
850 type = g_param_type_register_static ("GParamEnum", &pspec_info);
851 g_assert (type == G_TYPE_PARAM_ENUM);
854 /* G_TYPE_PARAM_FLAGS
857 static const GParamSpecTypeInfo pspec_info = {
858 sizeof (GParamSpecFlags), /* instance_size */
859 16, /* n_preallocs */
860 param_spec_flags_init, /* instance_init */
861 G_TYPE_FLAGS, /* value_type */
862 param_spec_flags_finalize,/* finalize */
863 param_flags_set_default, /* value_set_default */
864 param_flags_validate, /* value_validate */
865 param_ulong_values_cmp, /* values_cmp */
867 type = g_param_type_register_static ("GParamFlags", &pspec_info);
868 g_assert (type == G_TYPE_PARAM_FLAGS);
871 /* G_TYPE_PARAM_FLOAT
874 static const GParamSpecTypeInfo pspec_info = {
875 sizeof (GParamSpecFloat), /* instance_size */
876 16, /* n_preallocs */
877 param_spec_float_init, /* instance_init */
878 G_TYPE_FLOAT, /* value_type */
880 param_float_set_default, /* value_set_default */
881 param_float_validate, /* value_validate */
882 param_float_values_cmp, /* values_cmp */
884 type = g_param_type_register_static ("GParamFloat", &pspec_info);
885 g_assert (type == G_TYPE_PARAM_FLOAT);
888 /* G_TYPE_PARAM_DOUBLE
891 static const GParamSpecTypeInfo pspec_info = {
892 sizeof (GParamSpecDouble), /* instance_size */
893 16, /* n_preallocs */
894 param_spec_double_init, /* instance_init */
895 G_TYPE_DOUBLE, /* value_type */
897 param_double_set_default, /* value_set_default */
898 param_double_validate, /* value_validate */
899 param_double_values_cmp, /* values_cmp */
901 type = g_param_type_register_static ("GParamDouble", &pspec_info);
902 g_assert (type == G_TYPE_PARAM_DOUBLE);
905 /* G_TYPE_PARAM_STRING
908 static const GParamSpecTypeInfo pspec_info = {
909 sizeof (GParamSpecString), /* instance_size */
910 16, /* n_preallocs */
911 param_spec_string_init, /* instance_init */
912 G_TYPE_STRING, /* value_type */
913 param_spec_string_finalize, /* finalize */
914 param_string_set_default, /* value_set_default */
915 param_string_validate, /* value_validate */
916 param_string_values_cmp, /* values_cmp */
918 type = g_param_type_register_static ("GParamString", &pspec_info);
919 g_assert (type == G_TYPE_PARAM_STRING);
922 /* G_TYPE_PARAM_OBJECT
925 static const GParamSpecTypeInfo pspec_info = {
926 sizeof (GParamSpecObject), /* instance_size */
927 16, /* n_preallocs */
928 param_spec_object_init, /* instance_init */
929 G_TYPE_OBJECT, /* value_type */
931 param_object_set_default, /* value_set_default */
932 param_object_validate, /* value_validate */
933 param_object_values_cmp, /* values_cmp */
935 type = g_param_type_register_static ("GParamObject", &pspec_info);
936 g_assert (type == G_TYPE_PARAM_OBJECT);
939 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UCHAR, value_exch_memcpy);
940 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_BOOLEAN, value_exch_memcpy);
941 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_INT, value_exch_memcpy);
942 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_UINT, value_exch_memcpy);
943 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_ENUM, value_exch_memcpy);
944 g_value_register_exchange_func (G_TYPE_CHAR, G_TYPE_FLAGS, value_exch_memcpy);
945 g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_BOOLEAN, value_exch_memcpy);
946 g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_INT, value_exch_memcpy);
947 g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_UINT, value_exch_memcpy);
948 g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_ENUM, value_exch_memcpy);
949 g_value_register_exchange_func (G_TYPE_UCHAR, G_TYPE_FLAGS, value_exch_memcpy);
950 g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_INT, value_exch_memcpy);
951 g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_UINT, value_exch_memcpy);
952 g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_ENUM, value_exch_memcpy);
953 g_value_register_exchange_func (G_TYPE_BOOLEAN, G_TYPE_FLAGS, value_exch_memcpy);
954 g_value_register_exchange_func (G_TYPE_INT, G_TYPE_UINT, value_exch_memcpy);
955 g_value_register_exchange_func (G_TYPE_INT, G_TYPE_ENUM, value_exch_memcpy);
956 g_value_register_exchange_func (G_TYPE_INT, G_TYPE_FLAGS, value_exch_memcpy);
957 g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_ENUM, value_exch_memcpy);
958 g_value_register_exchange_func (G_TYPE_UINT, G_TYPE_FLAGS, value_exch_memcpy);
959 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_CHAR, value_exch_long_int);
960 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UCHAR, value_exch_long_uint);
961 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_BOOLEAN, value_exch_long_int);
962 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_INT, value_exch_long_int);
963 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_UINT, value_exch_long_uint);
964 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ULONG, value_exch_memcpy);
965 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_ENUM, value_exch_long_int);
966 g_value_register_exchange_func (G_TYPE_LONG, G_TYPE_FLAGS, value_exch_long_uint);
967 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_CHAR, value_exch_ulong_int);
968 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UCHAR, value_exch_ulong_uint);
969 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_BOOLEAN, value_exch_ulong_int);
970 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_INT, value_exch_ulong_int);
971 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_UINT, value_exch_ulong_uint);
972 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_ENUM, value_exch_ulong_int);
973 g_value_register_exchange_func (G_TYPE_ULONG, G_TYPE_FLAGS, value_exch_ulong_uint);
974 g_value_register_exchange_func (G_TYPE_ENUM, G_TYPE_FLAGS, value_exch_memcpy);
975 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_CHAR, value_exch_float_int);
976 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UCHAR, value_exch_float_uint);
977 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_BOOLEAN, value_exch_float_int);
978 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_INT, value_exch_float_int);
979 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_UINT, value_exch_float_uint);
980 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_LONG, value_exch_float_long);
981 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ULONG, value_exch_float_ulong);
982 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_ENUM, value_exch_float_int);
983 g_value_register_exchange_func (G_TYPE_FLOAT, G_TYPE_FLAGS, value_exch_float_uint);
984 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_CHAR, value_exch_double_int);
985 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UCHAR, value_exch_double_uint);
986 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_BOOLEAN, value_exch_double_int);
987 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_INT, value_exch_double_int);
988 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_UINT, value_exch_double_uint);
989 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_LONG, value_exch_double_long);
990 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ULONG, value_exch_double_ulong);
991 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_ENUM, value_exch_double_int);
992 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLAGS, value_exch_double_uint);
993 g_value_register_exchange_func (G_TYPE_DOUBLE, G_TYPE_FLOAT, value_exch_double_float);
997 /* --- GParamSpec initialization --- */
999 g_param_spec_char (const gchar *name,
1004 gint8 default_value,
1007 GParamSpecChar *cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1013 cspec->minimum = minimum;
1014 cspec->maximum = maximum;
1015 cspec->default_value = default_value;
1017 return G_PARAM_SPEC (cspec);
1021 g_param_spec_uchar (const gchar *name,
1026 guint8 default_value,
1029 GParamSpecUChar *uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1035 uspec->minimum = minimum;
1036 uspec->maximum = maximum;
1037 uspec->default_value = default_value;
1039 return G_PARAM_SPEC (uspec);
1043 g_param_spec_boolean (const gchar *name,
1046 gboolean default_value,
1049 GParamSpecBoolean *bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1055 bspec->default_value = default_value;
1057 return G_PARAM_SPEC (bspec);
1061 g_param_spec_int (const gchar *name,
1069 GParamSpecInt *ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1075 ispec->minimum = minimum;
1076 ispec->maximum = maximum;
1077 ispec->default_value = default_value;
1079 return G_PARAM_SPEC (ispec);
1083 g_param_spec_uint (const gchar *name,
1088 guint default_value,
1091 GParamSpecUInt *uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
1097 uspec->minimum = minimum;
1098 uspec->maximum = maximum;
1099 uspec->default_value = default_value;
1101 return G_PARAM_SPEC (uspec);
1105 g_param_spec_long (const gchar *name,
1110 glong default_value,
1113 GParamSpecLong *lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
1119 lspec->minimum = minimum;
1120 lspec->maximum = maximum;
1121 lspec->default_value = default_value;
1123 return G_PARAM_SPEC (lspec);
1127 g_param_spec_ulong (const gchar *name,
1132 gulong default_value,
1135 GParamSpecULong *uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
1141 uspec->minimum = minimum;
1142 uspec->maximum = maximum;
1143 uspec->default_value = default_value;
1145 return G_PARAM_SPEC (uspec);
1149 g_param_spec_enum (const gchar *name,
1156 GParamSpecEnum *espec;
1158 g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
1160 espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
1166 espec->enum_class = g_type_class_ref (enum_type);
1167 espec->default_value = default_value;
1169 return G_PARAM_SPEC (espec);
1173 g_param_spec_flags (const gchar *name,
1177 guint default_value,
1180 GParamSpecFlags *fspec;
1182 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
1184 fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
1190 fspec->flags_class = g_type_class_ref (flags_type);
1191 fspec->default_value = default_value;
1193 return G_PARAM_SPEC (fspec);
1197 g_param_spec_float (const gchar *name,
1202 gfloat default_value,
1205 GParamSpecFloat *fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
1211 fspec->minimum = minimum;
1212 fspec->maximum = maximum;
1213 fspec->default_value = default_value;
1215 return G_PARAM_SPEC (fspec);
1219 g_param_spec_double (const gchar *name,
1224 gdouble default_value,
1227 GParamSpecDouble *dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
1233 dspec->minimum = minimum;
1234 dspec->maximum = maximum;
1235 dspec->default_value = default_value;
1237 return G_PARAM_SPEC (dspec);
1241 g_param_spec_string (const gchar *name,
1244 const gchar *default_value,
1247 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
1252 g_free (sspec->default_value);
1253 sspec->default_value = g_strdup (default_value);
1255 return G_PARAM_SPEC (sspec);
1259 g_param_spec_string_c (const gchar *name,
1262 const gchar *default_value,
1265 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
1270 g_free (sspec->default_value);
1271 sspec->default_value = g_strdup (default_value);
1272 g_free (sspec->cset_first);
1273 sspec->cset_first = g_strdup (G_CSET_a_2_z "_" G_CSET_A_2_Z);
1274 g_free (sspec->cset_nth);
1275 sspec->cset_nth = g_strdup (G_CSET_a_2_z
1277 /* G_CSET_LATINS G_CSET_LATINC */
1280 return G_PARAM_SPEC (sspec);
1284 g_param_spec_object (const gchar *name,
1290 GParamSpecObject *ospec;
1292 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
1294 ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
1299 ospec->object_type = object_type;
1301 return G_PARAM_SPEC (ospec);