Exemple #1
0
func toGValue(v interface{}) *C.GValue {
	value := C.gvalue_new()
	switch reflect.TypeOf(v).Kind() {
	case reflect.String:
		C.g_value_init(value, C.G_TYPE_STRING)
		cStr := C.CString(v.(string))
		defer C.free(unsafe.Pointer(cStr))
		C.g_value_set_string(value, (*C.gchar)(unsafe.Pointer(cStr)))
	case reflect.Int:
		C.g_value_init(value, C.G_TYPE_INT)
		C.g_value_set_int(value, C.gint(v.(int)))
	case reflect.Struct:
		switch rv := v.(type) {
		case Fraction:
			C.g_value_init(value, C.gst_fraction_get_type())
			C.gst_value_set_fraction(value, C.gint(rv.N), C.gint(rv.D))
		default:
			p("unknown struct type %v\n", v)
			panic("fixme") //TODO
		}
	case reflect.Ptr:
		switch reflect.TypeOf(v) {
		case gstCapsType:
			C.g_value_init(value, C.gst_caps_get_type())
			C.gst_value_set_caps(value, v.(*C.GstCaps))
		default:
			panic(fmt.Sprintf("unknown type %v", v)) //TODO
		}
	default:
		panic(fmt.Sprintf("unknown type %v", v)) //TODO
	}
	return value
}
Exemple #2
0
func toGValue(v interface{}) *C.GValue {
	value := C.gvalue_new()
	switch reflect.TypeOf(v).Kind() {
	case reflect.String:
		C.g_value_init(value, C.G_TYPE_STRING)
		cStr := C.CString(v.(string))
		defer C.free(unsafe.Pointer(cStr))
		C.g_value_set_string(value, (*C.gchar)(unsafe.Pointer(cStr)))
	case reflect.Int:
		C.g_value_init(value, C.G_TYPE_INT)
		C.g_value_set_int(value, C.gint(v.(int)))
	case reflect.Ptr, reflect.UnsafePointer:
		p := unsafe.Pointer(reflect.ValueOf(v).Pointer())
		if IsObject(p) {
			C.g_value_init(value, C.G_TYPE_OBJECT)
			C.g_value_set_object(value, C.gpointer(p))
		} else {
			panic(fmt.Sprintf("unknown pointer type %v", v))
		}
	default:
		panic(fmt.Sprintf("unknown type %v", v)) //TODO
	}
	return value
}