Hacking:Code Snippets/GObject

From GIMP Developer Wiki
Jump to: navigation, search

The example described here is a GObject implementation of the following C++ class:

class GimpCageConfig : public GimpImageMapConfig
{
  public:
    GimpCageConfig() {};
    virtual ~GimpCageConfig() {};
};


Header

#define GIMP_TYPE_CAGE_CONFIG            (gimp_cage_config_get_type ())
#define GIMP_CAGE_CONFIG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CAGE_CONFIG, GimpCageConfig))
#define GIMP_CAGE_CONFIG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_CAGE_CONFIG, GimpCageConfigClass))
#define GIMP_IS_CAGE_CONFIG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CAGE_CONFIG))
#define GIMP_IS_CAGE_CONFIG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CAGE_CONFIG))
#define GIMP_CAGE_CONFIG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_CAGE_CONFIG, GimpCageConfigClass))


typedef struct _GimpCageConfigClass GimpCageConfigClass;

struct _GimpCageConfig
{
  GimpImageMapConfig parent_instance;
};

struct _GimpCageConfigClass
{
  GimpImageMapConfigClass parent_class;
};

GType gimp_cage_config_get_type (void) G_GNUC_CONST;

Implementation

#include "gimpcageconfig.h"

static void gimp_cage_config_finalize (GObject *object);


G_DEFINE_TYPE (GimpCageConfig,
               gimp_cage_config,
               GIMP_TYPE_IMAGE_MAP_CONFIG)

static void
gimp_cage_config_class_init (GimpCageConfigClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  object_class->finalize     = gimp_cage_config_finalize;
}

static void
gimp_cage_config_finalize (GObject *object)
{
  GimpCageConfig  *gcc = GIMP_CAGE_CONFIG (object);

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

Code Generator

A good way to learn or hack GObject is to use a boilerplate generator. There is a good one in the Anjuta IDE.

Personal tools