Пример #1
0
// Set is a generic wrapper around g_key_file_set_xxx() with type assertion.
func (kf *KeyFile) Set(group string, key string, uncasted interface{}) error {
	cGroup := (*C.gchar)(C.CString(group))
	defer C.g_free(C.gpointer(cGroup))
	cKey := (*C.gchar)(C.CString(key))
	defer C.g_free(C.gpointer(cKey))

	switch value := uncasted.(type) {
	case bool:
		C.g_key_file_set_boolean(kf.cKey, cGroup, cKey, cBool(value))

	case int:
		C.g_key_file_set_integer(kf.cKey, cGroup, cKey, C.gint(value))

	case float64:
		C.g_key_file_set_double(kf.cKey, cGroup, cKey, C.gdouble(value))

	case string:
		cstr := (*C.gchar)(C.CString(value))
		defer C.g_free(C.gpointer(cstr))
		C.g_key_file_set_string(kf.cKey, cGroup, cKey, cstr)

	case []bool:
		clist := cListBool(value)
		defer C.g_free(C.gpointer(clist))
		C.g_key_file_set_boolean_list(kf.cKey, cGroup, cKey, clist, C.gsize(len(value)))

	case []int:
		clist := cListInt(value)
		defer C.g_free(C.gpointer(clist))
		C.g_key_file_set_integer_list(kf.cKey, cGroup, cKey, clist, C.gsize(len(value)))

	case []float64:
		clist := cListDouble(value)
		defer C.g_free(C.gpointer(clist))
		C.g_key_file_set_double_list(kf.cKey, cGroup, cKey, clist, C.gsize(len(value)))

	case []string:
		clist := cListString(value)
		C.g_key_file_set_string_list(kf.cKey, cGroup, cKey, clist, C.gsize(len(value)))
		for i := range value {
			C.g_free(C.gpointer((*(*[999999]*C.gchar)(unsafe.Pointer(clist)))[i]))
		}
		C.g_free(C.gpointer(clist))

	default:
		return errors.New("type unknown")
	}
	return nil
}
Пример #2
0
// Write() is a wrapper around gdk_pixbuf_loader_write().  The
// function signature differs from the C equivalent to satisify the
// io.Writer interface.
func (v *PixbufLoader) Write(data []byte) (int, error) {
	// n is set to 0 on error, and set to len(data) otherwise.
	// This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
	// which would allow access to all io and ioutil goodies,
	// and play along nice with go environment.

	if len(data) == 0 {
		return 0, nil
	}

	var err *C.GError
	c := C.gdk_pixbuf_loader_write(v.native(),
		(*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)),
		&err)
	if !gobool(c) {
		defer C.g_error_free(err)
		return 0, errors.New(C.GoString((*C.char)(err.message)))
	}

	return len(data), nil
}
Пример #3
0
// =================================
//gsize       gst_buffer_memset              (GstBuffer *buffer, gsize offset, guint8 val, gsize size);
func (this *Buffer) MemSet(offset uint, val byte, size uint) int {
	return (int)(C.gst_buffer_memset((*C.GstBuffer)(this.GstBuffer), C.gsize(offset), C.guint8(val), C.gsize(size)))
}
Пример #4
0
// =================================
//GstBuffer * gst_buffer_new_allocate        (GstAllocator * allocator, gsize size,  GstAllocationParams * params);
func NewBufferAllocate(size uint) *Buffer {
	buffer := new(Buffer)
	buffer.GstBuffer = (*GstBufferStruct)(C.gst_buffer_new_allocate(nil, C.gsize(size), nil))
	return buffer
}
Пример #5
0
// =================================
//  gsize       gst_buffer_fill                (GstBuffer *buffer, gsize offset, gconstpointer src, gsize size);
func (this *Buffer) Fill(offset uint, src unsafe.Pointer, size uint) int {
	return (int)(C.gst_buffer_fill((*C.GstBuffer)(this.GstBuffer), C.gsize(offset), C.gconstpointer(src), C.gsize(size)))
}
Пример #6
0
func (v Loader) Write(buf []byte) (bool, *glib.Error) {
	var err *C.GError
	var pbuf *byte
	pbuf = &buf[0]
	ret := gobool(C.gdk_pixbuf_loader_write(v.GPixbufLoader, C.to_gucharptr(unsafe.Pointer(pbuf)), C.gsize(len(buf)), &err))
	if err != nil {
		return ret, glib.ErrorFromNative(unsafe.Pointer(err))
	}
	return ret, nil
}
Пример #7
0
/*
This will cause a pixbuf loader to parse the next @count bytes of
an image.  It will return %TRUE if the data was loaded successfully,
and %FALSE if an error occurred.  In the latter case, the loader
will be closed, and will not accept further writes. If %FALSE is
returned, @error will be set to an error from the #GDK_PIXBUF_ERROR
or #G_FILE_ERROR domains.
*/
func (self *TraitPixbufLoader) Write(buf []byte, count int64) (return__ bool, __err__ error) {
	__header__buf := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
	var __cgo_error__ *C.GError
	var __cgo__return__ C.gboolean
	__cgo__return__ = C.gdk_pixbuf_loader_write(self.CPointer, (*C.guchar)(unsafe.Pointer(__header__buf.Data)), C.gsize(count), &__cgo_error__)
	return__ = __cgo__return__ == C.gboolean(1)
	if __cgo_error__ != nil {
		__err__ = errors.New(C.GoString((*C.char)(unsafe.Pointer(__cgo_error__.message))))
	}
	return
}
Пример #8
0
func (v GdkPixbufLoader) Write(buf []byte) (ret bool, err *C.GError) {
	var error *C.GError
	var pbuf *byte
	pbuf = &buf[0]
	ret = gboolean2bool(C.gdk_pixbuf_loader_write(v.PixbufLoader, C.to_gucharptr(unsafe.Pointer(pbuf)), C.gsize(len(buf)), &error))
	err = error
	return
}
Пример #9
0
func Allocate(size uint32) *Memory {
	return (*Memory)(C.gst_allocator_alloc(nil, C.gsize(size), nil))
}
Пример #10
0
func (v *GVariant) GetChildValue(i int) *GVariant {
	cchild := C.g_variant_get_child_value(v.native(), C.gsize(i))
	return GVariantNew(unsafe.Pointer(cchild))
}