1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 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_gruntime;
29 #define G_TYPE_FUNDAMENTAL(type) ((type) & 0xff)
30 #define G_TYPE_FUNDAMENTAL_MAX (0xff)
31 #define G_TYPE_DERIVE_ID(ptype, branch_seqno) (G_TYPE_FUNDAMENTAL (ptype) | ((branch_seqno) << 8))
32 #define G_TYPE_BRANCH_SEQNO(type) ((type) >> 8)
33 #define G_TYPE_FUNDAMENTAL_LAST ((GType) g_type_fundamental_last ())
36 /* predefined fundamental and derived types
38 typedef enum /*< skip >*/
40 /* standard types, introduced by g_type_init() */
63 /* reserved fundamental type ids,
64 * mail gtk-devel-list@redhat.com for reservations
66 G_TYPE_RESERVED_BSE_FIRST,
67 G_TYPE_RESERVED_BSE_LAST = G_TYPE_RESERVED_BSE_FIRST + 15,
68 G_TYPE_RESERVED_LAST_FUNDAMENTAL,
70 /* derived type ids */
71 G_TYPE_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 1),
72 G_TYPE_VALUE = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 2),
73 G_TYPE_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 3),
74 G_TYPE_GSTRING = G_TYPE_DERIVE_ID (G_TYPE_BOXED, 4),
75 G_TYPE_PARAM_CHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 1),
76 G_TYPE_PARAM_UCHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 2),
77 G_TYPE_PARAM_BOOLEAN = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 3),
78 G_TYPE_PARAM_INT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 4),
79 G_TYPE_PARAM_UINT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 5),
80 G_TYPE_PARAM_LONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 6),
81 G_TYPE_PARAM_ULONG = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 7),
82 G_TYPE_PARAM_UNICHAR = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 8),
83 G_TYPE_PARAM_ENUM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 9),
84 G_TYPE_PARAM_FLAGS = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 10),
85 G_TYPE_PARAM_FLOAT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 11),
86 G_TYPE_PARAM_DOUBLE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 12),
87 G_TYPE_PARAM_STRING = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13),
88 G_TYPE_PARAM_PARAM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14),
89 G_TYPE_PARAM_BOXED = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15),
90 G_TYPE_PARAM_POINTER = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16),
91 G_TYPE_PARAM_VALUE_ARRAY = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17),
92 G_TYPE_PARAM_CLOSURE = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 18),
93 G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 19)
97 /* Type Checking Macros
99 #define G_TYPE_IS_FUNDAMENTAL(type) (G_TYPE_BRANCH_SEQNO (type) == 0)
100 #define G_TYPE_IS_DERIVED(type) (G_TYPE_BRANCH_SEQNO (type) > 0)
101 #define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
102 #define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED))
103 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
104 #define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE))
105 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
106 #define G_TYPE_IS_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_ABSTRACT))
107 #define G_TYPE_IS_VALUE_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_VALUE_ABSTRACT))
108 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
109 #define G_TYPE_IS_VALUE_TYPE(type) (g_type_check_is_value_type (type))
110 #define G_TYPE_HAS_VALUE_TABLE(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;
126 typedef struct _GTypeQuery GTypeQuery;
129 /* Basic Type Structures
136 struct _GTypeInstance
141 struct _GTypeInterface
144 GType g_type; /* iface type */
145 GType g_instance_type;
150 const gchar *type_name;
156 /* Casts, checks and accessors for structured types
157 * usage of these macros is reserved to type implementations only
160 #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
161 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
162 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
163 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
164 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
165 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
166 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
167 #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
168 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVH ((value), (g_type)))
169 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
170 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
171 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
174 /* debug flags for g_type_init() */
175 typedef enum /*< skip >*/
177 G_TYPE_DEBUG_NONE = 0,
178 G_TYPE_DEBUG_OBJECTS = 1 << 0,
179 G_TYPE_DEBUG_SIGNALS = 1 << 1,
180 G_TYPE_DEBUG_MASK = 0x03
184 /* --- prototypes --- */
185 void g_type_init (GTypeDebugFlags debug_flags);
186 G_CONST_RETURN gchar* g_type_name (GType type);
187 GQuark g_type_qname (GType type);
188 GType g_type_from_name (const gchar *name);
189 GType g_type_parent (GType type);
190 guint g_type_depth (GType type);
191 GType g_type_next_base (GType leaf_type,
193 gboolean g_type_is_a (GType type,
195 guint g_type_fundamental_branch_last (GType type);
196 gpointer g_type_class_ref (GType type);
197 gpointer g_type_class_peek (GType type);
198 void g_type_class_unref (gpointer g_class);
199 gpointer g_type_class_peek_parent (gpointer g_class);
200 gpointer g_type_interface_peek (gpointer instance_class,
203 /* g_free() the returned arrays */
204 GType* g_type_children (GType type,
206 GType* g_type_interfaces (GType type,
207 guint *n_interfaces);
209 /* per-type _static_ data */
210 void g_type_set_qdata (GType type,
213 gpointer g_type_get_qdata (GType type,
215 void g_type_query (GType type,
219 /* --- type registration --- */
220 typedef void (*GBaseInitFunc) (gpointer g_class);
221 typedef void (*GBaseFinalizeFunc) (gpointer g_class);
222 typedef void (*GClassInitFunc) (gpointer g_class,
223 gpointer class_data);
224 typedef void (*GClassFinalizeFunc) (gpointer g_class,
225 gpointer class_data);
226 typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
228 typedef void (*GInterfaceInitFunc) (gpointer g_iface,
229 gpointer iface_data);
230 typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
231 gpointer iface_data);
232 typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
233 GTypeClass *g_class);
234 typedef enum /*< skip >*/
236 G_TYPE_FLAG_CLASSED = (1 << 0),
237 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
238 G_TYPE_FLAG_DERIVABLE = (1 << 2),
239 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
240 } GTypeFundamentalFlags;
241 typedef enum /*< skip >*/
243 G_TYPE_FLAG_ABSTRACT = (1 << 4),
244 G_TYPE_FLAG_VALUE_ABSTRACT = (1 << 5)
248 /* interface types, classed types, instantiated types */
251 GBaseInitFunc base_init;
252 GBaseFinalizeFunc base_finalize;
254 /* classed types, instantiated types */
255 GClassInitFunc class_init;
256 GClassFinalizeFunc class_finalize;
257 gconstpointer class_data;
259 /* instantiated types */
260 guint16 instance_size;
262 GInstanceInitFunc instance_init;
265 const GTypeValueTable *value_table;
267 struct _GTypeFundamentalInfo
269 GTypeFundamentalFlags type_flags;
271 struct _GInterfaceInfo
273 GInterfaceInitFunc interface_init;
274 GInterfaceFinalizeFunc interface_finalize;
275 gpointer interface_data;
277 struct _GTypeValueTable
279 void (*value_init) (GValue *value);
280 void (*value_free) (GValue *value);
281 void (*value_copy) (const GValue *src_value,
283 /* varargs functionality (optional) */
284 gpointer (*value_peek_pointer) (const GValue *value);
285 gchar *collect_format;
286 gchar* (*collect_value) (GValue *value,
287 guint n_collect_values,
288 GTypeCValue *collect_values,
289 guint collect_flags);
291 gchar* (*lcopy_value) (const GValue *value,
292 guint n_collect_values,
293 GTypeCValue *collect_values,
294 guint collect_flags);
296 GType g_type_register_static (GType parent_type,
297 const gchar *type_name,
298 const GTypeInfo *info,
300 GType g_type_register_dynamic (GType parent_type,
301 const gchar *type_name,
304 GType g_type_register_fundamental (GType type_id,
305 const gchar *type_name,
306 const GTypeInfo *info,
307 const GTypeFundamentalInfo *finfo,
309 void g_type_add_interface_static (GType instance_type,
310 GType interface_type,
311 const GInterfaceInfo *info);
312 void g_type_add_interface_dynamic (GType instance_type,
313 GType interface_type,
314 GTypePlugin *plugin);
315 void g_type_interface_add_prerequisite (GType interface_type,
316 GType prerequisite_type);
319 /* --- protected (for fundamental type implementations) --- */
320 GTypePlugin* g_type_get_plugin (GType type);
321 GTypePlugin* g_type_interface_get_plugin (GType instance_type,
322 GType implementation_type);
324 GType g_type_fundamental_last (void);
325 gboolean g_type_check_flags (GType type,
327 GTypeInstance* g_type_create_instance (GType type);
328 void g_type_free_instance (GTypeInstance *instance);
329 void g_type_add_class_cache_func (gpointer cache_data,
330 GTypeClassCacheFunc cache_func);
331 void g_type_remove_class_cache_func (gpointer cache_data,
332 GTypeClassCacheFunc cache_func);
333 void g_type_class_unref_uncached (gpointer g_class);
337 gboolean g_type_check_instance (GTypeInstance *instance);
338 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
340 gboolean g_type_instance_is_a (GTypeInstance *instance,
342 GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
344 gboolean g_type_class_is_a (GTypeClass *g_class,
346 gboolean g_type_check_is_value_type (GType type);
347 gboolean g_type_check_value (GValue *value);
348 gboolean g_type_check_value_holds (GValue *value,
350 GTypeValueTable* g_type_value_table_peek (GType type);
353 /* --- debugging functions --- */
354 G_CONST_RETURN gchar* g_type_name_from_instance (GTypeInstance *instance);
355 G_CONST_RETURN gchar* g_type_name_from_class (GTypeClass *g_class);
358 /* --- implementation bits --- */
359 #ifndef G_DISABLE_CAST_CHECKS
360 # define _G_TYPE_CIC(ip, gt, ct) \
361 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
362 # define _G_TYPE_CCC(cp, gt, ct) \
363 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
364 #else /* G_DISABLE_CAST_CHECKS */
365 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
366 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
367 #endif /* G_DISABLE_CAST_CHECKS */
368 #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
369 #define _G_TYPE_CIT(ip, gt) (g_type_instance_is_a ((GTypeInstance*) ip, gt))
370 #define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
371 #define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
372 #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
373 #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
374 #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
375 #define G_TYPE_FLAG_RESERVED_ID_BIT (1 << 30)
376 extern GTypeDebugFlags _g_type_debug_flags;
380 #endif /* __G_TYPE_H__ */