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 g_free (value->data[0].v_pointer);
228 value_string_copy_value (const GValue *src_value,
231 dest_value->data[0].v_pointer = g_strdup (src_value->data[0].v_pointer);
235 value_string_collect_value (GValue *value,
238 GTypeCValue *collect_value)
240 value->data[0].v_pointer = g_strdup (collect_value->v_pointer);
247 value_string_lcopy_value (const GValue *value,
250 GTypeCValue *collect_value)
252 gchar **string_p = collect_value->v_pointer;
255 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
257 *string_p = g_strdup (value->data[0].v_pointer);
264 value_pointer_init (GValue *value)
266 value->data[0].v_pointer = 0;
270 value_pointer_copy (const GValue *src_value,
273 dest_value->data[0].v_pointer = src_value->data[0].v_pointer;
277 value_pointer_peek_pointer (const GValue *value)
279 return value->data[0].v_pointer;
283 value_pointer_collect_value (GValue *value,
286 GTypeCValue *collect_value)
288 value->data[0].v_pointer = collect_value->v_pointer;
295 value_pointer_lcopy_value (const GValue *value,
298 GTypeCValue *collect_value)
300 gpointer *pointer_p = collect_value->v_pointer;
303 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
305 *pointer_p = value->data[0].v_pointer;
312 /* --- type initialization --- */
314 g_value_types_init (void) /* sync with gtype.c */
318 NULL, /* base_init */
319 NULL, /* base_destroy */
320 NULL, /* class_init */
321 NULL, /* class_destroy */
322 NULL, /* class_data */
323 0, /* instance_size */
325 NULL, /* instance_init */
326 NULL, /* value_table */
328 const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
331 /* G_TYPE_CHAR / G_TYPE_UCHAR
334 static const GTypeValueTable value_table = {
335 value_long0_init, /* value_init */
336 NULL, /* value_free */
337 value_long0_copy, /* value_copy */
338 NULL, /* value_peek_pointer */
339 G_VALUE_COLLECT_INT, /* collect_type */
340 value_int_collect_value, /* collect_value */
341 G_VALUE_COLLECT_POINTER, /* lcopy_type */
342 value_char_lcopy_value, /* lcopy_value */
344 info.value_table = &value_table;
345 type = g_type_register_fundamental (G_TYPE_CHAR, "gchar", &info, &finfo, 0);
346 g_assert (type == G_TYPE_CHAR);
347 type = g_type_register_fundamental (G_TYPE_UCHAR, "guchar", &info, &finfo, 0);
348 g_assert (type == G_TYPE_UCHAR);
354 static const GTypeValueTable value_table = {
355 value_long0_init, /* value_init */
356 NULL, /* value_free */
357 value_long0_copy, /* value_copy */
358 NULL, /* value_peek_pointer */
359 G_VALUE_COLLECT_INT, /* collect_type */
360 value_int_collect_value, /* collect_value */
361 G_VALUE_COLLECT_POINTER, /* lcopy_type */
362 value_boolean_lcopy_value, /* lcopy_value */
364 info.value_table = &value_table;
365 type = g_type_register_fundamental (G_TYPE_BOOLEAN, "gboolean", &info, &finfo, 0);
366 g_assert (type == G_TYPE_BOOLEAN);
369 /* G_TYPE_INT / G_TYPE_UINT
372 static const GTypeValueTable value_table = {
373 value_long0_init, /* value_init */
374 NULL, /* value_free */
375 value_long0_copy, /* value_copy */
376 NULL, /* value_peek_pointer */
377 G_VALUE_COLLECT_INT, /* collect_type */
378 value_int_collect_value, /* collect_value */
379 G_VALUE_COLLECT_POINTER, /* lcopy_type */
380 value_int_lcopy_value, /* lcopy_value */
382 info.value_table = &value_table;
383 type = g_type_register_fundamental (G_TYPE_INT, "gint", &info, &finfo, 0);
384 g_assert (type == G_TYPE_INT);
385 type = g_type_register_fundamental (G_TYPE_UINT, "guint", &info, &finfo, 0);
386 g_assert (type == G_TYPE_UINT);
389 /* G_TYPE_LONG / G_TYPE_ULONG
392 static const GTypeValueTable value_table = {
393 value_long0_init, /* value_init */
394 NULL, /* value_free */
395 value_long0_copy, /* value_copy */
396 NULL, /* value_peek_pointer */
397 G_VALUE_COLLECT_LONG, /* collect_type */
398 value_long_collect_value, /* collect_value */
399 G_VALUE_COLLECT_POINTER, /* lcopy_type */
400 value_long_lcopy_value, /* lcopy_value */
402 info.value_table = &value_table;
403 type = g_type_register_fundamental (G_TYPE_LONG, "glong", &info, &finfo, 0);
404 g_assert (type == G_TYPE_LONG);
405 type = g_type_register_fundamental (G_TYPE_ULONG, "gulong", &info, &finfo, 0);
406 g_assert (type == G_TYPE_ULONG);
412 static const GTypeValueTable value_table = {
413 value_float_init, /* value_init */
414 NULL, /* value_free */
415 value_float_copy, /* value_copy */
416 NULL, /* value_peek_pointer */
417 G_VALUE_COLLECT_DOUBLE, /* collect_type */
418 value_float_collect_value, /* collect_value */
419 G_VALUE_COLLECT_POINTER, /* lcopy_type */
420 value_float_lcopy_value, /* lcopy_value */
422 info.value_table = &value_table;
423 type = g_type_register_fundamental (G_TYPE_FLOAT, "gfloat", &info, &finfo, 0);
424 g_assert (type == G_TYPE_FLOAT);
430 static const GTypeValueTable value_table = {
431 value_double_init, /* value_init */
432 NULL, /* value_free */
433 value_double_copy, /* value_copy */
434 NULL, /* value_peek_pointer */
435 G_VALUE_COLLECT_DOUBLE, /* collect_type */
436 value_double_collect_value, /* collect_value */
437 G_VALUE_COLLECT_POINTER, /* lcopy_type */
438 value_double_lcopy_value, /* lcopy_value */
440 info.value_table = &value_table;
441 type = g_type_register_fundamental (G_TYPE_DOUBLE, "gdouble", &info, &finfo, 0);
442 g_assert (type == G_TYPE_DOUBLE);
448 static const GTypeValueTable value_table = {
449 value_string_init, /* value_init */
450 value_string_free_value, /* value_free */
451 value_string_copy_value, /* value_copy */
452 value_pointer_peek_pointer, /* value_peek_pointer */
453 G_VALUE_COLLECT_POINTER, /* collect_type */
454 value_string_collect_value, /* collect_value */
455 G_VALUE_COLLECT_POINTER, /* lcopy_type */
456 value_string_lcopy_value, /* lcopy_value */
458 info.value_table = &value_table;
459 type = g_type_register_fundamental (G_TYPE_STRING, "gstring", &info, &finfo, 0);
460 g_assert (type == G_TYPE_STRING);
466 static const GTypeValueTable value_table = {
467 value_pointer_init, /* value_init */
468 NULL, /* value_free */
469 value_pointer_copy, /* value_copy */
470 value_pointer_peek_pointer, /* value_peek_pointer */
471 G_VALUE_COLLECT_POINTER, /* collect_type */
472 value_pointer_collect_value, /* collect_value */
473 G_VALUE_COLLECT_POINTER, /* lcopy_type */
474 value_pointer_lcopy_value, /* lcopy_value */
476 info.value_table = &value_table;
477 type = g_type_register_fundamental (G_TYPE_POINTER, "gpointer", &info, &finfo, 0);
478 g_assert (type == G_TYPE_POINTER);
483 /* --- GValue functions --- */
485 g_value_set_char (GValue *value,
488 g_return_if_fail (G_IS_VALUE_CHAR (value));
490 value->data[0].v_int = v_char;
494 g_value_get_char (const GValue *value)
496 g_return_val_if_fail (G_IS_VALUE_CHAR (value), 0);
498 return value->data[0].v_int;
502 g_value_set_uchar (GValue *value,
505 g_return_if_fail (G_IS_VALUE_UCHAR (value));
507 value->data[0].v_uint = v_uchar;
511 g_value_get_uchar (const GValue *value)
513 g_return_val_if_fail (G_IS_VALUE_UCHAR (value), 0);
515 return value->data[0].v_uint;
519 g_value_set_boolean (GValue *value,
522 g_return_if_fail (G_IS_VALUE_BOOLEAN (value));
524 value->data[0].v_int = v_boolean;
528 g_value_get_boolean (const GValue *value)
530 g_return_val_if_fail (G_IS_VALUE_BOOLEAN (value), 0);
532 return value->data[0].v_int;
536 g_value_set_int (GValue *value,
539 g_return_if_fail (G_IS_VALUE_INT (value));
541 value->data[0].v_int = v_int;
545 g_value_get_int (const GValue *value)
547 g_return_val_if_fail (G_IS_VALUE_INT (value), 0);
549 return value->data[0].v_int;
553 g_value_set_uint (GValue *value,
556 g_return_if_fail (G_IS_VALUE_UINT (value));
558 value->data[0].v_uint = v_uint;
562 g_value_get_uint (const GValue *value)
564 g_return_val_if_fail (G_IS_VALUE_UINT (value), 0);
566 return value->data[0].v_uint;
570 g_value_set_long (GValue *value,
573 g_return_if_fail (G_IS_VALUE_LONG (value));
575 value->data[0].v_long = v_long;
579 g_value_get_long (const GValue *value)
581 g_return_val_if_fail (G_IS_VALUE_LONG (value), 0);
583 return value->data[0].v_long;
587 g_value_set_ulong (GValue *value,
590 g_return_if_fail (G_IS_VALUE_ULONG (value));
592 value->data[0].v_ulong = v_ulong;
596 g_value_get_ulong (const GValue *value)
598 g_return_val_if_fail (G_IS_VALUE_ULONG (value), 0);
600 return value->data[0].v_ulong;
604 g_value_set_float (GValue *value,
607 g_return_if_fail (G_IS_VALUE_FLOAT (value));
609 value->data[0].v_float = v_float;
613 g_value_get_float (const GValue *value)
615 g_return_val_if_fail (G_IS_VALUE_FLOAT (value), 0);
617 return value->data[0].v_float;
621 g_value_set_double (GValue *value,
624 g_return_if_fail (G_IS_VALUE_DOUBLE (value));
626 value->data[0].v_double = v_double;
630 g_value_get_double (const GValue *value)
632 g_return_val_if_fail (G_IS_VALUE_DOUBLE (value), 0);
634 return value->data[0].v_double;
638 g_value_set_string (GValue *value,
639 const gchar *v_string)
641 g_return_if_fail (G_IS_VALUE_STRING (value));
643 g_free (value->data[0].v_pointer);
644 value->data[0].v_pointer = g_strdup (v_string);
648 g_value_get_string (const GValue *value)
650 g_return_val_if_fail (G_IS_VALUE_STRING (value), NULL);
652 return value->data[0].v_pointer;
656 g_value_dup_string (const GValue *value)
658 g_return_val_if_fail (G_IS_VALUE_STRING (value), NULL);
660 return g_strdup (value->data[0].v_pointer);
664 g_value_set_pointer (GValue *value,
667 g_return_if_fail (G_IS_VALUE_POINTER (value));
669 value->data[0].v_pointer = v_pointer;
673 g_value_get_pointer (GValue *value)
675 g_return_val_if_fail (G_IS_VALUE_POINTER (value), NULL);
677 return value->data[0].v_pointer;