Difference between revisions of "Hacking:Code Snippets/GObject"

From GIMP Developer Wiki
Jump to: navigation, search
(Implementation)
(Header)
Line 24: Line 24:
 
struct _GimpCageConfig
 
struct _GimpCageConfig
 
{
 
{
   GimpImageMapConfig parent_instance;
+
   GimpImageMapConfig parent_instance;
 
};
 
};
  
 
struct _GimpCageConfigClass
 
struct _GimpCageConfigClass
 
{
 
{
   GimpImageMapConfigClass parent_class;
+
   GimpImageMapConfigClass parent_class;
 
};
 
};
  
GType         gimp_cage_config_get_type               (void) G_GNUC_CONST;</pre>
+
GType gimp_cage_config_get_type (void) G_GNUC_CONST;</pre>
 
+
  
 
== Implementation ==
 
== Implementation ==

Revision as of 09:50, 24 March 2011

The example described here is a GObject implementation of the following Java 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_WITH_CODE (GimpCageConfig, gimp_cage_config,
                         GIMP_TYPE_IMAGE_MAP_CONFIG,
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONFIG,
                                                NULL))

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);
}