Пример #1
0
func CreateCGValue(tn GType, object ...unsafe.Pointer) *GValue {
	var cv C.GValue
	C.g_value_init(&cv, C.GType(tn))

	// If no data, then return Gvalue initialized with default
	if len(object) == 0 {
		gv := GValue{tn, &cv}
		return &gv
	}
	obj := object[0]

	// Foundamental types are special
	// TODO: Handle more cases, like creating GValue from GdkEvents
	switch tn {
	case G_TYPE_STRING:
		C.g_value_take_string(&cv, (*C.gchar)(obj))
	case G_TYPE_BOOLEAN:
		C.g_value_set_boolean(&cv, *((*C.gboolean)(obj)))
	case G_TYPE_CHAR:
		C.g_value_set_char(&cv, *((*C.gchar)(obj)))
	case G_TYPE_INT:
		C.g_value_set_int(&cv, *((*C.gint)(obj)))
	case G_TYPE_LONG:
		C.g_value_set_long(&cv, *((*C.glong)(obj)))
	case G_TYPE_INT64:
		C.g_value_set_int64(&cv, *((*C.gint64)(obj)))
	case G_TYPE_UCHAR:
		C.g_value_set_uchar(&cv, *((*C.guchar)(obj)))
	case G_TYPE_UINT:
		C.g_value_set_uint(&cv, *((*C.guint)(obj)))
	case G_TYPE_ULONG:
		C.g_value_set_ulong(&cv, *((*C.gulong)(obj)))
	case G_TYPE_UINT64:
		C.g_value_set_uint64(&cv, *((*C.guint64)(obj)))
	case G_TYPE_FLOAT:
		C.g_value_set_float(&cv, *((*C.gfloat)(obj)))
	case G_TYPE_DOUBLE:
		C.g_value_set_double(&cv, *((*C.gdouble)(obj)))
	default:
		C.g_value_set_object(&cv, C.gpointer(obj))
	}

	gv := GValue{tn, &cv}
	return &gv
}
Пример #2
0
// g_value_take_string
func (this *Value) SetString(v string) {
	cstr := _GString(v)
	C.g_value_take_string(this.asC(), cstr)
	// not freeing, because GValue takes the ownership
}