Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:17:40

0001 /* GObject - GLib Type, Object, Parameter and Signal Library
0002  * Copyright (C) 2000 Red Hat, Inc.
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
0018  */
0019 #ifndef __G_TYPE_MODULE_H__
0020 #define __G_TYPE_MODULE_H__
0021 
0022 #if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
0023 #error "Only <glib-object.h> can be included directly."
0024 #endif
0025 
0026 #include <gobject/gobject.h>
0027 #include <gobject/genums.h>
0028 
0029 G_BEGIN_DECLS
0030 
0031 typedef struct _GTypeModule      GTypeModule;
0032 typedef struct _GTypeModuleClass GTypeModuleClass;
0033 
0034 #define G_TYPE_TYPE_MODULE              (g_type_module_get_type ())
0035 #define G_TYPE_MODULE(module)           (G_TYPE_CHECK_INSTANCE_CAST ((module), G_TYPE_TYPE_MODULE, GTypeModule))
0036 #define G_TYPE_MODULE_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TYPE_MODULE, GTypeModuleClass))
0037 #define G_IS_TYPE_MODULE(module)        (G_TYPE_CHECK_INSTANCE_TYPE ((module), G_TYPE_TYPE_MODULE))
0038 #define G_IS_TYPE_MODULE_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TYPE_MODULE))
0039 #define G_TYPE_MODULE_GET_CLASS(module) (G_TYPE_INSTANCE_GET_CLASS ((module), G_TYPE_TYPE_MODULE, GTypeModuleClass))
0040 
0041 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTypeModule, g_object_unref)
0042 
0043 struct _GTypeModule 
0044 {
0045   GObject parent_instance;
0046 
0047   guint use_count;
0048   GSList *type_infos;
0049   GSList *interface_infos;
0050 
0051   /*< public >*/
0052   gchar *name;
0053 };
0054 
0055 /**
0056  * GTypeModuleClass:
0057  * @parent_class: the parent class
0058  * @load: loads the module and registers one or more types using
0059  *  g_type_module_register_type().
0060  * @unload: unloads the module
0061  * 
0062  * In order to implement dynamic loading of types based on #GTypeModule, 
0063  * the @load and @unload functions in #GTypeModuleClass must be implemented.
0064  */
0065 struct _GTypeModuleClass
0066 {
0067   GObjectClass parent_class;
0068 
0069   /*< public >*/
0070   gboolean (* load)   (GTypeModule *module);
0071   void     (* unload) (GTypeModule *module);
0072 
0073   /*< private >*/
0074   /* Padding for future expansion */
0075   void (*reserved1) (void);
0076   void (*reserved2) (void);
0077   void (*reserved3) (void);
0078   void (*reserved4) (void);
0079 };
0080 
0081 /**
0082  * G_DEFINE_DYNAMIC_TYPE:
0083  * @TN: The name of the new type, in Camel case.
0084  * @t_n: The name of the new type, in lowercase, with words
0085  *  separated by '_'.
0086  * @T_P: The #GType of the parent type.
0087  * 
0088  * A convenience macro for dynamic type implementations, which declares a
0089  * class initialization function, an instance initialization function (see 
0090  * #GTypeInfo for information about these) and a static variable named 
0091  * `t_n`_parent_class pointing to the parent class.
0092  *
0093  * Furthermore, it defines a `*_get_type()` and a static `*_register_type()`
0094  * functions for use in your `module_init()`.
0095  *
0096  * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example.
0097  * 
0098  * Since: 2.14
0099  */
0100 #define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P)          G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
0101 /**
0102  * G_DEFINE_DYNAMIC_TYPE_EXTENDED:
0103  * @TypeName: The name of the new type, in Camel case.
0104  * @type_name: The name of the new type, in lowercase, with words
0105  *  separated by '_'.
0106  * @TYPE_PARENT: The #GType of the parent type.
0107  * @flags: #GTypeFlags to pass to g_type_module_register_type()
0108  * @CODE: Custom code that gets inserted in the *_get_type() function.
0109  * 
0110  * A more general version of G_DEFINE_DYNAMIC_TYPE() which
0111  * allows to specify #GTypeFlags and custom code.
0112  * 
0113  * |[<!-- language="C" -->
0114  * G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget,
0115  *                                 gtk_gadget,
0116  *                                 GTK_TYPE_THING,
0117  *                                 0,
0118  *                                 G_IMPLEMENT_INTERFACE_DYNAMIC (TYPE_GIZMO,
0119  *                                                                gtk_gadget_gizmo_init));
0120  * ]|
0121  *
0122  * expands to
0123  *
0124  * |[<!-- language="C" -->
0125  * static void     gtk_gadget_init              (GtkGadget      *self);
0126  * static void     gtk_gadget_class_init        (GtkGadgetClass *klass);
0127  * static void     gtk_gadget_class_finalize    (GtkGadgetClass *klass);
0128  * 
0129  * static gpointer gtk_gadget_parent_class = NULL;
0130  * static GType    gtk_gadget_type_id = 0;
0131  * 
0132  * static void     gtk_gadget_class_intern_init (gpointer klass)
0133  * {
0134  *   gtk_gadget_parent_class = g_type_class_peek_parent (klass); 
0135  *   gtk_gadget_class_init ((GtkGadgetClass*) klass); 
0136  * }
0137  * 
0138  * GType
0139  * gtk_gadget_get_type (void)
0140  * {
0141  *   return gtk_gadget_type_id;
0142  * }
0143  * 
0144  * static void
0145  * gtk_gadget_register_type (GTypeModule *type_module)
0146  * {
0147  *   const GTypeInfo g_define_type_info = {
0148  *     sizeof (GtkGadgetClass),
0149  *     (GBaseInitFunc) NULL,
0150  *     (GBaseFinalizeFunc) NULL,
0151  *     (GClassInitFunc) gtk_gadget_class_intern_init,
0152  *     (GClassFinalizeFunc) gtk_gadget_class_finalize,
0153  *     NULL,   // class_data
0154  *     sizeof (GtkGadget),
0155  *     0,      // n_preallocs
0156  *     (GInstanceInitFunc) gtk_gadget_init, 
0157  *     NULL    // value_table
0158  *   };
0159  *   gtk_gadget_type_id = g_type_module_register_type (type_module,
0160  *                                                     GTK_TYPE_THING,
0161  *                                                     "GtkGadget",
0162  *                                                     &g_define_type_info,
0163  *                                                     (GTypeFlags) flags);
0164  *   {
0165  *     const GInterfaceInfo g_implement_interface_info = {
0166  *       (GInterfaceInitFunc) gtk_gadget_gizmo_init
0167  *     };
0168  *     g_type_module_add_interface (type_module, g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
0169  *   }
0170  * }
0171  * ]|
0172  * 
0173  * Since: 2.14
0174  */
0175 #define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
0176 static void     type_name##_init              (TypeName        *self); \
0177 static void     type_name##_class_init        (TypeName##Class *klass); \
0178 static void     type_name##_class_finalize    (TypeName##Class *klass); \
0179 static gpointer type_name##_parent_class = NULL; \
0180 static GType    type_name##_type_id = 0; \
0181 static gint     TypeName##_private_offset; \
0182 \
0183 _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
0184 \
0185 G_GNUC_UNUSED \
0186 static inline gpointer \
0187 type_name##_get_instance_private (TypeName *self) \
0188 { \
0189   return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
0190 } \
0191 \
0192 GType \
0193 type_name##_get_type (void) \
0194 { \
0195   return type_name##_type_id; \
0196 } \
0197 static void \
0198 type_name##_register_type (GTypeModule *type_module) \
0199 { \
0200   GType g_define_type_id G_GNUC_UNUSED; \
0201   const GTypeInfo g_define_type_info = { \
0202     sizeof (TypeName##Class), \
0203     (GBaseInitFunc) NULL, \
0204     (GBaseFinalizeFunc) NULL, \
0205     (GClassInitFunc)(void (*)(void)) type_name##_class_intern_init, \
0206     (GClassFinalizeFunc)(void (*)(void)) type_name##_class_finalize, \
0207     NULL,   /* class_data */ \
0208     sizeof (TypeName), \
0209     0,      /* n_preallocs */ \
0210     (GInstanceInitFunc)(void (*)(void)) type_name##_init, \
0211     NULL    /* value_table */ \
0212   }; \
0213   type_name##_type_id = g_type_module_register_type (type_module, \
0214                              TYPE_PARENT, \
0215                              #TypeName, \
0216                              &g_define_type_info, \
0217                              (GTypeFlags) flags); \
0218   g_define_type_id = type_name##_type_id; \
0219   { CODE ; } \
0220 }
0221 
0222 /**
0223  * G_IMPLEMENT_INTERFACE_DYNAMIC:
0224  * @TYPE_IFACE: The #GType of the interface to add
0225  * @iface_init: The interface init function
0226  *
0227  * A convenience macro to ease interface addition in the @_C_ section
0228  * of G_DEFINE_DYNAMIC_TYPE_EXTENDED().
0229  *
0230  * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example.
0231  *
0232  * Note that this macro can only be used together with the
0233  * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable
0234  * names from that macro.
0235  *
0236  * Since: 2.24
0237  */
0238 #define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init)       { \
0239   const GInterfaceInfo g_implement_interface_info = { \
0240     (GInterfaceInitFunc)(void (*)(void)) iface_init, NULL, NULL      \
0241   }; \
0242   g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
0243 }
0244 
0245 /**
0246  * G_ADD_PRIVATE_DYNAMIC:
0247  * @TypeName: the name of the type in CamelCase
0248  *
0249  * A convenience macro to ease adding private data to instances of a new dynamic
0250  * type in the @_C_ section of G_DEFINE_DYNAMIC_TYPE_EXTENDED().
0251  *
0252  * See G_ADD_PRIVATE() for details, it is similar but for static types.
0253  *
0254  * Note that this macro can only be used together with the
0255  * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable
0256  * names from that macro.
0257  *
0258  * Since: 2.38
0259  */
0260 #define G_ADD_PRIVATE_DYNAMIC(TypeName)         { \
0261   TypeName##_private_offset = sizeof (TypeName##Private); \
0262 }
0263 
0264 GOBJECT_AVAILABLE_IN_ALL
0265 GType    g_type_module_get_type       (void) G_GNUC_CONST;
0266 GOBJECT_AVAILABLE_IN_ALL
0267 gboolean g_type_module_use            (GTypeModule          *module);
0268 GOBJECT_AVAILABLE_IN_ALL
0269 void     g_type_module_unuse          (GTypeModule          *module);
0270 GOBJECT_AVAILABLE_IN_ALL
0271 void     g_type_module_set_name       (GTypeModule          *module,
0272                                        const gchar          *name);
0273 GOBJECT_AVAILABLE_IN_ALL
0274 GType    g_type_module_register_type  (GTypeModule          *module,
0275                                        GType                 parent_type,
0276                                        const gchar          *type_name,
0277                                        const GTypeInfo      *type_info,
0278                                        GTypeFlags            flags);
0279 GOBJECT_AVAILABLE_IN_ALL
0280 void     g_type_module_add_interface  (GTypeModule          *module,
0281                                        GType                 instance_type,
0282                                        GType                 interface_type,
0283                                        const GInterfaceInfo *interface_info);
0284 GOBJECT_AVAILABLE_IN_ALL
0285 GType    g_type_module_register_enum  (GTypeModule          *module,
0286                                        const gchar          *name,
0287                                        const GEnumValue     *const_static_values);
0288 GOBJECT_AVAILABLE_IN_ALL
0289 GType    g_type_module_register_flags (GTypeModule          *module,
0290                                        const gchar          *name,
0291                                        const GFlagsValue    *const_static_values);
0292 
0293 G_END_DECLS
0294 
0295 #endif /* __G_TYPE_MODULE_H__ */