1 /* 2 * Distributed under the Boost Software License, Version 1.0. 3 * (See accompanying file LICENSE_1_0.txt or copy at 4 * http://www.boost.org/LICENSE_1_0.txt) 5 */ 6 module gobject.gtypemodule; 7 8 import gobject.gobject; 9 import gobject.genums; 10 import gobject.gtype; 11 12 import glib; 13 14 15 // #define G_TYPE_TYPE_MODULE (g_type_module_get_type ()) 16 // #define G_TYPE_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), G_TYPE_TYPE_MODULE, GTypeModule)) 17 // #define G_TYPE_MODULE_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TYPE_MODULE, GTypeModuleClass)) 18 // #define G_IS_TYPE_MODULE(module) (G_TYPE_CHECK_INSTANCE_TYPE ((module), G_TYPE_TYPE_MODULE)) 19 // #define G_IS_TYPE_MODULE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TYPE_MODULE)) 20 // #define G_TYPE_MODULE_GET_CLASS(module) (G_TYPE_INSTANCE_GET_CLASS ((module), G_TYPE_TYPE_MODULE, GTypeModuleClass)) 21 22 23 extern (C): 24 25 struct GTypeModule 26 { 27 GObject parent_instance; 28 29 guint use_count; 30 GSList *type_infos; 31 GSList *interface_infos; 32 33 /*< public >*/ 34 gchar *name; 35 } 36 37 struct GTypeModuleClass 38 { 39 GObjectClass parent_class; 40 41 /*< public >*/ 42 gboolean function (GTypeModule *mod) load; 43 void function (GTypeModule *mod) unload; 44 45 /*< private >*/ 46 /* Padding for future expansion */ 47 void function () reserved1; 48 void function () reserved2; 49 void function () reserved3; 50 void function () reserved4; 51 } 52 53 // /** 54 // * G_DEFINE_DYNAMIC_TYPE: 55 // * @TN: The name of the new type, in Camel case. 56 // * @t_n: The name of the new type, in lowercase, with words 57 // * separated by '_'. 58 // * @T_P: The #GType of the parent type. 59 // * 60 // * A convenience macro for dynamic type implementations, which declares a 61 // * class initialization function, an instance initialization function (see 62 // * #GTypeInfo for information about these) and a static variable named 63 // * @t_n<!-- -->_parent_class pointing to the parent class. Furthermore, 64 // * it defines a `*_get_type()` and a static `*_register_type()` functions 65 // * for use in your `module_init()`. 66 // * 67 // * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example. 68 // * 69 // * Since: 2.14 70 // */ 71 // #define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) 72 // /** 73 // * G_DEFINE_DYNAMIC_TYPE_EXTENDED: 74 // * @TypeName: The name of the new type, in Camel case. 75 // * @type_name: The name of the new type, in lowercase, with words 76 // * separated by '_'. 77 // * @TYPE_PARENT: The #GType of the parent type. 78 // * @flags: #GTypeFlags to pass to g_type_module_register_type() 79 // * @CODE: Custom code that gets inserted in the *_get_type() function. 80 // * 81 // * A more general version of G_DEFINE_DYNAMIC_TYPE() which 82 // * allows to specify #GTypeFlags and custom code. 83 // * 84 // * |[ 85 // * G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget, 86 // * gtk_gadget, 87 // * GTK_TYPE_THING, 88 // * 0, 89 // * G_IMPLEMENT_INTERFACE_DYNAMIC (TYPE_GIZMO, 90 // * gtk_gadget_gizmo_init)); 91 // * ]| 92 // * expands to 93 // * |[ 94 // * static void gtk_gadget_init (GtkGadget *self); 95 // * static void gtk_gadget_class_init (GtkGadgetClass *klass); 96 // * static void gtk_gadget_class_finalize (GtkGadgetClass *klass); 97 // * 98 // * static gpointer gtk_gadget_parent_class = NULL; 99 // * static GType gtk_gadget_type_id = 0; 100 // * 101 // * static void gtk_gadget_class_intern_init (gpointer klass) 102 // * { 103 // * gtk_gadget_parent_class = g_type_class_peek_parent (klass); 104 // * gtk_gadget_class_init ((GtkGadgetClass*) klass); 105 // * } 106 // * 107 // * GType 108 // * gtk_gadget_get_type (void) 109 // * { 110 // * return gtk_gadget_type_id; 111 // * } 112 // * 113 // * static void 114 // * gtk_gadget_register_type (GTypeModule *type_module) 115 // * { 116 // * const GTypeInfo g_define_type_info = { 117 // * sizeof (GtkGadgetClass), 118 // * (GBaseInitFunc) NULL, 119 // * (GBaseFinalizeFunc) NULL, 120 // * (GClassInitFunc) gtk_gadget_class_intern_init, 121 // * (GClassFinalizeFunc) gtk_gadget_class_finalize, 122 // * NULL, // class_data 123 // * sizeof (GtkGadget), 124 // * 0, // n_preallocs 125 // * (GInstanceInitFunc) gtk_gadget_init, 126 // * NULL // value_table 127 // * }; 128 // * gtk_gadget_type_id = g_type_module_register_type (type_module, 129 // * GTK_TYPE_THING, 130 // * "GtkGadget", 131 // * &g_define_type_info, 132 // * (GTypeFlags) flags); 133 // * { 134 // * const GInterfaceInfo g_implement_interface_info = { 135 // * (GInterfaceInitFunc) gtk_gadget_gizmo_init 136 // * }; 137 // * g_type_module_add_interface (type_module, g_define_type_id, TYPE_GIZMO, &g_implement_interface_info); 138 // * } 139 // * } 140 // * ]| 141 // * 142 // * Since: 2.14 143 // */ 144 // #define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \ 145 // static void type_name##_init (TypeName *self); \ 146 // static void type_name##_class_init (TypeName##Class *klass); \ 147 // static void type_name##_class_finalize (TypeName##Class *klass); \ 148 // static gpointer type_name##_parent_class = NULL; \ 149 // static GType type_name##_type_id = 0; \ 150 // static gint TypeName##_private_offset; \ 151 // \ 152 // _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \ 153 // \ 154 // static inline gpointer \ 155 // type_name##_get_instance_private (TypeName *self) \ 156 // { \ 157 // return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \ 158 // } \ 159 // \ 160 // GType \ 161 // type_name##_get_type (void) \ 162 // { \ 163 // return type_name##_type_id; \ 164 // } \ 165 // static void \ 166 // type_name##_register_type (GTypeModule *type_module) \ 167 // { \ 168 // GType g_define_type_id G_GNUC_UNUSED; \ 169 // const GTypeInfo g_define_type_info = { \ 170 // sizeof (TypeName##Class), \ 171 // (GBaseInitFunc) NULL, \ 172 // (GBaseFinalizeFunc) NULL, \ 173 // (GClassInitFunc) type_name##_class_intern_init, \ 174 // (GClassFinalizeFunc) type_name##_class_finalize, \ 175 // NULL, /* class_data */ \ 176 // sizeof (TypeName), \ 177 // 0, /* n_preallocs */ \ 178 // (GInstanceInitFunc) type_name##_init, \ 179 // NULL /* value_table */ \ 180 // }; \ 181 // type_name##_type_id = g_type_module_register_type (type_module, \ 182 // TYPE_PARENT, \ 183 // #TypeName, \ 184 // &g_define_type_info, \ 185 // (GTypeFlags) flags); \ 186 // g_define_type_id = type_name##_type_id; \ 187 // { CODE ; } \ 188 // } 189 // 190 // /** 191 // * G_IMPLEMENT_INTERFACE_DYNAMIC: 192 // * @TYPE_IFACE: The #GType of the interface to add 193 // * @iface_init: The interface init function 194 // * 195 // * A convenience macro to ease interface addition in the @_C_ section 196 // * of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See G_DEFINE_DYNAMIC_TYPE_EXTENDED() 197 // * for an example. 198 // * 199 // * Note that this macro can only be used together with the 200 // * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable 201 // * names from that macro. 202 // * 203 // * Since: 2.24 204 // */ 205 // #define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) { \ 206 // const GInterfaceInfo g_implement_interface_info = { \ 207 // (GInterfaceInitFunc) iface_init, NULL, NULL \ 208 // }; \ 209 // g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \ 210 // } 211 // 212 // #define G_ADD_PRIVATE_DYNAMIC(TypeName) { \ 213 // TypeName##_private_offset = sizeof (TypeName##Private); \ 214 // } 215 216 217 pure GType g_type_module_get_type (); 218 219 gboolean g_type_module_use (GTypeModule *mod); 220 221 void g_type_module_unuse (GTypeModule *mod); 222 223 void g_type_module_set_name (GTypeModule *mod, 224 const(gchar) *name); 225 226 GType g_type_module_register_type (GTypeModule *mod, 227 GType parent_type, 228 const(gchar) *type_name, 229 const(GTypeInfo) *type_info, 230 GTypeFlags flags); 231 232 void g_type_module_add_interface (GTypeModule *mod, 233 GType instance_type, 234 GType interface_type, 235 const(GInterfaceInfo) *interface_info); 236 237 GType g_type_module_register_enum (GTypeModule *mod, 238 const(gchar) *name, 239 const(GEnumValue) *const_static_values); 240 241 GType g_type_module_register_flags (GTypeModule *mod, 242 const(gchar) *name, 243 const(GFlagsValue) *const_static_values); 244