define gstring in terms of gchar*. this typedef reflects the type name of
[platform/upstream/glib.git] / gobject / gtype.h
1 /* GObject - GLib Type, Object, Parameter and Signal Library
2  * Copyright (C) 1998, 1999, 2000 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 #ifndef __G_TYPE_H__
20 #define __G_TYPE_H__
21
22 extern const char *g_log_domain_gobject;
23 #include        <glib.h>
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30
31 /* Basic Type Macros
32  */
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)
38
39
40 /* predefined fundamental and derived types
41  */
42 typedef enum    /*< skip >*/
43 {
44   /* standard types, introduced by g_type_init() */
45   G_TYPE_INVALID,
46   G_TYPE_NONE,
47   G_TYPE_INTERFACE,
48
49   /* GLib type ids */
50   G_TYPE_CHAR,
51   G_TYPE_UCHAR,
52   G_TYPE_BOOLEAN,
53   G_TYPE_INT,
54   G_TYPE_UINT,
55   G_TYPE_LONG,
56   G_TYPE_ULONG,
57   G_TYPE_ENUM,
58   G_TYPE_FLAGS,
59   G_TYPE_FLOAT,
60   G_TYPE_DOUBLE,
61   G_TYPE_STRING,
62   G_TYPE_PARAM,
63   G_TYPE_OBJECT,
64
65   /* the following reserved ids should vanish soon */
66   G_TYPE_GTK_BOXED,
67   G_TYPE_GTK_POINTER,
68   G_TYPE_GTK_SIGNAL,
69
70   /* reserved fundamental type ids,
71    * mail gtk-devel-list@redhat.com for reservations
72    */
73   G_TYPE_BSE_PROCEDURE,
74   G_TYPE_BSE_TIME,
75   G_TYPE_BSE_NOTE,
76   G_TYPE_BSE_DOTS,
77   G_TYPE_GLE_GOBJECT,
78
79   G_TYPE_LAST_RESERVED_FUNDAMENTAL,
80
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)
97 } GTypeFundamentals;
98
99
100 /* Type Checking Macros
101  */
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)
108
109
110 /* Typedefs
111  */
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;
124
125
126 /* Basic Type Structures
127  */
128 struct _GTypeClass
129 {
130   /*< private >*/
131   GType g_type;
132 };
133 struct _GTypeInstance
134 {
135   /*< private >*/
136   GTypeClass *g_class;
137 };
138 struct _GTypeInterface
139 {
140   /*< private >*/
141   GType g_type;         /* iface type */
142   GType g_instance_type;
143 };
144
145
146 /* Casts, Checks And Convenience Macros For Structured Types
147  */
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)
156
157
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,
165                                          GType                   base_type);
166 gboolean g_type_is_a                    (GType                   type,
167                                          GType                   is_a_type);
168 gboolean g_type_conforms_to             (GType                   type,
169                                          GType                   iface_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,
176                                          GType                   iface_type);
177 /* g_free() the returned arrays */
178 GType*   g_type_children                (GType                   type,
179                                          guint                  *n_children);
180 GType*   g_type_interfaces              (GType                   type,
181                                          guint                  *n_interfaces);
182 /* per-type _static_ data */
183 void     g_type_set_qdata               (GType                   type,
184                                          GQuark                  quark,
185                                          gpointer                data);
186 gpointer g_type_get_qdata               (GType                   type,
187                                          GQuark                  quark);
188                                           
189
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,
198                                               gpointer         g_class);
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,
206                                               GType            g_type,
207                                               GTypeInfo       *info,
208                                               GTypeValueTable *value_table);
209 typedef void (*GTypePluginFillInterfaceInfo) (GTypePlugin     *plugin,
210                                               GType            interface_type,
211                                               GType            instance_type,
212                                               GInterfaceInfo  *info);
213 typedef gboolean (*GTypeClassCacheFunc)      (gpointer         cache_data,
214                                               GTypeClass      *g_class);
215 struct _GTypePlugin
216 {
217   GTypePluginVTable     *vtable;
218 };
219 struct _GTypePluginVTable
220 {
221   GTypePluginRef                plugin_ref;
222   GTypePluginUnRef              plugin_unref;
223   GTypePluginFillTypeInfo       complete_type_info;
224   GTypePluginFillInterfaceInfo  complete_interface_info;
225 };
226 typedef enum    /*< skip >*/
227 {
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)
232 } GTypeFlags;
233 struct _GTypeInfo
234 {
235   /* interface types, classed types, instantiated types */
236   guint16                class_size;
237
238   GBaseInitFunc          base_init;
239   GBaseFinalizeFunc      base_finalize;
240
241   /* classed types, instantiated types */
242   GClassInitFunc         class_init;
243   GClassFinalizeFunc     class_finalize;
244   gconstpointer          class_data;
245
246   /* instantiated types */
247   guint16                instance_size;
248   guint16                n_preallocs;
249   GInstanceInitFunc      instance_init;
250
251   /* value handling */
252   const GTypeValueTable *value_table;
253 };
254 struct _GTypeFundamentalInfo
255 {
256   GTypeFlags             type_flags;
257 };
258 struct _GInterfaceInfo
259 {
260   GInterfaceInitFunc     interface_init;
261   GInterfaceFinalizeFunc interface_finalize;
262   gpointer               interface_data;
263 };
264 struct _GTypeValueTable
265 {
266   void   (*value_init)    (GValue       *value);
267   void   (*value_free)    (GValue       *value);
268   void   (*value_copy)    (const GValue *src_value,
269                            GValue       *dest_value);
270   /* varargs functionality (optional) */
271   guint    collect_type;
272   gchar* (*collect_value) (GValue       *value,
273                            guint         nth_value,
274                            GType        *collect_type,
275                            GTypeCValue  *collect_value);
276   guint    lcopy_type;
277   gchar* (*lcopy_value)   (const GValue *value,
278                            guint         nth_value,
279                            GType        *collect_type,
280                            GTypeCValue  *collect_value);
281 };
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);
298
299
300 /* --- implementation details --- */
301 gboolean         g_type_class_is_a              (GTypeClass         *g_class,
302                                                  GType               is_a_type);
303 GTypeClass*      g_type_check_class_cast        (GTypeClass         *g_class,
304                                                  GType               is_a_type);
305 GTypeInstance*   g_type_check_instance_cast     (GTypeInstance      *instance,
306                                                  GType               iface_type);
307 gboolean         g_type_instance_conforms_to    (GTypeInstance      *instance,
308                                                  GType               iface_type);
309 gboolean         g_type_check_flags             (GType               type,
310                                                  GTypeFlags          flags);
311 gboolean         g_type_is_dynamic              (GType               type,
312                                                  GTypeFlags          flags);
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);
321
322
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))
335
336 #ifdef G_OS_WIN32
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 */
345
346 GTYPE_C_VAR GType    _g_type_fundamental_last;
347
348 #ifdef __cplusplus
349 }
350 #endif /* __cplusplus */
351
352 #endif /* __G_TYPE_H__ */