static VALUE rg_set_child_property(VALUE self, VALUE child, VALUE prop_name, VALUE val) { GParamSpec* pspec; const char* name; if (SYMBOL_P(prop_name)) { name = rb_id2name(SYM2ID(prop_name)); } else { StringValue(prop_name); name = StringValuePtr(prop_name); } pspec = goo_canvas_item_class_find_child_property(G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name); if (!pspec) rb_raise(rb_eRuntimeError, "No such child property: %s", name); #define _SET_PROP_FOR_TYPE(gtype, ctype, val) \ case gtype: \ goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, (ctype)(val), NULL); \ break; switch (G_TYPE_FUNDAMENTAL(G_PARAM_SPEC_VALUE_TYPE(pspec))) { _SET_PROP_FOR_TYPE(G_TYPE_CHAR, gchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UCHAR, guchar, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_BOOLEAN, gboolean, RTEST(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT, gint, NUM2INT(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT, guint, NUM2UINT(val)); _SET_PROP_FOR_TYPE(G_TYPE_LONG, glong, NUM2LONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_ULONG, gulong, NUM2ULONG(val)); _SET_PROP_FOR_TYPE(G_TYPE_INT64, gint64, rbglib_num_to_int64(val)); _SET_PROP_FOR_TYPE(G_TYPE_UINT64, guint64, rbglib_num_to_uint64(val)); _SET_PROP_FOR_TYPE(G_TYPE_ENUM, gint, rbgobj_get_enum(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLAGS, guint, rbgobj_get_flags(val, G_PARAM_SPEC_VALUE_TYPE(pspec))); _SET_PROP_FOR_TYPE(G_TYPE_FLOAT, gfloat, NUM2DBL(val)); _SET_PROP_FOR_TYPE(G_TYPE_DOUBLE, gdouble, NUM2DBL(val)); case G_TYPE_STRING: { if (SYMBOL_P(val)) val = rb_funcall(val, rb_intern("to_s"), 0); goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, StringValuePtr(val), NULL); break; } default: g_warning("rb_goo_canvas_item_set_child_property: unsupported type: %s\n", g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec))); return Qnil; } #undef _SET_PROP_FOR_TYPE G_CHILD_ADD(child, val); return self; }
static VALUE stream_put_int64(int argc, VALUE *argv, VALUE self) { VALUE value, cancellable; GError *error = NULL; rb_scan_args(argc, argv, "11", &value, &cancellable); if (!g_data_output_stream_put_int64(_SELF(self), rbglib_num_to_int64(value), RVAL2GCANCELLABLE(cancellable), &error)) rbgio_raise_io_error(error); return self; }
void rbgobj_rvalue_to_gvalue(VALUE val, GValue* result) { GType type, fundamental_type; type = G_VALUE_TYPE(result); if (rbgobj_convert_rvalue2gvalue(type, val, result)) return; fundamental_type = G_TYPE_FUNDAMENTAL(type); switch (fundamental_type) { case G_TYPE_NONE: return; case G_TYPE_CHAR: g_value_set_char(result, NUM2INT(val)); return; case G_TYPE_UCHAR: g_value_set_uchar(result, NUM2UINT(val)); return; case G_TYPE_BOOLEAN: g_value_set_boolean(result, RVAL2CBOOL(val)); return; case G_TYPE_INT: g_value_set_int(result, NUM2INT(val)); return; case G_TYPE_UINT: g_value_set_uint(result, NUM2UINT(val)); return; case G_TYPE_LONG: g_value_set_long(result, NUM2LONG(val)); return; case G_TYPE_ULONG: g_value_set_ulong(result, NUM2ULONG(val)); return; case G_TYPE_INT64: g_value_set_int64(result, rbglib_num_to_int64(val)); return; case G_TYPE_UINT64: g_value_set_uint64(result, rbglib_num_to_uint64(val)); return; case G_TYPE_ENUM: g_value_set_enum(result, rbgobj_get_enum(val, G_VALUE_TYPE(result))); return; case G_TYPE_FLAGS: g_value_set_flags(result, rbgobj_get_flags(val, G_VALUE_TYPE(result))); return; case G_TYPE_FLOAT: g_value_set_float(result, NUM2DBL(val)); return; case G_TYPE_DOUBLE: g_value_set_double(result, NUM2DBL(val)); return; case G_TYPE_STRING: { if (SYMBOL_P(val)) val = rb_funcall(val, id_to_s, 0); g_value_set_string(result, RVAL2CSTR_ACCEPT_NIL(val)); return; } case G_TYPE_OBJECT: case G_TYPE_INTERFACE: g_value_set_object(result, NIL_P(val) ? NULL : RVAL2GOBJ(val)); return; case G_TYPE_PARAM: g_value_set_param(result, NIL_P(val) ? NULL : RVAL2GOBJ(val)); return; case G_TYPE_POINTER: g_value_set_pointer(result, NIL_P(val) ? NULL : rbgobj_ptr2cptr(val)); return; case G_TYPE_BOXED: { GType gtype; for (gtype = type; gtype != G_TYPE_INVALID; gtype = g_type_parent(gtype)) { RValueToGValueFunc func = g_type_get_qdata(gtype, qRValueToGValueFunc); if (!func) continue; func(val, result); return; } } default: if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) { RValueToGValueFunc func = g_type_get_qdata(type, qRValueToGValueFunc); if (!func){ g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n", g_type_name(type)); } else { func(val, result); } } } }