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_gruntime;
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() */
68 /* the following reserved ids should vanish soon */
71 /* reserved fundamental type ids,
72 * mail gtk-devel-list@redhat.com for reservations
80 G_TYPE_LAST_RESERVED_FUNDAMENTAL,
82 /* derived type ids */
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 G_TYPE_PARAM_PARAM = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 13),
96 G_TYPE_PARAM_POINTER = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 14),
97 G_TYPE_PARAM_CCALLBACK = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 15),
98 G_TYPE_PARAM_BOXED = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 16),
99 G_TYPE_PARAM_OBJECT = G_TYPE_DERIVE_ID (G_TYPE_PARAM, 17)
103 /* Type Checking Macros
105 #define G_TYPE_IS_FUNDAMENTAL(type) (G_TYPE_BRANCH_SEQNO (type) == 0)
106 #define G_TYPE_IS_DERIVED(type) (G_TYPE_BRANCH_SEQNO (type) > 0)
107 #define G_TYPE_IS_INTERFACE(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_INTERFACE)
108 #define G_TYPE_IS_CLASSED(type) (g_type_check_flags ((type), G_TYPE_FLAG_CLASSED))
109 #define G_TYPE_IS_INSTANTIATABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))
110 #define G_TYPE_IS_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DERIVABLE))
111 #define G_TYPE_IS_DEEP_DERIVABLE(type) (g_type_check_flags ((type), G_TYPE_FLAG_DEEP_DERIVABLE))
112 #define G_TYPE_IS_ABSTRACT(type) (g_type_check_flags ((type), G_TYPE_FLAG_ABSTRACT))
113 #define G_TYPE_IS_PARAM(type) (G_TYPE_FUNDAMENTAL (type) == G_TYPE_PARAM)
114 #define G_TYPE_IS_VALUE_TYPE(type) (g_type_value_table_peek (type) != NULL)
119 typedef guint32 GType;
120 typedef struct _GValue GValue;
121 typedef union _GTypeCValue GTypeCValue;
122 typedef struct _GTypePlugin GTypePlugin;
123 typedef struct _GTypeClass GTypeClass;
124 typedef struct _GTypeInterface GTypeInterface;
125 typedef struct _GTypeInstance GTypeInstance;
126 typedef struct _GTypeInfo GTypeInfo;
127 typedef struct _GTypeFundamentalInfo GTypeFundamentalInfo;
128 typedef struct _GInterfaceInfo GInterfaceInfo;
129 typedef struct _GTypeValueTable GTypeValueTable;
132 /* Basic Type Structures
139 struct _GTypeInstance
144 struct _GTypeInterface
147 GType g_type; /* iface type */
148 GType g_instance_type;
152 /* Casts, checks and accessors for structured types
153 * usage of these macros is reserved to type implementations only
157 #define G_TYPE_CHECK_INSTANCE(instance) (_G_TYPE_CHI ((GTypeInstance*) (instance)))
158 #define G_TYPE_CHECK_INSTANCE_CAST(instance, g_type, c_type) (_G_TYPE_CIC ((instance), (g_type), c_type))
159 #define G_TYPE_CHECK_INSTANCE_TYPE(instance, g_type) (_G_TYPE_CIT ((instance), (g_type)))
160 #define G_TYPE_INSTANCE_GET_CLASS(instance, g_type, c_type) (_G_TYPE_IGC ((instance), (g_type), c_type))
161 #define G_TYPE_INSTANCE_GET_INTERFACE(instance, g_type, c_type) (_G_TYPE_IGI ((instance), (g_type), c_type))
162 #define G_TYPE_CHECK_CLASS_CAST(g_class, g_type, c_type) (_G_TYPE_CCC ((g_class), (g_type), c_type))
163 #define G_TYPE_CHECK_CLASS_TYPE(g_class, g_type) (_G_TYPE_CCT ((g_class), (g_type)))
164 #define G_TYPE_CHECK_VALUE(value) (_G_TYPE_CHV ((value)))
165 #define G_TYPE_CHECK_VALUE_TYPE(value, g_type) (_G_TYPE_CVT ((value), (g_type)))
166 #define G_TYPE_FROM_INSTANCE(instance) (G_TYPE_FROM_CLASS (((GTypeInstance*) (instance))->g_class))
167 #define G_TYPE_FROM_CLASS(g_class) (((GTypeClass*) (g_class))->g_type)
168 #define G_TYPE_FROM_INTERFACE(g_iface) (((GTypeInterface*) (g_iface))->g_type)
171 /* debug flags for g_type_init() */
172 typedef enum /*< skip >*/
174 G_TYPE_DEBUG_NONE = 0,
175 G_TYPE_DEBUG_OBJECTS = 1 << 0,
176 G_TYPE_DEBUG_SIGNALS = 1 << 1,
177 G_TYPE_DEBUG_MASK = 0x03
181 /* --- prototypes --- */
182 void g_type_init (GTypeDebugFlags debug_flags);
183 G_CONST_RETURN gchar* g_type_name (GType type);
184 GQuark g_type_qname (GType type);
185 GType g_type_from_name (const gchar *name);
186 GType g_type_parent (GType type);
187 GType g_type_next_base (GType type,
189 gboolean g_type_is_a (GType type,
191 guint g_type_fundamental_branch_last (GType type);
192 gpointer g_type_class_ref (GType type);
193 gpointer g_type_class_peek (GType type);
194 void g_type_class_unref (gpointer g_class);
195 gpointer g_type_class_peek_parent (gpointer g_class);
196 gpointer g_type_interface_peek (gpointer instance_class,
199 /* g_free() the returned arrays */
200 GType* g_type_children (GType type,
202 GType* g_type_interfaces (GType type,
203 guint *n_interfaces);
205 /* per-type _static_ data */
206 void g_type_set_qdata (GType type,
209 gpointer g_type_get_qdata (GType type,
213 /* --- type registration --- */
214 typedef void (*GBaseInitFunc) (gpointer g_class);
215 typedef void (*GBaseFinalizeFunc) (gpointer g_class);
216 typedef void (*GClassInitFunc) (gpointer g_class,
217 gpointer class_data);
218 typedef void (*GClassFinalizeFunc) (gpointer g_class,
219 gpointer class_data);
220 typedef void (*GInstanceInitFunc) (GTypeInstance *instance,
222 typedef void (*GInterfaceInitFunc) (gpointer g_iface,
223 gpointer iface_data);
224 typedef void (*GInterfaceFinalizeFunc) (gpointer g_iface,
225 gpointer iface_data);
226 typedef gboolean (*GTypeClassCacheFunc) (gpointer cache_data,
227 GTypeClass *g_class);
228 typedef enum /*< skip >*/
230 G_TYPE_FLAG_CLASSED = (1 << 0),
231 G_TYPE_FLAG_INSTANTIATABLE = (1 << 1),
232 G_TYPE_FLAG_DERIVABLE = (1 << 2),
233 G_TYPE_FLAG_DEEP_DERIVABLE = (1 << 3)
234 } GTypeFundamentalFlags;
235 typedef enum /*< skip >*/
237 G_TYPE_FLAG_ABSTRACT = (1 << 4)
241 /* interface types, classed types, instantiated types */
244 GBaseInitFunc base_init;
245 GBaseFinalizeFunc base_finalize;
247 /* classed types, instantiated types */
248 GClassInitFunc class_init;
249 GClassFinalizeFunc class_finalize;
250 gconstpointer class_data;
252 /* instantiated types */
253 guint16 instance_size;
255 GInstanceInitFunc instance_init;
258 const GTypeValueTable *value_table;
260 struct _GTypeFundamentalInfo
262 GTypeFundamentalFlags type_flags;
264 struct _GInterfaceInfo
266 GInterfaceInitFunc interface_init;
267 GInterfaceFinalizeFunc interface_finalize;
268 gpointer interface_data;
270 struct _GTypeValueTable
272 void (*value_init) (GValue *value);
273 void (*value_free) (GValue *value);
274 void (*value_copy) (const GValue *src_value,
276 /* varargs functionality (optional) */
277 gpointer (*value_peek_pointer) (const GValue *value);
278 gchar *collect_format;
279 gchar* (*collect_value) (GValue *value,
280 guint n_collect_values,
281 GTypeCValue *collect_values,
282 guint collect_flags);
284 gchar* (*lcopy_value) (const GValue *value,
285 guint n_collect_values,
286 GTypeCValue *collect_values,
287 guint collect_flags);
289 GType g_type_register_static (GType parent_type,
290 const gchar *type_name,
291 const GTypeInfo *info,
293 GType g_type_register_dynamic (GType parent_type,
294 const gchar *type_name,
297 GType g_type_register_fundamental (GType type_id,
298 const gchar *type_name,
299 const GTypeInfo *info,
300 const GTypeFundamentalInfo *finfo,
302 void g_type_add_interface_static (GType instance_type,
303 GType interface_type,
304 const GInterfaceInfo *info);
305 void g_type_add_interface_dynamic (GType instance_type,
306 GType interface_type,
307 GTypePlugin *plugin);
310 /* --- protected (for fundamental type implementations) --- */
311 GTypePlugin* g_type_get_plugin (GType type);
312 GTypePlugin* g_type_interface_get_plugin (GType instance_type,
313 GType implementation_type);
315 GType g_type_fundamental_last (void);
316 gboolean g_type_check_flags (GType type,
318 GTypeInstance* g_type_create_instance (GType type);
319 void g_type_free_instance (GTypeInstance *instance);
320 void g_type_add_class_cache_func (gpointer cache_data,
321 GTypeClassCacheFunc cache_func);
322 void g_type_remove_class_cache_func (gpointer cache_data,
323 GTypeClassCacheFunc cache_func);
324 void g_type_class_unref_uncached (gpointer g_class);
328 gboolean g_type_check_instance (GTypeInstance *instance);
329 GTypeInstance* g_type_check_instance_cast (GTypeInstance *instance,
331 gboolean g_type_instance_is_a (GTypeInstance *instance,
333 GTypeClass* g_type_check_class_cast (GTypeClass *g_class,
335 gboolean g_type_class_is_a (GTypeClass *g_class,
337 gboolean g_type_check_value (GValue *value);
338 gboolean g_type_value_is_a (GValue *value,
340 GTypeValueTable* g_type_value_table_peek (GType type);
343 /* --- implementation bits --- */
344 #ifndef G_DISABLE_CAST_CHECKS
345 # define _G_TYPE_CIC(ip, gt, ct) \
346 ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
347 # define _G_TYPE_CCC(cp, gt, ct) \
348 ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
349 #else /* G_DISABLE_CAST_CHECKS */
350 # define _G_TYPE_CIC(ip, gt, ct) ((ct*) ip)
351 # define _G_TYPE_CCC(cp, gt, ct) ((ct*) cp)
352 #endif /* G_DISABLE_CAST_CHECKS */
353 #define _G_TYPE_CHI(ip) (g_type_check_instance ((GTypeInstance*) ip))
354 #define _G_TYPE_CIT(ip, gt) (g_type_instance_is_a ((GTypeInstance*) ip, gt))
355 #define _G_TYPE_CCT(cp, gt) (g_type_class_is_a ((GTypeClass*) cp, gt))
356 #define _G_TYPE_CVT(vl, gt) (g_type_value_is_a ((GValue*) vl, gt))
357 #define _G_TYPE_CHV(vl) (g_type_check_value ((GValue*) vl))
358 #define _G_TYPE_IGC(ip, gt, ct) ((ct*) (((GTypeInstance*) ip)->g_class))
359 #define _G_TYPE_IGI(ip, gt, ct) ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
360 #define G_TYPE_FLAG_RESERVED_ID_BIT (1 << 30)
361 extern GTypeDebugFlags _g_type_debug_flags;
366 #endif /* __cplusplus */
368 #endif /* __G_TYPE_H__ */