Skip to content

Commit

Permalink
Add typemap for wxVector
Browse files Browse the repository at this point in the history
  • Loading branch information
dontpanic92 committed Jun 20, 2017
1 parent 8da0a0e commit c981d31
Show file tree
Hide file tree
Showing 10 changed files with 21,058 additions and 18,626 deletions.
Binary file removed build/docview
Binary file not shown.
4 changes: 2 additions & 2 deletions build/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys, os, re

regex = re.compile("^const (.+?) int = (.+?)$", re.MULTILINE)
regex_ctor = re.compile("^func New(.+?)\((.+?)\)(.+?) {$", re.MULTILINE)
regex_ctor = re.compile("^func New(.+?)\((.*?)\)(.+?) {$", re.MULTILINE)

def calc_new_value(var_value):
values = var_value.split('+')
Expand All @@ -37,7 +37,7 @@ def replace_hex(match_object):
return match_object.group(0)

def add_tracked_type(code):
exceptions = ["DirectorGoCallbackDispatcher"]
exceptions = ["DirectorGoCallbackDispatcher", "EventType"]

for match_object in regex_ctor.finditer(code):
type_name = match_object.group(1)
Expand Down
146 changes: 136 additions & 10 deletions src/typemap.i
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,6 @@ func swigCopyStringSlice(strSlice *[]string) []string {
Swig_free(uintptr($1))
%}

%{
struct StringSliceWithPointer {
_goslice_ slice;
_goslice_* ptr;
};
%}

%insert(go_header) %{
type stringSliceWithPointer struct {
slice []string
Expand All @@ -194,7 +187,7 @@ type stringSliceWithPointer struct {
%}

%typemap(in) wxArrayString & %{
StringSliceWithPointer* $1_ptr = (StringSliceWithPointer*)$input;
sliceWithPointer* $1_ptr = (sliceWithPointer*)$input;

$*1_ltype $1_arr;
$1_arr = gostringSliceToArrayString($1_ptr->slice);
Expand Down Expand Up @@ -290,7 +283,7 @@ func swigCopyIntSlice(intSlice *[]int) []int {
%}

%{
struct IntSliceWithPointer {
struct sliceWithPointer {
_goslice_ slice;
_goslice_* ptr;
};
Expand Down Expand Up @@ -318,7 +311,7 @@ type intSliceWithPointer struct {
%}

%typemap(in) wxArrayInt & %{
IntSliceWithPointer* $1_ptr = (IntSliceWithPointer*)$input;
sliceWithPointer* $1_ptr = (sliceWithPointer*)$input;

$*1_ltype $1_arr;
$1_arr = intgoSliceToArrayInt($1_ptr->slice);
Expand Down Expand Up @@ -408,6 +401,139 @@ type intSliceWithPointer struct {
$result = newSlice
%}

// Typemaps for wxVectors

%define _APPLY_WXVECTOR(wxtype, ref, deref)
%{
wxVector< wx##wxtype ref > wxtype##SliceToVector (_goslice_ slice) {
wxVector< wx##wxtype ref > vector;
for (int i = 0; i < slice.len; i++) {
wx##wxtype * a = (( wx##wxtype ** )slice.array)[i];
vector.push_back( deref a);
}
return vector;
}

_goslice_ vectorTo##wxtype##Slice (const wxVector< wx##wxtype ref >& arr) {
_goslice_ slice;
size_t count = arr.size();
wx##wxtype * ref go_arr = ( wx##wxtype * ref )malloc(sizeof( wx##wxtype ref [count]));
slice.array = go_arr;
slice.len = slice.cap = count;

for (int i = 0; i < count; i++) {
go_arr[i] = arr[i];
}

return slice;
}
%}

%insert(go_header) %{
func swigCopy##wxtype##Slice (s *[] wxtype ) [] wxtype {
newSlice := make([] wxtype, len(*s))
for i := range newSlice {
newSlice[i] = (*s)[i]
}
p := *(*swig_goslice)(unsafe.Pointer(s))
Swig_free(p.arr)
return newSlice
}
%}

%typemap(gotype) wxVector< wx##wxtype ref > "[] wxtype"

%typemap(in) wxVector< wx##wxtype ref > %{
$1 = wxtype##SliceToVector($input);
%}

%typemap(out) wxVector< wx##wxtype ref > %{
$result = vectorTo##wxtype##Slice ($1);
%}

%typemap(goout) wxVector< wx##wxtype ref > %{
$result = swigCopy##wxtype##Slice(&$1)
%}


%typemap(gotype) const wxVector< wx##wxtype ref >& "[] wxtype"
%typemap(imtype) const wxVector< wx##wxtype ref >& "[] wxtype"

%typemap(goin) const wxVector< wx##wxtype ref > & %{
$result = $1
%}

%typemap(goargout) const wxVector< wx##wxtype ref > & %{
%}

%typemap(argout) const wxVector< wx##wxtype ref > & %{
%}

%typemap(in) const wxVector< wx##wxtype ref > & %{
$*1_ltype $1_arr;
$1_arr = wxtype##SliceToVector ($input);
$1 = &$1_arr;
%}

%typemap(out) const wxVector< wx##wxtype ref > & %{
$result = vectorTo##wxtype##Slice (*$1);
%}

%typemap(goout) const wxVector< wx##wxtype ref > & %{
$result = swigCopy##wxtype##Slice(&$1)
%}

%insert(go_header) %{
type wxtype##SliceWithPointer struct {
slice [] wxtype
ptr uintptr
}
%}

%typemap(gotype) wxVector< wx##wxtype ref > * "*[] wxtype"
%typemap(imtype) wxVector< wx##wxtype ref > * "* wxtype##SliceWithPointer"

%typemap(goin) wxVector< wx##wxtype ref > * %{
var $1_var wxtype##SliceWithPointer
$result = &$1_var
$result.slice = *$1
%}

%typemap(goargout) wxVector< wx##wxtype ref > * %{
*$1 = swigCopyIntSlice((*[]int)(unsafe.Pointer($1_var.ptr)))
Swig_free($1_var.ptr)
%}

%typemap(in) wxVector< wx##wxtype ref > * %{
sliceWithPointer* $1_ptr = (sliceWithPointer*)$input;

$*1_ltype $1_arr;
$1_arr = type##SliceToVector($1_ptr->slice);
$1 = &$1_arr;
%}

%typemap(argout) wxVector< wx##wxtype ref > * %{
$1_ptr->ptr = (_goslice_*)malloc(sizeof(_goslice_));
*$1_ptr->ptr = arrayIntToIntgoSlice(*$1);
%}

%enddef
#define APPLY_WXVECTOR(type) _APPLY_WXVECTOR(type, ,*)
#define APPLY_POINTER_WXVECTOR(type) _APPLY_WXVECTOR(type, *, )

%{
#include <wx/variant.h>
#include <wx/docview.h>
#include <wx/treelist.h>
#include <wx/dataview.h>
%}

APPLY_WXVECTOR(Variant)
APPLY_WXVECTOR(TreeListItem)
APPLY_POINTER_WXVECTOR(View)
APPLY_POINTER_WXVECTOR(Document)
APPLY_POINTER_WXVECTOR(DocTemplate)
APPLY_POINTER_WXVECTOR(DataViewColumn)

// Typemaps for wxChar & wxUniChar

Expand Down
17 changes: 11 additions & 6 deletions utils/build_binary_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ if [ -z $1 ] || [ -z $2 ]; then
fi;

WXGO_SUFFIX=$1_$2
WXGO_LIB_FOLDER=$WXGO_SUFFIX

if [ "$3" == "gtk2" ]; then
WXGO_LIB_FOLDER=${WXGO_LIB_FOLDER}_gtk2
fi

wxGoTmpDir="/tmp/wxGo_tmp_$WXGO_SUFFIX"

Expand All @@ -16,7 +21,7 @@ fi;

mkdir -p $wxGoTmpDir/pkg/$WXGO_SUFFIX/github.com/dontpanic92/wxGo/
mkdir -p $wxGoTmpDir/src/github.com/dontpanic92/wxGo/wx
cp $GOPATH/src/github.com/dontpanic92/wxGo/wx/$WXGO_SUFFIX/lib/*.a $wxGoTmpDir
cp $GOPATH/src/github.com/dontpanic92/wxGo/wx/$WXGO_LIB_FOLDER/lib/*.a $wxGoTmpDir

cd $wxGoTmpDir

Expand Down Expand Up @@ -64,7 +69,7 @@ export GOOS=$1
export CGO_ENABLED=1
go version
go env
go install -tags "wxgo_binary_package_build" -x github.com/dontpanic92/wxGo/wx
go install -tags "wxgo_binary_package_build $3" -x github.com/dontpanic92/wxGo/wx


cp $GOPATH/pkg/$WXGO_SUFFIX/github.com/dontpanic92/wxGo/wx.a $wxGoTmpDir/pkg/$WXGO_SUFFIX/github.com/dontpanic92/wxGo/wx.a
Expand All @@ -73,15 +78,15 @@ echo -e "//go:binary-only-package\n\npackage wx" > $wxGoTmpDir/src/github.com/do

rm $GOPATH/src/github.com/dontpanic92/wxGo/wx/*_$WXGO_SUFFIX.syso

zip -9 wxGo_$WXGO_SUFFIX.zip -r pkg src
zip -9 wxGo_$WXGO_LIB_FOLDER.zip -r pkg src

cd -

if [ -e wxGo_$WXGO_SUFFIX.zip ]; then
rm wxGo_$WXGO_SUFFIX.zip
if [ -e wxGo_$WXGO_LIB_FOLDER.zip ]; then
rm wxGo_$WXGO_LIB_FOLDER.zip
fi;

mv $wxGoTmpDir/wxGo_$WXGO_SUFFIX.zip .
mv $wxGoTmpDir/wxGo_$WXGO_LIB_FOLDER.zip .

rm -r $wxGoTmpDir

Loading

0 comments on commit c981d31

Please sign in to comment.