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 "gvaluetypes.h"
21 #include "gvaluecollector.h"
25 /* --- value functions --- */
27 value_long0_init (GValue
*value
)
29 value
->data
[0].v_long
= 0;
33 value_long0_copy (const GValue
*src_value
,
36 dest_value
->data
[0].v_long
= src_value
->data
[0].v_long
;
40 value_char_lcopy_value (const GValue
*value
,
43 GTypeCValue
*collect_value
)
45 gint8
*int8_p
= collect_value
->v_pointer
;
48 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
50 *int8_p
= value
->data
[0].v_int
;
57 value_boolean_lcopy_value (const GValue
*value
,
60 GTypeCValue
*collect_value
)
62 gboolean
*bool_p
= collect_value
->v_pointer
;
65 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
67 *bool_p
= value
->data
[0].v_int
;
74 value_int_collect_value (GValue
*value
,
77 GTypeCValue
*collect_value
)
79 value
->data
[0].v_int
= collect_value
->v_int
;
86 value_int_lcopy_value (const GValue
*value
,
89 GTypeCValue
*collect_value
)
91 gint
*int_p
= collect_value
->v_pointer
;
94 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
96 *int_p
= value
->data
[0].v_int
;
103 value_long_collect_value (GValue
*value
,
106 GTypeCValue
*collect_value
)
108 value
->data
[0].v_long
= collect_value
->v_long
;
115 value_long_lcopy_value (const GValue
*value
,
118 GTypeCValue
*collect_value
)
120 glong
*long_p
= collect_value
->v_pointer
;
123 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
125 *long_p
= value
->data
[0].v_long
;
132 value_float_init (GValue
*value
)
134 value
->data
[0].v_float
= 0.0;
138 value_float_copy (const GValue
*src_value
,
141 dest_value
->data
[0].v_float
= src_value
->data
[0].v_float
;
145 value_float_collect_value (GValue
*value
,
148 GTypeCValue
*collect_value
)
150 value
->data
[0].v_float
= collect_value
->v_double
;
157 value_float_lcopy_value (const GValue
*value
,
160 GTypeCValue
*collect_value
)
162 gfloat
*float_p
= collect_value
->v_pointer
;
165 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
167 *float_p
= value
->data
[0].v_float
;
174 value_double_init (GValue
*value
)
176 value
->data
[0].v_double
= 0.0;
180 value_double_copy (const GValue
*src_value
,
183 dest_value
->data
[0].v_double
= src_value
->data
[0].v_double
;
187 value_double_collect_value (GValue
*value
,
190 GTypeCValue
*collect_value
)
192 value
->data
[0].v_double
= collect_value
->v_double
;
199 value_double_lcopy_value (const GValue
*value
,
202 GTypeCValue
*collect_value
)
204 gdouble
*double_p
= collect_value
->v_pointer
;
207 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
209 *double_p
= value
->data
[0].v_double
;
216 value_string_init (GValue
*value
)
218 value
->data
[0].v_pointer
= NULL
;
222 value_string_free_value (GValue
*value
)
224 if (!(value
->data
[1].v_uint
& G_VALUE_STATIC_TAG
))
225 g_free (value
->data
[0].v_pointer
);
229 value_string_copy_value (const GValue
*src_value
,
232 dest_value
->data
[0].v_pointer
= g_strdup (src_value
->data
[0].v_pointer
);
236 value_string_collect_value (GValue
*value
,
239 GTypeCValue
*collect_value
)
241 value
->data
[0].v_pointer
= g_strdup (collect_value
->v_pointer
);
248 value_string_lcopy_value (const GValue
*value
,
251 GTypeCValue
*collect_value
)
253 gchar
**string_p
= collect_value
->v_pointer
;
256 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
258 *string_p
= g_strdup (value
->data
[0].v_pointer
);
265 value_pointer_init (GValue
*value
)
267 value
->data
[0].v_pointer
= 0;
271 value_pointer_copy (const GValue
*src_value
,
274 dest_value
->data
[0].v_pointer
= src_value
->data
[0].v_pointer
;
278 value_pointer_peek_pointer (const GValue
*value
)
280 return value
->data
[0].v_pointer
;
284 value_pointer_collect_value (GValue
*value
,
287 GTypeCValue
*collect_value
)
289 value
->data
[0].v_pointer
= collect_value
->v_pointer
;
296 value_pointer_lcopy_value (const GValue
*value
,
299 GTypeCValue
*collect_value
)
301 gpointer
*pointer_p
= collect_value
->v_pointer
;
304 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value
));
306 *pointer_p
= value
->data
[0].v_pointer
;
313 /* --- type initialization --- */
315 g_value_types_init (void) /* sync with gtype.c */
319 NULL
, /* base_init */
320 NULL
, /* base_destroy */
321 NULL
, /* class_init */
322 NULL
, /* class_destroy */
323 NULL
, /* class_data */
324 0, /* instance_size */
326 NULL
, /* instance_init */
327 NULL
, /* value_table */
329 const GTypeFundamentalInfo finfo
= { G_TYPE_FLAG_DERIVABLE
, };
332 /* G_TYPE_CHAR / G_TYPE_UCHAR
335 static const GTypeValueTable value_table
= {
336 value_long0_init
, /* value_init */
337 NULL
, /* value_free */
338 value_long0_copy
, /* value_copy */
339 NULL
, /* value_peek_pointer */
340 G_VALUE_COLLECT_INT
, /* collect_type */
341 value_int_collect_value
, /* collect_value */
342 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
343 value_char_lcopy_value
, /* lcopy_value */
345 info
.value_table
= &value_table
;
346 type
= g_type_register_fundamental (G_TYPE_CHAR
, "gchar", &info
, &finfo
, 0);
347 g_assert (type
== G_TYPE_CHAR
);
348 type
= g_type_register_fundamental (G_TYPE_UCHAR
, "guchar", &info
, &finfo
, 0);
349 g_assert (type
== G_TYPE_UCHAR
);
355 static const GTypeValueTable value_table
= {
356 value_long0_init
, /* value_init */
357 NULL
, /* value_free */
358 value_long0_copy
, /* value_copy */
359 NULL
, /* value_peek_pointer */
360 G_VALUE_COLLECT_INT
, /* collect_type */
361 value_int_collect_value
, /* collect_value */
362 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
363 value_boolean_lcopy_value
, /* lcopy_value */
365 info
.value_table
= &value_table
;
366 type
= g_type_register_fundamental (G_TYPE_BOOLEAN
, "gboolean", &info
, &finfo
, 0);
367 g_assert (type
== G_TYPE_BOOLEAN
);
370 /* G_TYPE_INT / G_TYPE_UINT
373 static const GTypeValueTable value_table
= {
374 value_long0_init
, /* value_init */
375 NULL
, /* value_free */
376 value_long0_copy
, /* value_copy */
377 NULL
, /* value_peek_pointer */
378 G_VALUE_COLLECT_INT
, /* collect_type */
379 value_int_collect_value
, /* collect_value */
380 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
381 value_int_lcopy_value
, /* lcopy_value */
383 info
.value_table
= &value_table
;
384 type
= g_type_register_fundamental (G_TYPE_INT
, "gint", &info
, &finfo
, 0);
385 g_assert (type
== G_TYPE_INT
);
386 type
= g_type_register_fundamental (G_TYPE_UINT
, "guint", &info
, &finfo
, 0);
387 g_assert (type
== G_TYPE_UINT
);
390 /* G_TYPE_LONG / G_TYPE_ULONG
393 static const GTypeValueTable value_table
= {
394 value_long0_init
, /* value_init */
395 NULL
, /* value_free */
396 value_long0_copy
, /* value_copy */
397 NULL
, /* value_peek_pointer */
398 G_VALUE_COLLECT_LONG
, /* collect_type */
399 value_long_collect_value
, /* collect_value */
400 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
401 value_long_lcopy_value
, /* lcopy_value */
403 info
.value_table
= &value_table
;
404 type
= g_type_register_fundamental (G_TYPE_LONG
, "glong", &info
, &finfo
, 0);
405 g_assert (type
== G_TYPE_LONG
);
406 type
= g_type_register_fundamental (G_TYPE_ULONG
, "gulong", &info
, &finfo
, 0);
407 g_assert (type
== G_TYPE_ULONG
);
413 static const GTypeValueTable value_table
= {
414 value_float_init
, /* value_init */
415 NULL
, /* value_free */
416 value_float_copy
, /* value_copy */
417 NULL
, /* value_peek_pointer */
418 G_VALUE_COLLECT_DOUBLE
, /* collect_type */
419 value_float_collect_value
, /* collect_value */
420 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
421 value_float_lcopy_value
, /* lcopy_value */
423 info
.value_table
= &value_table
;
424 type
= g_type_register_fundamental (G_TYPE_FLOAT
, "gfloat", &info
, &finfo
, 0);
425 g_assert (type
== G_TYPE_FLOAT
);
431 static const GTypeValueTable value_table
= {
432 value_double_init
, /* value_init */
433 NULL
, /* value_free */
434 value_double_copy
, /* value_copy */
435 NULL
, /* value_peek_pointer */
436 G_VALUE_COLLECT_DOUBLE
, /* collect_type */
437 value_double_collect_value
, /* collect_value */
438 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
439 value_double_lcopy_value
, /* lcopy_value */
441 info
.value_table
= &value_table
;
442 type
= g_type_register_fundamental (G_TYPE_DOUBLE
, "gdouble", &info
, &finfo
, 0);
443 g_assert (type
== G_TYPE_DOUBLE
);
449 static const GTypeValueTable value_table
= {
450 value_string_init
, /* value_init */
451 value_string_free_value
, /* value_free */
452 value_string_copy_value
, /* value_copy */
453 value_pointer_peek_pointer
, /* value_peek_pointer */
454 G_VALUE_COLLECT_POINTER
, /* collect_type */
455 value_string_collect_value
, /* collect_value */
456 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
457 value_string_lcopy_value
, /* lcopy_value */
459 info
.value_table
= &value_table
;
460 type
= g_type_register_fundamental (G_TYPE_STRING
, "gstring", &info
, &finfo
, 0);
461 g_assert (type
== G_TYPE_STRING
);
467 static const GTypeValueTable value_table
= {
468 value_pointer_init
, /* value_init */
469 NULL
, /* value_free */
470 value_pointer_copy
, /* value_copy */
471 value_pointer_peek_pointer
, /* value_peek_pointer */
472 G_VALUE_COLLECT_POINTER
, /* collect_type */
473 value_pointer_collect_value
, /* collect_value */
474 G_VALUE_COLLECT_POINTER
, /* lcopy_type */
475 value_pointer_lcopy_value
, /* lcopy_value */
477 info
.value_table
= &value_table
;
478 type
= g_type_register_fundamental (G_TYPE_POINTER
, "gpointer", &info
, &finfo
, 0);
479 g_assert (type
== G_TYPE_POINTER
);
484 /* --- GValue functions --- */
486 g_value_set_char (GValue
*value
,
489 g_return_if_fail (G_IS_VALUE_CHAR (value
));
491 value
->data
[0].v_int
= v_char
;
495 g_value_get_char (const GValue
*value
)
497 g_return_val_if_fail (G_IS_VALUE_CHAR (value
), 0);
499 return value
->data
[0].v_int
;
503 g_value_set_uchar (GValue
*value
,
506 g_return_if_fail (G_IS_VALUE_UCHAR (value
));
508 value
->data
[0].v_uint
= v_uchar
;
512 g_value_get_uchar (const GValue
*value
)
514 g_return_val_if_fail (G_IS_VALUE_UCHAR (value
), 0);
516 return value
->data
[0].v_uint
;
520 g_value_set_boolean (GValue
*value
,
523 g_return_if_fail (G_IS_VALUE_BOOLEAN (value
));
525 value
->data
[0].v_int
= v_boolean
;
529 g_value_get_boolean (const GValue
*value
)
531 g_return_val_if_fail (G_IS_VALUE_BOOLEAN (value
), 0);
533 return value
->data
[0].v_int
;
537 g_value_set_int (GValue
*value
,
540 g_return_if_fail (G_IS_VALUE_INT (value
));
542 value
->data
[0].v_int
= v_int
;
546 g_value_get_int (const GValue
*value
)
548 g_return_val_if_fail (G_IS_VALUE_INT (value
), 0);
550 return value
->data
[0].v_int
;
554 g_value_set_uint (GValue
*value
,
557 g_return_if_fail (G_IS_VALUE_UINT (value
));
559 value
->data
[0].v_uint
= v_uint
;
563 g_value_get_uint (const GValue
*value
)
565 g_return_val_if_fail (G_IS_VALUE_UINT (value
), 0);
567 return value
->data
[0].v_uint
;
571 g_value_set_long (GValue
*value
,
574 g_return_if_fail (G_IS_VALUE_LONG (value
));
576 value
->data
[0].v_long
= v_long
;
580 g_value_get_long (const GValue
*value
)
582 g_return_val_if_fail (G_IS_VALUE_LONG (value
), 0);
584 return value
->data
[0].v_long
;
588 g_value_set_ulong (GValue
*value
,
591 g_return_if_fail (G_IS_VALUE_ULONG (value
));
593 value
->data
[0].v_ulong
= v_ulong
;
597 g_value_get_ulong (const GValue
*value
)
599 g_return_val_if_fail (G_IS_VALUE_ULONG (value
), 0);
601 return value
->data
[0].v_ulong
;
605 g_value_set_float (GValue
*value
,
608 g_return_if_fail (G_IS_VALUE_FLOAT (value
));
610 value
->data
[0].v_float
= v_float
;
614 g_value_get_float (const GValue
*value
)
616 g_return_val_if_fail (G_IS_VALUE_FLOAT (value
), 0);
618 return value
->data
[0].v_float
;
622 g_value_set_double (GValue
*value
,
625 g_return_if_fail (G_IS_VALUE_DOUBLE (value
));
627 value
->data
[0].v_double
= v_double
;
631 g_value_get_double (const GValue
*value
)
633 g_return_val_if_fail (G_IS_VALUE_DOUBLE (value
), 0);
635 return value
->data
[0].v_double
;
639 g_value_set_string (GValue
*value
,
640 const gchar
*v_string
)
642 g_return_if_fail (G_IS_VALUE_STRING (value
));
644 if (value
->data
[1].v_uint
& G_VALUE_STATIC_TAG
)
645 value
->data
[1].v_uint
= 0;
647 g_free (value
->data
[0].v_pointer
);
648 value
->data
[0].v_pointer
= g_strdup (v_string
);
652 g_value_set_static_string (GValue
*value
,
653 const gchar
*v_string
)
655 g_return_if_fail (G_IS_VALUE_STRING (value
));
657 if (!(value
->data
[1].v_uint
& G_VALUE_STATIC_TAG
))
658 g_free (value
->data
[0].v_pointer
);
659 value
->data
[1].v_uint
= G_VALUE_STATIC_TAG
;
660 value
->data
[0].v_pointer
= (gchar
*) v_string
;
664 g_value_get_string (const GValue
*value
)
666 g_return_val_if_fail (G_IS_VALUE_STRING (value
), NULL
);
668 return value
->data
[0].v_pointer
;
672 g_value_dup_string (const GValue
*value
)
674 g_return_val_if_fail (G_IS_VALUE_STRING (value
), NULL
);
676 return g_strdup (value
->data
[0].v_pointer
);
680 g_value_set_pointer (GValue
*value
,
683 g_return_if_fail (G_IS_VALUE_POINTER (value
));
685 value
->data
[0].v_pointer
= v_pointer
;
689 g_value_get_pointer (const GValue
*value
)
691 g_return_val_if_fail (G_IS_VALUE_POINTER (value
), NULL
);
693 return value
->data
[0].v_pointer
;