func fromGValue(v *C.GValue) (ret interface{}) { valueType := C.gvalue_get_type(v) fundamentalType := C.gtype_get_fundamental(valueType) switch fundamentalType { case C.G_TYPE_OBJECT: ret = unsafe.Pointer(C.g_value_get_object(v)) case C.G_TYPE_STRING: ret = fromGStr(C.g_value_get_string(v)) case C.G_TYPE_UINT: ret = int(C.g_value_get_uint(v)) case C.G_TYPE_BOXED: ret = unsafe.Pointer(C.g_value_get_boxed(v)) case C.G_TYPE_BOOLEAN: ret = C.g_value_get_boolean(v) == C.gboolean(1) case C.G_TYPE_ENUM: ret = int(C.g_value_get_enum(v)) default: panic(fmt.Sprintf("from type %s %T", fromGStr(C.g_type_name(fundamentalType)), v)) } return }
func marshalWrapMode(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return WrapMode(c), nil }
func marshalStateChangeReturn(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return StateChangeReturn(c), nil }
func marshalSeekFlags(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return SeekFlags(c), nil }
func marshalPadLinkReturn(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return PadLinkReturn(c), nil }
func marshalMessageType(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return MessageType(c), nil }
func marshalOperator(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return Operator(c), nil }
func marshalStackTransitionType(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return StackTransitionType(c), nil }
func marshalAlignment(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return Alignment(c), nil }
func marshalTLSErrorsPolicy(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return TLSErrorsPolicy(c), nil }
func marshalProcessModel(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return ProcessModel(c), nil }
// GoValue() converts a Value to comparable Go type. GoValue() // returns a non-nil error if the conversion was unsuccessful. The // returned interface{} must be type asserted as the actual Go // representation of the Value. // // This function is a wrapper around the many g_value_get_*() // functions, depending on the type of the Value. func (v *Value) GoValue() (interface{}, error) { _, fundamental, err := v.Type() if err != nil { return nil, err } // TODO: verify that all of these cases are indeed fundamental types switch fundamental { case TYPE_INVALID: return nil, errors.New("invalid type") case TYPE_NONE: return nil, nil case TYPE_INTERFACE: return nil, errors.New("interface conversion not yet implemented") case TYPE_CHAR: c := C.g_value_get_schar(v.Native()) return int8(c), nil case TYPE_UCHAR: c := C.g_value_get_uchar(v.Native()) return uint8(c), nil case TYPE_BOOLEAN: c := C.g_value_get_boolean(v.Native()) return gobool(c), nil // TODO: TYPE_INT should probably be a Go int32. case TYPE_INT, TYPE_LONG: c := C.g_value_get_int(v.Native()) return int(c), nil case TYPE_ENUM: c := C.g_value_get_enum(v.Native()) return int(c), nil case TYPE_INT64: c := C.g_value_get_int64(v.Native()) return int64(c), nil // TODO: TYPE_UINT should probably be a Go uint32. case TYPE_UINT, TYPE_ULONG, TYPE_FLAGS: c := C.g_value_get_uint(v.Native()) return uint(c), nil case TYPE_UINT64: c := C.g_value_get_uint64(v.Native()) return uint64(c), nil case TYPE_FLOAT: c := C.g_value_get_float(v.Native()) return float32(c), nil case TYPE_DOUBLE: c := C.g_value_get_double(v.Native()) return float64(c), nil case TYPE_STRING: c := C.g_value_get_string(v.Native()) return C.GoString((*C.char)(c)), nil case TYPE_POINTER: c := C.g_value_get_pointer(v.Native()) return unsafe.Pointer(c), nil case TYPE_OBJECT: c := C.g_value_get_object(v.Native()) // TODO: need to try and return an actual pointer to the correct object type // this may require an additional cast()-like method for each module return ObjectNew(unsafe.Pointer(c)), nil case TYPE_VARIANT: return nil, errors.New("variant conversion not yet implemented") default: return nil, errors.New("type conversion not supported") } }
func marshalDragAction(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return DragAction(c), nil }
func marshalEventMask(p uintptr) (interface{}, error) { c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) return EventMask(c), nil }