Permalink
Browse files

re-add gvariant, add gvarianttype

  • Loading branch information...
jmoiron committed Jun 24, 2016
1 parent 084ef7e commit 76e6c78c0490f22d97e3c116a4e1c0264f1e43d6
View
@@ -4,12 +4,11 @@
package glib
// #cgo pkg-config: glib-2.0 gobject-2.0
// #include <glib.h>
// #include <glib-object.h>
// #include "glib.go.h"
// #include "gvariant.go.h"
//import "C"
//import "unsafe"
// #include "glib.go.h"
import "C"
import "unsafe"
/*
* GVariant
@@ -18,7 +17,7 @@ package glib
// IVariant is an interface type implemented by Variant and all types which embed
// an Variant. It is meant to be used as a type for function arguments which
// require GVariants or any subclasses thereof.
/* todo fix bugs
type IVariant interface {
ToGVariant() *C.GVariant
ToVariant() *Variant
@@ -54,6 +53,7 @@ func (v *Variant) native() *C.GVariant {
if v == nil || v.GVariant == nil {
return nil
}
return v.GVariant
p := unsafe.Pointer(v.GVariant)
return C.toGVariant(p)
}
@@ -62,17 +62,52 @@ func (v *Variant) native() *C.GVariant {
func (v *Variant) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
*/
func (v *Variant) GetStrv() []string {
gstrv := C.g_variant_get_strv(v.native(), nil)
// we do not own the memory for these strings, so we must not use strfreev
// but we must free the actual pointer we receive.
c := gstrv
defer C.g_free(gstrv)
var strs []string
for *c != nil {
strs = append(strs, C.GoString((*C.char)(*c)))
c = C.next_gcharptr(c)
}
return strs
}
func (v *Variant) TypeString() string {
// the string returned from this belongs to GVariant and must not be freed.
return C.GoString((*C.char)(C.g_variant_get_type_string(v.native())))
}
func (v *Variant) IsContainer() bool {
return gobool(C.g_variant_is_container(v.native()))
}
func (v *Variant) IsFloating() bool {
return gobool(C.g_variant_is_floating(v.native()))
}
func (v *Variant) GetBoolean() bool {
return gobool(C.g_variant_get_boolean(v.native()))
}
func (v *Variant) GetString() string {
var len C.gsize
gc := C.g_variant_get_string(v.native(), &len)
defer C.g_free(gc)
return C.GoStringN((*C.char)(gc), (C.int)(len))
}
//void g_variant_unref ()
//GVariant * g_variant_ref ()
//GVariant * g_variant_ref_sink ()
//gboolean g_variant_is_floating ()
//GVariant * g_variant_take_ref ()
//const GVariantType * g_variant_get_type ()
//const gchar * g_variant_get_type_string ()
//gboolean g_variant_is_of_type ()
//gboolean g_variant_is_container ()
//gint g_variant_compare ()
//GVariantClass g_variant_classify ()
//gboolean g_variant_check_format_string ()
@@ -102,7 +137,6 @@ func (v *Variant) Native() uintptr {
//GVariant * g_variant_new_objv ()
//GVariant * g_variant_new_bytestring ()
//GVariant * g_variant_new_bytestring_array ()
//gboolean g_variant_get_boolean ()
//guchar g_variant_get_byte ()
//gint16 g_variant_get_int16 ()
//guint16 g_variant_get_uint16 ()
View
@@ -3,39 +3,38 @@
//GVariant : GVariant — strongly typed value datatype
// https://developer.gnome.org/glib/2.26/glib-GVariant.html
/* todo fix bugs
#ifndef __GVARIANT_GO_H__
#define __GVARIANT_GO_H__
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <glib/gvariant.h>
#include <glib.h>
// Type Casting
static GVariant *
toGVariant(void *p)
{
return (_GVariant(p));
return (GVariant*)p;
}
static GVariantBuilder *
toGVariantBuilder(void *p)
{
return (GVariantBuilder(p));
return (GVariantBuilder*)p;
}
static GVariantDict *
toGVariantDict(void *p)
{
return (_GVariantDict(p));
return (GVariantDict*)p;
}
static GVariantIter *
toGVariantIter(void *p)
{
return (_GVariantIter(p));
return (GVariantIter*)p;
}
#endif
*/
View
@@ -2,13 +2,13 @@
package glib_test
/* todo fix bugs
import (
"testing"
)
func Test_AcceleratorParse(t *testing.T) {
testVariant := &Variant{}
t.Log("native: " + testVariant.Native())
/*
testVariant := &Variant{}
t.Log("native: " + testVariant.Native())
*/
}
*/
View
@@ -10,13 +10,13 @@ package glib
// #include <glib-object.h>
// #include "glib.go.h"
// #include "gvariant.go.h"
//import "C"
//import "unsafe"
import "C"
import "unsafe"
/*
* GVariantBuilder
*/
/* todo fix bugs
// VariantBuilder is a representation of GLib's VariantBuilder.
type VariantBuilder struct {
GVariantBuilder *C.GVariantBuilder
@@ -51,4 +51,3 @@ func (v *VariantBuilder) native() *C.GVariantBuilder {
func (v *VariantBuilder) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
*/
View
@@ -9,6 +9,7 @@ package glib
// #include <glib.h>
// #include <glib-object.h>
// #include "glib.go.h"
// #include "gvariant.go.h"
import "C"
/*
View
@@ -10,13 +10,13 @@ package glib
// #include <glib-object.h>
// #include "glib.go.h"
// #include "gvariant.go.h"
//import "C"
//import "unsafe"
import "C"
import "unsafe"
/*
* GVariantDict
*/
/* todo fix bugs
// VariantDict is a representation of GLib's VariantDict.
type VariantDict struct {
GVariantDict *C.GVariantDict
@@ -51,4 +51,3 @@ func (v *VariantDict) native() *C.GVariantDict {
func (v *VariantDict) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
*/
View
@@ -10,13 +10,13 @@ package glib
// #include <glib-object.h>
// #include "glib.go.h"
// #include "gvariant.go.h"
//import "C"
//import "unsafe"
import "C"
import "unsafe"
/*
* GVariantIter
*/
/* todo fix bugs
// VariantIter is a representation of GLib's GVariantIter.
type VariantIter struct {
GVariantIter *C.GVariantIter
@@ -51,4 +51,3 @@ func (v *VariantIter) native() *C.GVariantIter {
func (v *VariantIter) Native() uintptr {
return uintptr(unsafe.Pointer(v.native()))
}
*/
View
@@ -0,0 +1,53 @@
// Same copyright and license as the rest of the files in this project
//GVariant : GVariant — strongly typed value datatype
// https://developer.gnome.org/glib/2.26/glib-GVariant.html
package glib
// #cgo pkg-config: glib-2.0 gobject-2.0
// #include <glib.h>
// #include "gvarianttype.go.h"
import "C"
type VariantType struct {
GVariantType *C.GVariantType
}
func (v *VariantType) native() *C.GVariantType {
return v.GVariantType
}
func (v *VariantType) String() string {
ch := C.g_variant_type_dup_string(v.native())
defer C.g_free(ch)
return C.GoString((*C.char)(ch))
}
func newVariantType(v *C.GVariantType) *VariantType {
return &VariantType{v}
}
var (
VARIANT_TYPE_BOOLEAN = newVariantType(C._G_VARIANT_TYPE_BOOLEAN)
VARIANT_TYPE_BYTE = newVariantType(C._G_VARIANT_TYPE_BYTE)
VARIANT_TYPE_INT16 = newVariantType(C._G_VARIANT_TYPE_INT16)
VARIANT_TYPE_UINT16 = newVariantType(C._G_VARIANT_TYPE_UINT16)
VARIANT_TYPE_INT32 = newVariantType(C._G_VARIANT_TYPE_INT32)
VARIANT_TYPE_UINT32 = newVariantType(C._G_VARIANT_TYPE_UINT32)
VARIANT_TYPE_INT64 = newVariantType(C._G_VARIANT_TYPE_INT64)
VARIANT_TYPE_UINT64 = newVariantType(C._G_VARIANT_TYPE_UINT64)
VARIANT_TYPE_HANDLE = newVariantType(C._G_VARIANT_TYPE_HANDLE)
VARIANT_TYPE_DOUBLE = newVariantType(C._G_VARIANT_TYPE_DOUBLE)
VARIANT_TYPE_STRING = newVariantType(C._G_VARIANT_TYPE_STRING)
VARIANT_TYPE_ANY = newVariantType(C._G_VARIANT_TYPE_ANY)
VARIANT_TYPE_BASIC = newVariantType(C._G_VARIANT_TYPE_BASIC)
VARIANT_TYPE_TUPLE = newVariantType(C._G_VARIANT_TYPE_TUPLE)
VARIANT_TYPE_UNIT = newVariantType(C._G_VARIANT_TYPE_UNIT)
VARIANT_TYPE_DICTIONARY = newVariantType(C._G_VARIANT_TYPE_DICTIONARY)
VARIANT_TYPE_STRING_ARRAY = newVariantType(C._G_VARIANT_TYPE_STRING_ARRAY)
VARIANT_TYPE_OBJECT_PATH_ARRAY = newVariantType(C._G_VARIANT_TYPE_OBJECT_PATH_ARRAY)
VARIANT_TYPE_BYTESTRING = newVariantType(C._G_VARIANT_TYPE_BYTESTRING)
VARIANT_TYPE_BYTESTRING_ARRAY = newVariantType(C._G_VARIANT_TYPE_BYTESTRING_ARRAY)
VARIANT_TYPE_VARDICT = newVariantType(C._G_VARIANT_TYPE_VARDICT)
)
View
@@ -0,0 +1,37 @@
// Same copyright and license as the rest of the files in this project
//GVariant : GVariant — strongly typed value datatype
// https://developer.gnome.org/glib/2.26/glib-GVariant.html
#ifndef __GVARIANTTYPE_GO_H__
#define __GVARIANTTYPE_GO_H__
const GVariantType* _G_VARIANT_TYPE_BOOLEAN = G_VARIANT_TYPE_BOOLEAN;
const GVariantType* _G_VARIANT_TYPE_BYTE = G_VARIANT_TYPE_BYTE;
const GVariantType* _G_VARIANT_TYPE_INT16 = G_VARIANT_TYPE_INT16;
const GVariantType* _G_VARIANT_TYPE_UINT16 = G_VARIANT_TYPE_UINT16;
const GVariantType* _G_VARIANT_TYPE_INT32 = G_VARIANT_TYPE_INT32;
const GVariantType* _G_VARIANT_TYPE_UINT32 = G_VARIANT_TYPE_UINT32;
const GVariantType* _G_VARIANT_TYPE_INT64 = G_VARIANT_TYPE_INT64;
const GVariantType* _G_VARIANT_TYPE_UINT64 = G_VARIANT_TYPE_UINT64;
const GVariantType* _G_VARIANT_TYPE_HANDLE = G_VARIANT_TYPE_HANDLE;
const GVariantType* _G_VARIANT_TYPE_DOUBLE = G_VARIANT_TYPE_DOUBLE;
const GVariantType* _G_VARIANT_TYPE_STRING = G_VARIANT_TYPE_STRING;
const GVariantType* _G_VARIANT_TYPE_OBJECT_PATH = G_VARIANT_TYPE_OBJECT_PATH;
const GVariantType* _G_VARIANT_TYPE_SIGNATURE = G_VARIANT_TYPE_SIGNATURE;
const GVariantType* _G_VARIANT_TYPE_VARIANT = G_VARIANT_TYPE_VARIANT;
const GVariantType* _G_VARIANT_TYPE_ANY = G_VARIANT_TYPE_ANY;
const GVariantType* _G_VARIANT_TYPE_BASIC = G_VARIANT_TYPE_BASIC;
const GVariantType* _G_VARIANT_TYPE_MAYBE = G_VARIANT_TYPE_MAYBE;
const GVariantType* _G_VARIANT_TYPE_ARRAY = G_VARIANT_TYPE_ARRAY;
const GVariantType* _G_VARIANT_TYPE_TUPLE = G_VARIANT_TYPE_TUPLE;
const GVariantType* _G_VARIANT_TYPE_UNIT = G_VARIANT_TYPE_UNIT;
const GVariantType* _G_VARIANT_TYPE_DICT_ENTRY = G_VARIANT_TYPE_DICT_ENTRY;
const GVariantType* _G_VARIANT_TYPE_DICTIONARY = G_VARIANT_TYPE_DICTIONARY;
const GVariantType* _G_VARIANT_TYPE_STRING_ARRAY = G_VARIANT_TYPE_STRING_ARRAY;
const GVariantType* _G_VARIANT_TYPE_OBJECT_PATH_ARRAY = G_VARIANT_TYPE_OBJECT_PATH_ARRAY;
const GVariantType* _G_VARIANT_TYPE_BYTESTRING = G_VARIANT_TYPE_BYTESTRING;
const GVariantType* _G_VARIANT_TYPE_BYTESTRING_ARRAY = G_VARIANT_TYPE_BYTESTRING_ARRAY;
const GVariantType* _G_VARIANT_TYPE_VARDICT = G_VARIANT_TYPE_VARDICT;
#endif

0 comments on commit 76e6c78

Please sign in to comment.