added some function documentations.
[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_gruntime;
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_BOXED,
64   G_TYPE_POINTER,
65   G_TYPE_CCALLBACK,
66   G_TYPE_OBJECT,
67
68   /* the following reserved ids should vanish soon */
69   G_TYPE_GTK_SIGNAL,
70
71   /* reserved fundamental type ids,
72    * mail gtk-devel-list@redhat.com for reservations
73    */
74   G_TYPE_BSE_PROCEDURE,
75   G_TYPE_BSE_TIME,
76   G_TYPE_BSE_NOTE,
77   G_TYPE_BSE_DOTS,
78   G_TYPE_GLE_GOBJECT,
79
80   G_TYPE_LAST_RESERVED_FUNDAMENTAL,
81
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)
100 } GTypeFundamentals;
101
102
103 /* Type Checking Macros
104  */
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)
115
116
117 /* Typedefs
118  */
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;
130
131
132 /* Basic Type Structures
133  */
134 struct _GTypeClass
135 {
136   /*< private >*/
137   GType g_type;
138 };
139 struct _GTypeInstance
140 {
141   /*< private >*/
142   GTypeClass *g_class;
143 };
144 struct _GTypeInterface
145 {
146   /*< private >*/
147   GType g_type;         /* iface type */
148   GType g_instance_type;
149 };
150
151
152 /* Casts, checks and accessors for structured types
153  * usage of these macros is reserved to type implementations only
154  * 
155  */
156 /*< protected >*/
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)
169
170
171 /* --- prototypes --- */
172 void     g_type_init                    (void);
173 gchar*   g_type_name                    (GType                   type);
174 GQuark   g_type_qname                   (GType                   type);
175 GType    g_type_from_name               (const gchar            *name);
176 GType    g_type_parent                  (GType                   type);
177 GType    g_type_next_base               (GType                   type,
178                                          GType                   base_type);
179 gboolean g_type_is_a                    (GType                   type,
180                                          GType                   is_a_type);
181 guint    g_type_fundamental_branch_last (GType                   type);
182 gpointer g_type_class_ref               (GType                   type);
183 gpointer g_type_class_peek              (GType                   type);
184 void     g_type_class_unref             (gpointer                g_class);
185 gpointer g_type_class_peek_parent       (gpointer                g_class);
186 gpointer g_type_interface_peek          (gpointer                instance_class,
187                                          GType                   iface_type);
188 /* g_free() the returned arrays */
189 GType*   g_type_children                (GType                   type,
190                                          guint                  *n_children);
191 GType*   g_type_interfaces              (GType                   type,
192                                          guint                  *n_interfaces);
193 /* per-type _static_ data */
194 void     g_type_set_qdata               (GType                   type,
195                                          GQuark                  quark,
196                                          gpointer                data);
197 gpointer g_type_get_qdata               (GType                   type,
198                                          GQuark                  quark);
199                                           
200
201 /* --- type registration --- */
202 typedef void   (*GBaseInitFunc)              (gpointer         g_class);
203 typedef void   (*GBaseFinalizeFunc)          (gpointer         g_class);
204 typedef void   (*GClassInitFunc)             (gpointer         g_class,
205                                               gpointer         class_data);
206 typedef void   (*GClassFinalizeFunc)         (gpointer         g_class,
207                                               gpointer         class_data);
208 typedef void   (*GInstanceInitFunc)          (GTypeInstance   *instance,
209                                               gpointer         g_class);
210 typedef void   (*GInterfaceInitFunc)         (gpointer         g_iface,
211                                               gpointer         iface_data);
212 typedef void   (*GInterfaceFinalizeFunc)     (gpointer         g_iface,
213                                               gpointer         iface_data);
214 typedef gboolean (*GTypeClassCacheFunc)      (gpointer         cache_data,
215                                               GTypeClass      *g_class);
216 typedef enum    /*< skip >*/
217 {
218   G_TYPE_FLAG_CLASSED           = (1 << 0),
219   G_TYPE_FLAG_INSTANTIATABLE    = (1 << 1),
220   G_TYPE_FLAG_DERIVABLE         = (1 << 2),
221   G_TYPE_FLAG_DEEP_DERIVABLE    = (1 << 3)
222 } GTypeFundamentalFlags;
223 typedef enum    /*< skip >*/
224 {
225   G_TYPE_FLAG_ABSTRACT          = (1 << 4)
226 } GTypeFlags;
227 struct _GTypeInfo
228 {
229   /* interface types, classed types, instantiated types */
230   guint16                class_size;
231
232   GBaseInitFunc          base_init;
233   GBaseFinalizeFunc      base_finalize;
234
235   /* classed types, instantiated types */
236   GClassInitFunc         class_init;
237   GClassFinalizeFunc     class_finalize;
238   gconstpointer          class_data;
239
240   /* instantiated types */
241   guint16                instance_size;
242   guint16                n_preallocs;
243   GInstanceInitFunc      instance_init;
244
245   /* value handling */
246   const GTypeValueTable *value_table;
247 };
248 struct _GTypeFundamentalInfo
249 {
250   GTypeFundamentalFlags  type_flags;
251 };
252 struct _GInterfaceInfo
253 {
254   GInterfaceInitFunc     interface_init;
255   GInterfaceFinalizeFunc interface_finalize;
256   gpointer               interface_data;
257 };
258 struct _GTypeValueTable
259 {
260   void     (*value_init)         (GValue       *value);
261   void     (*value_free)         (GValue       *value);
262   void     (*value_copy)         (const GValue *src_value,
263                                   GValue       *dest_value);
264   /* varargs functionality (optional) */
265   gpointer (*value_peek_pointer) (const GValue *value);
266   guint      collect_type;
267   gchar*   (*collect_value)      (GValue       *value,
268                                   guint         nth_value,
269                                   GType        *collect_type,
270                                   GTypeCValue  *collect_value);
271   guint      lcopy_type;
272   gchar*   (*lcopy_value)        (const GValue *value,
273                                   guint         nth_value,
274                                   GType        *collect_type,
275                                   GTypeCValue  *collect_value);
276 };
277 GType g_type_register_static       (GType                       parent_type,
278                                     const gchar                *type_name,
279                                     const GTypeInfo            *info,
280                                     GTypeFlags                  flags);
281 GType g_type_register_dynamic      (GType                       parent_type,
282                                     const gchar                *type_name,
283                                     GTypePlugin                *plugin,
284                                     GTypeFlags                  flags);
285 GType g_type_register_fundamental  (GType                       type_id,
286                                     const gchar                *type_name,
287                                     const GTypeInfo            *info,
288                                     const GTypeFundamentalInfo *finfo,
289                                     GTypeFlags                  flags);
290 void  g_type_add_interface_static  (GType                       instance_type,
291                                     GType                       interface_type,
292                                     const GInterfaceInfo       *info);
293 void  g_type_add_interface_dynamic (GType                       instance_type,
294                                     GType                       interface_type,
295                                     GTypePlugin                *plugin);
296
297
298 /* --- protected (for fundamental type implementations) --- */
299 GTypePlugin*     g_type_get_plugin              (GType               type);
300 GTypePlugin*     g_type_interface_get_plugin    (GType               instance_type,
301                                                  GType               implementation_type);
302
303 GType            g_type_fundamental_last        (void);
304 gboolean         g_type_check_flags             (GType               type,
305                                                  guint               flags);
306 GTypeInstance*   g_type_create_instance         (GType               type);
307 void             g_type_free_instance           (GTypeInstance      *instance);
308 void             g_type_add_class_cache_func    (gpointer            cache_data,
309                                                  GTypeClassCacheFunc cache_func);
310 void             g_type_remove_class_cache_func (gpointer            cache_data,
311                                                  GTypeClassCacheFunc cache_func);
312 void             g_type_class_unref_uncached    (gpointer            g_class);
313
314
315 /*< private >*/
316 gboolean         g_type_check_instance          (GTypeInstance      *instance);
317 GTypeInstance*   g_type_check_instance_cast     (GTypeInstance      *instance,
318                                                  GType               iface_type);
319 gboolean         g_type_instance_is_a           (GTypeInstance      *instance,
320                                                  GType               iface_type);
321 GTypeClass*      g_type_check_class_cast        (GTypeClass         *g_class,
322                                                  GType               is_a_type);
323 gboolean         g_type_class_is_a              (GTypeClass         *g_class,
324                                                  GType               is_a_type);
325 gboolean         g_type_check_value             (GValue             *value);
326 gboolean         g_type_value_is_a              (GValue             *value,
327                                                  GType               type);
328 GTypeValueTable* g_type_value_table_peek        (GType               type);
329
330
331 #ifndef G_DISABLE_CAST_CHECKS
332 #  define _G_TYPE_CIC(ip, gt, ct) \
333     ((ct*) g_type_check_instance_cast ((GTypeInstance*) ip, gt))
334 #  define _G_TYPE_CCC(cp, gt, ct) \
335     ((ct*) g_type_check_class_cast ((GTypeClass*) cp, gt))
336 #else /* G_DISABLE_CAST_CHECKS */
337 #  define _G_TYPE_CIC(ip, gt, ct)       ((ct*) ip)
338 #  define _G_TYPE_CCC(cp, gt, ct)       ((ct*) cp)
339 #endif /* G_DISABLE_CAST_CHECKS */
340 #define _G_TYPE_CHI(ip)                 (g_type_check_instance ((GTypeInstance*) ip))
341 #define _G_TYPE_CIT(ip, gt)             (g_type_instance_is_a ((GTypeInstance*) ip, gt))
342 #define _G_TYPE_CCT(cp, gt)             (g_type_class_is_a ((GTypeClass*) cp, gt))
343 #define _G_TYPE_CVT(vl, gt)             (g_type_value_is_a ((GValue*) vl, gt))
344 #define _G_TYPE_CHV(vl)                 (g_type_check_value ((GValue*) vl))
345 #define _G_TYPE_IGC(ip, gt, ct)         ((ct*) (((GTypeInstance*) ip)->g_class))
346 #define _G_TYPE_IGI(ip, gt, ct)         ((ct*) g_type_interface_peek (((GTypeInstance*) ip)->g_class, gt))
347
348
349 #ifdef __cplusplus
350 }
351 #endif /* __cplusplus */
352
353 #endif /* __G_TYPE_H__ */