Tizen 2.1 base
[platform/upstream/glib2.0.git] / gobject / gvalue.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc.
3  *
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.
8  *
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.
13  *
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.
18  *
19  * gvalue.h: generic GValue functions
20  */
21 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
22 #error "Only <glib-object.h> can be included directly."
23 #endif
24
25 #ifndef __G_VALUE_H__
26 #define __G_VALUE_H__
27
28 #include        <gobject/gtype.h>
29
30 G_BEGIN_DECLS
31
32 /* --- type macros --- */
33 /**
34  * G_TYPE_IS_VALUE:
35  * @type: A #GType value.
36  * 
37  * Checks whether the passed in type ID can be used for g_value_init().
38  * That is, this macro checks whether this type provides an implementation
39  * of the #GTypeValueTable functions required for a type to create a #GValue of.
40  * 
41  * Returns: Whether @type is suitable as a #GValue type.
42  */
43 #define G_TYPE_IS_VALUE(type)           (g_type_check_is_value_type (type))
44 /**
45  * G_IS_VALUE:
46  * @value: A #GValue structure.
47  * 
48  * Checks if @value is a valid and initialized #GValue structure.
49  *
50  * Returns: %TRUE on success.
51  */
52 #define G_IS_VALUE(value)               (G_TYPE_CHECK_VALUE (value))
53 /**
54  * G_VALUE_TYPE:
55  * @value: A #GValue structure.
56  * 
57  * Get the type identifier of @value.
58  *
59  * Returns: the #GType.
60  */
61 #define G_VALUE_TYPE(value)             (((GValue*) (value))->g_type)
62 /**
63  * G_VALUE_TYPE_NAME:
64  * @value: A #GValue structure.
65  *
66  * Gets the the type name of @value. 
67  *
68  * Returns: the type name.
69  */
70 #define G_VALUE_TYPE_NAME(value)        (g_type_name (G_VALUE_TYPE (value)))
71 /**
72  * G_VALUE_HOLDS:
73  * @value: A #GValue structure.
74  * @type: A #GType value.
75  * 
76  * Checks if @value holds (or contains) a value of @type.
77  * This macro will also check for @value != %NULL and issue a
78  * warning if the check fails.
79  *
80  * Returns: %TRUE if @value holds the @type.
81  */
82 #define G_VALUE_HOLDS(value,type)       (G_TYPE_CHECK_VALUE_TYPE ((value), (type)))
83
84
85 /* --- typedefs & structures --- */
86 /**
87  * GValueTransform:
88  * @src_value: Source value.
89  * @dest_value: Target value.
90  * 
91  * The type of value transformation functions which can be registered with
92  * g_value_register_transform_func().
93  */
94 typedef void (*GValueTransform) (const GValue *src_value,
95                                  GValue       *dest_value);
96 /**
97  * GValue:
98  * 
99  * An opaque structure used to hold different types of values.
100  * The data within the structure has protected scope: it is accessible only
101  * to functions within a #GTypeValueTable structure, or implementations of
102  * the g_value_*() API. That is, code portions which implement new fundamental
103  * types.
104  * #GValue users cannot make any assumptions about how data is stored
105  * within the 2 element @data union, and the @g_type member should
106  * only be accessed through the G_VALUE_TYPE() macro.
107  */
108 struct _GValue
109 {
110   /*< private >*/
111   GType         g_type;
112
113   /* public for GTypeValueTable methods */
114   union {
115     gint        v_int;
116     guint       v_uint;
117     glong       v_long;
118     gulong      v_ulong;
119     gint64      v_int64;
120     guint64     v_uint64;
121     gfloat      v_float;
122     gdouble     v_double;
123     gpointer    v_pointer;
124   } data[2];
125 };
126
127
128 /* --- prototypes --- */
129 GValue*         g_value_init            (GValue       *value,
130                                          GType         g_type);
131 void            g_value_copy            (const GValue *src_value,
132                                          GValue       *dest_value);
133 GValue*         g_value_reset           (GValue       *value);
134 void            g_value_unset           (GValue       *value);
135 void            g_value_set_instance    (GValue       *value,
136                                          gpointer      instance);
137
138
139 /* --- private --- */
140 gboolean        g_value_fits_pointer    (const GValue *value);
141 gpointer        g_value_peek_pointer    (const GValue *value);
142
143
144 /* --- implementation details --- */
145 gboolean g_value_type_compatible        (GType           src_type,
146                                          GType           dest_type);
147 gboolean g_value_type_transformable     (GType           src_type,
148                                          GType           dest_type);
149 gboolean g_value_transform              (const GValue   *src_value,
150                                          GValue         *dest_value);
151 void    g_value_register_transform_func (GType           src_type,
152                                          GType           dest_type,
153                                          GValueTransform transform_func);
154
155 /**
156  * G_VALUE_NOCOPY_CONTENTS:
157  *
158  * If passed to G_VALUE_COLLECT(), allocated data won't be copied
159  * but used verbatim. This does not affect ref-counted types like
160  * objects.
161  */
162 #define G_VALUE_NOCOPY_CONTENTS (1 << 27)
163
164 /**
165  * G_VALUE_INIT:
166  *
167  * A #GValue must be initialized before it can be used.
168  * This macro can be used as initializer instead of an explicit
169  * <literal>{ 0 }</literal> when declaring a variable,
170  * but it cannot be assigned to a variable.
171  *
172  * |[
173  *   GValue value = G_VALUE_INIT;
174  * ]|
175  *
176  * Since: 2.30
177  */
178 #define G_VALUE_INIT  { 0, { { 0 } } }
179
180
181 G_END_DECLS
182
183 #endif /* __G_VALUE_H__ */