Move initialization of variables after g_return_val_if_fail. (#131564,
[glib.git] / gobject / gparamspecs.c
blob93f9b9dedc9b53a71fecfe7de1ad393545820922
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.
21 * MT safe
24 #include "../config.h"
26 #include "gparamspecs.h"
28 #include "gvaluecollector.h"
29 #include "gvaluearray.h"
30 #include <string.h>
32 #define G_FLOAT_EPSILON (1e-30)
33 #define G_DOUBLE_EPSILON (1e-90)
36 /* --- param spec functions --- */
37 static void
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;
47 static void
48 param_char_set_default (GParamSpec *pspec,
49 GValue *value)
51 value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
54 static gboolean
55 param_char_validate (GParamSpec *pspec,
56 GValue *value)
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;
66 static void
67 param_uchar_init (GParamSpec *pspec)
69 GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
71 uspec->minimum = 0;
72 uspec->maximum = 0xff;
73 uspec->default_value = 0;
76 static void
77 param_uchar_set_default (GParamSpec *pspec,
78 GValue *value)
80 value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
83 static gboolean
84 param_uchar_validate (GParamSpec *pspec,
85 GValue *value)
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;
95 static void
96 param_boolean_set_default (GParamSpec *pspec,
97 GValue *value)
99 value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
102 static gboolean
103 param_boolean_validate (GParamSpec *pspec,
104 GValue *value)
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;
113 static void
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;
123 static void
124 param_int_set_default (GParamSpec *pspec,
125 GValue *value)
127 value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
130 static gboolean
131 param_int_validate (GParamSpec *pspec,
132 GValue *value)
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;
142 static gint
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)
148 return -1;
149 else
150 return value1->data[0].v_int > value2->data[0].v_int;
153 static void
154 param_uint_init (GParamSpec *pspec)
156 GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
158 uspec->minimum = 0;
159 uspec->maximum = 0xffffffff;
160 uspec->default_value = 0;
163 static void
164 param_uint_set_default (GParamSpec *pspec,
165 GValue *value)
167 value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
170 static gboolean
171 param_uint_validate (GParamSpec *pspec,
172 GValue *value)
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;
182 static gint
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)
188 return -1;
189 else
190 return value1->data[0].v_uint > value2->data[0].v_uint;
193 static void
194 param_long_init (GParamSpec *pspec)
196 GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
198 #if SIZEOF_LONG == 4
199 lspec->minimum = 0x7fffffff;
200 lspec->maximum = 0x80000000;
201 #else /* SIZEOF_LONG != 4 (8) */
202 lspec->minimum = 0x7fffffffffffffff;
203 lspec->maximum = 0x8000000000000000;
204 #endif
205 lspec->default_value = 0;
208 static void
209 param_long_set_default (GParamSpec *pspec,
210 GValue *value)
212 value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
215 static gboolean
216 param_long_validate (GParamSpec *pspec,
217 GValue *value)
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;
227 static gint
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)
233 return -1;
234 else
235 return value1->data[0].v_long > value2->data[0].v_long;
238 static void
239 param_ulong_init (GParamSpec *pspec)
241 GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
243 uspec->minimum = 0;
244 #if SIZEOF_LONG == 4
245 uspec->maximum = 0xffffffff;
246 #else /* SIZEOF_LONG != 4 (8) */
247 uspec->maximum = 0xffffffffffffffff;
248 #endif
249 uspec->default_value = 0;
252 static void
253 param_ulong_set_default (GParamSpec *pspec,
254 GValue *value)
256 value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
259 static gboolean
260 param_ulong_validate (GParamSpec *pspec,
261 GValue *value)
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;
271 static gint
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)
277 return -1;
278 else
279 return value1->data[0].v_ulong > value2->data[0].v_ulong;
282 static void
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;
292 static void
293 param_int64_set_default (GParamSpec *pspec,
294 GValue *value)
296 value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
299 static gboolean
300 param_int64_validate (GParamSpec *pspec,
301 GValue *value)
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;
311 static gint
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)
317 return -1;
318 else
319 return value1->data[0].v_int64 > value2->data[0].v_int64;
322 static void
323 param_uint64_init (GParamSpec *pspec)
325 GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
327 uspec->minimum = 0;
328 uspec->maximum = G_MAXUINT64;
329 uspec->default_value = 0;
332 static void
333 param_uint64_set_default (GParamSpec *pspec,
334 GValue *value)
336 value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
339 static gboolean
340 param_uint64_validate (GParamSpec *pspec,
341 GValue *value)
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;
351 static gint
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)
357 return -1;
358 else
359 return value1->data[0].v_uint64 > value2->data[0].v_uint64;
362 static void
363 param_unichar_init (GParamSpec *pspec)
365 GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
367 uspec->default_value = 0;
370 static void
371 param_unichar_set_default (GParamSpec *pspec,
372 GValue *value)
374 value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
377 static gboolean
378 param_unichar_validate (GParamSpec *pspec,
379 GValue *value)
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;
387 changed = TRUE;
390 return changed;
393 static gint
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)
399 return -1;
400 else
401 return value1->data[0].v_uint > value2->data[0].v_uint;
404 static void
405 param_enum_init (GParamSpec *pspec)
407 GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
409 espec->enum_class = NULL;
410 espec->default_value = 0;
413 static void
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);
428 static void
429 param_enum_set_default (GParamSpec *pspec,
430 GValue *value)
432 value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
435 static gboolean
436 param_enum_validate (GParamSpec *pspec,
437 GValue *value)
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;
449 static void
450 param_flags_init (GParamSpec *pspec)
452 GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
454 fspec->flags_class = NULL;
455 fspec->default_value = 0;
458 static void
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);
473 static void
474 param_flags_set_default (GParamSpec *pspec,
475 GValue *value)
477 value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
480 static gboolean
481 param_flags_validate (GParamSpec *pspec,
482 GValue *value)
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;
489 else
490 value->data[0].v_ulong = fspec->default_value;
492 return value->data[0].v_ulong != oval;
495 static void
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;
506 static void
507 param_float_set_default (GParamSpec *pspec,
508 GValue *value)
510 value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
513 static gboolean
514 param_float_validate (GParamSpec *pspec,
515 GValue *value)
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;
525 static gint
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);
534 else
535 return value1->data[0].v_float - value2->data[0].v_float > epsilon;
538 static void
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;
549 static void
550 param_double_set_default (GParamSpec *pspec,
551 GValue *value)
553 value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
556 static gboolean
557 param_double_validate (GParamSpec *pspec,
558 GValue *value)
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;
568 static gint
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);
577 else
578 return value1->data[0].v_double - value2->data[0].v_double > epsilon;
581 static void
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;
594 static void
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);
610 static void
611 param_string_set_default (GParamSpec *pspec,
612 GValue *value)
614 value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
617 static gboolean
618 param_string_validate (GParamSpec *pspec,
619 GValue *value)
621 GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
622 gchar *string = value->data[0].v_pointer;
623 guint changed = 0;
625 if (string && string[0])
627 gchar *s;
629 if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
631 string[0] = sspec->substitutor;
632 changed++;
634 if (sspec->cset_nth)
635 for (s = string + 1; *s; s++)
636 if (!strchr (sspec->cset_nth, *s))
638 *s = sspec->substitutor;
639 changed++;
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;
646 changed++;
647 string = value->data[0].v_pointer;
649 if (sspec->ensure_non_null && !string)
651 value->data[0].v_pointer = g_strdup ("");
652 changed++;
653 string = value->data[0].v_pointer;
656 return changed;
659 static gint
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;
668 else
669 return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
672 static void
673 param_param_init (GParamSpec *pspec)
675 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
678 static void
679 param_param_set_default (GParamSpec *pspec,
680 GValue *value)
682 value->data[0].v_pointer = NULL;
685 static gboolean
686 param_param_validate (GParamSpec *pspec,
687 GValue *value)
689 /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
690 GParamSpec *param = value->data[0].v_pointer;
691 guint changed = 0;
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;
697 changed++;
700 return changed;
703 static void
704 param_boxed_init (GParamSpec *pspec)
706 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
709 static void
710 param_boxed_set_default (GParamSpec *pspec,
711 GValue *value)
713 value->data[0].v_pointer = NULL;
716 static gboolean
717 param_boxed_validate (GParamSpec *pspec,
718 GValue *value)
720 /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
721 guint changed = 0;
723 /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */
725 return changed;
728 static gint
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;
741 static void
742 param_pointer_init (GParamSpec *pspec)
744 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
747 static void
748 param_pointer_set_default (GParamSpec *pspec,
749 GValue *value)
751 value->data[0].v_pointer = NULL;
754 static gboolean
755 param_pointer_validate (GParamSpec *pspec,
756 GValue *value)
758 /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
759 guint changed = 0;
761 return changed;
764 static gint
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;
777 static void
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 */
786 static inline guint
787 value_array_ensure_size (GValueArray *value_array,
788 guint fixed_n_elements)
790 guint changed = 0;
792 if (fixed_n_elements)
794 while (value_array->n_values < fixed_n_elements)
796 g_value_array_append (value_array, NULL);
797 changed++;
799 while (value_array->n_values > fixed_n_elements)
801 g_value_array_remove (value_array, value_array->n_values - 1);
802 changed++;
805 return changed;
808 static void
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);
823 static void
824 param_value_array_set_default (GParamSpec *pspec,
825 GValue *value)
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);
839 static gboolean
840 param_value_array_validate (GParamSpec *pspec,
841 GValue *value)
843 GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
844 GValueArray *value_array = value->data[0].v_pointer;
845 guint changed = 0;
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;
859 guint i;
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);
872 changed++;
874 /* validate array value against element_spec */
875 changed += g_param_value_validate (element_spec, element);
880 return changed;
883 static gint
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 */
906 guint i;
908 for (i = 0; i < value_array1->n_values; i++)
910 GValue *element1 = value_array1->values + i;
911 GValue *element2 = value_array2->values + i;
912 gint cmp;
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);
918 if (cmp)
919 return cmp;
921 return 0;
925 static void
926 param_object_init (GParamSpec *pspec)
928 /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
931 static void
932 param_object_set_default (GParamSpec *pspec,
933 GValue *value)
935 value->data[0].v_pointer = NULL;
938 static gboolean
939 param_object_validate (GParamSpec *pspec,
940 GValue *value)
942 GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
943 GObject *object = value->data[0].v_pointer;
944 guint changed = 0;
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;
950 changed++;
953 return changed;
956 static gint
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;
969 static void
970 param_override_init (GParamSpec *pspec)
972 /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
975 static void
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);
990 static void
991 param_override_set_default (GParamSpec *pspec,
992 GValue *value)
994 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
996 g_param_value_set_default (ospec->overridden, value);
999 static gboolean
1000 param_override_validate (GParamSpec *pspec,
1001 GValue *value)
1003 GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1005 return g_param_value_validate (ospec->overridden, value);
1008 static gint
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;
1021 void
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);
1085 /* G_TYPE_PARAM_INT
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 --- */
1415 GParamSpec*
1416 g_param_spec_char (const gchar *name,
1417 const gchar *nick,
1418 const gchar *blurb,
1419 gint8 minimum,
1420 gint8 maximum,
1421 gint8 default_value,
1422 GParamFlags flags)
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,
1429 name,
1430 nick,
1431 blurb,
1432 flags);
1434 cspec->minimum = minimum;
1435 cspec->maximum = maximum;
1436 cspec->default_value = default_value;
1438 return G_PARAM_SPEC (cspec);
1441 GParamSpec*
1442 g_param_spec_uchar (const gchar *name,
1443 const gchar *nick,
1444 const gchar *blurb,
1445 guint8 minimum,
1446 guint8 maximum,
1447 guint8 default_value,
1448 GParamFlags flags)
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,
1455 name,
1456 nick,
1457 blurb,
1458 flags);
1460 uspec->minimum = minimum;
1461 uspec->maximum = maximum;
1462 uspec->default_value = default_value;
1464 return G_PARAM_SPEC (uspec);
1467 GParamSpec*
1468 g_param_spec_boolean (const gchar *name,
1469 const gchar *nick,
1470 const gchar *blurb,
1471 gboolean default_value,
1472 GParamFlags flags)
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,
1479 name,
1480 nick,
1481 blurb,
1482 flags);
1484 bspec->default_value = default_value;
1486 return G_PARAM_SPEC (bspec);
1489 GParamSpec*
1490 g_param_spec_int (const gchar *name,
1491 const gchar *nick,
1492 const gchar *blurb,
1493 gint minimum,
1494 gint maximum,
1495 gint default_value,
1496 GParamFlags flags)
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,
1503 name,
1504 nick,
1505 blurb,
1506 flags);
1508 ispec->minimum = minimum;
1509 ispec->maximum = maximum;
1510 ispec->default_value = default_value;
1512 return G_PARAM_SPEC (ispec);
1515 GParamSpec*
1516 g_param_spec_uint (const gchar *name,
1517 const gchar *nick,
1518 const gchar *blurb,
1519 guint minimum,
1520 guint maximum,
1521 guint default_value,
1522 GParamFlags flags)
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,
1529 name,
1530 nick,
1531 blurb,
1532 flags);
1534 uspec->minimum = minimum;
1535 uspec->maximum = maximum;
1536 uspec->default_value = default_value;
1538 return G_PARAM_SPEC (uspec);
1541 GParamSpec*
1542 g_param_spec_long (const gchar *name,
1543 const gchar *nick,
1544 const gchar *blurb,
1545 glong minimum,
1546 glong maximum,
1547 glong default_value,
1548 GParamFlags flags)
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,
1555 name,
1556 nick,
1557 blurb,
1558 flags);
1560 lspec->minimum = minimum;
1561 lspec->maximum = maximum;
1562 lspec->default_value = default_value;
1564 return G_PARAM_SPEC (lspec);
1567 GParamSpec*
1568 g_param_spec_ulong (const gchar *name,
1569 const gchar *nick,
1570 const gchar *blurb,
1571 gulong minimum,
1572 gulong maximum,
1573 gulong default_value,
1574 GParamFlags flags)
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,
1581 name,
1582 nick,
1583 blurb,
1584 flags);
1586 uspec->minimum = minimum;
1587 uspec->maximum = maximum;
1588 uspec->default_value = default_value;
1590 return G_PARAM_SPEC (uspec);
1593 GParamSpec*
1594 g_param_spec_int64 (const gchar *name,
1595 const gchar *nick,
1596 const gchar *blurb,
1597 gint64 minimum,
1598 gint64 maximum,
1599 gint64 default_value,
1600 GParamFlags flags)
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,
1607 name,
1608 nick,
1609 blurb,
1610 flags);
1612 lspec->minimum = minimum;
1613 lspec->maximum = maximum;
1614 lspec->default_value = default_value;
1616 return G_PARAM_SPEC (lspec);
1619 GParamSpec*
1620 g_param_spec_uint64 (const gchar *name,
1621 const gchar *nick,
1622 const gchar *blurb,
1623 guint64 minimum,
1624 guint64 maximum,
1625 guint64 default_value,
1626 GParamFlags flags)
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,
1633 name,
1634 nick,
1635 blurb,
1636 flags);
1638 uspec->minimum = minimum;
1639 uspec->maximum = maximum;
1640 uspec->default_value = default_value;
1642 return G_PARAM_SPEC (uspec);
1645 GParamSpec*
1646 g_param_spec_unichar (const gchar *name,
1647 const gchar *nick,
1648 const gchar *blurb,
1649 gunichar default_value,
1650 GParamFlags flags)
1652 GParamSpecUnichar *uspec;
1654 uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
1655 name,
1656 nick,
1657 blurb,
1658 flags);
1660 uspec->default_value = default_value;
1662 return G_PARAM_SPEC (uspec);
1665 GParamSpec*
1666 g_param_spec_enum (const gchar *name,
1667 const gchar *nick,
1668 const gchar *blurb,
1669 GType enum_type,
1670 gint default_value,
1671 GParamFlags flags)
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,
1683 name,
1684 nick,
1685 blurb,
1686 flags);
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);
1695 GParamSpec*
1696 g_param_spec_flags (const gchar *name,
1697 const gchar *nick,
1698 const gchar *blurb,
1699 GType flags_type,
1700 guint default_value,
1701 GParamFlags flags)
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,
1713 name,
1714 nick,
1715 blurb,
1716 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);
1725 GParamSpec*
1726 g_param_spec_float (const gchar *name,
1727 const gchar *nick,
1728 const gchar *blurb,
1729 gfloat minimum,
1730 gfloat maximum,
1731 gfloat default_value,
1732 GParamFlags flags)
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,
1739 name,
1740 nick,
1741 blurb,
1742 flags);
1744 fspec->minimum = minimum;
1745 fspec->maximum = maximum;
1746 fspec->default_value = default_value;
1748 return G_PARAM_SPEC (fspec);
1751 GParamSpec*
1752 g_param_spec_double (const gchar *name,
1753 const gchar *nick,
1754 const gchar *blurb,
1755 gdouble minimum,
1756 gdouble maximum,
1757 gdouble default_value,
1758 GParamFlags flags)
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,
1765 name,
1766 nick,
1767 blurb,
1768 flags);
1770 dspec->minimum = minimum;
1771 dspec->maximum = maximum;
1772 dspec->default_value = default_value;
1774 return G_PARAM_SPEC (dspec);
1777 GParamSpec*
1778 g_param_spec_string (const gchar *name,
1779 const gchar *nick,
1780 const gchar *blurb,
1781 const gchar *default_value,
1782 GParamFlags flags)
1784 GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
1785 name,
1786 nick,
1787 blurb,
1788 flags);
1789 g_free (sspec->default_value);
1790 sspec->default_value = g_strdup (default_value);
1792 return G_PARAM_SPEC (sspec);
1795 GParamSpec*
1796 g_param_spec_param (const gchar *name,
1797 const gchar *nick,
1798 const gchar *blurb,
1799 GType param_type,
1800 GParamFlags flags)
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,
1807 name,
1808 nick,
1809 blurb,
1810 flags);
1811 G_PARAM_SPEC (pspec)->value_type = param_type;
1813 return G_PARAM_SPEC (pspec);
1816 GParamSpec*
1817 g_param_spec_boxed (const gchar *name,
1818 const gchar *nick,
1819 const gchar *blurb,
1820 GType boxed_type,
1821 GParamFlags flags)
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,
1829 name,
1830 nick,
1831 blurb,
1832 flags);
1833 G_PARAM_SPEC (bspec)->value_type = boxed_type;
1835 return G_PARAM_SPEC (bspec);
1838 GParamSpec*
1839 g_param_spec_pointer (const gchar *name,
1840 const gchar *nick,
1841 const gchar *blurb,
1842 GParamFlags flags)
1844 GParamSpecPointer *pspec;
1846 pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
1847 name,
1848 nick,
1849 blurb,
1850 flags);
1851 return G_PARAM_SPEC (pspec);
1854 GParamSpec*
1855 g_param_spec_value_array (const gchar *name,
1856 const gchar *nick,
1857 const gchar *blurb,
1858 GParamSpec *element_spec,
1859 GParamFlags flags)
1861 GParamSpecValueArray *aspec;
1863 if (element_spec)
1864 g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL);
1866 aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY,
1867 name,
1868 nick,
1869 blurb,
1870 flags);
1871 if (element_spec)
1873 aspec->element_spec = g_param_spec_ref (element_spec);
1874 g_param_spec_sink (element_spec);
1877 return G_PARAM_SPEC (aspec);
1880 GParamSpec*
1881 g_param_spec_object (const gchar *name,
1882 const gchar *nick,
1883 const gchar *blurb,
1884 GType object_type,
1885 GParamFlags flags)
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,
1892 name,
1893 nick,
1894 blurb,
1895 flags);
1896 G_PARAM_SPEC (ospec)->value_type = object_type;
1898 return G_PARAM_SPEC (ospec);
1901 GParamSpec*
1902 g_param_spec_override (const gchar *name,
1903 GParamSpec *overridden)
1905 GParamSpec *pspec;
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
1912 while (TRUE)
1914 GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
1915 if (indirect)
1916 overridden = indirect;
1917 else
1918 break;
1921 pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
1922 name, NULL, NULL,
1923 overridden->flags);
1925 pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
1926 G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
1928 return pspec;