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() */
65 /* 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_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
103 #define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED))
104 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
105 #define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE))
106 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
107 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
112 typedef guint32 GType;
113 typedef struct _GValue GValue;
114 typedef union _GTypeCValue GTypeCValue;
115 typedef struct _GTypePlugin GTypePlugin;
116 typedef struct _GTypePluginVTable GTypePluginVTable;
117 typedef struct _GTypeClass GTypeClass;
118 typedef struct _GTypeInterface GTypeInterface;
119 typedef struct _GTypeInstance GTypeInstance;
120 typedef struct _GTypeInfo GTypeInfo;
121 typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
122 typedef struct _GInterfaceInfo GInterfaceInfo;
123 typedef struct _GTypeValueTable GTypeValueTable;
126 /* Basic Type Structures
133 struct _GTypeInstance
138 struct _GTypeInterface
141 GType g_type; /* iface type */
142 GType g_instance_type;
146 /* Casts, Checks And Convenience Macros For Structured Types
148 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
149 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
150 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
151 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
152 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), c_type))
153 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
154 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
155 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
158 /* --- prototypes --- */
159 void g_type_init (void);
160 gchar* g_type_name (GType type);
161 GQuark g_type_qname (GType type);
162 GType g_type_from_name (const gchar *name);
163 GType g_type_parent (GType type);
164 GType g_type_next_base (GType type,
166 gboolean g_type_is_a (GType type,
168 gboolean g_type_conforms_to (GType type,
170 guint g_type_fundamental_branch_last (GType type);
171 gpointer g_type_class_ref (GType type);
172 gpointer g_type_class_peek (GType type);
173 void g_type_class_unref (gpointer g_class);
174 gpointer g_type_class_peek_parent (gpointer g_class);
175 gpointer g_type_interface_peek (gpointer instance_class,
177 /* g_free() the returned arrays */
178 GType* g_type_children (GType type,
180 GType* g_type_interfaces (GType type,
181 guint *n_interfaces);
182 /* per-type _static_ data */
183 void g_type_set_qdata (GType type,
186 gpointer g_type_get_qdata (GType type,
190 /* --- type registration --- */
191 typedef void (*GBaseInitFunc) (gpointer g_class);
192 typedef void (*GBaseFinalizeFunc) (gpointer g_class);
193 typedef void (*GClassInitFunc) (gpointer g_class,
194 gpointer class_data);
195 typedef void (*GClassFinalizeFunc) (gpointer g_class,
196 gpointer class_data);
197 typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
199 typedef void (*GInterfaceInitFunc) (gpointer g_iface,
200 gpointer iface_data);
201 typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
202 gpointer iface_data);
203 typedef void (*GTypePluginRef) (GTypePlugin *plugin);
204 typedef void (*GTypePluginUnRef) (GTypePlugin *plugin);
205 typedef void (*GTypePluginFillTypeInfo) (GTypePlugin *plugin,
208 GTypeValueTable *value_table);
209 typedef void (*GTypePluginFillInterfaceInfo) (GTypePlugin *plugin,
210 GType interface_type,
212 GInterfaceInfo *info);
213 typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
214 GTypeClass *g_class);
217 GTypePluginVTable *vtable;
219 struct _GTypePluginVTable
221 GTypePluginRef plugin_ref;
222 GTypePluginUnRef plugin_unref;
223 GTypePluginFillTypeInfo complete_type_info;
224 GTypePluginFillInterfaceInfo complete_interface_info;
226 typedef enum /*< skip >*/
228 G_TYPE_FLAG_CLASSED = (1 << 0),
229 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
230 G_TYPE_FLAG_DERIVABLE = (1 << 2),
231 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
235 /* interface types, classed types, instantiated types */
238 GBaseInitFunc base_init;
239 GBaseFinalizeFunc base_finalize;
241 /* classed types, instantiated types */
242 GClassInitFunc class_init;
243 GClassFinalizeFunc class_finalize;
244 gconstpointer class_data;
246 /* instantiated types */
247 guint16 instance_size;
249 GInstanceInitFunc instance_init;
252 const GTypeValueTable *value_table;
254 struct _GTypeFundamentalInfo
256 GTypeFlags type_flags;
258 struct _GInterfaceInfo
260 GInterfaceInitFunc interface_init;
261 GInterfaceFinalizeFunc interface_finalize;
262 gpointer interface_data;
264 struct _GTypeValueTable
266 void (*value_init) (GValue *value);
267 void (*value_free) (GValue *value);
268 void (*value_copy) (const GValue *src_value,
270 /* varargs functionality (optional) */
272 gchar* (*collect_value) (GValue *value,
275 GTypeCValue *collect_value);
277 gchar* (*lcopy_value) (const GValue *value,
280 GTypeCValue *collect_value);
282 GType g_type_register_static (GType parent_type,
283 const gchar *type_name,
284 const GTypeInfo *info);
285 GType g_type_register_dynamic (GType parent_type,
286 const gchar *type_name,
287 GTypePlugin *plugin);
288 GType g_type_register_fundamental (GType type_id,
289 const gchar *type_name,
290 const GTypeInfo *info,
291 const GTypeFundamentalInfo *finfo);
292 void g_type_add_interface_static (GType instance_type,
293 GType interface_type,
294 GInterfaceInfo *info);
295 void g_type_add_interface_dynamic (GType instance_type,
296 GType interface_type,
297 GTypePlugin *plugin);
300 /* --- implementation details --- */
301 gboolean g_type_class_is_a (GTypeClass *g_class,
303 GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
305 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
307 gboolean g_type_instance_conforms_to (GTypeInstance *instance,
309 gboolean g_type_check_flags (GType type,
311 gboolean g_type_is_dynamic (GType type,
313 GTypeInstance* g_type_create_instance (GType type);
314 void g_type_free_instance (GTypeInstance *instance);
315 GTypeValueTable* g_type_value_table_peek (GType type);
316 void g_type_add_class_cache_func (gpointer cache_data,
317 GTypeClassCacheFunc cache_func);
318 void g_type_remove_class_cache_func (gpointer cache_data,
319 GTypeClassCacheFunc cache_func);
320 void g_type_class_unref_uncached (gpointer g_class);
323 #ifndef G_DISABLE_CAST_CHECKS
324 # define _G_TYPE_CIC(ip, gt, ct) \
325 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
326 # define _G_TYPE_CCC(cp, gt, ct) \
327 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
328 #else /* G_DISABLE_CAST_CHECKS */
329 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
330 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
331 #endif /* G_DISABLE_CAST_CHECKS */
332 #define _G_TYPE_IGC(ip, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
333 #define _G_TYPE_CIT(ip, gt) (g_type_instance_conforms_to ((GTypeInstance*) ip, gt))
334 #define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
337 # ifdef GMODULE_COMPILATION
338 # define GTYPE_C_VAR __declspec(dllexport)
339 # else /* !GLIB_COMPILATION */
340 # define GTYPE_C_VAR extern __declspec(dllimport)
341 # endif /* !GLIB_COMPILATION */
342 #else /* !G_OS_WIN32 */
343 # define GTYPE_C_VAR extern
344 #endif /* !G_OS_WIN32 */
346 GTYPE_C_VAR GType _g_type_fundamental_last;
350 #endif /* __cplusplus */
352 #endif /* __G_TYPE_H__ */