コード例 #1
0
ファイル: value.go プロジェクト: ziutek/glib
func (v *Value) Get() interface{} {
	t := Type(v.g().g_type)
	switch t {
	case TYPE_INVALID:
		return nil

	case TYPE_STRING:
		return C.GoString((*C.char)(C.g_value_get_string(v.g())))

	case TYPE_GO_INT:
		return int(C.g_value_get_long(v.g()))

	case TYPE_GO_UINT:
		return uint(C.g_value_get_ulong(v.g()))

	case TYPE_CHAR:
		return int8(C.g_value_get_schar(v.g()))

	case TYPE_UCHAR:
		return uint8(C.g_value_get_uchar(v.g()))

	case TYPE_GO_INT32:
		return int32(C.g_value_get_int(v.g()))

	case TYPE_GO_UINT32:
		return uint32(C.g_value_get_uint(v.g()))

	case TYPE_INT64:
		return int64(C.g_value_get_int64(v.g()))

	case TYPE_UINT64:
		return uint64(C.g_value_get_uint64(v.g()))

	case TYPE_BOOLEAN:
		return (C.g_value_get_boolean(v.g()) != C.gboolean(0))

	case TYPE_FLOAT:
		return float32(C.g_value_get_float(v.g()))

	case TYPE_DOUBLE:
		return float64(C.g_value_get_double(v.g()))

	case TYPE_POINTER:
		return Pointer(C.g_value_get_pointer(v.g()))

	case TYPE_GTYPE:
		return Type(C.g_value_get_gtype(v.g()))
	}
	if t.IsA(TYPE_OBJECT) {
		o := new(Object)
		o.SetPtr(Pointer(C.g_value_get_object(v.g())))
		return o
	}
	if C.g_value_fits_pointer(v.g()) != 0 {
		return Pointer(C.g_value_peek_pointer(v.g()))
	}
	// Value of unknown type is returned as is
	return v
}
コード例 #2
0
ファイル: glib.go プロジェクト: vvanpo/gotk3
func marshalUlong(p uintptr) (interface{}, error) {
	c := C.g_value_get_ulong((*C.GValue)(unsafe.Pointer(p)))
	return uint(c), nil
}
コード例 #3
0
ファイル: gtype.go プロジェクト: napsy/go-gtk3
func (self GValue) GetPtr() unsafe.Pointer {
	switch self.gtype {
	case G_TYPE_STRING:
		return unsafe.Pointer(C.g_value_get_string(self.value))
	case G_TYPE_BOOLEAN:
		b := C.g_value_get_boolean(self.value)
		return unsafe.Pointer(&b)
	case G_TYPE_CHAR:
		c := C.g_value_get_char(self.value)
		return unsafe.Pointer(&c)
	case G_TYPE_INT:
		i := C.g_value_get_int(self.value)
		return unsafe.Pointer(&i)
	case G_TYPE_LONG:
		l := C.g_value_get_long(self.value)
		return unsafe.Pointer(&l)
	case G_TYPE_INT64:
		i := C.g_value_get_int64(self.value)
		return unsafe.Pointer(&i)
	case G_TYPE_UCHAR:
		c := C.g_value_get_uchar(self.value)
		return unsafe.Pointer(&c)
	case G_TYPE_UINT:
		i := C.g_value_get_uint(self.value)
		return unsafe.Pointer(&i)
	case G_TYPE_ULONG:
		l := C.g_value_get_ulong(self.value)
		return unsafe.Pointer(&l)
	case G_TYPE_UINT64:
		i := C.g_value_get_uint64(self.value)
		return unsafe.Pointer(&i)
	case G_TYPE_FLOAT:
		f := C.g_value_get_float(self.value)
		return unsafe.Pointer(&f)
	case G_TYPE_DOUBLE:
		d := C.g_value_get_double(self.value)
		return unsafe.Pointer(&d)
	}

	// Now things get tricky
	// We know the type, but how is it stored?

	// Is it pointer?
	isIt := C.pointer_in_gvalue(self.value)
	if GoBool(unsafe.Pointer(&isIt)) {
		val := C.g_value_get_pointer(self.value)
		return unsafe.Pointer(val)
	}

	// Is it object?
	isIt = C.object_in_gvalue(self.value)
	if GoBool(unsafe.Pointer(&isIt)) {
		o := C.g_value_get_object(self.value)
		return unsafe.Pointer(o)
	}
	//Hmmm....
	ptr := C.g_value_peek_pointer(self.value)
	if ptr != nil {
		return unsafe.Pointer(ptr)
	}
	return nil
}