static GObject * constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { gpointer klass = g_type_class_peek(GEGL_TYPE_OPERATION_META_JSON); GObjectClass *gobject_class = G_OBJECT_CLASS(klass); GObject *obj = gobject_class->constructor(type, n_construct_properties, construct_properties); JsonOpClass *json_op_class = G_TYPE_INSTANCE_GET_CLASS(obj, type, JsonOpClass); JsonOp *json_op = (JsonOp *)obj; json_op->json_root = json_op_class->json_root; // to avoid looking up via class/gtype return obj; }
/** * go_combo_box_set_title * @combo: Combo box * @title: Title * * Set a title to display over the tearoff window. * * FIXME: * * This should really change the title even when the popup is already torn off. * I guess the tearoff window could attach a listener to title change or * something. But I don't think we need the functionality, so I didn't bother * to investigate. * * MW: Just make it a property. */ void go_combo_box_set_title (GOComboBox *combo, char const *title) { GOComboBoxClass *klass = G_TYPE_INSTANCE_GET_CLASS (combo, GO_COMBO_BOX_TYPE, GOComboBoxClass); g_return_if_fail (klass != NULL); g_object_set_data_full (G_OBJECT (combo), "go-combo-title", g_strdup (title), (GDestroyNotify) g_free); if (klass->set_title) (klass->set_title) (combo, title); }
int main () { g_type_init (); Base *base = (Base *) g_type_create_instance (base_get_type ()); base_class_set_i (101); base_instance_set_i (base, 201); Derived *derived = (Derived *) g_type_create_instance (derived_get_type ()); derived_instance_set_i (derived, 401); /* test polymorphism */ Base *instance [2] = { base, (Base *) derived}; int i; for (i = 0; i < 2; i++) { Base *inst = instance [i]; BaseClass *klass = G_TYPE_INSTANCE_GET_CLASS (inst, base_get_type (), BaseClass); klass -> base_instance_dump (inst); } return 0; }