GVala: interface gen() added.

This commit is contained in:
Kolan Sh 2012-10-15 15:21:42 +04:00
parent 52a6bbbcb5
commit 9226e0923b
8 changed files with 189 additions and 5 deletions

View File

@ -6,6 +6,7 @@
#include <glib-object.h> #include <glib-object.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#define TYPE_GVALA (gvala_get_type ()) #define TYPE_GVALA (gvala_get_type ())
@ -48,6 +49,35 @@ typedef struct _TXRDocClass TXRDocClass;
typedef struct _TXRGraphics TXRGraphics; typedef struct _TXRGraphics TXRGraphics;
typedef struct _TXRGraphicsClass TXRGraphicsClass; typedef struct _TXRGraphicsClass TXRGraphicsClass;
#define TYPE_TXR_OBJECT_LIST (txr_object_list_get_type ())
#define TXR_OBJECT_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_OBJECT_LIST, TXRObjectList))
#define TXR_OBJECT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_OBJECT_LIST, TXRObjectListClass))
#define IS_TXR_OBJECT_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TXR_OBJECT_LIST))
#define IS_TXR_OBJECT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TXR_OBJECT_LIST))
#define TXR_OBJECT_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TXR_OBJECT_LIST, TXRObjectListClass))
typedef struct _TXRObjectList TXRObjectList;
typedef struct _TXRObjectListClass TXRObjectListClass;
#define TYPE_TXR_ADD_SPACES (txr_add_spaces_get_type ())
#define TXR_ADD_SPACES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_ADD_SPACES, TXRAddSpaces))
#define TXR_ADD_SPACES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_ADD_SPACES, TXRAddSpacesClass))
#define IS_TXR_ADD_SPACES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TXR_ADD_SPACES))
#define IS_TXR_ADD_SPACES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TXR_ADD_SPACES))
#define TXR_ADD_SPACES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TXR_ADD_SPACES, TXRAddSpacesClass))
typedef struct _TXRAddSpaces TXRAddSpaces;
typedef struct _TXRAddSpacesClass TXRAddSpacesClass;
#define TYPE_TXR_DOC_IFACE (txr_doc_iface_get_type ())
#define TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_DOC_IFACE, TXRDocIface))
#define IS_TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TXR_DOC_IFACE))
#define TXR_DOC_IFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TXR_DOC_IFACE, TXRDocIfaceIface))
typedef struct _TXRDocIface TXRDocIface;
typedef struct _TXRDocIfaceIface TXRDocIfaceIface;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
struct _GVala { struct _GVala {
@ -59,6 +89,11 @@ struct _GValaClass {
GObjectClass parent_class; GObjectClass parent_class;
}; };
struct _TXRDocIfaceIface {
GTypeInterface parent_iface;
gchar* (*gen) (TXRDocIface* self);
};
static gpointer gvala_parent_class = NULL; static gpointer gvala_parent_class = NULL;
@ -73,6 +108,12 @@ GType txr_object_get_type (void) G_GNUC_CONST;
GType txr_doc_get_type (void) G_GNUC_CONST; GType txr_doc_get_type (void) G_GNUC_CONST;
GType txr_graphics_get_type (void) G_GNUC_CONST; GType txr_graphics_get_type (void) G_GNUC_CONST;
void txr_object_copy (TXRObject* self, TXRObject* copy); void txr_object_copy (TXRObject* self, TXRObject* copy);
TXRAddSpaces* txr_add_spaces_new (void);
TXRAddSpaces* txr_add_spaces_construct (GType object_type);
GType txr_object_list_get_type (void) G_GNUC_CONST;
GType txr_add_spaces_get_type (void) G_GNUC_CONST;
GType txr_doc_iface_get_type (void) G_GNUC_CONST;
gchar* txr_doc_iface_gen (TXRDocIface* self);
GVala* gvala_new (void); GVala* gvala_new (void);
GVala* gvala_construct (GType object_type); GVala* gvala_construct (GType object_type);
@ -83,12 +124,38 @@ gint gvala_main (gchar** args, int args_length1) {
TXRGraphics* graphics1; TXRGraphics* graphics1;
TXRGraphics* _tmp1_; TXRGraphics* _tmp1_;
TXRGraphics* graphics2; TXRGraphics* graphics2;
TXRAddSpaces* _tmp2_;
TXRAddSpaces* addspaces;
FILE* _tmp3_;
gchar* _tmp4_ = NULL;
gchar* _tmp5_;
TXRGraphics* _tmp6_;
TXRGraphics* graphics;
FILE* _tmp7_;
gchar* _tmp8_ = NULL;
gchar* _tmp9_;
_tmp0_ = txr_graphics_new (); _tmp0_ = txr_graphics_new ();
graphics1 = _tmp0_; graphics1 = _tmp0_;
_tmp1_ = txr_graphics_new (); _tmp1_ = txr_graphics_new ();
graphics2 = _tmp1_; graphics2 = _tmp1_;
txr_object_copy ((TXRObject*) graphics1, (TXRObject*) graphics2); txr_object_copy ((TXRObject*) graphics1, (TXRObject*) graphics2);
_tmp2_ = txr_add_spaces_new ();
addspaces = _tmp2_;
_tmp3_ = stdout;
_tmp4_ = txr_doc_iface_gen ((TXRDocIface*) addspaces);
_tmp5_ = _tmp4_;
fprintf (_tmp3_, "addspaces.gen() = %s\n", _tmp5_);
_g_free0 (_tmp5_);
_tmp6_ = txr_graphics_new ();
graphics = _tmp6_;
_tmp7_ = stdout;
_tmp8_ = txr_doc_iface_gen ((TXRDocIface*) graphics);
_tmp9_ = _tmp8_;
fprintf (_tmp7_, "graphics.gen() = %s\n", _tmp9_);
_g_free0 (_tmp9_);
result = 0; result = 0;
_g_object_unref0 (graphics);
_g_object_unref0 (addspaces);
_g_object_unref0 (graphics2); _g_object_unref0 (graphics2);
_g_object_unref0 (graphics1); _g_object_unref0 (graphics1);
return result; return result;

View File

@ -7,6 +7,11 @@ public class GVala : GLib.Object {
//doc.copy ((TXRObject) graphics); //doc.copy ((TXRObject) graphics);
//graphics.copy ((TXRObject) doc); //graphics.copy ((TXRObject) doc);
var addspaces = new TXRAddSpaces ();
stdout.printf ("addspaces.gen() = %s\n", addspaces.gen());
var graphics = new TXRGraphics ();
stdout.printf ("graphics.gen() = %s\n", graphics.gen());
return 0; return 0;
} }
} }

View File

@ -1,4 +1,4 @@
public class TXRAddSpaces : TXRObjectList { public class TXRAddSpaces : TXRObjectList, TXRDocIface {
public int addspaces_field; public int addspaces_field;
public override void copy (TXRObject copy) { public override void copy (TXRObject copy) {
@ -8,4 +8,8 @@ public class TXRAddSpaces : TXRObjectList {
((TXRAddSpaces)copy).addspaces_field = this.addspaces_field; ((TXRAddSpaces)copy).addspaces_field = this.addspaces_field;
} }
} }
public string gen () {
return "TXRAddSpaces generated string.";
}
} }

View File

@ -4,9 +4,19 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#define TYPE_TXR_DOC_IFACE (txr_doc_iface_get_type ())
#define TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_DOC_IFACE, TXRDocIface))
#define IS_TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TXR_DOC_IFACE))
#define TXR_DOC_IFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TXR_DOC_IFACE, TXRDocIfaceIface))
typedef struct _TXRDocIface TXRDocIface;
typedef struct _TXRDocIfaceIface TXRDocIfaceIface;
#define TYPE_TXR_OBJECT (txr_object_get_type ()) #define TYPE_TXR_OBJECT (txr_object_get_type ())
#define TXR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_OBJECT, TXRObject)) #define TXR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_OBJECT, TXRObject))
#define TXR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_OBJECT, TXRObjectClass)) #define TXR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_OBJECT, TXRObjectClass))
@ -29,6 +39,11 @@ typedef struct _TXRDoc TXRDoc;
typedef struct _TXRDocClass TXRDocClass; typedef struct _TXRDocClass TXRDocClass;
typedef struct _TXRDocPrivate TXRDocPrivate; typedef struct _TXRDocPrivate TXRDocPrivate;
struct _TXRDocIfaceIface {
GTypeInterface parent_iface;
gchar* (*gen) (TXRDocIface* self);
};
struct _TXRObject { struct _TXRObject {
GObject parent_instance; GObject parent_instance;
TXRObjectPrivate * priv; TXRObjectPrivate * priv;
@ -53,12 +68,15 @@ struct _TXRDocClass {
static gpointer txr_doc_parent_class = NULL; static gpointer txr_doc_parent_class = NULL;
GType txr_doc_iface_get_type (void) G_GNUC_CONST;
gchar* txr_doc_iface_gen (TXRDocIface* self);
GType txr_object_get_type (void) G_GNUC_CONST; GType txr_object_get_type (void) G_GNUC_CONST;
GType txr_doc_get_type (void) G_GNUC_CONST; GType txr_doc_get_type (void) G_GNUC_CONST;
enum { enum {
TXR_DOC_DUMMY_PROPERTY TXR_DOC_DUMMY_PROPERTY
}; };
static void txr_doc_real_copy (TXRObject* base, TXRObject* copy); static void txr_doc_real_copy (TXRObject* base, TXRObject* copy);
void txr_object_copy (TXRObject* self, TXRObject* copy);
TXRDoc* txr_doc_new (void); TXRDoc* txr_doc_new (void);
TXRDoc* txr_doc_construct (GType object_type); TXRDoc* txr_doc_construct (GType object_type);
TXRObject* txr_object_new (void); TXRObject* txr_object_new (void);
@ -66,18 +84,52 @@ TXRObject* txr_object_construct (GType object_type);
static void txr_doc_finalize (GObject* obj); static void txr_doc_finalize (GObject* obj);
gchar* txr_doc_iface_gen (TXRDocIface* self) {
g_return_val_if_fail (self != NULL, NULL);
return TXR_DOC_IFACE_GET_INTERFACE (self)->gen (self);
}
static void txr_doc_iface_base_init (TXRDocIfaceIface * iface) {
static gboolean initialized = FALSE;
if (!initialized) {
initialized = TRUE;
}
}
GType txr_doc_iface_get_type (void) {
static volatile gsize txr_doc_iface_type_id__volatile = 0;
if (g_once_init_enter (&txr_doc_iface_type_id__volatile)) {
static const GTypeInfo g_define_type_info = { sizeof (TXRDocIfaceIface), (GBaseInitFunc) txr_doc_iface_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
GType txr_doc_iface_type_id;
txr_doc_iface_type_id = g_type_register_static (G_TYPE_INTERFACE, "TXRDocIface", &g_define_type_info, 0);
g_type_interface_add_prerequisite (txr_doc_iface_type_id, G_TYPE_OBJECT);
g_once_init_leave (&txr_doc_iface_type_id__volatile, txr_doc_iface_type_id);
}
return txr_doc_iface_type_id__volatile;
}
static void txr_doc_real_copy (TXRObject* base, TXRObject* copy) { static void txr_doc_real_copy (TXRObject* base, TXRObject* copy) {
TXRDoc * self; TXRDoc * self;
FILE* _tmp0_; FILE* _tmp0_;
TXRObject* _tmp1_; TXRObject* _tmp1_;
gint _tmp2_;
self = (TXRDoc*) base; self = (TXRDoc*) base;
g_return_if_fail (copy != NULL); g_return_if_fail (copy != NULL);
_tmp0_ = stdout; _tmp0_ = stdout;
fprintf (_tmp0_, "TXRDoc:copy() called\n"); fprintf (_tmp0_, "TXRDoc:copy() called\n");
_tmp1_ = copy; _tmp1_ = copy;
_tmp2_ = self->doc_field; if (IS_TXR_OBJECT (_tmp1_)) {
TXR_DOC (_tmp1_)->doc_field = _tmp2_; TXRObject* _tmp2_;
TXRObject* _tmp3_;
gint _tmp4_;
_tmp2_ = copy;
TXR_OBJECT_CLASS (txr_doc_parent_class)->copy (TXR_OBJECT (self), _tmp2_);
_tmp3_ = copy;
_tmp4_ = self->doc_field;
TXR_DOC (_tmp3_)->doc_field = _tmp4_;
}
} }

View File

@ -1,3 +1,7 @@
public interface TXRDocIface : Object {
public abstract string gen ();
}
public class TXRDoc : TXRObject { public class TXRDoc : TXRObject {
public int doc_field; public int doc_field;

View File

@ -4,6 +4,8 @@
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
@ -29,6 +31,14 @@ typedef struct _TXRDoc TXRDoc;
typedef struct _TXRDocClass TXRDocClass; typedef struct _TXRDocClass TXRDocClass;
typedef struct _TXRDocPrivate TXRDocPrivate; typedef struct _TXRDocPrivate TXRDocPrivate;
#define TYPE_TXR_DOC_IFACE (txr_doc_iface_get_type ())
#define TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_DOC_IFACE, TXRDocIface))
#define IS_TXR_DOC_IFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TXR_DOC_IFACE))
#define TXR_DOC_IFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_TXR_DOC_IFACE, TXRDocIfaceIface))
typedef struct _TXRDocIface TXRDocIface;
typedef struct _TXRDocIfaceIface TXRDocIfaceIface;
#define TYPE_TXR_GRAPHICS (txr_graphics_get_type ()) #define TYPE_TXR_GRAPHICS (txr_graphics_get_type ())
#define TXR_GRAPHICS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_GRAPHICS, TXRGraphics)) #define TXR_GRAPHICS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TXR_GRAPHICS, TXRGraphics))
#define TXR_GRAPHICS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_GRAPHICS, TXRGraphicsClass)) #define TXR_GRAPHICS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TXR_GRAPHICS, TXRGraphicsClass))
@ -61,6 +71,11 @@ struct _TXRDocClass {
TXRObjectClass parent_class; TXRObjectClass parent_class;
}; };
struct _TXRDocIfaceIface {
GTypeInterface parent_iface;
gchar* (*gen) (TXRDocIface* self);
};
struct _TXRGraphics { struct _TXRGraphics {
TXRDoc parent_instance; TXRDoc parent_instance;
TXRGraphicsPrivate * priv; TXRGraphicsPrivate * priv;
@ -73,15 +88,18 @@ struct _TXRGraphicsClass {
static gpointer txr_graphics_parent_class = NULL; static gpointer txr_graphics_parent_class = NULL;
static TXRDocIfaceIface* txr_graphics_txr_doc_iface_parent_iface = NULL;
GType txr_object_get_type (void) G_GNUC_CONST; GType txr_object_get_type (void) G_GNUC_CONST;
GType txr_doc_get_type (void) G_GNUC_CONST; GType txr_doc_get_type (void) G_GNUC_CONST;
GType txr_doc_iface_get_type (void) G_GNUC_CONST;
GType txr_graphics_get_type (void) G_GNUC_CONST; GType txr_graphics_get_type (void) G_GNUC_CONST;
enum { enum {
TXR_GRAPHICS_DUMMY_PROPERTY TXR_GRAPHICS_DUMMY_PROPERTY
}; };
static void txr_graphics_real_copy (TXRObject* base, TXRObject* copy); static void txr_graphics_real_copy (TXRObject* base, TXRObject* copy);
void txr_object_copy (TXRObject* self, TXRObject* copy); void txr_object_copy (TXRObject* self, TXRObject* copy);
static gchar* txr_graphics_real_gen (TXRDocIface* base);
TXRGraphics* txr_graphics_new (void); TXRGraphics* txr_graphics_new (void);
TXRGraphics* txr_graphics_construct (GType object_type); TXRGraphics* txr_graphics_construct (GType object_type);
TXRDoc* txr_doc_new (void); TXRDoc* txr_doc_new (void);
@ -111,6 +129,17 @@ static void txr_graphics_real_copy (TXRObject* base, TXRObject* copy) {
} }
static gchar* txr_graphics_real_gen (TXRDocIface* base) {
TXRGraphics * self;
gchar* result = NULL;
gchar* _tmp0_;
self = (TXRGraphics*) base;
_tmp0_ = g_strdup ("TXRGraphics generated string.");
result = _tmp0_;
return result;
}
TXRGraphics* txr_graphics_construct (GType object_type) { TXRGraphics* txr_graphics_construct (GType object_type) {
TXRGraphics * self = NULL; TXRGraphics * self = NULL;
self = (TXRGraphics*) txr_doc_construct (object_type); self = (TXRGraphics*) txr_doc_construct (object_type);
@ -130,6 +159,12 @@ static void txr_graphics_class_init (TXRGraphicsClass * klass) {
} }
static void txr_graphics_txr_doc_iface_interface_init (TXRDocIfaceIface * iface) {
txr_graphics_txr_doc_iface_parent_iface = g_type_interface_peek_parent (iface);
iface->gen = (gchar* (*)(TXRDocIface*)) txr_graphics_real_gen;
}
static void txr_graphics_instance_init (TXRGraphics * self) { static void txr_graphics_instance_init (TXRGraphics * self) {
} }
@ -145,8 +180,10 @@ GType txr_graphics_get_type (void) {
static volatile gsize txr_graphics_type_id__volatile = 0; static volatile gsize txr_graphics_type_id__volatile = 0;
if (g_once_init_enter (&txr_graphics_type_id__volatile)) { if (g_once_init_enter (&txr_graphics_type_id__volatile)) {
static const GTypeInfo g_define_type_info = { sizeof (TXRGraphicsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) txr_graphics_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TXRGraphics), 0, (GInstanceInitFunc) txr_graphics_instance_init, NULL }; static const GTypeInfo g_define_type_info = { sizeof (TXRGraphicsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) txr_graphics_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TXRGraphics), 0, (GInstanceInitFunc) txr_graphics_instance_init, NULL };
static const GInterfaceInfo txr_doc_iface_info = { (GInterfaceInitFunc) txr_graphics_txr_doc_iface_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
GType txr_graphics_type_id; GType txr_graphics_type_id;
txr_graphics_type_id = g_type_register_static (TYPE_TXR_DOC, "TXRGraphics", &g_define_type_info, 0); txr_graphics_type_id = g_type_register_static (TYPE_TXR_DOC, "TXRGraphics", &g_define_type_info, 0);
g_type_add_interface_static (txr_graphics_type_id, TYPE_TXR_DOC_IFACE, &txr_doc_iface_info);
g_once_init_leave (&txr_graphics_type_id__volatile, txr_graphics_type_id); g_once_init_leave (&txr_graphics_type_id__volatile, txr_graphics_type_id);
} }
return txr_graphics_type_id__volatile; return txr_graphics_type_id__volatile;

View File

@ -1,4 +1,4 @@
public class TXRGraphics : TXRDoc { public class TXRGraphics : TXRDoc, TXRDocIface {
public int graphics_field; public int graphics_field;
public override void copy (TXRObject copy) { public override void copy (TXRObject copy) {
@ -8,4 +8,8 @@ public class TXRGraphics : TXRDoc {
((TXRGraphics)copy).graphics_field = this.graphics_field; ((TXRGraphics)copy).graphics_field = this.graphics_field;
} }
} }
public string gen () {
return "TXRGraphics generated string.";
}
} }

View File

@ -0,0 +1,11 @@
public class TXRObjectList : TXRObject {
public int objectlist_field;
public override void copy (TXRObject copy) {
stdout.printf ("TXRObjectList:copy() called\n");
if (copy is TXRObjectList) {
base.copy (copy);
((TXRAddSpaces)copy).objectlist_field = this.objectlist_field;
}
}
}