1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 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.
22 extern const char *g_log_domain_gobject;
28 #endif /* __cplusplus */
33 #define G_TYPE_FUNDAMENTAL(type) ((type) & 0xff)
34 #define G_TYPE_FUNDAMENTAL_MAX (0xff)
35 #define G_TYPE_DERIVE_ID(ptype, branch_seqno) (G_TYPE_FUNDAMENTAL (ptype) | ((branch_seqno) << 8))
36 #define G_TYPE_BRANCH_SEQNO(type) ((type) >> 8)
37 #define G_TYPE_FUNDAMENTAL_LAST ((GType) g_type_fundamental_last ())
40 /* predefined fundamental and derived types
42 typedef enum /*< skip >*/
44 /* standard types, introduced by g_type_init() */
67 /* the following reserved ids should vanish soon */
70 /* reserved fundamental type ids,
71 * mail gtk-devel-list@redhat.com for reservations
79 G_TYPE_LAST_RESERVED_FUNDAMENTAL,
81 /* derived type ids */
82 /* FIXME: G_TYPE_PARAM_INTERFACE */
83 G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1),
84 G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2),
85 G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3),
86 G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4),
87 G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5),
88 G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6),
89 G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7),
90 G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8),
91 G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9),
92 G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10),
93 G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11),
94 G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12),
95 /* FIXME: G_TYPE_PARAM_PARAM */
96 G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13)
100 /* Type Checking Macros
102 #define G_TYPE_IS_FUNDAMENTAL(type) (G_TYPE_BRANCH_SEQNO (type) == 0)
103 #define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
104 #define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED))
105 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
106 #define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE))
107 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
108 #define G_TYPE_IS_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_ABSTRACT))
109 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
110 #define G_TYPE_IS_VALUE_TYPE(type) (g_type_value_table_peek (type) != NULL)
115 typedef guint32 GType;
116 typedef struct _GValue GValue;
117 typedef union _GTypeCValue GTypeCValue;
118 typedef struct _GTypePlugin GTypePlugin;
119 typedef struct _GTypeClass GTypeClass;
120 typedef struct _GTypeInterface GTypeInterface;
121 typedef struct _GTypeInstance GTypeInstance;
122 typedef struct _GTypeInfo GTypeInfo;
123 typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
124 typedef struct _GInterfaceInfo GInterfaceInfo;
125 typedef struct _GTypeValueTable GTypeValueTable;
128 /* Basic Type Structures
135 struct _GTypeInstance
140 struct _GTypeInterface
143 GType g_type; /* iface type */
144 GType g_instance_type;
148 /* Casts, checks and accessors for structured types
149 * usage of these macros is reserved to type implementations only
153 #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
154 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
155 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
156 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
157 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
158 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
159 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
160 #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
161 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVT ((value), (g_type)))
162 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
163 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
164 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
167 /* --- prototypes --- */
168 void g_type_init (void);
169 gchar* g_type_name (GType type);
170 GQuark g_type_qname (GType type);
171 GType g_type_from_name (const gchar *name);
172 GType g_type_parent (GType type);
173 GType g_type_next_base (GType type,
175 gboolean g_type_is_a (GType type,
177 gboolean g_type_conforms_to (GType type,
179 guint g_type_fundamental_branch_last (GType type);
180 gpointer g_type_class_ref (GType type);
181 gpointer g_type_class_peek (GType type);
182 void g_type_class_unref (gpointer g_class);
183 gpointer g_type_class_peek_parent (gpointer g_class);
184 gpointer g_type_interface_peek (gpointer instance_class,
186 /* g_free() the returned arrays */
187 GType* g_type_children (GType type,
189 GType* g_type_interfaces (GType type,
190 guint *n_interfaces);
191 /* per-type _static_ data */
192 void g_type_set_qdata (GType type,
195 gpointer g_type_get_qdata (GType type,
199 /* --- type registration --- */
200 typedef void (*GBaseInitFunc) (gpointer g_class);
201 typedef void (*GBaseFinalizeFunc) (gpointer g_class);
202 typedef void (*GClassInitFunc) (gpointer g_class,
203 gpointer class_data);
204 typedef void (*GClassFinalizeFunc) (gpointer g_class,
205 gpointer class_data);
206 typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
208 typedef void (*GInterfaceInitFunc) (gpointer g_iface,
209 gpointer iface_data);
210 typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
211 gpointer iface_data);
212 typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
213 GTypeClass *g_class);
214 typedef enum /*< skip >*/
216 G_TYPE_FLAG_CLASSED = (1 << 0),
217 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
218 G_TYPE_FLAG_DERIVABLE = (1 << 2),
219 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
220 } GTypeFundamentalFlags;
221 typedef enum /*< skip >*/
223 G_TYPE_FLAG_ABSTRACT = (1 << 4)
227 /* interface types, classed types, instantiated types */
230 GBaseInitFunc base_init;
231 GBaseFinalizeFunc base_finalize;
233 /* classed types, instantiated types */
234 GClassInitFunc class_init;
235 GClassFinalizeFunc class_finalize;
236 gconstpointer class_data;
238 /* instantiated types */
239 guint16 instance_size;
241 GInstanceInitFunc instance_init;
244 const GTypeValueTable *value_table;
246 struct _GTypeFundamentalInfo
248 GTypeFundamentalFlags type_flags;
250 struct _GInterfaceInfo
252 GInterfaceInitFunc interface_init;
253 GInterfaceFinalizeFunc interface_finalize;
254 gpointer interface_data;
256 struct _GTypeValueTable
258 void (*value_init) (GValue *value);
259 void (*value_free) (GValue *value);
260 void (*value_copy) (const GValue *src_value,
262 /* varargs functionality (optional) */
263 gpointer (*value_peek_pointer) (const GValue *value);
265 gchar* (*collect_value) (GValue *value,
268 GTypeCValue *collect_value);
270 gchar* (*lcopy_value) (const GValue *value,
273 GTypeCValue *collect_value);
275 GType g_type_register_static (GType parent_type,
276 const gchar *type_name,
277 const GTypeInfo *info,
279 GType g_type_register_dynamic (GType parent_type,
280 const gchar *type_name,
283 GType g_type_register_fundamental (GType type_id,
284 const gchar *type_name,
285 const GTypeInfo *info,
286 const GTypeFundamentalInfo *finfo,
288 void g_type_add_interface_static (GType instance_type,
289 GType interface_type,
290 const GInterfaceInfo *info);
291 void g_type_add_interface_dynamic (GType instance_type,
292 GType interface_type,
293 GTypePlugin *plugin);
296 /* --- protected (for fundamental type implementations) --- */
297 GTypePlugin* g_type_get_plugin (GType type);
298 GTypePlugin* g_type_interface_get_plugin (GType instance_type,
299 GType implementation_type);
301 GType g_type_fundamental_last (void);
302 gboolean g_type_check_flags (GType type,
304 GTypeInstance* g_type_create_instance (GType type);
305 void g_type_free_instance (GTypeInstance *instance);
306 void g_type_add_class_cache_func (gpointer cache_data,
307 GTypeClassCacheFunc cache_func);
308 void g_type_remove_class_cache_func (gpointer cache_data,
309 GTypeClassCacheFunc cache_func);
310 void g_type_class_unref_uncached (gpointer g_class);
314 GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
316 gboolean g_type_class_is_a (GTypeClass *g_class,
318 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
320 gboolean g_type_instance_conforms_to (GTypeInstance *instance,
322 gboolean g_type_check_value (GValue *value);
323 gboolean g_type_value_conforms_to (GValue *value,
325 gboolean g_type_check_instance (GTypeInstance *instance);
326 GTypeValueTable* g_type_value_table_peek (GType type);
329 #ifndef G_DISABLE_CAST_CHECKS
330 # define _G_TYPE_CIC(ip, gt, ct) \
331 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
332 # define _G_TYPE_CCC(cp, gt, ct) \
333 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
334 #else /* G_DISABLE_CAST_CHECKS */
335 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
336 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
337 #endif /* G_DISABLE_CAST_CHECKS */
338 #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
339 #define _G_TYPE_CIT(ip, gt) (g_type_instance_conforms_to ((GTypeInstance*) ip, gt))
340 #define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
341 #define _G_TYPE_CVT(vl, gt) (g_type_value_conforms_to ((GValue*) vl, gt))
342 #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
343 #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
344 #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
349 #endif /* __cplusplus */
351 #endif /* __G_TYPE_H__ */