1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3 * Copyright © 2010 Christian Persch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include <stdlib.h> /* qsort() */
28 #include "gvaluetypes.h"
29 #include "gtype-private.h"
30 #include "gvaluecollector.h"
37 /* --- value functions --- */
39 value_init_long0 (GValue
*value
)
41 value
->data
[0].v_long
= 0;
45 value_copy_long0 (const GValue
*src_value
,
48 dest_value
->data
[0].v_long
= src_value
->data
[0].v_long
;
52 value_lcopy_char (const GValue
*value
,
53 guint n_collect_values
,
54 GTypeCValue
*collect_values
,
57 gint8
*int8_p
= collect_values
[0].v_pointer
;
60 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
62 *int8_p
= value
->data
[0].v_int
;
68 value_lcopy_boolean (const GValue
*value
,
69 guint n_collect_values
,
70 GTypeCValue
*collect_values
,
73 gboolean
*bool_p
= collect_values
[0].v_pointer
;
76 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
78 *bool_p
= value
->data
[0].v_int
;
84 value_collect_int (GValue
*value
,
85 guint n_collect_values
,
86 GTypeCValue
*collect_values
,
89 value
->data
[0].v_int
= collect_values
[0].v_int
;
95 value_lcopy_int (const GValue
*value
,
96 guint n_collect_values
,
97 GTypeCValue
*collect_values
,
100 gint
*int_p
= collect_values
[0].v_pointer
;
103 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
105 *int_p
= value
->data
[0].v_int
;
111 value_collect_long (GValue
*value
,
112 guint n_collect_values
,
113 GTypeCValue
*collect_values
,
116 value
->data
[0].v_long
= collect_values
[0].v_long
;
122 value_lcopy_long (const GValue
*value
,
123 guint n_collect_values
,
124 GTypeCValue
*collect_values
,
127 glong
*long_p
= collect_values
[0].v_pointer
;
130 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
132 *long_p
= value
->data
[0].v_long
;
138 value_init_int64 (GValue
*value
)
140 value
->data
[0].v_int64
= 0;
144 value_copy_int64 (const GValue
*src_value
,
147 dest_value
->data
[0].v_int64
= src_value
->data
[0].v_int64
;
151 value_collect_int64 (GValue
*value
,
152 guint n_collect_values
,
153 GTypeCValue
*collect_values
,
156 value
->data
[0].v_int64
= collect_values
[0].v_int64
;
162 value_lcopy_int64 (const GValue
*value
,
163 guint n_collect_values
,
164 GTypeCValue
*collect_values
,
167 gint64
*int64_p
= collect_values
[0].v_pointer
;
170 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
172 *int64_p
= value
->data
[0].v_int64
;
178 value_init_float (GValue
*value
)
180 value
->data
[0].v_float
= 0.0;
184 value_copy_float (const GValue
*src_value
,
187 dest_value
->data
[0].v_float
= src_value
->data
[0].v_float
;
191 value_collect_float (GValue
*value
,
192 guint n_collect_values
,
193 GTypeCValue
*collect_values
,
196 value
->data
[0].v_float
= collect_values
[0].v_double
;
202 value_lcopy_float (const GValue
*value
,
203 guint n_collect_values
,
204 GTypeCValue
*collect_values
,
207 gfloat
*float_p
= collect_values
[0].v_pointer
;
210 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
212 *float_p
= value
->data
[0].v_float
;
218 value_init_double (GValue
*value
)
220 value
->data
[0].v_double
= 0.0;
224 value_copy_double (const GValue
*src_value
,
227 dest_value
->data
[0].v_double
= src_value
->data
[0].v_double
;
231 value_collect_double (GValue
*value
,
232 guint n_collect_values
,
233 GTypeCValue
*collect_values
,
236 value
->data
[0].v_double
= collect_values
[0].v_double
;
242 value_lcopy_double (const GValue
*value
,
243 guint n_collect_values
,
244 GTypeCValue
*collect_values
,
247 gdouble
*double_p
= collect_values
[0].v_pointer
;
250 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
252 *double_p
= value
->data
[0].v_double
;
258 value_init_string (GValue
*value
)
260 value
->data
[0].v_pointer
= NULL
;
264 value_free_string (GValue
*value
)
266 if (!(value
->data
[1].v_uint
& G_VALUE_NOCOPY_CONTENTS
))
267 g_free (value
->data
[0].v_pointer
);
271 value_copy_string (const GValue
*src_value
,
274 dest_value
->data
[0].v_pointer
= g_strdup (src_value
->data
[0].v_pointer
);
278 value_collect_string (GValue
*value
,
279 guint n_collect_values
,
280 GTypeCValue
*collect_values
,
283 if (!collect_values
[0].v_pointer
)
284 value
->data
[0].v_pointer
= NULL
;
285 else if (collect_flags
& G_VALUE_NOCOPY_CONTENTS
)
287 value
->data
[0].v_pointer
= collect_values
[0].v_pointer
;
288 value
->data
[1].v_uint
= G_VALUE_NOCOPY_CONTENTS
;
291 value
->data
[0].v_pointer
= g_strdup (collect_values
[0].v_pointer
);
297 value_lcopy_string (const GValue
*value
,
298 guint n_collect_values
,
299 GTypeCValue
*collect_values
,
302 gchar
**string_p
= collect_values
[0].v_pointer
;
305 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
307 if (!value
->data
[0].v_pointer
)
309 else if (collect_flags
& G_VALUE_NOCOPY_CONTENTS
)
310 *string_p
= value
->data
[0].v_pointer
;
312 *string_p
= g_strdup (value
->data
[0].v_pointer
);
318 value_init_pointer (GValue
*value
)
320 value
->data
[0].v_pointer
= NULL
;
324 value_copy_pointer (const GValue
*src_value
,
327 dest_value
->data
[0].v_pointer
= src_value
->data
[0].v_pointer
;
331 value_peek_pointer0 (const GValue
*value
)
333 return value
->data
[0].v_pointer
;
337 value_collect_pointer (GValue
*value
,
338 guint n_collect_values
,
339 GTypeCValue
*collect_values
,
342 value
->data
[0].v_pointer
= collect_values
[0].v_pointer
;
348 value_lcopy_pointer (const GValue
*value
,
349 guint n_collect_values
,
350 GTypeCValue
*collect_values
,
353 gpointer
*pointer_p
= collect_values
[0].v_pointer
;
356 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
358 *pointer_p
= value
->data
[0].v_pointer
;
364 value_free_variant (GValue
*value
)
366 if (!(value
->data
[1].v_uint
& G_VALUE_NOCOPY_CONTENTS
) &&
367 value
->data
[0].v_pointer
)
368 g_variant_unref (value
->data
[0].v_pointer
);
372 value_copy_variant (const GValue
*src_value
,
375 if (src_value
->data
[0].v_pointer
)
376 dest_value
->data
[0].v_pointer
= g_variant_ref_sink (src_value
->data
[0].v_pointer
);
378 dest_value
->data
[0].v_pointer
= NULL
;
382 value_collect_variant (GValue
*value
,
383 guint n_collect_values
,
384 GTypeCValue
*collect_values
,
387 if (!collect_values
[0].v_pointer
)
388 value
->data
[0].v_pointer
= NULL
;
389 else if (collect_flags
& G_VALUE_NOCOPY_CONTENTS
)
391 value
->data
[0].v_pointer
= collect_values
[0].v_pointer
;
392 value
->data
[1].v_uint
= G_VALUE_NOCOPY_CONTENTS
;
395 value
->data
[0].v_pointer
= g_variant_ref_sink (collect_values
[0].v_pointer
);
401 value_lcopy_variant (const GValue
*value
,
402 guint n_collect_values
,
403 GTypeCValue
*collect_values
,
406 GVariant
**variant_p
= collect_values
[0].v_pointer
;
409 return g_strdup_printf ("value location for '%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
411 if (!value
->data
[0].v_pointer
)
413 else if (collect_flags
& G_VALUE_NOCOPY_CONTENTS
)
414 *variant_p
= value
->data
[0].v_pointer
;
416 *variant_p
= g_variant_ref_sink (value
->data
[0].v_pointer
);
421 /* --- type initialization --- */
423 _g_value_types_init (void)
427 NULL
, /* base_init */
428 NULL
, /* base_destroy */
429 NULL
, /* class_init */
430 NULL
, /* class_destroy */
431 NULL
, /* class_data */
432 0, /* instance_size */
434 NULL
, /* instance_init */
435 NULL
, /* value_table */
437 const GTypeFundamentalInfo finfo
= { G_TYPE_FLAG_DERIVABLE
, };
440 /* G_TYPE_CHAR / G_TYPE_UCHAR
443 static const GTypeValueTable value_table
= {
444 value_init_long0
, /* value_init */
445 NULL
, /* value_free */
446 value_copy_long0
, /* value_copy */
447 NULL
, /* value_peek_pointer */
448 "i", /* collect_format */
449 value_collect_int
, /* collect_value */
450 "p", /* lcopy_format */
451 value_lcopy_char
, /* lcopy_value */
453 info
.value_table
= &value_table
;
454 type
= g_type_register_fundamental (G_TYPE_CHAR
, g_intern_static_string ("gchar"), &info
, &finfo
, 0);
455 g_assert (type
== G_TYPE_CHAR
);
456 type
= g_type_register_fundamental (G_TYPE_UCHAR
, g_intern_static_string ("guchar"), &info
, &finfo
, 0);
457 g_assert (type
== G_TYPE_UCHAR
);
463 static const GTypeValueTable value_table
= {
464 value_init_long0
, /* value_init */
465 NULL
, /* value_free */
466 value_copy_long0
, /* value_copy */
467 NULL
, /* value_peek_pointer */
468 "i", /* collect_format */
469 value_collect_int
, /* collect_value */
470 "p", /* lcopy_format */
471 value_lcopy_boolean
, /* lcopy_value */
473 info
.value_table
= &value_table
;
474 type
= g_type_register_fundamental (G_TYPE_BOOLEAN
, g_intern_static_string ("gboolean"), &info
, &finfo
, 0);
475 g_assert (type
== G_TYPE_BOOLEAN
);
478 /* G_TYPE_INT / G_TYPE_UINT
481 static const GTypeValueTable value_table
= {
482 value_init_long0
, /* value_init */
483 NULL
, /* value_free */
484 value_copy_long0
, /* value_copy */
485 NULL
, /* value_peek_pointer */
486 "i", /* collect_format */
487 value_collect_int
, /* collect_value */
488 "p", /* lcopy_format */
489 value_lcopy_int
, /* lcopy_value */
491 info
.value_table
= &value_table
;
492 type
= g_type_register_fundamental (G_TYPE_INT
, g_intern_static_string ("gint"), &info
, &finfo
, 0);
493 g_assert (type
== G_TYPE_INT
);
494 type
= g_type_register_fundamental (G_TYPE_UINT
, g_intern_static_string ("guint"), &info
, &finfo
, 0);
495 g_assert (type
== G_TYPE_UINT
);
498 /* G_TYPE_LONG / G_TYPE_ULONG
501 static const GTypeValueTable value_table
= {
502 value_init_long0
, /* value_init */
503 NULL
, /* value_free */
504 value_copy_long0
, /* value_copy */
505 NULL
, /* value_peek_pointer */
506 "l", /* collect_format */
507 value_collect_long
, /* collect_value */
508 "p", /* lcopy_format */
509 value_lcopy_long
, /* lcopy_value */
511 info
.value_table
= &value_table
;
512 type
= g_type_register_fundamental (G_TYPE_LONG
, g_intern_static_string ("glong"), &info
, &finfo
, 0);
513 g_assert (type
== G_TYPE_LONG
);
514 type
= g_type_register_fundamental (G_TYPE_ULONG
, g_intern_static_string ("gulong"), &info
, &finfo
, 0);
515 g_assert (type
== G_TYPE_ULONG
);
518 /* G_TYPE_INT64 / G_TYPE_UINT64
521 static const GTypeValueTable value_table
= {
522 value_init_int64
, /* value_init */
523 NULL
, /* value_free */
524 value_copy_int64
, /* value_copy */
525 NULL
, /* value_peek_pointer */
526 "q", /* collect_format */
527 value_collect_int64
, /* collect_value */
528 "p", /* lcopy_format */
529 value_lcopy_int64
, /* lcopy_value */
531 info
.value_table
= &value_table
;
532 type
= g_type_register_fundamental (G_TYPE_INT64
, g_intern_static_string ("gint64"), &info
, &finfo
, 0);
533 g_assert (type
== G_TYPE_INT64
);
534 type
= g_type_register_fundamental (G_TYPE_UINT64
, g_intern_static_string ("guint64"), &info
, &finfo
, 0);
535 g_assert (type
== G_TYPE_UINT64
);
541 static const GTypeValueTable value_table
= {
542 value_init_float
, /* value_init */
543 NULL
, /* value_free */
544 value_copy_float
, /* value_copy */
545 NULL
, /* value_peek_pointer */
546 "d", /* collect_format */
547 value_collect_float
, /* collect_value */
548 "p", /* lcopy_format */
549 value_lcopy_float
, /* lcopy_value */
551 info
.value_table
= &value_table
;
552 type
= g_type_register_fundamental (G_TYPE_FLOAT
, g_intern_static_string ("gfloat"), &info
, &finfo
, 0);
553 g_assert (type
== G_TYPE_FLOAT
);
559 static const GTypeValueTable value_table
= {
560 value_init_double
, /* value_init */
561 NULL
, /* value_free */
562 value_copy_double
, /* value_copy */
563 NULL
, /* value_peek_pointer */
564 "d", /* collect_format */
565 value_collect_double
, /* collect_value */
566 "p", /* lcopy_format */
567 value_lcopy_double
, /* lcopy_value */
569 info
.value_table
= &value_table
;
570 type
= g_type_register_fundamental (G_TYPE_DOUBLE
, g_intern_static_string ("gdouble"), &info
, &finfo
, 0);
571 g_assert (type
== G_TYPE_DOUBLE
);
577 static const GTypeValueTable value_table
= {
578 value_init_string
, /* value_init */
579 value_free_string
, /* value_free */
580 value_copy_string
, /* value_copy */
581 value_peek_pointer0
, /* value_peek_pointer */
582 "p", /* collect_format */
583 value_collect_string
, /* collect_value */
584 "p", /* lcopy_format */
585 value_lcopy_string
, /* lcopy_value */
587 info
.value_table
= &value_table
;
588 type
= g_type_register_fundamental (G_TYPE_STRING
, g_intern_static_string ("gchararray"), &info
, &finfo
, 0);
589 g_assert (type
== G_TYPE_STRING
);
595 static const GTypeValueTable value_table
= {
596 value_init_pointer
, /* value_init */
597 NULL
, /* value_free */
598 value_copy_pointer
, /* value_copy */
599 value_peek_pointer0
, /* value_peek_pointer */
600 "p", /* collect_format */
601 value_collect_pointer
, /* collect_value */
602 "p", /* lcopy_format */
603 value_lcopy_pointer
, /* lcopy_value */
605 info
.value_table
= &value_table
;
606 type
= g_type_register_fundamental (G_TYPE_POINTER
, g_intern_static_string ("gpointer"), &info
, &finfo
, 0);
607 g_assert (type
== G_TYPE_POINTER
);
613 static const GTypeValueTable value_table
= {
614 value_init_pointer
, /* value_init */
615 value_free_variant
, /* value_free */
616 value_copy_variant
, /* value_copy */
617 value_peek_pointer0
, /* value_peek_pointer */
618 "p", /* collect_format */
619 value_collect_variant
, /* collect_value */
620 "p", /* lcopy_format */
621 value_lcopy_variant
, /* lcopy_value */
623 info
.value_table
= &value_table
;
624 type
= g_type_register_fundamental (G_TYPE_VARIANT
, g_intern_static_string ("GVariant"), &info
, &finfo
, 0);
625 g_assert (type
== G_TYPE_VARIANT
);
630 /* --- GValue functions --- */
633 * @value: a valid #GValue of type %G_TYPE_CHAR
634 * @v_char: character value to be set
636 * Set the contents of a %G_TYPE_CHAR #GValue to @v_char.
637 * Deprecated: 2.32: This function's input type is broken, see g_value_set_schar()
640 g_value_set_char (GValue
*value
,
643 g_return_if_fail (G_VALUE_HOLDS_CHAR (value
));
645 value
->data
[0].v_int
= v_char
;
650 * @value: a valid #GValue of type %G_TYPE_CHAR
652 * Do not use this function; it is broken on platforms where the %char
653 * type is unsigned, such as ARM and PowerPC. See g_value_get_schar().
655 * Get the contents of a %G_TYPE_CHAR #GValue.
657 * Returns: character contents of @value
658 * Deprecated: 2.32: This function's return type is broken, see g_value_get_schar()
661 g_value_get_char (const GValue
*value
)
663 g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value
), 0);
665 return value
->data
[0].v_int
;
670 * @value: a valid #GValue of type %G_TYPE_CHAR
671 * @v_char: signed 8 bit integer to be set
673 * Set the contents of a %G_TYPE_CHAR #GValue to @v_char.
678 g_value_set_schar (GValue
*value
,
681 g_return_if_fail (G_VALUE_HOLDS_CHAR (value
));
683 value
->data
[0].v_int
= v_char
;
688 * @value: a valid #GValue of type %G_TYPE_CHAR
690 * Get the contents of a %G_TYPE_CHAR #GValue.
692 * Returns: signed 8 bit integer contents of @value
696 g_value_get_schar (const GValue
*value
)
698 g_return_val_if_fail (G_VALUE_HOLDS_CHAR (value
), 0);
700 return value
->data
[0].v_int
;
705 * @value: a valid #GValue of type %G_TYPE_UCHAR
706 * @v_uchar: unsigned character value to be set
708 * Set the contents of a %G_TYPE_UCHAR #GValue to @v_uchar.
711 g_value_set_uchar (GValue
*value
,
714 g_return_if_fail (G_VALUE_HOLDS_UCHAR (value
));
716 value
->data
[0].v_uint
= v_uchar
;
721 * @value: a valid #GValue of type %G_TYPE_UCHAR
723 * Get the contents of a %G_TYPE_UCHAR #GValue.
725 * Returns: unsigned character contents of @value
728 g_value_get_uchar (const GValue
*value
)
730 g_return_val_if_fail (G_VALUE_HOLDS_UCHAR (value
), 0);
732 return value
->data
[0].v_uint
;
736 * g_value_set_boolean:
737 * @value: a valid #GValue of type %G_TYPE_BOOLEAN
738 * @v_boolean: boolean value to be set
740 * Set the contents of a %G_TYPE_BOOLEAN #GValue to @v_boolean.
743 g_value_set_boolean (GValue
*value
,
746 g_return_if_fail (G_VALUE_HOLDS_BOOLEAN (value
));
748 value
->data
[0].v_int
= v_boolean
!= FALSE
;
752 * g_value_get_boolean:
753 * @value: a valid #GValue of type %G_TYPE_BOOLEAN
755 * Get the contents of a %G_TYPE_BOOLEAN #GValue.
757 * Returns: boolean contents of @value
760 g_value_get_boolean (const GValue
*value
)
762 g_return_val_if_fail (G_VALUE_HOLDS_BOOLEAN (value
), 0);
764 return value
->data
[0].v_int
;
769 * @value: a valid #GValue of type %G_TYPE_INT
770 * @v_int: integer value to be set
772 * Set the contents of a %G_TYPE_INT #GValue to @v_int.
775 g_value_set_int (GValue
*value
,
778 g_return_if_fail (G_VALUE_HOLDS_INT (value
));
780 value
->data
[0].v_int
= v_int
;
785 * @value: a valid #GValue of type %G_TYPE_INT
787 * Get the contents of a %G_TYPE_INT #GValue.
789 * Returns: integer contents of @value
792 g_value_get_int (const GValue
*value
)
794 g_return_val_if_fail (G_VALUE_HOLDS_INT (value
), 0);
796 return value
->data
[0].v_int
;
801 * @value: a valid #GValue of type %G_TYPE_UINT
802 * @v_uint: unsigned integer value to be set
804 * Set the contents of a %G_TYPE_UINT #GValue to @v_uint.
807 g_value_set_uint (GValue
*value
,
810 g_return_if_fail (G_VALUE_HOLDS_UINT (value
));
812 value
->data
[0].v_uint
= v_uint
;
817 * @value: a valid #GValue of type %G_TYPE_UINT
819 * Get the contents of a %G_TYPE_UINT #GValue.
821 * Returns: unsigned integer contents of @value
824 g_value_get_uint (const GValue
*value
)
826 g_return_val_if_fail (G_VALUE_HOLDS_UINT (value
), 0);
828 return value
->data
[0].v_uint
;
833 * @value: a valid #GValue of type %G_TYPE_LONG
834 * @v_long: long integer value to be set
836 * Set the contents of a %G_TYPE_LONG #GValue to @v_long.
839 g_value_set_long (GValue
*value
,
842 g_return_if_fail (G_VALUE_HOLDS_LONG (value
));
844 value
->data
[0].v_long
= v_long
;
849 * @value: a valid #GValue of type %G_TYPE_LONG
851 * Get the contents of a %G_TYPE_LONG #GValue.
853 * Returns: long integer contents of @value
856 g_value_get_long (const GValue
*value
)
858 g_return_val_if_fail (G_VALUE_HOLDS_LONG (value
), 0);
860 return value
->data
[0].v_long
;
865 * @value: a valid #GValue of type %G_TYPE_ULONG
866 * @v_ulong: unsigned long integer value to be set
868 * Set the contents of a %G_TYPE_ULONG #GValue to @v_ulong.
871 g_value_set_ulong (GValue
*value
,
874 g_return_if_fail (G_VALUE_HOLDS_ULONG (value
));
876 value
->data
[0].v_ulong
= v_ulong
;
881 * @value: a valid #GValue of type %G_TYPE_ULONG
883 * Get the contents of a %G_TYPE_ULONG #GValue.
885 * Returns: unsigned long integer contents of @value
888 g_value_get_ulong (const GValue
*value
)
890 g_return_val_if_fail (G_VALUE_HOLDS_ULONG (value
), 0);
892 return value
->data
[0].v_ulong
;
897 * @value: a valid #GValue of type %G_TYPE_INT64
899 * Get the contents of a %G_TYPE_INT64 #GValue.
901 * Returns: 64bit integer contents of @value
904 g_value_set_int64 (GValue
*value
,
907 g_return_if_fail (G_VALUE_HOLDS_INT64 (value
));
909 value
->data
[0].v_int64
= v_int64
;
914 * @value: a valid #GValue of type %G_TYPE_INT64
915 * @v_int64: 64bit integer value to be set
917 * Set the contents of a %G_TYPE_INT64 #GValue to @v_int64.
920 g_value_get_int64 (const GValue
*value
)
922 g_return_val_if_fail (G_VALUE_HOLDS_INT64 (value
), 0);
924 return value
->data
[0].v_int64
;
928 * g_value_set_uint64:
929 * @value: a valid #GValue of type %G_TYPE_UINT64
930 * @v_uint64: unsigned 64bit integer value to be set
932 * Set the contents of a %G_TYPE_UINT64 #GValue to @v_uint64.
935 g_value_set_uint64 (GValue
*value
,
938 g_return_if_fail (G_VALUE_HOLDS_UINT64 (value
));
940 value
->data
[0].v_uint64
= v_uint64
;
944 * g_value_get_uint64:
945 * @value: a valid #GValue of type %G_TYPE_UINT64
947 * Get the contents of a %G_TYPE_UINT64 #GValue.
949 * Returns: unsigned 64bit integer contents of @value
952 g_value_get_uint64 (const GValue
*value
)
954 g_return_val_if_fail (G_VALUE_HOLDS_UINT64 (value
), 0);
956 return value
->data
[0].v_uint64
;
961 * @value: a valid #GValue of type %G_TYPE_FLOAT
962 * @v_float: float value to be set
964 * Set the contents of a %G_TYPE_FLOAT #GValue to @v_float.
967 g_value_set_float (GValue
*value
,
970 g_return_if_fail (G_VALUE_HOLDS_FLOAT (value
));
972 value
->data
[0].v_float
= v_float
;
977 * @value: a valid #GValue of type %G_TYPE_FLOAT
979 * Get the contents of a %G_TYPE_FLOAT #GValue.
981 * Returns: float contents of @value
984 g_value_get_float (const GValue
*value
)
986 g_return_val_if_fail (G_VALUE_HOLDS_FLOAT (value
), 0);
988 return value
->data
[0].v_float
;
992 * g_value_set_double:
993 * @value: a valid #GValue of type %G_TYPE_DOUBLE
994 * @v_double: double value to be set
996 * Set the contents of a %G_TYPE_DOUBLE #GValue to @v_double.
999 g_value_set_double (GValue
*value
,
1002 g_return_if_fail (G_VALUE_HOLDS_DOUBLE (value
));
1004 value
->data
[0].v_double
= v_double
;
1008 * g_value_get_double:
1009 * @value: a valid #GValue of type %G_TYPE_DOUBLE
1011 * Get the contents of a %G_TYPE_DOUBLE #GValue.
1013 * Returns: double contents of @value
1016 g_value_get_double (const GValue
*value
)
1018 g_return_val_if_fail (G_VALUE_HOLDS_DOUBLE (value
), 0);
1020 return value
->data
[0].v_double
;
1024 * g_value_set_string:
1025 * @value: a valid #GValue of type %G_TYPE_STRING
1026 * @v_string: (nullable): caller-owned string to be duplicated for the #GValue
1028 * Set the contents of a %G_TYPE_STRING #GValue to @v_string.
1031 g_value_set_string (GValue
*value
,
1032 const gchar
*v_string
)
1036 g_return_if_fail (G_VALUE_HOLDS_STRING (value
));
1038 new_val
= g_strdup (v_string
);
1040 if (value
->data
[1].v_uint
& G_VALUE_NOCOPY_CONTENTS
)
1041 value
->data
[1].v_uint
= 0;
1043 g_free (value
->data
[0].v_pointer
);
1045 value
->data
[0].v_pointer
= new_val
;
1049 * g_value_set_static_string:
1050 * @value: a valid #GValue of type %G_TYPE_STRING
1051 * @v_string: (nullable): static string to be set
1053 * Set the contents of a %G_TYPE_STRING #GValue to @v_string.
1054 * The string is assumed to be static, and is thus not duplicated
1055 * when setting the #GValue.
1058 g_value_set_static_string (GValue
*value
,
1059 const gchar
*v_string
)
1061 g_return_if_fail (G_VALUE_HOLDS_STRING (value
));
1063 if (!(value
->data
[1].v_uint
& G_VALUE_NOCOPY_CONTENTS
))
1064 g_free (value
->data
[0].v_pointer
);
1065 value
->data
[1].v_uint
= G_VALUE_NOCOPY_CONTENTS
;
1066 value
->data
[0].v_pointer
= (gchar
*) v_string
;
1070 * g_value_set_string_take_ownership:
1071 * @value: a valid #GValue of type %G_TYPE_STRING
1072 * @v_string: (nullable): duplicated unowned string to be set
1074 * This is an internal function introduced mainly for C marshallers.
1076 * Deprecated: 2.4: Use g_value_take_string() instead.
1079 g_value_set_string_take_ownership (GValue
*value
,
1082 g_value_take_string (value
, v_string
);
1086 * g_value_take_string:
1087 * @value: a valid #GValue of type %G_TYPE_STRING
1088 * @v_string: (nullable): string to take ownership of
1090 * Sets the contents of a %G_TYPE_STRING #GValue to @v_string.
1095 g_value_take_string (GValue
*value
,
1098 g_return_if_fail (G_VALUE_HOLDS_STRING (value
));
1100 if (value
->data
[1].v_uint
& G_VALUE_NOCOPY_CONTENTS
)
1101 value
->data
[1].v_uint
= 0;
1103 g_free (value
->data
[0].v_pointer
);
1104 value
->data
[0].v_pointer
= v_string
;
1108 * g_value_get_string:
1109 * @value: a valid #GValue of type %G_TYPE_STRING
1111 * Get the contents of a %G_TYPE_STRING #GValue.
1113 * Returns: string content of @value
1116 g_value_get_string (const GValue
*value
)
1118 g_return_val_if_fail (G_VALUE_HOLDS_STRING (value
), NULL
);
1120 return value
->data
[0].v_pointer
;
1124 * g_value_dup_string:
1125 * @value: a valid #GValue of type %G_TYPE_STRING
1127 * Get a copy the contents of a %G_TYPE_STRING #GValue.
1129 * Returns: a newly allocated copy of the string content of @value
1132 g_value_dup_string (const GValue
*value
)
1134 g_return_val_if_fail (G_VALUE_HOLDS_STRING (value
), NULL
);
1136 return g_strdup (value
->data
[0].v_pointer
);
1140 * g_value_set_pointer:
1141 * @value: a valid #GValue of %G_TYPE_POINTER
1142 * @v_pointer: pointer value to be set
1144 * Set the contents of a pointer #GValue to @v_pointer.
1147 g_value_set_pointer (GValue
*value
,
1150 g_return_if_fail (G_VALUE_HOLDS_POINTER (value
));
1152 value
->data
[0].v_pointer
= v_pointer
;
1156 * g_value_get_pointer:
1157 * @value: a valid #GValue of %G_TYPE_POINTER
1159 * Get the contents of a pointer #GValue.
1161 * Returns: (transfer none): pointer contents of @value
1164 g_value_get_pointer (const GValue
*value
)
1166 g_return_val_if_fail (G_VALUE_HOLDS_POINTER (value
), NULL
);
1168 return value
->data
[0].v_pointer
;
1171 G_DEFINE_POINTER_TYPE (GType
, g_gtype
)
1174 * g_value_set_gtype:
1175 * @value: a valid #GValue of type %G_TYPE_GTYPE
1176 * @v_gtype: #GType to be set
1178 * Set the contents of a %G_TYPE_GTYPE #GValue to @v_gtype.
1183 g_value_set_gtype (GValue
*value
,
1186 g_return_if_fail (G_VALUE_HOLDS_GTYPE (value
));
1188 value
->data
[0].v_pointer
= GSIZE_TO_POINTER (v_gtype
);
1193 * g_value_get_gtype:
1194 * @value: a valid #GValue of type %G_TYPE_GTYPE
1196 * Get the contents of a %G_TYPE_GTYPE #GValue.
1200 * Returns: the #GType stored in @value
1203 g_value_get_gtype (const GValue
*value
)
1205 g_return_val_if_fail (G_VALUE_HOLDS_GTYPE (value
), 0);
1207 return GPOINTER_TO_SIZE (value
->data
[0].v_pointer
);
1211 * g_value_set_variant:
1212 * @value: a valid #GValue of type %G_TYPE_VARIANT
1213 * @variant: (nullable): a #GVariant, or %NULL
1215 * Set the contents of a variant #GValue to @variant.
1216 * If the variant is floating, it is consumed.
1221 g_value_set_variant (GValue
*value
,
1224 GVariant
*old_variant
;
1226 g_return_if_fail (G_VALUE_HOLDS_VARIANT (value
));
1228 old_variant
= value
->data
[0].v_pointer
;
1231 value
->data
[0].v_pointer
= g_variant_ref_sink (variant
);
1233 value
->data
[0].v_pointer
= NULL
;
1236 g_variant_unref (old_variant
);
1240 * g_value_take_variant:
1241 * @value: a valid #GValue of type %G_TYPE_VARIANT
1242 * @variant: (nullable) (transfer full): a #GVariant, or %NULL
1244 * Set the contents of a variant #GValue to @variant, and takes over
1245 * the ownership of the caller's reference to @variant;
1246 * the caller doesn't have to unref it any more (i.e. the reference
1247 * count of the variant is not increased).
1249 * If @variant was floating then its floating reference is converted to
1252 * If you want the #GValue to hold its own reference to @variant, use
1253 * g_value_set_variant() instead.
1255 * This is an internal function introduced mainly for C marshallers.
1260 g_value_take_variant (GValue
*value
,
1263 GVariant
*old_variant
;
1265 g_return_if_fail (G_VALUE_HOLDS_VARIANT (value
));
1267 old_variant
= value
->data
[0].v_pointer
;
1270 value
->data
[0].v_pointer
= g_variant_take_ref (variant
);
1272 value
->data
[0].v_pointer
= NULL
;
1275 g_variant_unref (old_variant
);
1279 * g_value_get_variant:
1280 * @value: a valid #GValue of type %G_TYPE_VARIANT
1282 * Get the contents of a variant #GValue.
1284 * Returns: variant contents of @value
1289 g_value_get_variant (const GValue
*value
)
1291 g_return_val_if_fail (G_VALUE_HOLDS_VARIANT (value
), NULL
);
1293 return value
->data
[0].v_pointer
;
1297 * g_value_dup_variant:
1298 * @value: a valid #GValue of type %G_TYPE_VARIANT
1300 * Get the contents of a variant #GValue, increasing its refcount.
1302 * Returns: variant contents of @value, should be unrefed using
1303 * g_variant_unref() when no longer needed
1308 g_value_dup_variant (const GValue
*value
)
1312 g_return_val_if_fail (G_VALUE_HOLDS_VARIANT (value
), NULL
);
1314 variant
= value
->data
[0].v_pointer
;
1316 g_variant_ref_sink (variant
);
1322 * g_strdup_value_contents:
1323 * @value: #GValue which contents are to be described.
1325 * Return a newly allocated string, which describes the contents of a
1326 * #GValue. The main purpose of this function is to describe #GValue
1327 * contents for debugging output, the way in which the contents are
1328 * described may change between different GLib versions.
1330 * Returns: Newly allocated string.
1333 g_strdup_value_contents (const GValue
*value
)
1338 g_return_val_if_fail (G_IS_VALUE (value
), NULL
);
1340 if (G_VALUE_HOLDS_STRING (value
))
1342 src
= g_value_get_string (value
);
1345 contents
= g_strdup ("NULL");
1348 gchar
*s
= g_strescape (src
, NULL
);
1350 contents
= g_strdup_printf ("\"%s\"", s
);
1354 else if (g_value_type_transformable (G_VALUE_TYPE (value
), G_TYPE_STRING
))
1356 GValue tmp_value
= G_VALUE_INIT
;
1359 g_value_init (&tmp_value
, G_TYPE_STRING
);
1360 g_value_transform (value
, &tmp_value
);
1361 s
= g_strescape (g_value_get_string (&tmp_value
), NULL
);
1362 g_value_unset (&tmp_value
);
1363 if (G_VALUE_HOLDS_ENUM (value
) || G_VALUE_HOLDS_FLAGS (value
))
1364 contents
= g_strdup_printf ("((%s) %s)",
1365 g_type_name (G_VALUE_TYPE (value
)),
1368 contents
= g_strdup (s
? s
: "NULL");
1371 else if (g_value_fits_pointer (value
))
1373 gpointer p
= g_value_peek_pointer (value
);
1376 contents
= g_strdup ("NULL");
1377 else if (G_VALUE_HOLDS_OBJECT (value
))
1378 contents
= g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p
), p
);
1379 else if (G_VALUE_HOLDS_PARAM (value
))
1380 contents
= g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p
), p
);
1381 else if (G_VALUE_HOLDS (value
, G_TYPE_STRV
))
1383 GStrv strv
= g_value_get_boxed (value
);
1384 GString
*tmp
= g_string_new ("[");
1386 while (*strv
!= NULL
)
1388 gchar
*escaped
= g_strescape (*strv
, NULL
);
1390 g_string_append_printf (tmp
, "\"%s\"", escaped
);
1393 if (*++strv
!= NULL
)
1394 g_string_append (tmp
, ", ");
1397 g_string_append (tmp
, "]");
1398 contents
= g_string_free (tmp
, FALSE
);
1400 else if (G_VALUE_HOLDS_BOXED (value
))
1401 contents
= g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value
)), p
);
1402 else if (G_VALUE_HOLDS_POINTER (value
))
1403 contents
= g_strdup_printf ("((gpointer) %p)", p
);
1405 contents
= g_strdup ("???");
1408 contents
= g_strdup ("???");
1414 * g_pointer_type_register_static:
1415 * @name: the name of the new pointer type.
1417 * Creates a new %G_TYPE_POINTER derived type id for a new
1418 * pointer type with name @name.
1420 * Returns: a new %G_TYPE_POINTER derived type id for @name.
1423 g_pointer_type_register_static (const gchar
*name
)
1425 const GTypeInfo type_info
= {
1427 NULL
, /* base_init */
1428 NULL
, /* base_finalize */
1429 NULL
, /* class_init */
1430 NULL
, /* class_finalize */
1431 NULL
, /* class_data */
1432 0, /* instance_size */
1433 0, /* n_preallocs */
1434 NULL
, /* instance_init */
1435 NULL
/* value_table */
1439 g_return_val_if_fail (name
!= NULL
, 0);
1440 g_return_val_if_fail (g_type_from_name (name
) == 0, 0);
1442 type
= g_type_register_static (G_TYPE_POINTER
, name
, &type_info
, 0);