Blame gobject/gtypemodule.h

Packit ae235b
/* GObject - GLib Type, Object, Parameter and Signal Library
Packit ae235b
 * Copyright (C) 2000 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
#ifndef __G_TYPE_MODULE_H__
Packit ae235b
#define __G_TYPE_MODULE_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_GOBJECT_H_INSIDE__) && !defined (GOBJECT_COMPILATION)
Packit ae235b
#error "Only <glib-object.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <gobject/gobject.h>
Packit ae235b
#include <gobject/genums.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
typedef struct _GTypeModule      GTypeModule;
Packit ae235b
typedef struct _GTypeModuleClass GTypeModuleClass;
Packit ae235b
Packit ae235b
#define G_TYPE_TYPE_MODULE              (g_type_module_get_type ())
Packit ae235b
#define G_TYPE_MODULE(module)           (G_TYPE_CHECK_INSTANCE_CAST ((module), G_TYPE_TYPE_MODULE, GTypeModule))
Packit ae235b
#define G_TYPE_MODULE_CLASS(class)      (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TYPE_MODULE, GTypeModuleClass))
Packit ae235b
#define G_IS_TYPE_MODULE(module)        (G_TYPE_CHECK_INSTANCE_TYPE ((module), G_TYPE_TYPE_MODULE))
Packit ae235b
#define G_IS_TYPE_MODULE_CLASS(class)   (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TYPE_MODULE))
Packit ae235b
#define G_TYPE_MODULE_GET_CLASS(module) (G_TYPE_INSTANCE_GET_CLASS ((module), G_TYPE_TYPE_MODULE, GTypeModuleClass))
Packit ae235b
Packit ae235b
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTypeModule, g_object_unref)
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GTypeModule:
Packit ae235b
 * @name: the name of the module
Packit ae235b
 * 
Packit ae235b
 * The members of the GTypeModule structure should not 
Packit ae235b
 * be accessed directly, except for the @name field.
Packit ae235b
 */
Packit ae235b
struct _GTypeModule 
Packit ae235b
{
Packit ae235b
  GObject parent_instance;
Packit ae235b
Packit ae235b
  guint use_count;
Packit ae235b
  GSList *type_infos;
Packit ae235b
  GSList *interface_infos;
Packit ae235b
Packit ae235b
  /*< public >*/
Packit ae235b
  gchar *name;
Packit ae235b
};
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GTypeModuleClass:
Packit ae235b
 * @parent_class: the parent class
Packit ae235b
 * @load: loads the module and registers one or more types using
Packit ae235b
 *  g_type_module_register_type().
Packit ae235b
 * @unload: unloads the module
Packit ae235b
 * 
Packit ae235b
 * In order to implement dynamic loading of types based on #GTypeModule, 
Packit ae235b
 * the @load and @unload functions in #GTypeModuleClass must be implemented.
Packit ae235b
 */
Packit ae235b
struct _GTypeModuleClass
Packit ae235b
{
Packit ae235b
  GObjectClass parent_class;
Packit ae235b
Packit ae235b
  /*< public >*/
Packit ae235b
  gboolean (* load)   (GTypeModule *module);
Packit ae235b
  void     (* unload) (GTypeModule *module);
Packit ae235b
Packit ae235b
  /*< private >*/
Packit ae235b
  /* Padding for future expansion */
Packit ae235b
  void (*reserved1) (void);
Packit ae235b
  void (*reserved2) (void);
Packit ae235b
  void (*reserved3) (void);
Packit ae235b
  void (*reserved4) (void);
Packit ae235b
};
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_DEFINE_DYNAMIC_TYPE:
Packit ae235b
 * @TN: The name of the new type, in Camel case.
Packit ae235b
 * @t_n: The name of the new type, in lowercase, with words
Packit ae235b
 *  separated by '_'.
Packit ae235b
 * @T_P: The #GType of the parent type.
Packit ae235b
 * 
Packit ae235b
 * A convenience macro for dynamic type implementations, which declares a
Packit ae235b
 * class initialization function, an instance initialization function (see 
Packit ae235b
 * #GTypeInfo for information about these) and a static variable named 
Packit ae235b
 * `t_n`_parent_class pointing to the parent class. Furthermore,
Packit ae235b
 * it defines a `*_get_type()` and a static `*_register_type()` functions
Packit ae235b
 * for use in your `module_init()`.
Packit ae235b
 *
Packit ae235b
 * See G_DEFINE_DYNAMIC_TYPE_EXTENDED() for an example.
Packit ae235b
 * 
Packit ae235b
 * Since: 2.14
Packit ae235b
 */
Packit ae235b
#define G_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P)          G_DEFINE_DYNAMIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {})
Packit ae235b
/**
Packit ae235b
 * G_DEFINE_DYNAMIC_TYPE_EXTENDED:
Packit ae235b
 * @TypeName: The name of the new type, in Camel case.
Packit ae235b
 * @type_name: The name of the new type, in lowercase, with words
Packit ae235b
 *  separated by '_'.
Packit ae235b
 * @TYPE_PARENT: The #GType of the parent type.
Packit ae235b
 * @flags: #GTypeFlags to pass to g_type_module_register_type()
Packit ae235b
 * @CODE: Custom code that gets inserted in the *_get_type() function.
Packit ae235b
 * 
Packit ae235b
 * A more general version of G_DEFINE_DYNAMIC_TYPE() which
Packit ae235b
 * allows to specify #GTypeFlags and custom code.
Packit ae235b
 * 
Packit ae235b
 * |[
Packit ae235b
 * G_DEFINE_DYNAMIC_TYPE_EXTENDED (GtkGadget,
Packit ae235b
 *                                 gtk_gadget,
Packit ae235b
 *                                 GTK_TYPE_THING,
Packit ae235b
 *                                 0,
Packit ae235b
 *                                 G_IMPLEMENT_INTERFACE_DYNAMIC (TYPE_GIZMO,
Packit ae235b
 *                                                                gtk_gadget_gizmo_init));
Packit ae235b
 * ]|
Packit ae235b
 * expands to
Packit ae235b
 * |[
Packit ae235b
 * static void     gtk_gadget_init              (GtkGadget      *self);
Packit ae235b
 * static void     gtk_gadget_class_init        (GtkGadgetClass *klass);
Packit ae235b
 * static void     gtk_gadget_class_finalize    (GtkGadgetClass *klass);
Packit ae235b
 * 
Packit ae235b
 * static gpointer gtk_gadget_parent_class = NULL;
Packit ae235b
 * static GType    gtk_gadget_type_id = 0;
Packit ae235b
 * 
Packit ae235b
 * static void     gtk_gadget_class_intern_init (gpointer klass)
Packit ae235b
 * {
Packit ae235b
 *   gtk_gadget_parent_class = g_type_class_peek_parent (klass); 
Packit ae235b
 *   gtk_gadget_class_init ((GtkGadgetClass*) klass); 
Packit ae235b
 * }
Packit ae235b
 * 
Packit ae235b
 * GType
Packit ae235b
 * gtk_gadget_get_type (void)
Packit ae235b
 * {
Packit ae235b
 *   return gtk_gadget_type_id;
Packit ae235b
 * }
Packit ae235b
 * 
Packit ae235b
 * static void
Packit ae235b
 * gtk_gadget_register_type (GTypeModule *type_module)
Packit ae235b
 * {
Packit ae235b
 *   const GTypeInfo g_define_type_info = {
Packit ae235b
 *     sizeof (GtkGadgetClass),
Packit ae235b
 *     (GBaseInitFunc) NULL,
Packit ae235b
 *     (GBaseFinalizeFunc) NULL,
Packit ae235b
 *     (GClassInitFunc) gtk_gadget_class_intern_init,
Packit ae235b
 *     (GClassFinalizeFunc) gtk_gadget_class_finalize,
Packit ae235b
 *     NULL,   // class_data
Packit ae235b
 *     sizeof (GtkGadget),
Packit ae235b
 *     0,      // n_preallocs
Packit ae235b
 *     (GInstanceInitFunc) gtk_gadget_init, 
Packit ae235b
 *     NULL    // value_table
Packit ae235b
 *   };
Packit ae235b
 *   gtk_gadget_type_id = g_type_module_register_type (type_module,
Packit ae235b
 *                                                     GTK_TYPE_THING,
Packit ae235b
 *                                                     "GtkGadget",
Packit ae235b
 *                                                     &g_define_type_info,
Packit ae235b
 *                                                     (GTypeFlags) flags);
Packit ae235b
 *   {
Packit ae235b
 *     const GInterfaceInfo g_implement_interface_info = {
Packit ae235b
 *       (GInterfaceInitFunc) gtk_gadget_gizmo_init
Packit ae235b
 *     };
Packit ae235b
 *     g_type_module_add_interface (type_module, g_define_type_id, TYPE_GIZMO, &g_implement_interface_info);
Packit ae235b
 *   }
Packit ae235b
 * }
Packit ae235b
 * ]|
Packit ae235b
 * 
Packit ae235b
 * Since: 2.14
Packit ae235b
 */
Packit ae235b
#define G_DEFINE_DYNAMIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \
Packit ae235b
static void     type_name##_init              (TypeName        *self); \
Packit ae235b
static void     type_name##_class_init        (TypeName##Class *klass); \
Packit ae235b
static void     type_name##_class_finalize    (TypeName##Class *klass); \
Packit ae235b
static gpointer type_name##_parent_class = NULL; \
Packit ae235b
static GType    type_name##_type_id = 0; \
Packit ae235b
static gint     TypeName##_private_offset; \
Packit ae235b
\
Packit ae235b
_G_DEFINE_TYPE_EXTENDED_CLASS_INIT(TypeName, type_name) \
Packit ae235b
\
Packit ae235b
G_GNUC_UNUSED \
Packit ae235b
static inline gpointer \
Packit ae235b
type_name##_get_instance_private (TypeName *self) \
Packit ae235b
{ \
Packit ae235b
  return (G_STRUCT_MEMBER_P (self, TypeName##_private_offset)); \
Packit ae235b
} \
Packit ae235b
\
Packit ae235b
GType \
Packit ae235b
type_name##_get_type (void) \
Packit ae235b
{ \
Packit ae235b
  return type_name##_type_id; \
Packit ae235b
} \
Packit ae235b
static void \
Packit ae235b
type_name##_register_type (GTypeModule *type_module) \
Packit ae235b
{ \
Packit ae235b
  GType g_define_type_id G_GNUC_UNUSED; \
Packit ae235b
  const GTypeInfo g_define_type_info = { \
Packit ae235b
    sizeof (TypeName##Class), \
Packit ae235b
    (GBaseInitFunc) NULL, \
Packit ae235b
    (GBaseFinalizeFunc) NULL, \
Packit ae235b
    (GClassInitFunc) type_name##_class_intern_init, \
Packit ae235b
    (GClassFinalizeFunc) type_name##_class_finalize, \
Packit ae235b
    NULL,   /* class_data */ \
Packit ae235b
    sizeof (TypeName), \
Packit ae235b
    0,      /* n_preallocs */ \
Packit ae235b
    (GInstanceInitFunc) type_name##_init, \
Packit ae235b
    NULL    /* value_table */ \
Packit ae235b
  }; \
Packit ae235b
  type_name##_type_id = g_type_module_register_type (type_module, \
Packit ae235b
						     TYPE_PARENT, \
Packit ae235b
						     #TypeName, \
Packit ae235b
						     &g_define_type_info, \
Packit ae235b
						     (GTypeFlags) flags); \
Packit ae235b
  g_define_type_id = type_name##_type_id; \
Packit ae235b
  { CODE ; } \
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_IMPLEMENT_INTERFACE_DYNAMIC:
Packit ae235b
 * @TYPE_IFACE: The #GType of the interface to add
Packit ae235b
 * @iface_init: The interface init function
Packit ae235b
 *
Packit ae235b
 * A convenience macro to ease interface addition in the @_C_ section
Packit ae235b
 * of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See G_DEFINE_DYNAMIC_TYPE_EXTENDED()
Packit ae235b
 * for an example.
Packit ae235b
 *
Packit ae235b
 * Note that this macro can only be used together with the
Packit ae235b
 * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable
Packit ae235b
 * names from that macro.
Packit ae235b
 *
Packit ae235b
 * Since: 2.24
Packit ae235b
 */
Packit ae235b
#define G_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init)       { \
Packit ae235b
  const GInterfaceInfo g_implement_interface_info = { \
Packit ae235b
    (GInterfaceInitFunc) iface_init, NULL, NULL      \
Packit ae235b
  }; \
Packit ae235b
  g_type_module_add_interface (type_module, g_define_type_id, TYPE_IFACE, &g_implement_interface_info); \
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * G_ADD_PRIVATE_DYNAMIC:
Packit ae235b
 * @TypeName: the name of the type in CamelCase
Packit ae235b
 *
Packit ae235b
 * A convenience macro to ease adding private data to instances of a new dynamic
Packit ae235b
 * type in the @_C_ section of G_DEFINE_DYNAMIC_TYPE_EXTENDED(). See
Packit ae235b
 * G_ADD_PRIVATE() for details, it is similar but for static types.
Packit ae235b
 *
Packit ae235b
 * Note that this macro can only be used together with the
Packit ae235b
 * G_DEFINE_DYNAMIC_TYPE_EXTENDED macros, since it depends on variable
Packit ae235b
 * names from that macro.
Packit ae235b
 *
Packit ae235b
 * Since: 2.38
Packit ae235b
 */
Packit ae235b
#define G_ADD_PRIVATE_DYNAMIC(TypeName)         { \
Packit ae235b
  TypeName##_private_offset = sizeof (TypeName##Private); \
Packit ae235b
}
Packit ae235b
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType    g_type_module_get_type       (void) G_GNUC_CONST;
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gboolean g_type_module_use            (GTypeModule          *module);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_type_module_unuse          (GTypeModule          *module);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_type_module_set_name       (GTypeModule          *module,
Packit ae235b
                                       const gchar          *name);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType    g_type_module_register_type  (GTypeModule          *module,
Packit ae235b
                                       GType                 parent_type,
Packit ae235b
                                       const gchar          *type_name,
Packit ae235b
                                       const GTypeInfo      *type_info,
Packit ae235b
                                       GTypeFlags            flags);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_type_module_add_interface  (GTypeModule          *module,
Packit ae235b
                                       GType                 instance_type,
Packit ae235b
                                       GType                 interface_type,
Packit ae235b
                                       const GInterfaceInfo *interface_info);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType    g_type_module_register_enum  (GTypeModule          *module,
Packit ae235b
                                       const gchar          *name,
Packit ae235b
                                       const GEnumValue     *const_static_values);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
GType    g_type_module_register_flags (GTypeModule          *module,
Packit ae235b
                                       const gchar          *name,
Packit ae235b
                                       const GFlagsValue    *const_static_values);
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_TYPE_MODULE_H__ */