Function Macro

GObjectDECLARE_INTERFACE

since: 2.44

Declaration [src]

#define G_DECLARE_INTERFACE (
  ModuleObjName,
  module_obj_name,
  MODULE,
  OBJ_NAME,
  PrerequisiteName
)

Description [src]

A convenience macro for emitting the usual declarations in the header file for a GInterface type.

You might use it in a header as follows:

#ifndef _my_model_h_
#define _my_model_h_

#define MY_TYPE_MODEL my_model_get_type ()
GDK_AVAILABLE_IN_3_12
G_DECLARE_INTERFACE (MyModel, my_model, MY, MODEL, GObject)

struct _MyModelInterface
{
  GTypeInterface g_iface;

  gpointer (* get_item)  (MyModel *model);
};

gpointer my_model_get_item (MyModel *model);

...

#endif

And use it as follow in your C file:

G_DEFINE_INTERFACE (MyModel, my_model, G_TYPE_OBJECT);

static void
my_model_default_init (MyModelInterface *iface)
{
  ...
}

This results in the following things happening:

  • the usual my_model_get_type() function is declared with a return type of GType

  • the MyModelInterface type is defined as a typedef to struct _MyModelInterface, which is left undefined. You should do this from the header file directly after you use the macro.

  • the MY_MODEL() cast is emitted as static inline functions along with the MY_IS_MODEL() type checking function and MY_MODEL_GET_IFACE() function.

  • g_autoptr() support being added for your type, based on your prerequisite type.

You can only use this function if your prerequisite type also supports g_autoptr().

Because the type macro (MY_TYPE_MODEL in the above example) is not a callable, you must continue to manually define this as a macro for yourself.

The declaration of the _get_type() function is the first thing emitted by the macro. This allows this macro to be used in the usual way with export control and API versioning macros.

Available since: 2.44

This function is not directly available to language bindings.

Parameters

ModuleObjName

Type: -

The name of the new type, in camel case (like GtkWidget).

module_obj_name

Type: -

The name of the new type in lowercase, with words separated by _ (like gtk_widget).

MODULE

Type: -

The name of the module, in all caps (like GTK).

OBJ_NAME

Type: -

The bare name of the type, in all caps (like WIDGET).

PrerequisiteName

Type: -

The name of the prerequisite type, in camel case (like GtkWidget).