Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Created May 13, 2014 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebrainz/f8000c1f0d07e8c0c336 to your computer and use it in GitHub Desktop.
Save codebrainz/f8000c1f0d07e8c0c336 to your computer and use it in GitHub Desktop.
Minimal GObject boilerplate (~ 8 lines of additional code)
#include "foobar.h"
G_DEFINE_TYPE (FooBar, foo_bar, G_TYPE_OBJECT)
static void foo_bar_class_init (FooBarClass *klass) {}
static void foo_bar_init (FooBar *self) {}
// Test program, doesn't count :)
int main()
{
g_type_init();
GObject *theObj = g_object_new(foo_bar_get_type(), NULL);
g_object_ref(theObj);
g_object_unref(theObj);
g_object_unref(theObj);
return 0;
}
#ifndef FOOBAR_H_
#define FOOBAR_H_ 1
#include <glib-object.h>
typedef struct FooBar_ {
GObject parent;
}
FooBar;
typedef struct FooBarClass_ {
GObjectClass parent_class;
}
FooBarClass;
GType foo_bar_get_type(void);
#endif /* FOOBAR_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment