Conventions

There are a number of conventions users are expected to follow when creating new types which are to be exported in a header file:

The implementation of these macros is pretty straightforward: a number of simple-to-use macros are provided in gtype.h. For the example we used above, we would write the following trivial code to declare the macros:

1
2
#define MAMAN_TYPE_BAR maman_bar_get_type ()
G_DECLARE_FINAL_TYPE (MamanBar, maman_bar, MAMAN, BAR, GObject)

Unless your code has special requirements, you can use the G_DEFINE_TYPE macro to define a class:

1
G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT)

Otherwise, the maman_bar_get_type function must be implemented manually:

1
2
3
4
5
6
7
8
9
10
11
12
13
GType maman_bar_get_type (void)
{
  static GType type = 0;
  if (type == 0) {
    const GTypeInfo info = {
      /* You fill this structure. */
    };
    type = g_type_register_static (G_TYPE_OBJECT,
                                   "MamanBarType",
                                   &info, 0);
  }
  return type;
}



[2] Maman is the French word for mum or mother — nothing more and nothing less.