├── basic ├── extend │ ├── example │ │ ├── extend.cxx │ │ ├── example.i │ │ ├── ceo.go │ │ └── example.h │ └── runme.go ├── template │ ├── template │ └── example │ │ ├── example.i │ │ └── example.h ├── callback │ ├── example │ │ ├── callback.cxx │ │ ├── example.i │ │ ├── example.h │ │ ├── gocallback.go │ │ └── example.go │ └── runme.go ├── variables │ ├── example │ │ ├── example.h │ │ ├── example.i │ │ └── variables.c │ └── runme.go ├── simple │ ├── example │ │ ├── example.i │ │ └── simple.c │ └── runme.go ├── class │ ├── example │ │ ├── example.i │ │ ├── class.cxx │ │ ├── example.h │ │ ├── example.go │ │ └── example_wrap.cxx │ └── runme.go ├── enum │ ├── example │ │ ├── example.i │ │ ├── example.h │ │ └── example.go │ └── runme.go ├── funcptr │ ├── example │ │ ├── example.h │ │ └── example.i │ └── runme.go ├── director │ ├── example │ │ ├── example.i │ │ ├── director.h │ │ └── director.go │ └── runme.go ├── pointer │ ├── example │ │ ├── pointer.c │ │ ├── example.i │ │ ├── example.go │ │ └── example_wrap.c │ └── runme.go ├── reference │ ├── example │ │ ├── example.h │ │ ├── example.i │ │ ├── reference.cxx │ │ ├── example.go │ │ └── example_wrap.cxx │ └── runme.go ├── multimap │ ├── runme.go │ ├── multimap.c │ └── example.i ├── constants │ ├── example │ │ └── example.i │ └── runme.go └── ReadMe.md ├── cgo ├── hello.c ├── hello.h ├── ReadMe.md └── main.go ├── .gitignore ├── ReadMe.md └── LICENSE /basic/extend/example/extend.cxx: -------------------------------------------------------------------------------- 1 | /* File : example.cxx */ 2 | 3 | #include "example.h" 4 | 5 | -------------------------------------------------------------------------------- /basic/template/template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feixiao/swig/HEAD/basic/template/template -------------------------------------------------------------------------------- /basic/callback/example/callback.cxx: -------------------------------------------------------------------------------- 1 | /* File : example.cxx */ 2 | 3 | #include "example.h" 4 | 5 | -------------------------------------------------------------------------------- /basic/variables/example/example.h: -------------------------------------------------------------------------------- 1 | /* File: example.h */ 2 | 3 | typedef struct { 4 | int x,y; 5 | } Point; 6 | 7 | -------------------------------------------------------------------------------- /cgo/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "hello.h" 3 | 4 | int hello(char *name, int age) { 5 | printf("Hello %s, your age is %d.\n", name, age); 6 | return age; 7 | } 8 | -------------------------------------------------------------------------------- /cgo/hello.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | extern int hello(char *name, int age); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /basic/simple/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example // 定义模块 3 | 4 | %inline %{ 5 | extern int gcd(int x, int y); // 导出方法 6 | extern double Foo; // 导出全局变量 7 | %} 8 | -------------------------------------------------------------------------------- /basic/class/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | #include "example.h" 6 | %} 7 | 8 | /* Let's just grab the original header file here */ 9 | %include "example.h" 10 | -------------------------------------------------------------------------------- /basic/enum/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | #include "example.h" 6 | %} 7 | 8 | /* Let's just grab the original header file here */ 9 | 10 | %include "example.h" 11 | 12 | -------------------------------------------------------------------------------- /basic/funcptr/example/example.h: -------------------------------------------------------------------------------- 1 | /* file: example.h */ 2 | 3 | extern int do_op(int,int, int (*op)(int,int)); 4 | extern int add(int,int); 5 | extern int sub(int,int); 6 | extern int mul(int,int); 7 | 8 | extern int (*funcvar)(int,int); 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | -------------------------------------------------------------------------------- /basic/callback/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module(directors="1") example 3 | %{ 4 | #include "example.h" 5 | %} 6 | 7 | /* turn on director wrapping Callback */ 8 | %feature("director") Callback; 9 | 10 | %include "example.h" 11 | 12 | -------------------------------------------------------------------------------- /basic/director/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module(directors="1") example 3 | 4 | %include "std_string.i" 5 | 6 | %header %{ 7 | #include "director.h" 8 | %} 9 | 10 | %feature("director") FooBarAbstract; 11 | %include "director.h" 12 | -------------------------------------------------------------------------------- /cgo/ReadMe.md: -------------------------------------------------------------------------------- 1 | ## 使用 2 | 3 | #### 编译C库 4 | ```sh 5 | gcc -Wall -c hello.c 6 | ar -rv libhello.a hello.o 7 | ``` 8 | 9 | #### 编译Go程序 10 | ```sh 11 | go build 12 | ``` 13 | 14 | #### 注意事项 15 | + /* ... */ cgo 注释部分和 import "C" 之间不能存在空行 16 | + import 分成了两部分 17 | -------------------------------------------------------------------------------- /basic/enum/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | enum color { RED, BLUE, GREEN }; 4 | 5 | class Foo { 6 | public: 7 | Foo() { } 8 | enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 }; 9 | void enum_test(speed s); 10 | }; 11 | 12 | void enum_test(color c, Foo::speed s); 13 | 14 | -------------------------------------------------------------------------------- /basic/pointer/example/pointer.c: -------------------------------------------------------------------------------- 1 | /* File : example.c */ 2 | 3 | void add(int *x, int *y, int *result) { 4 | *result = *x + *y; 5 | } 6 | 7 | void sub(int *x, int *y, int *result) { 8 | *result = *x - *y; 9 | } 10 | 11 | int divide(int n, int d, int *r) { 12 | int q; 13 | q = n/d; 14 | *r = n - q*d; 15 | return q; 16 | } 17 | -------------------------------------------------------------------------------- /basic/extend/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module(directors="1") example 3 | %{ 4 | #include "example.h" 5 | %} 6 | 7 | %include "std_vector.i" 8 | %include "std_string.i" 9 | 10 | /* turn on director wrapping for Manager */ 11 | %feature("director") Employee; 12 | %feature("director") Manager; 13 | 14 | %include "example.h" 15 | 16 | -------------------------------------------------------------------------------- /basic/simple/example/simple.c: -------------------------------------------------------------------------------- 1 | /* File : example.c */ 2 | 3 | /* A global variable */ 4 | double Foo = 3.0; 5 | 6 | /* Compute the greatest common divisor of positive integers */ 7 | int gcd(int x, int y) { 8 | int g; 9 | g = y; 10 | while (x > 0) { 11 | g = x; 12 | x = y % x; 13 | y = g; 14 | } 15 | return g; 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /basic/template/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | #include "example.h" 6 | %} 7 | 8 | /* Let's just grab the original header file here */ 9 | %include "example.h" 10 | 11 | /* Now instantiate some specific template declarations */ 12 | 13 | %template(maxint) max; 14 | %template(maxdouble) max; 15 | %template(vecint) vector; 16 | %template(vecdouble) vector; 17 | 18 | -------------------------------------------------------------------------------- /cgo/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | #cgo CFLAGS: -I. 5 | #cgo LDFLAGS: -L. -lhello 6 | #include 7 | #include 8 | #include "hello.h" 9 | */ 10 | import "C" 11 | import ( 12 | "fmt" 13 | "unsafe" 14 | ) 15 | 16 | func main() { 17 | name := C.CString("Jack") 18 | defer C.free(unsafe.Pointer(name)) 19 | age := C.int(18) 20 | 21 | result := C.hello(name, age) 22 | fmt.Println(result) 23 | } -------------------------------------------------------------------------------- /basic/funcptr/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | %{ 4 | #include "example.h" 5 | %} 6 | 7 | /* Wrap a function taking a pointer to a function */ 8 | extern int do_op(int a, int b, int (*op)(int, int)); 9 | 10 | /* Now install a bunch of "ops" as constants */ 11 | %constant int (*ADD)(int,int) = add; 12 | %constant int (*SUB)(int,int) = sub; 13 | %constant int (*MUL)(int,int) = mul; 14 | 15 | extern int (*funcvar)(int,int); 16 | 17 | -------------------------------------------------------------------------------- /basic/reference/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | class Vector { 4 | private: 5 | double x,y,z; 6 | public: 7 | Vector() : x(0), y(0), z(0) { } 8 | Vector(double x, double y, double z) : x(x), y(y), z(z) { } 9 | friend Vector operator+(const Vector &a, const Vector &b); 10 | char *print(); 11 | }; 12 | 13 | class VectorArray { 14 | private: 15 | Vector *items; 16 | int maxsize; 17 | public: 18 | VectorArray(int maxsize); 19 | ~VectorArray(); 20 | Vector &operator[](int); 21 | int size(); 22 | }; 23 | -------------------------------------------------------------------------------- /basic/simple/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | // Call our gcd() function 10 | x := 42 11 | y := 105 12 | g := example.Gcd(x, y) 13 | fmt.Println("The gcd of", x, "and", y, "is", g) 14 | 15 | // Manipulate the Foo global variable 16 | 17 | // Output its current value 18 | fmt.Println("Foo =", example.GetFoo()) 19 | 20 | // Change its value 21 | example.SetFoo(3.1415926) 22 | 23 | // See if the change took effect 24 | fmt.Println("Foo =", example.GetFoo()) 25 | } 26 | -------------------------------------------------------------------------------- /basic/class/example/class.cxx: -------------------------------------------------------------------------------- 1 | /* File : class.cxx */ 2 | 3 | #include "example.h" 4 | #define M_PI 3.14159265358979323846 5 | 6 | /* Move the shape to a new location */ 7 | void Shape::move(double dx, double dy) { 8 | x += dx; 9 | y += dy; 10 | } 11 | 12 | int Shape::nshapes = 0; 13 | 14 | double Circle::area() { 15 | return M_PI*radius*radius; 16 | } 17 | 18 | double Circle::perimeter() { 19 | return 2*M_PI*radius; 20 | } 21 | 22 | double Square::area() { 23 | return width*width; 24 | } 25 | 26 | double Square::perimeter() { 27 | return 4*width; 28 | } 29 | -------------------------------------------------------------------------------- /basic/multimap/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | . "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | // Call our gcd() function 10 | x := 42 11 | y := 105 12 | g := Gcd(x, y) 13 | fmt.Println("The gcd of ", x, " and ", y, " is ", g) 14 | 15 | // Call the gcdmain() function 16 | args := []string{"gcdmain", "42", "105"} 17 | Gcdmain(args) 18 | 19 | // Call the count function 20 | fmt.Println(Count("Hello World", 'l')) 21 | 22 | // Call the capitalize function 23 | capitalizeMe := []string{"hello world"} 24 | Capitalize(capitalizeMe) 25 | fmt.Println(capitalizeMe[0]) 26 | } 27 | -------------------------------------------------------------------------------- /basic/callback/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | #include 4 | #include 5 | 6 | class Callback { 7 | public: 8 | virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; } 9 | virtual void run() { std::cout << "Callback::run()" << std::endl; } 10 | }; 11 | 12 | 13 | class Caller { 14 | private: 15 | Callback *_callback; 16 | public: 17 | Caller(): _callback(0) {} 18 | ~Caller() { delCallback(); } 19 | void delCallback() { delete _callback; _callback = 0; } 20 | void setCallback(Callback *cb) { delCallback(); _callback = cb; } 21 | void call() { if (_callback) _callback->run(); } 22 | }; 23 | -------------------------------------------------------------------------------- /basic/template/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | // Some template definitions 4 | 5 | template T max(T a, T b) { return a>b ? a : b; } 6 | 7 | template class vector { 8 | T *v; 9 | int sz; 10 | public: 11 | vector(int _sz) { 12 | v = new T[_sz]; 13 | sz = _sz; 14 | } 15 | T &get(int index) { 16 | return v[index]; 17 | } 18 | void set(int index, T &val) { 19 | v[index] = val; 20 | } 21 | #ifdef SWIG 22 | %extend { 23 | T getitem(int index) { 24 | return $self->get(index); 25 | } 26 | void setitem(int index, T val) { 27 | $self->set(index,val); 28 | } 29 | } 30 | #endif 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /basic/extend/example/ceo.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | type CEO interface { 4 | Manager 5 | deleteManager() 6 | IsCEO() 7 | } 8 | 9 | type ceo struct { 10 | Manager 11 | } 12 | 13 | func (p *ceo) deleteManager() { 14 | DeleteDirectorManager(p.Manager) 15 | } 16 | 17 | func (p *ceo) IsCEO() {} 18 | 19 | type overwrittenMethodsOnManager struct { 20 | p Manager 21 | } 22 | 23 | func NewCEO(name string) CEO { 24 | om := &overwrittenMethodsOnManager{} 25 | p := NewDirectorManager(om, name) 26 | om.p = p 27 | 28 | return &ceo{Manager: p} 29 | } 30 | 31 | func DeleteCEO(p CEO) { 32 | p.deleteManager() 33 | } 34 | 35 | func (p *ceo) GetPosition() string { 36 | return "CEO" 37 | } 38 | -------------------------------------------------------------------------------- /basic/funcptr/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | . "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | a := 37 10 | b := 42 11 | 12 | // Now call our C function with a bunch of callbacks 13 | 14 | fmt.Println("Trying some C callback functions") 15 | fmt.Println(" a = ", a) 16 | fmt.Println(" b = ", b) 17 | fmt.Println(" ADD(a,b) = ", Do_op(a, b, ADD)) 18 | fmt.Println(" SUB(a,b) = ", Do_op(a, b, SUB)) 19 | fmt.Println(" MUL(a,b) = ", Do_op(a, b, MUL)) 20 | 21 | fmt.Println("Here is what the C callback function classes are called in Go") 22 | fmt.Println(" ADD = ", ADD) 23 | fmt.Println(" SUB = ", SUB) 24 | fmt.Println(" MUL = ", MUL) 25 | } 26 | -------------------------------------------------------------------------------- /basic/constants/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | /* A few preprocessor macros */ 5 | 6 | #define ICONST 42 7 | #define FCONST 2.1828 8 | #define CCONST 'x' 9 | #define CCONST2 '\n' 10 | #define SCONST "Hello World" 11 | #define SCONST2 "\"Hello World\"" 12 | 13 | /* This should work just fine */ 14 | #define EXPR ICONST + 3*(FCONST) 15 | 16 | /* This shouldn't do anything */ 17 | #define EXTERN extern 18 | 19 | /* Neither should this (BAR isn't defined) */ 20 | #define FOO (ICONST + BAR) 21 | 22 | /* The following directives also produce constants */ 23 | 24 | %constant int iconst = 37; 25 | %constant double fconst = 3.14; 26 | -------------------------------------------------------------------------------- /basic/director/example/director.h: -------------------------------------------------------------------------------- 1 | #ifndef DIRECTOR_H 2 | #define DIRECTOR_H 3 | 4 | 5 | #include 6 | #include 7 | 8 | 9 | class FooBarAbstract 10 | { 11 | public: 12 | FooBarAbstract() {}; 13 | virtual ~FooBarAbstract() {}; 14 | 15 | std::string FooBar() { 16 | return this->Foo() + ", " + this->Bar(); 17 | }; 18 | 19 | protected: 20 | virtual std::string Foo() { 21 | return "Foo"; 22 | }; 23 | 24 | virtual std::string Bar() = 0; 25 | }; 26 | 27 | 28 | class FooBarCpp : public FooBarAbstract 29 | { 30 | protected: 31 | virtual std::string Foo() { 32 | return "C++ " + FooBarAbstract::Foo(); 33 | } 34 | 35 | virtual std::string Bar() { 36 | return "C++ Bar"; 37 | } 38 | }; 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /basic/callback/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | . "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("Adding and calling a normal C++ callback") 10 | fmt.Println("----------------------------------------") 11 | 12 | caller := NewCaller() 13 | callback := NewCallback() 14 | 15 | caller.SetCallback(callback) 16 | caller.Call() 17 | caller.DelCallback() 18 | 19 | go_callback := NewGoCallback() 20 | 21 | fmt.Println() 22 | fmt.Println("Adding and calling a Go callback") 23 | fmt.Println("--------------------------------") 24 | 25 | caller.SetCallback(go_callback) 26 | caller.Call() 27 | caller.DelCallback() 28 | 29 | DeleteGoCallback(go_callback) 30 | 31 | fmt.Println() 32 | fmt.Println("Go exit") 33 | } 34 | -------------------------------------------------------------------------------- /basic/class/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | class Shape { 4 | public: 5 | Shape() { 6 | nshapes++; 7 | } 8 | virtual ~Shape() { 9 | nshapes--; 10 | } 11 | double x, y; 12 | void move(double dx, double dy); 13 | virtual double area() = 0; 14 | virtual double perimeter() = 0; 15 | static int nshapes; 16 | }; 17 | 18 | class Circle : public Shape { 19 | private: 20 | double radius; 21 | public: 22 | Circle(double r) : radius(r) { } 23 | virtual double area(); 24 | virtual double perimeter(); 25 | }; 26 | 27 | class Square : public Shape { 28 | private: 29 | double width; 30 | public: 31 | Square(double w) : width(w) { } 32 | virtual double area(); 33 | virtual double perimeter(); 34 | }; 35 | -------------------------------------------------------------------------------- /basic/constants/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | fmt.Println("ICONST = ", example.ICONST, " (should be 42)") 10 | fmt.Println("FCONST = ", example.FCONST, " (should be 2.1828)") 11 | fmt.Printf("CCONST = %c (should be 'x')\n", example.CCONST) 12 | fmt.Printf("CCONST2 = %c(this should be on a new line)\n", example.CCONST2) 13 | fmt.Println("SCONST = ", example.SCONST, " (should be 'Hello World')") 14 | fmt.Println("SCONST2 = ", example.SCONST2, " (should be '\"Hello World\"')") 15 | fmt.Println("EXPR = ", example.EXPR, " (should be 48.5484)") 16 | fmt.Println("iconst = ", example.Iconst, " (should be 37)") 17 | fmt.Println("fconst = ", example.Fconst, " (should be 3.14)") 18 | } 19 | -------------------------------------------------------------------------------- /basic/pointer/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | extern void add(int *, int *, int *); 6 | extern void sub(int *, int *, int *); 7 | extern int divide(int, int, int *); 8 | %} 9 | 10 | /* This example illustrates a couple of different techniques 11 | for manipulating C pointers */ 12 | 13 | /* First we'll use the pointer library */ 14 | extern void add(int *x, int *y, int *result); 15 | %include cpointer.i 16 | %pointer_functions(int, intp); 17 | 18 | /* Next we'll use some typemaps */ 19 | 20 | %include typemaps.i 21 | extern void sub(int *INPUT, int *INPUT, int *OUTPUT); 22 | 23 | /* Next we'll use typemaps and the %apply directive */ 24 | 25 | %apply int *OUTPUT { int *r }; 26 | extern int divide(int n, int d, int *r); 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /basic/callback/example/gocallback.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type GoCallback interface { 8 | Callback 9 | deleteCallback() 10 | IsGoCallback() 11 | } 12 | 13 | type goCallback struct { 14 | Callback 15 | } 16 | 17 | func (p *goCallback) deleteCallback() { 18 | DeleteDirectorCallback(p.Callback) 19 | } 20 | 21 | func (p *goCallback) IsGoCallback() {} 22 | 23 | type overwrittenMethodsOnCallback struct { 24 | p Callback 25 | } 26 | 27 | func NewGoCallback() GoCallback { 28 | om := &overwrittenMethodsOnCallback{} 29 | p := NewDirectorCallback(om) 30 | om.p = p 31 | 32 | return &goCallback{Callback: p} 33 | } 34 | 35 | func DeleteGoCallback(p GoCallback) { 36 | p.deleteCallback() 37 | } 38 | 39 | func (p *goCallback) Run() { 40 | fmt.Println("GoCallback.Run") 41 | } 42 | -------------------------------------------------------------------------------- /basic/enum/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | . "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | // Print out the value of some enums 10 | fmt.Println("*** color ***") 11 | fmt.Println(" RED = ", RED) 12 | fmt.Println(" BLUE = ", BLUE) 13 | fmt.Println(" GREEN = ", GREEN) 14 | 15 | fmt.Println("\n*** Foo::speed ***") 16 | fmt.Println(" Foo::IMPULSE = ", FooIMPULSE) 17 | fmt.Println(" Foo::WARP = ", FooWARP) 18 | fmt.Println(" Foo::LUDICROUS = ", FooLUDICROUS) 19 | 20 | fmt.Println("\nTesting use of enums with functions\n") 21 | 22 | Enum_test(RED, FooIMPULSE) 23 | Enum_test(BLUE, FooWARP) 24 | Enum_test(GREEN, FooLUDICROUS) 25 | 26 | fmt.Println("\nTesting use of enum with class method") 27 | f := NewFoo() 28 | 29 | f.Enum_test(FooIMPULSE) 30 | f.Enum_test(FooWARP) 31 | f.Enum_test(FooLUDICROUS) 32 | } 33 | -------------------------------------------------------------------------------- /basic/reference/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | 3 | /* This file has a few "typical" uses of C++ references. */ 4 | 5 | %module example 6 | 7 | %{ 8 | #include "example.h" 9 | %} 10 | 11 | class Vector { 12 | public: 13 | Vector(double x, double y, double z); 14 | ~Vector(); 15 | char *print(); 16 | }; 17 | 18 | /* This helper function calls an overloaded operator */ 19 | %inline %{ 20 | Vector addv(Vector &a, Vector &b) { 21 | return a+b; 22 | } 23 | %} 24 | 25 | /* Wrapper around an array of vectors class */ 26 | 27 | class VectorArray { 28 | public: 29 | VectorArray(int maxsize); 30 | ~VectorArray(); 31 | int size(); 32 | 33 | /* This wrapper provides an alternative to the [] operator */ 34 | %extend { 35 | Vector &get(int index) { 36 | return (*$self)[index]; 37 | } 38 | void set(int index, Vector &a) { 39 | (*$self)[index] = a; 40 | } 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | ## SWIG快速入门 2 | #### 简介 3 | SWIG是一个软件开发工具,它将用C和c++编写的程序与各种高级编程语言连接起来(为其他需要生成库)。准确地说,SWIG生成了两个文件,一个文件是*_wrapper.cpp文件,一个是*.go文件。*_wrapper.cpp文件将C++接口封装为C接口。go文件通过上一节说的import "C"来引用C接口,并把对这些C接口的调用,封装为不涉及任何C特性的Go函数或方法。 4 | + [项目地址](https://github.com/swig/swig) 5 | + [项目自带Examples](https://github.com/swig/swig/tree/master/Examples) 6 | + [文档](http://www.swig.org/Doc3.0/Contents.html#Contents) 7 | 8 | #### SWIG安装 9 | + Mac/Ubuntu 10 | ```shell 11 | sudo apt-get install bison 12 | 13 | unzip swig-rel-3.0.12.zip 14 | cd swig-rel-3.0.12 15 | ./autogen.sh && ./configure 16 | make -j 4 && sudo make install 17 | ``` 18 | + Windows 10 19 | ```shell 20 | # swig windows版本 21 | https://sourceforge.net/projects/swig/files/swigwin 22 | # 解压然后添加环境变量即可 23 | windows不支持cgo,所以此路不通 24 | ``` 25 | 26 | 27 | #### 参考资料 28 | + [《go通过swig封装、调用c++共享库的技术总结》](https://www.cnblogs.com/terencezhou/p/10059156.html) 29 | + [《使用swig工具为go语言与c++进行交互》](https://www.cnblogs.com/dongc/p/6896850.html) -------------------------------------------------------------------------------- /basic/director/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "./example" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func Compare(name string, got string, exp string) error { 10 | fmt.Printf("%s; Got: '%s'; Expected: '%s'\n", name, got, exp) 11 | if got != exp { 12 | return fmt.Errorf("%s returned unexpected string! Got: '%s'; Expected: '%s'\n", name, got, exp) 13 | } 14 | return nil 15 | } 16 | 17 | func TestFooBarCpp() error { 18 | fb := example.NewFooBarCpp() 19 | defer example.DeleteFooBarCpp(fb) 20 | return Compare("FooBarCpp.FooBar()", fb.FooBar(), "C++ Foo, C++ Bar") 21 | } 22 | 23 | func TestFooBarGo() error { 24 | fb := example.NewFooBarGo() 25 | defer example.DeleteFooBarGo(fb) 26 | return Compare("FooBarGo.FooBar()", fb.FooBar(), "Go Foo, Go Bar") 27 | } 28 | 29 | func main() { 30 | fmt.Println("Test output:") 31 | fmt.Println("------------") 32 | err := TestFooBarCpp() 33 | err = TestFooBarGo() 34 | fmt.Println("------------") 35 | if err != nil { 36 | fmt.Fprintf(os.Stderr, "Tests failed! Last error: %s\n", err.Error()) 37 | os.Exit(1) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /basic/reference/example/reference.cxx: -------------------------------------------------------------------------------- 1 | /* File : example.cxx */ 2 | 3 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 4 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) 5 | # define _CRT_SECURE_NO_DEPRECATE 6 | #endif 7 | 8 | #include "example.h" 9 | #include 10 | #include 11 | 12 | Vector operator+(const Vector &a, const Vector &b) { 13 | Vector r; 14 | r.x = a.x + b.x; 15 | r.y = a.y + b.y; 16 | r.z = a.z + b.z; 17 | return r; 18 | } 19 | 20 | char *Vector::print() { 21 | static char temp[512]; 22 | sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z); 23 | return temp; 24 | } 25 | 26 | VectorArray::VectorArray(int size) { 27 | items = new Vector[size]; 28 | maxsize = size; 29 | } 30 | 31 | VectorArray::~VectorArray() { 32 | delete [] items; 33 | } 34 | 35 | Vector &VectorArray::operator[](int index) { 36 | if ((index < 0) || (index >= maxsize)) { 37 | printf("Panic! Array index out of bounds.\n"); 38 | exit(1); 39 | } 40 | return items[index]; 41 | } 42 | 43 | int VectorArray::size() { 44 | return maxsize; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /basic/multimap/multimap.c: -------------------------------------------------------------------------------- 1 | /* File : example.c */ 2 | #include 3 | #include 4 | #include 5 | 6 | /* Compute the greatest common divisor of positive integers */ 7 | int gcd(int x, int y) { 8 | int g; 9 | g = y; 10 | while (x > 0) { 11 | g = x; 12 | x = y % x; 13 | y = g; 14 | } 15 | return g; 16 | } 17 | 18 | int gcdmain(int argc, char *argv[]) { 19 | int x,y; 20 | if (argc != 3) { 21 | printf("usage: gcd x y\n"); 22 | return -1; 23 | } 24 | x = atoi(argv[1]); 25 | y = atoi(argv[2]); 26 | printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y)); 27 | return 0; 28 | } 29 | 30 | int count(char *bytes, int len, char c) { 31 | int i; 32 | int count = 0; 33 | for (i = 0; i < len; i++) { 34 | if (bytes[i] == c) count++; 35 | } 36 | return count; 37 | } 38 | 39 | void capitalize(char *str, int len) { 40 | int i; 41 | for (i = 0; i < len; i++) { 42 | str[i] = (char)toupper(str[i]); 43 | } 44 | } 45 | 46 | void circle(double x, double y) { 47 | double a = x*x + y*y; 48 | if (a > 1.0) { 49 | printf("Bad points %g, %g\n", x,y); 50 | } else { 51 | printf("Good points %g, %g\n", x,y); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /basic/pointer/runme.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | . "./example" 5 | "fmt" 6 | ) 7 | 8 | func main() { 9 | // First create some objects using the pointer library. 10 | fmt.Println("Testing the pointer library") 11 | a := New_intp() 12 | b := New_intp() 13 | c := New_intp() 14 | Intp_assign(a, 37) 15 | Intp_assign(b, 42) 16 | 17 | fmt.Println(" a =", a) 18 | fmt.Println(" b =", b) 19 | fmt.Println(" c =", c) 20 | 21 | // Call the add() function with some pointers 22 | Add(a, b, c) 23 | 24 | // Now get the result 25 | res := Intp_value(c) 26 | fmt.Println(" 37 + 42 =", res) 27 | 28 | // Clean up the pointers 29 | Delete_intp(a) 30 | Delete_intp(b) 31 | Delete_intp(c) 32 | 33 | // Now try the typemap library 34 | // Now it is no longer necessary to manufacture pointers. 35 | // Instead we use a single element slice which in Go is modifiable. 36 | 37 | fmt.Println("Trying the typemap library") 38 | r := []int{0} 39 | Sub(37, 42, r) 40 | fmt.Println(" 37 - 42 = ", r[0]) 41 | 42 | // Now try the version with return value 43 | 44 | fmt.Println("Testing return value") 45 | q := Divide(42, 37, r) 46 | fmt.Println(" 42/37 = ", q, " remainder ", r[0]) 47 | } 48 | -------------------------------------------------------------------------------- /basic/variables/example/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | %{ 4 | #include "example.h" 5 | %} 6 | 7 | /* Some global variable declarations */ 8 | %inline %{ 9 | extern int ivar; 10 | extern short svar; 11 | extern long lvar; 12 | extern unsigned int uivar; 13 | extern unsigned short usvar; 14 | extern unsigned long ulvar; 15 | extern signed char scvar; 16 | extern unsigned char ucvar; 17 | extern char cvar; 18 | extern float fvar; 19 | extern double dvar; 20 | extern char *strvar; 21 | extern const char cstrvar[]; 22 | extern int *iptrvar; 23 | extern char name[256]; 24 | 25 | extern Point *ptptr; 26 | extern Point pt; 27 | %} 28 | 29 | 30 | /* Some read-only variables */ 31 | 32 | %immutable; 33 | 34 | %inline %{ 35 | extern int status; 36 | extern char path[256]; 37 | %} 38 | 39 | %mutable; 40 | 41 | /* Some helper functions to make it easier to test */ 42 | %inline %{ 43 | extern void print_vars(); 44 | extern int *new_int(int value); 45 | extern Point *new_Point(int x, int y); 46 | extern char *Point_print(Point *p); 47 | extern void pt_print(); 48 | %} 49 | 50 | -------------------------------------------------------------------------------- /basic/extend/example/example.h: -------------------------------------------------------------------------------- 1 | /* File : example.h */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Employee { 10 | private: 11 | std::string name; 12 | public: 13 | Employee(const char* n): name(n) {} 14 | virtual std::string getTitle() { return getPosition() + " " + getName(); } 15 | virtual std::string getName() { return name; } 16 | virtual std::string getPosition() const { return "Employee"; } 17 | virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); } 18 | }; 19 | 20 | 21 | class Manager: public Employee { 22 | public: 23 | Manager(const char* n): Employee(n) {} 24 | virtual std::string getPosition() const { return "Manager"; } 25 | }; 26 | 27 | 28 | class EmployeeList { 29 | std::vector list; 30 | public: 31 | EmployeeList() { 32 | list.push_back(new Employee("Bob")); 33 | list.push_back(new Employee("Jane")); 34 | list.push_back(new Manager("Ted")); 35 | } 36 | void addEmployee(Employee *p) { 37 | list.push_back(p); 38 | std::cout << "New employee added. Current employees are:" << std::endl; 39 | std::vector::iterator i; 40 | for (i=list.begin(); i!=list.end(); i++) { 41 | std::cout << " " << (*i)->getTitle() << std::endl; 42 | } 43 | } 44 | const Employee *get_item(int i) { 45 | return list[i]; 46 | } 47 | ~EmployeeList() { 48 | std::vector::iterator i; 49 | std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl; 50 | for (i=list.begin(); i!=list.end(); i++) { 51 | delete *i; 52 | } 53 | std::cout << "~EmployeeList empty." << std::endl; 54 | } 55 | }; 56 | 57 | -------------------------------------------------------------------------------- /basic/class/runme.go: -------------------------------------------------------------------------------- 1 | // This example illustrates how C++ classes can be used from Go using SWIG. 2 | 3 | package main 4 | 5 | import ( 6 | . "./example" 7 | "fmt" 8 | ) 9 | 10 | func main() { 11 | // ----- Object creation ----- 12 | 13 | fmt.Println("Creating some objects:") 14 | c := NewCircle(10) 15 | fmt.Println(" Created circle", c) 16 | s := NewSquare(10) 17 | fmt.Println(" Created square", s) 18 | 19 | // ----- Access a static member ----- 20 | 21 | fmt.Println("\nA total of", GetShapeNshapes(), "shapes were created") 22 | 23 | // ----- Member data access ----- 24 | 25 | // Notice how we can do this using functions specific to 26 | // the 'Circle' class. 27 | c.SetX(20) 28 | c.SetY(30) 29 | 30 | // Now use the same functions in the base class 31 | var shape Shape = s 32 | shape.SetX(-10) 33 | shape.SetY(5) 34 | 35 | fmt.Println("\nHere is their current position:") 36 | fmt.Println(" Circle = (", c.GetX(), " ", c.GetY(), ")") 37 | fmt.Println(" Square = (", s.GetX(), " ", s.GetY(), ")") 38 | 39 | // ----- Call some methods ----- 40 | 41 | fmt.Println("\nHere are some properties of the shapes:") 42 | shapes := []Shape{c, s} 43 | for i := 0; i < len(shapes); i++ { 44 | fmt.Println(" ", shapes[i]) 45 | fmt.Println(" area = ", shapes[i].Area()) 46 | fmt.Println(" perimeter = ", shapes[i].Perimeter()) 47 | } 48 | 49 | // Notice how the area() and perimeter() functions really 50 | // invoke the appropriate virtual method on each object. 51 | 52 | // ----- Delete everything ----- 53 | 54 | fmt.Println("\nGuess I'll clean up now") 55 | 56 | // Note: this invokes the virtual destructor 57 | // You could leave this to the garbage collector 58 | DeleteCircle(c) 59 | DeleteSquare(s) 60 | 61 | fmt.Println(GetShapeNshapes(), " shapes remain") 62 | fmt.Println("Goodbye") 63 | } 64 | -------------------------------------------------------------------------------- /basic/reference/runme.go: -------------------------------------------------------------------------------- 1 | // This example illustrates the manipulation of C++ references in Java. 2 | 3 | package main 4 | 5 | import ( 6 | . "./example" 7 | "fmt" 8 | ) 9 | 10 | func main() { 11 | fmt.Println("Creating some objects:") 12 | a := NewVector(3, 4, 5) 13 | b := NewVector(10, 11, 12) 14 | 15 | fmt.Println(" Created ", a.Print()) 16 | fmt.Println(" Created ", b.Print()) 17 | 18 | // ----- Call an overloaded operator ----- 19 | 20 | // This calls the wrapper we placed around 21 | // 22 | // operator+(const Vector &a, const Vector &) 23 | // 24 | // It returns a new allocated object. 25 | 26 | fmt.Println("Adding a+b") 27 | c := Addv(a, b) 28 | fmt.Println(" a+b = " + c.Print()) 29 | 30 | // Because addv returns a reference, Addv will return a 31 | // pointer allocated using Go's memory allocator. That means 32 | // that it will be freed by Go's garbage collector, and we can 33 | // not use DeleteVector to release it. 34 | 35 | c = nil 36 | 37 | // ----- Create a vector array ----- 38 | 39 | fmt.Println("Creating an array of vectors") 40 | va := NewVectorArray(10) 41 | fmt.Println(" va = ", va) 42 | 43 | // ----- Set some values in the array ----- 44 | 45 | // These operators copy the value of Vector a and Vector b to 46 | // the vector array 47 | va.Set(0, a) 48 | va.Set(1, b) 49 | 50 | va.Set(2, Addv(a, b)) 51 | 52 | // Get some values from the array 53 | 54 | fmt.Println("Getting some array values") 55 | for i := 0; i < 5; i++ { 56 | fmt.Println(" va(", i, ") = ", va.Get(i).Print()) 57 | } 58 | 59 | // Watch under resource meter to check on this 60 | fmt.Println("Making sure we don't leak memory.") 61 | for i := 0; i < 1000000; i++ { 62 | c = va.Get(i % 10) 63 | } 64 | 65 | // ----- Clean up ----- This could be omitted. The garbage 66 | // collector would then clean up for us. 67 | fmt.Println("Cleaning up") 68 | DeleteVectorArray(va) 69 | DeleteVector(a) 70 | DeleteVector(b) 71 | } 72 | -------------------------------------------------------------------------------- /basic/ReadMe.md: -------------------------------------------------------------------------------- 1 | #### Basic 例子介绍 2 | 3 | ##### 指导go使用swig的例子 4 | + [simple](./simple) C函数和全局变量的使用。 5 | ``` 6 | cd ./simple/example 7 | swig -go -cgo -intgosize 64 example.i 8 | go build 9 | ``` 10 | + [constants](./constants) 常量的使用。 11 | ``` 12 | cd ./constants/example 13 | swig -go -cgo -intgosize 64 example.i 14 | go build 15 | ``` 16 | + [variables](./variables) 演示怎么从Go访问C的全局变量。。 17 | ``` 18 | cd ./variables/example 19 | swig -go -cgo -intgosize 64 example.i 20 | go build 21 | ``` 22 | + [enum](./enum) 枚举类型封装。 23 | ``` 24 | cd ./enum/example 25 | swig -go -cgo -c++ -intgosize 64 example.i 26 | go build 27 | ``` 28 | + [class](./class) C++类。 29 | ``` 30 | cd ./go/class/example 31 | swig -go -cgo -c++ -intgosize 64 example.i 32 | go build 33 | ``` 34 | + [reference](./reference) C++引用。 35 | ``` 36 | cd ./go/reference/example 37 | swig -go -cgo -c++ -intgosize 64 example.i 38 | go build 39 | ``` 40 | + [pointer](./pointer) 简单的指针操作。 41 | ``` 42 | cd ./go/pointer/example 43 | swig -go -cgo -intgosize 64 example.i 44 | go build 45 | ``` 46 | + [funcptr](./go/funcptr) 函数指针。 47 | ``` 48 | cd ./go/funcptr/example 49 | swig -go -cgo -intgosize 64 example.i 50 | go build 51 | ``` 52 | + [template](./template) C++模板类. 53 | ``` 54 | cd ./go/template/example 55 | swig -go -cgo -c++ -intgosize 64 example.i 56 | go build 57 | ``` 58 | + [callback](./go/callback) 利用directors使用C++回调函数。 59 | ``` 60 | cd ./go/callback/example 61 | swig -go -cgo -c++ -intgosize 64 example.i 62 | go build 63 | ``` 64 | + [extend](./extend) 利用directors使用C++多态。 65 | ``` 66 | cd ./extend/example 67 | swig -go -cgo -c++ -intgosize 64 example.i 68 | go build 69 | ``` 70 | + [director](./director) 如何利用utilize特性。 71 | ``` 72 | cd ./director/example 73 | swig -go -cgo -c++ -intgosize 64 example.i 74 | go build 75 | ``` -------------------------------------------------------------------------------- /basic/variables/runme.go: -------------------------------------------------------------------------------- 1 | // This example illustrates global variable access from Go. 2 | 3 | package main 4 | 5 | import ( 6 | "./example" 7 | "fmt" 8 | ) 9 | 10 | func main() { 11 | // Try to set the values of some global variables 12 | 13 | example.SetIvar(42) 14 | example.SetSvar(-31000) 15 | example.SetLvar(65537) 16 | example.SetUivar(123456) 17 | example.SetUsvar(61000) 18 | example.SetUlvar(654321) 19 | example.SetScvar(-13) 20 | example.SetUcvar(251) 21 | example.SetCvar('S') 22 | example.SetFvar(3.14159) 23 | example.SetDvar(2.1828) 24 | example.SetStrvar("Hello World") 25 | example.SetIptrvar(example.New_int(37)) 26 | example.SetPtptr(example.New_Point(37, 42)) 27 | example.SetName("Bill") 28 | 29 | // Now print out the values of the variables 30 | 31 | fmt.Println("Variables (values printed from Go)") 32 | 33 | fmt.Println("ivar =", example.GetIvar()) 34 | fmt.Println("svar =", example.GetSvar()) 35 | fmt.Println("lvar =", example.GetLvar()) 36 | fmt.Println("uivar =", example.GetUivar()) 37 | fmt.Println("usvar =", example.GetUsvar()) 38 | fmt.Println("ulvar =", example.GetUlvar()) 39 | fmt.Println("scvar =", example.GetScvar()) 40 | fmt.Println("ucvar =", example.GetUcvar()) 41 | fmt.Println("fvar =", example.GetFvar()) 42 | fmt.Println("dvar =", example.GetDvar()) 43 | fmt.Printf("cvar = %c\n", example.GetCvar()) 44 | fmt.Println("strvar =", example.GetStrvar()) 45 | fmt.Println("cstrvar =", example.GetCstrvar()) 46 | fmt.Println("iptrvar =", example.GetIptrvar()) 47 | fmt.Println("name =", example.GetName()) 48 | fmt.Println("ptptr =", example.GetPtptr(), example.Point_print(example.GetPtptr())) 49 | fmt.Println("pt =", example.GetPt(), example.Point_print(example.GetPt())) 50 | 51 | fmt.Println("\nVariables (values printed from C)") 52 | 53 | example.Print_vars() 54 | 55 | // This line would not compile: since status is marked with 56 | // %immutable, there is no SetStatus function. 57 | // fmt.Println("\nNow I'm going to try and modify some read only variables") 58 | // example.SetStatus(0) 59 | 60 | fmt.Println("\nI'm going to try and update a structure variable.\n") 61 | 62 | example.SetPt(example.GetPtptr()) 63 | 64 | fmt.Println("The new value is") 65 | example.Pt_print() 66 | fmt.Println("You should see the value", example.Point_print(example.GetPtptr())) 67 | } 68 | -------------------------------------------------------------------------------- /basic/variables/example/variables.c: -------------------------------------------------------------------------------- 1 | /* File : example.c */ 2 | 3 | /* I'm a file containing some C global variables */ 4 | 5 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 6 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) 7 | # define _CRT_SECURE_NO_DEPRECATE 8 | #endif 9 | 10 | #include 11 | #include 12 | #include "example.h" 13 | 14 | int ivar = 0; 15 | short svar = 0; 16 | long lvar = 0; 17 | unsigned int uivar = 0; 18 | unsigned short usvar = 0; 19 | unsigned long ulvar = 0; 20 | signed char scvar = 0; 21 | unsigned char ucvar = 0; 22 | char cvar = 0; 23 | float fvar = 0; 24 | double dvar = 0; 25 | char *strvar = 0; 26 | const char cstrvar[] = "Goodbye"; 27 | int *iptrvar = 0; 28 | char name[256] = "Dave"; 29 | char path[256] = "/home/beazley"; 30 | 31 | 32 | /* Global variables involving a structure */ 33 | Point *ptptr = 0; 34 | Point pt = { 10, 20 }; 35 | 36 | /* A variable that we will make read-only in the interface */ 37 | int status = 1; 38 | 39 | /* A debugging function to print out their values */ 40 | 41 | void print_vars() { 42 | printf("ivar = %d\n", ivar); 43 | printf("svar = %d\n", svar); 44 | printf("lvar = %ld\n", lvar); 45 | printf("uivar = %u\n", uivar); 46 | printf("usvar = %u\n", usvar); 47 | printf("ulvar = %lu\n", ulvar); 48 | printf("scvar = %d\n", scvar); 49 | printf("ucvar = %u\n", ucvar); 50 | printf("fvar = %g\n", fvar); 51 | printf("dvar = %g\n", dvar); 52 | printf("cvar = %c\n", cvar); 53 | printf("strvar = %s\n", strvar ? strvar : "(null)"); 54 | printf("cstrvar = %s\n", cstrvar); 55 | printf("iptrvar = %p\n", iptrvar); 56 | printf("name = %s\n", name); 57 | printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0); 58 | printf("pt = (%d, %d)\n", pt.x, pt.y); 59 | printf("status = %d\n", status); 60 | } 61 | 62 | /* A function to create an integer (to test iptrvar) */ 63 | 64 | int *new_int(int value) { 65 | int *ip = (int *) malloc(sizeof(int)); 66 | *ip = value; 67 | return ip; 68 | } 69 | 70 | /* A function to create a point */ 71 | 72 | Point *new_Point(int x, int y) { 73 | Point *p = (Point *) malloc(sizeof(Point)); 74 | p->x = x; 75 | p->y = y; 76 | return p; 77 | } 78 | 79 | char * Point_print(Point *p) { 80 | static char buffer[256]; 81 | if (p) { 82 | sprintf(buffer,"(%d,%d)", p->x,p->y); 83 | } else { 84 | sprintf(buffer,"null"); 85 | } 86 | return buffer; 87 | } 88 | 89 | void pt_print() { 90 | printf("(%d, %d)\n", pt.x, pt.y); 91 | } 92 | -------------------------------------------------------------------------------- /basic/multimap/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | extern int gcd(int x, int y); 6 | extern int gcdmain(int argc, char *argv[]); 7 | extern int count(char *bytes, int len, char c); 8 | extern void capitalize (char *str, int len); 9 | extern void circle (double cx, double cy); 10 | extern int squareCubed (int n, int *OUTPUT); 11 | %} 12 | 13 | extern int gcd(int x, int y); 14 | 15 | %typemap(gotype) (int argc, char *argv[]) "[]string" 16 | 17 | %typemap(in) (int argc, char *argv[]) 18 | %{ 19 | { 20 | int i; 21 | _gostring_* a; 22 | 23 | $1 = $input.len; 24 | a = (_gostring_*) $input.array; 25 | $2 = (char **) malloc (($1 + 1) * sizeof (char *)); 26 | for (i = 0; i < $1; i++) { 27 | _gostring_ *ps = &a[i]; 28 | $2[i] = (char *) ps->p; 29 | } 30 | $2[i] = NULL; 31 | } 32 | %} 33 | 34 | %typemap(argout) (int argc, char *argv[]) "" /* override char *[] default */ 35 | 36 | %typemap(freearg) (int argc, char *argv[]) 37 | %{ 38 | free($2); 39 | %} 40 | 41 | extern int gcdmain(int argc, char *argv[]); 42 | 43 | %typemap(gotype) (char *bytes, int len) "string" 44 | 45 | %typemap(in) (char *bytes, int len) 46 | %{ 47 | $1 = $input.p; 48 | $2 = $input.n; 49 | %} 50 | 51 | extern int count(char *bytes, int len, char c); 52 | 53 | /* This example shows how to wrap a function that mutates a c string. A one 54 | * element Go string slice is used so that the string can be returned 55 | * modified. 56 | */ 57 | 58 | %typemap(gotype) (char *str, int len) "[]string" 59 | 60 | %typemap(in) (char *str, int len) 61 | %{ 62 | { 63 | _gostring_ *a; 64 | char *p; 65 | int n; 66 | 67 | a = (_gostring_*) $input.array; 68 | p = a[0].p; 69 | n = a[0].n; 70 | $1 = malloc(n + 1); 71 | $2 = n; 72 | memcpy($1, p, n); 73 | } 74 | %} 75 | 76 | /* Return the mutated string as a modified element in the array. */ 77 | %typemap(argout,fragment="AllocateString") (char *str, int len) 78 | %{ 79 | { 80 | _gostring_ *a; 81 | 82 | a = (_gostring_*) $input.array; 83 | a[0] = Swig_AllocateString($1, $2); 84 | } 85 | %} 86 | 87 | %typemap(goargout,fragment="CopyString") (char *str, int len) 88 | %{ 89 | $input[0] = swigCopyString($input[0]) 90 | %} 91 | 92 | %typemap(freearg) (char *str, int len) 93 | %{ 94 | free($1); 95 | %} 96 | 97 | extern void capitalize(char *str, int len); 98 | 99 | /* A multi-valued constraint. Force two arguments to lie 100 | inside the unit circle */ 101 | 102 | %typemap(check) (double cx, double cy) 103 | %{ 104 | { 105 | double a = $1*$1 + $2*$2; 106 | if (a > 1.0) { 107 | _swig_gopanic("$1_name and $2_name must be in unit circle"); 108 | return; 109 | } 110 | } 111 | %} 112 | 113 | extern void circle(double cx, double cy); 114 | 115 | 116 | -------------------------------------------------------------------------------- /basic/director/example/director.go: -------------------------------------------------------------------------------- 1 | package example 2 | 3 | // FooBarGo is a superset of FooBarAbstract and hence FooBarGo can be used as a 4 | // drop in replacement for FooBarAbstract but the reverse causes a compile time 5 | // error. 6 | type FooBarGo interface { 7 | FooBarAbstract 8 | deleteFooBarAbstract() 9 | IsFooBarGo() 10 | } 11 | 12 | // Via embedding fooBarGo "inherits" all methods of FooBarAbstract. 13 | type fooBarGo struct { 14 | FooBarAbstract 15 | } 16 | 17 | func (fbgs *fooBarGo) deleteFooBarAbstract() { 18 | DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract) 19 | } 20 | 21 | // The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract. 22 | // This is also how the class hierarchy gets represented by the SWIG generated 23 | // wrapper code. For an instance FooBarCpp has the IsFooBarAbstract and 24 | // IsFooBarCpp methods. 25 | func (fbgs *fooBarGo) IsFooBarGo() {} 26 | 27 | // Go type that defines the DirectorInterface. It contains the Foo and Bar 28 | // methods that overwrite the respective virtual C++ methods on FooBarAbstract. 29 | type overwrittenMethodsOnFooBarAbstract struct { 30 | // Backlink to FooBarAbstract so that the rest of the class can be used by 31 | // the overridden methods. 32 | fb FooBarAbstract 33 | 34 | // If additional constructor arguments have been given they are typically 35 | // stored here so that the overriden methods can use them. 36 | } 37 | 38 | func (om *overwrittenMethodsOnFooBarAbstract) Foo() string { 39 | // DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo. 40 | return "Go " + DirectorFooBarAbstractFoo(om.fb) 41 | } 42 | 43 | func (om *overwrittenMethodsOnFooBarAbstract) Bar() string { 44 | return "Go Bar" 45 | } 46 | 47 | func NewFooBarGo() FooBarGo { 48 | // Instantiate FooBarAbstract with selected methods overridden. The methods 49 | // that will be overwritten are defined on 50 | // overwrittenMethodsOnFooBarAbstract and have a compatible signature to the 51 | // respective virtual C++ methods. Furthermore additional constructor 52 | // arguments will be typically stored in the 53 | // overwrittenMethodsOnFooBarAbstract struct. 54 | om := &overwrittenMethodsOnFooBarAbstract{} 55 | fb := NewDirectorFooBarAbstract(om) 56 | om.fb = fb // Backlink causes cycle as fb.v = om! 57 | 58 | fbgs := &fooBarGo{FooBarAbstract: fb} 59 | // The memory of the FooBarAbstract director object instance can be 60 | // automatically freed once the FooBarGo instance is garbage collected by 61 | // uncommenting the following line. Please make sure to understand the 62 | // runtime.SetFinalizer specific gotchas before doing this. Furthemore 63 | // DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo 64 | // struct needs additional data to prevent double deletion. 65 | // runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract) 66 | return fbgs 67 | } 68 | 69 | // Recommended to be removed if runtime.SetFinalizer is in use. 70 | func DeleteFooBarGo(fbg FooBarGo) { 71 | fbg.deleteFooBarAbstract() 72 | } 73 | -------------------------------------------------------------------------------- /basic/extend/runme.go: -------------------------------------------------------------------------------- 1 | // This file illustrates the cross language polymorphism using directors. 2 | 3 | package main 4 | 5 | import ( 6 | . "./example" 7 | "fmt" 8 | ) 9 | 10 | func main() { 11 | // Create an instance of CEO, a class derived from the Go 12 | // proxy of the underlying C++ class. The calls to getName() 13 | // and getPosition() are standard, the call to getTitle() uses 14 | // the director wrappers to call CEO.getPosition(). 15 | e := NewCEO("Alice") 16 | fmt.Println(e.GetName(), " is a ", e.GetPosition()) 17 | fmt.Println("Just call her \"", e.GetTitle(), "\"") 18 | fmt.Println("----------------------") 19 | 20 | // Create a new EmployeeList instance. This class does not 21 | // have a C++ director wrapper, but can be used freely with 22 | // other classes that do. 23 | list := NewEmployeeList() 24 | 25 | // EmployeeList owns its items, so we must surrender ownership 26 | // of objects we add. 27 | // e.DisownMemory() 28 | list.AddEmployee(e) 29 | fmt.Println("----------------------") 30 | 31 | // Now we access the first four items in list (three are C++ 32 | // objects that EmployeeList's constructor adds, the last is 33 | // our CEO). The virtual methods of all these instances are 34 | // treated the same. For items 0, 1, and 2, all methods 35 | // resolve in C++. For item 3, our CEO, GetTitle calls 36 | // GetPosition which resolves in Go. The call to GetPosition 37 | // is slightly different, however, because of the overridden 38 | // GetPosition() call, since now the object reference has been 39 | // "laundered" by passing through EmployeeList as an 40 | // Employee*. Previously, Go resolved the call immediately in 41 | // CEO, but now Go thinks the object is an instance of class 42 | // Employee. So the call passes through the Employee proxy 43 | // class and on to the C wrappers and C++ director, eventually 44 | // ending up back at the Go CEO implementation of 45 | // getPosition(). The call to GetTitle() for item 3 runs the 46 | // C++ Employee::getTitle() method, which in turn calls 47 | // GetPosition(). This virtual method call passes down 48 | // through the C++ director class to the Go implementation 49 | // in CEO. All this routing takes place transparently. 50 | fmt.Println("(position, title) for items 0-3:") 51 | fmt.Println(" ", list.Get_item(0).GetPosition(), ", \"", list.Get_item(0).GetTitle(), "\"") 52 | fmt.Println(" ", list.Get_item(1).GetPosition(), ", \"", list.Get_item(1).GetTitle(), "\"") 53 | fmt.Println(" ", list.Get_item(2).GetPosition(), ", \"", list.Get_item(2).GetTitle(), "\"") 54 | fmt.Println(" ", list.Get_item(3).GetPosition(), ", \"", list.Get_item(3).GetTitle(), "\"") 55 | fmt.Println("----------------------") 56 | 57 | // Time to delete the EmployeeList, which will delete all the 58 | // Employee* items it contains. The last item is our CEO, 59 | // which gets destroyed as well and hence there is no need to 60 | // call DeleteCEO. 61 | DeleteEmployeeList(list) 62 | fmt.Println("----------------------") 63 | 64 | // All done. 65 | fmt.Println("Go exit") 66 | } 67 | -------------------------------------------------------------------------------- /basic/pointer/example/example.go: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | package example 14 | 15 | /* 16 | #define intgo swig_intgo 17 | typedef void *swig_voidp; 18 | 19 | #include 20 | 21 | 22 | typedef long long intgo; 23 | typedef unsigned long long uintgo; 24 | 25 | 26 | 27 | typedef struct { char *p; intgo n; } _gostring_; 28 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 29 | 30 | 31 | typedef _goslice_ swig_type_1; 32 | typedef _goslice_ swig_type_2; 33 | extern void _wrap_Swig_free_example_94bf2401246d4292(uintptr_t arg1); 34 | extern uintptr_t _wrap_Swig_malloc_example_94bf2401246d4292(swig_intgo arg1); 35 | extern void _wrap_add_example_94bf2401246d4292(swig_voidp arg1, swig_voidp arg2, swig_voidp arg3); 36 | extern swig_voidp _wrap_new_intp_example_94bf2401246d4292(void); 37 | extern swig_voidp _wrap_copy_intp_example_94bf2401246d4292(swig_intgo arg1); 38 | extern void _wrap_delete_intp_example_94bf2401246d4292(swig_voidp arg1); 39 | extern void _wrap_intp_assign_example_94bf2401246d4292(swig_voidp arg1, swig_intgo arg2); 40 | extern swig_intgo _wrap_intp_value_example_94bf2401246d4292(swig_voidp arg1); 41 | extern void _wrap_sub_example_94bf2401246d4292(swig_intgo arg1, swig_intgo arg2, swig_type_1 arg3); 42 | extern swig_intgo _wrap_divide_example_94bf2401246d4292(swig_intgo arg1, swig_intgo arg2, swig_type_2 arg3); 43 | #undef intgo 44 | */ 45 | import "C" 46 | 47 | import "unsafe" 48 | import _ "runtime/cgo" 49 | import "sync" 50 | 51 | 52 | type _ unsafe.Pointer 53 | 54 | 55 | 56 | var Swig_escape_always_false bool 57 | var Swig_escape_val interface{} 58 | 59 | 60 | type _swig_fnptr *byte 61 | type _swig_memberptr *byte 62 | 63 | 64 | type _ sync.Mutex 65 | 66 | func Swig_free(arg1 uintptr) { 67 | _swig_i_0 := arg1 68 | C._wrap_Swig_free_example_94bf2401246d4292(C.uintptr_t(_swig_i_0)) 69 | } 70 | 71 | func Swig_malloc(arg1 int) (_swig_ret uintptr) { 72 | var swig_r uintptr 73 | _swig_i_0 := arg1 74 | swig_r = (uintptr)(C._wrap_Swig_malloc_example_94bf2401246d4292(C.swig_intgo(_swig_i_0))) 75 | return swig_r 76 | } 77 | 78 | func Add(arg1 *int, arg2 *int, arg3 *int) { 79 | _swig_i_0 := arg1 80 | _swig_i_1 := arg2 81 | _swig_i_2 := arg3 82 | C._wrap_add_example_94bf2401246d4292(C.swig_voidp(_swig_i_0), C.swig_voidp(_swig_i_1), C.swig_voidp(_swig_i_2)) 83 | } 84 | 85 | func New_intp() (_swig_ret *int) { 86 | var swig_r *int 87 | swig_r = (*int)(C._wrap_new_intp_example_94bf2401246d4292()) 88 | return swig_r 89 | } 90 | 91 | func Copy_intp(arg1 int) (_swig_ret *int) { 92 | var swig_r *int 93 | _swig_i_0 := arg1 94 | swig_r = (*int)(C._wrap_copy_intp_example_94bf2401246d4292(C.swig_intgo(_swig_i_0))) 95 | return swig_r 96 | } 97 | 98 | func Delete_intp(arg1 *int) { 99 | _swig_i_0 := arg1 100 | C._wrap_delete_intp_example_94bf2401246d4292(C.swig_voidp(_swig_i_0)) 101 | } 102 | 103 | func Intp_assign(arg1 *int, arg2 int) { 104 | _swig_i_0 := arg1 105 | _swig_i_1 := arg2 106 | C._wrap_intp_assign_example_94bf2401246d4292(C.swig_voidp(_swig_i_0), C.swig_intgo(_swig_i_1)) 107 | } 108 | 109 | func Intp_value(arg1 *int) (_swig_ret int) { 110 | var swig_r int 111 | _swig_i_0 := arg1 112 | swig_r = (int)(C._wrap_intp_value_example_94bf2401246d4292(C.swig_voidp(_swig_i_0))) 113 | return swig_r 114 | } 115 | 116 | func Sub(arg1 int, arg2 int, arg3 []int) { 117 | _swig_i_0 := arg1 118 | _swig_i_1 := arg2 119 | _swig_i_2 := arg3 120 | C._wrap_sub_example_94bf2401246d4292(C.swig_intgo(_swig_i_0), C.swig_intgo(_swig_i_1), *(*C.swig_type_1)(unsafe.Pointer(&_swig_i_2))) 121 | if Swig_escape_always_false { 122 | Swig_escape_val = arg3 123 | } 124 | } 125 | 126 | func Divide(arg1 int, arg2 int, arg3 []int) (_swig_ret int) { 127 | var swig_r int 128 | _swig_i_0 := arg1 129 | _swig_i_1 := arg2 130 | _swig_i_2 := arg3 131 | swig_r = (int)(C._wrap_divide_example_94bf2401246d4292(C.swig_intgo(_swig_i_0), C.swig_intgo(_swig_i_1), *(*C.swig_type_2)(unsafe.Pointer(&_swig_i_2)))) 132 | if Swig_escape_always_false { 133 | Swig_escape_val = arg3 134 | } 135 | return swig_r 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /basic/enum/example/example.go: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | package example 14 | 15 | /* 16 | #define intgo swig_intgo 17 | typedef void *swig_voidp; 18 | 19 | #include 20 | 21 | 22 | typedef long long intgo; 23 | typedef unsigned long long uintgo; 24 | 25 | 26 | 27 | typedef struct { char *p; intgo n; } _gostring_; 28 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 29 | 30 | 31 | extern void _wrap_Swig_free_example_4d9c8b93e2d13d1d(uintptr_t arg1); 32 | extern uintptr_t _wrap_Swig_malloc_example_4d9c8b93e2d13d1d(swig_intgo arg1); 33 | extern swig_intgo _wrap_RED_example_4d9c8b93e2d13d1d(void); 34 | extern swig_intgo _wrap_BLUE_example_4d9c8b93e2d13d1d(void); 35 | extern swig_intgo _wrap_GREEN_example_4d9c8b93e2d13d1d(void); 36 | extern uintptr_t _wrap_new_Foo_example_4d9c8b93e2d13d1d(void); 37 | extern swig_intgo _wrap_IMPULSE_Foo_example_4d9c8b93e2d13d1d(void); 38 | extern swig_intgo _wrap_WARP_Foo_example_4d9c8b93e2d13d1d(void); 39 | extern swig_intgo _wrap_LUDICROUS_Foo_example_4d9c8b93e2d13d1d(void); 40 | extern void _wrap_Foo_enum_test_example_4d9c8b93e2d13d1d(uintptr_t arg1, swig_intgo arg2); 41 | extern void _wrap_delete_Foo_example_4d9c8b93e2d13d1d(uintptr_t arg1); 42 | extern void _wrap_enum_test_example_4d9c8b93e2d13d1d(swig_intgo arg1, swig_intgo arg2); 43 | #undef intgo 44 | */ 45 | import "C" 46 | 47 | import "unsafe" 48 | import _ "runtime/cgo" 49 | import "sync" 50 | 51 | 52 | type _ unsafe.Pointer 53 | 54 | 55 | 56 | var Swig_escape_always_false bool 57 | var Swig_escape_val interface{} 58 | 59 | 60 | type _swig_fnptr *byte 61 | type _swig_memberptr *byte 62 | 63 | 64 | type _ sync.Mutex 65 | 66 | func Swig_free(arg1 uintptr) { 67 | _swig_i_0 := arg1 68 | C._wrap_Swig_free_example_4d9c8b93e2d13d1d(C.uintptr_t(_swig_i_0)) 69 | } 70 | 71 | func Swig_malloc(arg1 int) (_swig_ret uintptr) { 72 | var swig_r uintptr 73 | _swig_i_0 := arg1 74 | swig_r = (uintptr)(C._wrap_Swig_malloc_example_4d9c8b93e2d13d1d(C.swig_intgo(_swig_i_0))) 75 | return swig_r 76 | } 77 | 78 | type Color int 79 | func _swig_getRED() (_swig_ret Color) { 80 | var swig_r Color 81 | swig_r = (Color)(C._wrap_RED_example_4d9c8b93e2d13d1d()) 82 | return swig_r 83 | } 84 | 85 | var RED Color = _swig_getRED() 86 | func _swig_getBLUE() (_swig_ret Color) { 87 | var swig_r Color 88 | swig_r = (Color)(C._wrap_BLUE_example_4d9c8b93e2d13d1d()) 89 | return swig_r 90 | } 91 | 92 | var BLUE Color = _swig_getBLUE() 93 | func _swig_getGREEN() (_swig_ret Color) { 94 | var swig_r Color 95 | swig_r = (Color)(C._wrap_GREEN_example_4d9c8b93e2d13d1d()) 96 | return swig_r 97 | } 98 | 99 | var GREEN Color = _swig_getGREEN() 100 | type SwigcptrFoo uintptr 101 | 102 | func (p SwigcptrFoo) Swigcptr() uintptr { 103 | return (uintptr)(p) 104 | } 105 | 106 | func (p SwigcptrFoo) SwigIsFoo() { 107 | } 108 | 109 | func NewFoo() (_swig_ret Foo) { 110 | var swig_r Foo 111 | swig_r = (Foo)(SwigcptrFoo(C._wrap_new_Foo_example_4d9c8b93e2d13d1d())) 112 | return swig_r 113 | } 114 | 115 | type FooSpeed int 116 | func _swig_getFoo_IMPULSE_Foo() (_swig_ret FooSpeed) { 117 | var swig_r FooSpeed 118 | swig_r = (FooSpeed)(C._wrap_IMPULSE_Foo_example_4d9c8b93e2d13d1d()) 119 | return swig_r 120 | } 121 | 122 | var FooIMPULSE FooSpeed = _swig_getFoo_IMPULSE_Foo() 123 | func _swig_getFoo_WARP_Foo() (_swig_ret FooSpeed) { 124 | var swig_r FooSpeed 125 | swig_r = (FooSpeed)(C._wrap_WARP_Foo_example_4d9c8b93e2d13d1d()) 126 | return swig_r 127 | } 128 | 129 | var FooWARP FooSpeed = _swig_getFoo_WARP_Foo() 130 | func _swig_getFoo_LUDICROUS_Foo() (_swig_ret FooSpeed) { 131 | var swig_r FooSpeed 132 | swig_r = (FooSpeed)(C._wrap_LUDICROUS_Foo_example_4d9c8b93e2d13d1d()) 133 | return swig_r 134 | } 135 | 136 | var FooLUDICROUS FooSpeed = _swig_getFoo_LUDICROUS_Foo() 137 | func (arg1 SwigcptrFoo) Enum_test(arg2 FooSpeed) { 138 | _swig_i_0 := arg1 139 | _swig_i_1 := arg2 140 | C._wrap_Foo_enum_test_example_4d9c8b93e2d13d1d(C.uintptr_t(_swig_i_0), C.swig_intgo(_swig_i_1)) 141 | } 142 | 143 | func DeleteFoo(arg1 Foo) { 144 | _swig_i_0 := arg1.Swigcptr() 145 | C._wrap_delete_Foo_example_4d9c8b93e2d13d1d(C.uintptr_t(_swig_i_0)) 146 | } 147 | 148 | type Foo interface { 149 | Swigcptr() uintptr 150 | SwigIsFoo() 151 | Enum_test(arg2 FooSpeed) 152 | } 153 | 154 | func Enum_test(arg1 Color, arg2 FooSpeed) { 155 | _swig_i_0 := arg1 156 | _swig_i_1 := arg2 157 | C._wrap_enum_test_example_4d9c8b93e2d13d1d(C.swig_intgo(_swig_i_0), C.swig_intgo(_swig_i_1)) 158 | } 159 | 160 | 161 | -------------------------------------------------------------------------------- /basic/reference/example/example.go: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | package example 14 | 15 | /* 16 | #define intgo swig_intgo 17 | typedef void *swig_voidp; 18 | 19 | #include 20 | 21 | 22 | typedef long long intgo; 23 | typedef unsigned long long uintgo; 24 | 25 | 26 | 27 | typedef struct { char *p; intgo n; } _gostring_; 28 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 29 | 30 | 31 | typedef _gostring_ swig_type_1; 32 | extern void _wrap_Swig_free_example_7c6d0b865a722e37(uintptr_t arg1); 33 | extern uintptr_t _wrap_Swig_malloc_example_7c6d0b865a722e37(swig_intgo arg1); 34 | extern uintptr_t _wrap_new_Vector_example_7c6d0b865a722e37(double arg1, double arg2, double arg3); 35 | extern void _wrap_delete_Vector_example_7c6d0b865a722e37(uintptr_t arg1); 36 | extern swig_type_1 _wrap_Vector_print_example_7c6d0b865a722e37(uintptr_t arg1); 37 | extern uintptr_t _wrap_addv_example_7c6d0b865a722e37(uintptr_t arg1, uintptr_t arg2); 38 | extern uintptr_t _wrap_new_VectorArray_example_7c6d0b865a722e37(swig_intgo arg1); 39 | extern void _wrap_delete_VectorArray_example_7c6d0b865a722e37(uintptr_t arg1); 40 | extern swig_intgo _wrap_VectorArray_size_example_7c6d0b865a722e37(uintptr_t arg1); 41 | extern uintptr_t _wrap_VectorArray_get_example_7c6d0b865a722e37(uintptr_t arg1, swig_intgo arg2); 42 | extern void _wrap_VectorArray_set_example_7c6d0b865a722e37(uintptr_t arg1, swig_intgo arg2, uintptr_t arg3); 43 | #undef intgo 44 | */ 45 | import "C" 46 | 47 | import "unsafe" 48 | import _ "runtime/cgo" 49 | import "sync" 50 | 51 | 52 | type _ unsafe.Pointer 53 | 54 | 55 | 56 | var Swig_escape_always_false bool 57 | var Swig_escape_val interface{} 58 | 59 | 60 | type _swig_fnptr *byte 61 | type _swig_memberptr *byte 62 | 63 | 64 | type _ sync.Mutex 65 | 66 | 67 | type swig_gostring struct { p uintptr; n int } 68 | func swigCopyString(s string) string { 69 | p := *(*swig_gostring)(unsafe.Pointer(&s)) 70 | r := string((*[0x7fffffff]byte)(unsafe.Pointer(p.p))[:p.n]) 71 | Swig_free(p.p) 72 | return r 73 | } 74 | 75 | func Swig_free(arg1 uintptr) { 76 | _swig_i_0 := arg1 77 | C._wrap_Swig_free_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0)) 78 | } 79 | 80 | func Swig_malloc(arg1 int) (_swig_ret uintptr) { 81 | var swig_r uintptr 82 | _swig_i_0 := arg1 83 | swig_r = (uintptr)(C._wrap_Swig_malloc_example_7c6d0b865a722e37(C.swig_intgo(_swig_i_0))) 84 | return swig_r 85 | } 86 | 87 | type SwigcptrVector uintptr 88 | 89 | func (p SwigcptrVector) Swigcptr() uintptr { 90 | return (uintptr)(p) 91 | } 92 | 93 | func (p SwigcptrVector) SwigIsVector() { 94 | } 95 | 96 | func NewVector(arg1 float64, arg2 float64, arg3 float64) (_swig_ret Vector) { 97 | var swig_r Vector 98 | _swig_i_0 := arg1 99 | _swig_i_1 := arg2 100 | _swig_i_2 := arg3 101 | swig_r = (Vector)(SwigcptrVector(C._wrap_new_Vector_example_7c6d0b865a722e37(C.double(_swig_i_0), C.double(_swig_i_1), C.double(_swig_i_2)))) 102 | return swig_r 103 | } 104 | 105 | func DeleteVector(arg1 Vector) { 106 | _swig_i_0 := arg1.Swigcptr() 107 | C._wrap_delete_Vector_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0)) 108 | } 109 | 110 | func (arg1 SwigcptrVector) Print() (_swig_ret string) { 111 | var swig_r string 112 | _swig_i_0 := arg1 113 | swig_r_p := C._wrap_Vector_print_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0)) 114 | swig_r = *(*string)(unsafe.Pointer(&swig_r_p)) 115 | var swig_r_1 string 116 | swig_r_1 = swigCopyString(swig_r) 117 | return swig_r_1 118 | } 119 | 120 | type Vector interface { 121 | Swigcptr() uintptr 122 | SwigIsVector() 123 | Print() (_swig_ret string) 124 | } 125 | 126 | func Addv(arg1 Vector, arg2 Vector) (_swig_ret Vector) { 127 | var swig_r Vector 128 | _swig_i_0 := arg1.Swigcptr() 129 | _swig_i_1 := arg2.Swigcptr() 130 | swig_r = (Vector)(SwigcptrVector(C._wrap_addv_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0), C.uintptr_t(_swig_i_1)))) 131 | return swig_r 132 | } 133 | 134 | type SwigcptrVectorArray uintptr 135 | 136 | func (p SwigcptrVectorArray) Swigcptr() uintptr { 137 | return (uintptr)(p) 138 | } 139 | 140 | func (p SwigcptrVectorArray) SwigIsVectorArray() { 141 | } 142 | 143 | func NewVectorArray(arg1 int) (_swig_ret VectorArray) { 144 | var swig_r VectorArray 145 | _swig_i_0 := arg1 146 | swig_r = (VectorArray)(SwigcptrVectorArray(C._wrap_new_VectorArray_example_7c6d0b865a722e37(C.swig_intgo(_swig_i_0)))) 147 | return swig_r 148 | } 149 | 150 | func DeleteVectorArray(arg1 VectorArray) { 151 | _swig_i_0 := arg1.Swigcptr() 152 | C._wrap_delete_VectorArray_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0)) 153 | } 154 | 155 | func (arg1 SwigcptrVectorArray) Size() (_swig_ret int) { 156 | var swig_r int 157 | _swig_i_0 := arg1 158 | swig_r = (int)(C._wrap_VectorArray_size_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0))) 159 | return swig_r 160 | } 161 | 162 | func (arg1 SwigcptrVectorArray) Get(arg2 int) (_swig_ret Vector) { 163 | var swig_r Vector 164 | _swig_i_0 := arg1 165 | _swig_i_1 := arg2 166 | swig_r = (Vector)(SwigcptrVector(C._wrap_VectorArray_get_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0), C.swig_intgo(_swig_i_1)))) 167 | return swig_r 168 | } 169 | 170 | func (arg1 SwigcptrVectorArray) Set(arg2 int, arg3 Vector) { 171 | _swig_i_0 := arg1 172 | _swig_i_1 := arg2 173 | _swig_i_2 := arg3.Swigcptr() 174 | C._wrap_VectorArray_set_example_7c6d0b865a722e37(C.uintptr_t(_swig_i_0), C.swig_intgo(_swig_i_1), C.uintptr_t(_swig_i_2)) 175 | } 176 | 177 | type VectorArray interface { 178 | Swigcptr() uintptr 179 | SwigIsVectorArray() 180 | Size() (_swig_ret int) 181 | Get(arg2 int) (_swig_ret Vector) 182 | Set(arg2 int, arg3 Vector) 183 | } 184 | 185 | 186 | -------------------------------------------------------------------------------- /basic/callback/example/example.go: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | package example 14 | 15 | /* 16 | #define intgo swig_intgo 17 | typedef void *swig_voidp; 18 | 19 | #include 20 | 21 | 22 | typedef long long intgo; 23 | typedef unsigned long long uintgo; 24 | 25 | 26 | 27 | typedef struct { char *p; intgo n; } _gostring_; 28 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 29 | 30 | 31 | extern void _wrap_Swig_free_example_f0ef324ec2fa820a(uintptr_t arg1); 32 | extern uintptr_t _wrap_Swig_malloc_example_f0ef324ec2fa820a(swig_intgo arg1); 33 | extern uintptr_t _wrap__swig_NewDirectorCallbackCallback_example_f0ef324ec2fa820a(int); 34 | extern void _wrap_DeleteDirectorCallback_example_f0ef324ec2fa820a(uintptr_t arg1); 35 | extern void _wrap__swig_DirectorCallback_upcall_Run_example_f0ef324ec2fa820a(uintptr_t); 36 | extern void _wrap_delete_Callback_example_f0ef324ec2fa820a(uintptr_t arg1); 37 | extern void _wrap_Callback_run_example_f0ef324ec2fa820a(uintptr_t arg1); 38 | extern uintptr_t _wrap_new_Callback_example_f0ef324ec2fa820a(void); 39 | extern uintptr_t _wrap_new_Caller_example_f0ef324ec2fa820a(void); 40 | extern void _wrap_delete_Caller_example_f0ef324ec2fa820a(uintptr_t arg1); 41 | extern void _wrap_Caller_delCallback_example_f0ef324ec2fa820a(uintptr_t arg1); 42 | extern void _wrap_Caller_setCallback_example_f0ef324ec2fa820a(uintptr_t arg1, uintptr_t arg2); 43 | extern void _wrap_Caller_call_example_f0ef324ec2fa820a(uintptr_t arg1); 44 | #undef intgo 45 | */ 46 | import "C" 47 | 48 | import "unsafe" 49 | import _ "runtime/cgo" 50 | import "sync" 51 | 52 | 53 | type _ unsafe.Pointer 54 | 55 | 56 | 57 | var Swig_escape_always_false bool 58 | var Swig_escape_val interface{} 59 | 60 | 61 | type _swig_fnptr *byte 62 | type _swig_memberptr *byte 63 | 64 | 65 | type _ sync.Mutex 66 | 67 | func Swig_free(arg1 uintptr) { 68 | _swig_i_0 := arg1 69 | C._wrap_Swig_free_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 70 | } 71 | 72 | func Swig_malloc(arg1 int) (_swig_ret uintptr) { 73 | var swig_r uintptr 74 | _swig_i_0 := arg1 75 | swig_r = (uintptr)(C._wrap_Swig_malloc_example_f0ef324ec2fa820a(C.swig_intgo(_swig_i_0))) 76 | return swig_r 77 | } 78 | 79 | type _swig_DirectorCallback struct { 80 | SwigcptrCallback 81 | v interface{} 82 | } 83 | 84 | func (p *_swig_DirectorCallback) Swigcptr() uintptr { 85 | return p.SwigcptrCallback.Swigcptr() 86 | } 87 | 88 | func (p *_swig_DirectorCallback) SwigIsCallback() { 89 | } 90 | 91 | func (p *_swig_DirectorCallback) DirectorInterface() interface{} { 92 | return p.v 93 | } 94 | 95 | func NewDirectorCallback(v interface{}) Callback { 96 | p := &_swig_DirectorCallback{0, v} 97 | p.SwigcptrCallback = SwigcptrCallback(C._wrap__swig_NewDirectorCallbackCallback_example_f0ef324ec2fa820a(C.int(swigDirectorAdd(p)))) 98 | return p 99 | } 100 | 101 | func DeleteDirectorCallback(arg1 Callback) { 102 | _swig_i_0 := arg1.Swigcptr() 103 | C._wrap_DeleteDirectorCallback_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 104 | } 105 | 106 | //export Swiggo_DeleteDirector_Callback_example_f0ef324ec2fa820a 107 | func Swiggo_DeleteDirector_Callback_example_f0ef324ec2fa820a(c int) { 108 | swigDirectorLookup(c).(*_swig_DirectorCallback).SwigcptrCallback = 0 109 | swigDirectorDelete(c) 110 | } 111 | 112 | type _swig_DirectorInterfaceCallbackRun interface { 113 | Run() 114 | } 115 | 116 | func (swig_p *_swig_DirectorCallback) Run() { 117 | if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceCallbackRun); swig_ok { 118 | swig_g.Run() 119 | return 120 | } 121 | C._wrap__swig_DirectorCallback_upcall_Run_example_f0ef324ec2fa820a(C.uintptr_t(swig_p.SwigcptrCallback)) 122 | } 123 | 124 | func DirectorCallbackRun(p Callback) { 125 | C._wrap__swig_DirectorCallback_upcall_Run_example_f0ef324ec2fa820a(C.uintptr_t(p.(*_swig_DirectorCallback).SwigcptrCallback)) 126 | } 127 | 128 | //export Swig_DirectorCallback_callback_run_example_f0ef324ec2fa820a 129 | func Swig_DirectorCallback_callback_run_example_f0ef324ec2fa820a(swig_c int) { 130 | swig_p := swigDirectorLookup(swig_c).(*_swig_DirectorCallback) 131 | swig_p.Run() 132 | } 133 | 134 | type SwigcptrCallback uintptr 135 | 136 | func (p SwigcptrCallback) Swigcptr() uintptr { 137 | return (uintptr)(p) 138 | } 139 | 140 | func (p SwigcptrCallback) SwigIsCallback() { 141 | } 142 | 143 | func (p SwigcptrCallback) DirectorInterface() interface{} { 144 | return nil 145 | } 146 | 147 | func DeleteCallback(arg1 Callback) { 148 | _swig_i_0 := arg1.Swigcptr() 149 | C._wrap_delete_Callback_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 150 | } 151 | 152 | func (arg1 SwigcptrCallback) Run() { 153 | _swig_i_0 := arg1 154 | C._wrap_Callback_run_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 155 | } 156 | 157 | func NewCallback() (_swig_ret Callback) { 158 | var swig_r Callback 159 | swig_r = (Callback)(SwigcptrCallback(C._wrap_new_Callback_example_f0ef324ec2fa820a())) 160 | return swig_r 161 | } 162 | 163 | type Callback interface { 164 | Swigcptr() uintptr 165 | SwigIsCallback() 166 | DirectorInterface() interface{} 167 | Run() 168 | } 169 | 170 | type SwigcptrCaller uintptr 171 | 172 | func (p SwigcptrCaller) Swigcptr() uintptr { 173 | return (uintptr)(p) 174 | } 175 | 176 | func (p SwigcptrCaller) SwigIsCaller() { 177 | } 178 | 179 | func NewCaller() (_swig_ret Caller) { 180 | var swig_r Caller 181 | swig_r = (Caller)(SwigcptrCaller(C._wrap_new_Caller_example_f0ef324ec2fa820a())) 182 | return swig_r 183 | } 184 | 185 | func DeleteCaller(arg1 Caller) { 186 | _swig_i_0 := arg1.Swigcptr() 187 | C._wrap_delete_Caller_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 188 | } 189 | 190 | func (arg1 SwigcptrCaller) DelCallback() { 191 | _swig_i_0 := arg1 192 | C._wrap_Caller_delCallback_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 193 | } 194 | 195 | func (arg1 SwigcptrCaller) SetCallback(arg2 Callback) { 196 | _swig_i_0 := arg1 197 | _swig_i_1 := arg2.Swigcptr() 198 | C._wrap_Caller_setCallback_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0), C.uintptr_t(_swig_i_1)) 199 | } 200 | 201 | func (arg1 SwigcptrCaller) Call() { 202 | _swig_i_0 := arg1 203 | C._wrap_Caller_call_example_f0ef324ec2fa820a(C.uintptr_t(_swig_i_0)) 204 | } 205 | 206 | type Caller interface { 207 | Swigcptr() uintptr 208 | SwigIsCaller() 209 | DelCallback() 210 | SetCallback(arg2 Callback) 211 | Call() 212 | } 213 | 214 | 215 | type SwigcptrSwigDirector_Callback uintptr 216 | type SwigDirector_Callback interface { 217 | Swigcptr() uintptr; 218 | } 219 | func (p SwigcptrSwigDirector_Callback) Swigcptr() uintptr { 220 | return uintptr(p) 221 | } 222 | 223 | 224 | 225 | var swigDirectorTrack struct { 226 | sync.Mutex 227 | m map[int]interface{} 228 | c int 229 | } 230 | 231 | func swigDirectorAdd(v interface{}) int { 232 | swigDirectorTrack.Lock() 233 | defer swigDirectorTrack.Unlock() 234 | if swigDirectorTrack.m == nil { 235 | swigDirectorTrack.m = make(map[int]interface{}) 236 | } 237 | swigDirectorTrack.c++ 238 | ret := swigDirectorTrack.c 239 | swigDirectorTrack.m[ret] = v 240 | return ret 241 | } 242 | 243 | func swigDirectorLookup(c int) interface{} { 244 | swigDirectorTrack.Lock() 245 | defer swigDirectorTrack.Unlock() 246 | ret := swigDirectorTrack.m[c] 247 | if ret == nil { 248 | panic("C++ director pointer not found (possible use-after-free)") 249 | } 250 | return ret 251 | } 252 | 253 | func swigDirectorDelete(c int) { 254 | swigDirectorTrack.Lock() 255 | defer swigDirectorTrack.Unlock() 256 | if swigDirectorTrack.m[c] == nil { 257 | if c > swigDirectorTrack.c { 258 | panic("C++ director pointer invalid (possible memory corruption") 259 | } else { 260 | panic("C++ director pointer not found (possible use-after-free)") 261 | } 262 | } 263 | delete(swigDirectorTrack.m, c) 264 | } 265 | 266 | 267 | -------------------------------------------------------------------------------- /basic/pointer/example/example_wrap.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | /* source: example.i */ 12 | 13 | #define SWIGMODULE example 14 | /* ----------------------------------------------------------------------------- 15 | * This section contains generic SWIG labels for method/variable 16 | * declarations/attributes, and other compiler dependent labels. 17 | * ----------------------------------------------------------------------------- */ 18 | 19 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 20 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 21 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 22 | # define SWIGTEMPLATEDISAMBIGUATOR template 23 | # elif defined(__HP_aCC) 24 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 25 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 26 | # define SWIGTEMPLATEDISAMBIGUATOR template 27 | # else 28 | # define SWIGTEMPLATEDISAMBIGUATOR 29 | # endif 30 | #endif 31 | 32 | /* inline attribute */ 33 | #ifndef SWIGINLINE 34 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 35 | # define SWIGINLINE inline 36 | # else 37 | # define SWIGINLINE 38 | # endif 39 | #endif 40 | 41 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 42 | #ifndef SWIGUNUSED 43 | # if defined(__GNUC__) 44 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 45 | # define SWIGUNUSED __attribute__ ((__unused__)) 46 | # else 47 | # define SWIGUNUSED 48 | # endif 49 | # elif defined(__ICC) 50 | # define SWIGUNUSED __attribute__ ((__unused__)) 51 | # else 52 | # define SWIGUNUSED 53 | # endif 54 | #endif 55 | 56 | #ifndef SWIG_MSC_UNSUPPRESS_4505 57 | # if defined(_MSC_VER) 58 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 59 | # endif 60 | #endif 61 | 62 | #ifndef SWIGUNUSEDPARM 63 | # ifdef __cplusplus 64 | # define SWIGUNUSEDPARM(p) 65 | # else 66 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 67 | # endif 68 | #endif 69 | 70 | /* internal SWIG method */ 71 | #ifndef SWIGINTERN 72 | # define SWIGINTERN static SWIGUNUSED 73 | #endif 74 | 75 | /* internal inline SWIG method */ 76 | #ifndef SWIGINTERNINLINE 77 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 78 | #endif 79 | 80 | /* exporting methods */ 81 | #if defined(__GNUC__) 82 | # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 83 | # ifndef GCC_HASCLASSVISIBILITY 84 | # define GCC_HASCLASSVISIBILITY 85 | # endif 86 | # endif 87 | #endif 88 | 89 | #ifndef SWIGEXPORT 90 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 91 | # if defined(STATIC_LINKED) 92 | # define SWIGEXPORT 93 | # else 94 | # define SWIGEXPORT __declspec(dllexport) 95 | # endif 96 | # else 97 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 98 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 99 | # else 100 | # define SWIGEXPORT 101 | # endif 102 | # endif 103 | #endif 104 | 105 | /* calling conventions for Windows */ 106 | #ifndef SWIGSTDCALL 107 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 108 | # define SWIGSTDCALL __stdcall 109 | # else 110 | # define SWIGSTDCALL 111 | # endif 112 | #endif 113 | 114 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 115 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 116 | # define _CRT_SECURE_NO_DEPRECATE 117 | #endif 118 | 119 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 120 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 121 | # define _SCL_SECURE_NO_DEPRECATE 122 | #endif 123 | 124 | /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ 125 | #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) 126 | # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 127 | #endif 128 | 129 | /* Intel's compiler complains if a variable which was never initialised is 130 | * cast to void, which is a common idiom which we use to indicate that we 131 | * are aware a variable isn't used. So we just silence that warning. 132 | * See: https://github.com/swig/swig/issues/192 for more discussion. 133 | */ 134 | #ifdef __INTEL_COMPILER 135 | # pragma warning disable 592 136 | #endif 137 | 138 | 139 | #include 140 | #include 141 | #include 142 | #include 143 | #include 144 | 145 | 146 | 147 | typedef long long intgo; 148 | typedef unsigned long long uintgo; 149 | 150 | 151 | # if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__)) 152 | # define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__)) 153 | # else 154 | # define SWIGSTRUCTPACKED __attribute__((__packed__)) 155 | # endif 156 | 157 | 158 | 159 | typedef struct { char *p; intgo n; } _gostring_; 160 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 161 | 162 | 163 | 164 | 165 | #define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; 166 | #define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) 167 | 168 | swiggo_size_assert(char, 1) 169 | swiggo_size_assert(short, 2) 170 | swiggo_size_assert(int, 4) 171 | typedef long long swiggo_long_long; 172 | swiggo_size_assert(swiggo_long_long, 8) 173 | swiggo_size_assert(float, 4) 174 | swiggo_size_assert(double, 8) 175 | 176 | #ifdef __cplusplus 177 | extern "C" { 178 | #endif 179 | extern void crosscall2(void (*fn)(void *, int), void *, int); 180 | extern char* _cgo_topofstack(void) __attribute__ ((weak)); 181 | extern void _cgo_allocate(void *, int); 182 | extern void _cgo_panic(void *, int); 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | 187 | static char *_swig_topofstack() { 188 | if (_cgo_topofstack) { 189 | return _cgo_topofstack(); 190 | } else { 191 | return 0; 192 | } 193 | } 194 | 195 | static void _swig_gopanic(const char *p) { 196 | struct { 197 | const char *p; 198 | } SWIGSTRUCTPACKED a; 199 | a.p = p; 200 | crosscall2(_cgo_panic, &a, (int) sizeof a); 201 | } 202 | 203 | 204 | 205 | 206 | #define SWIG_contract_assert(expr, msg) \ 207 | if (!(expr)) { _swig_gopanic(msg); } else 208 | 209 | 210 | static void Swig_free(void* p) { 211 | free(p); 212 | } 213 | 214 | static void* Swig_malloc(int c) { 215 | return malloc(c); 216 | } 217 | 218 | 219 | extern void add(int *, int *, int *); 220 | extern void sub(int *, int *, int *); 221 | extern int divide(int, int, int *); 222 | 223 | 224 | static int *new_intp() { 225 | return (int *) calloc(1,sizeof(int)); 226 | } 227 | 228 | static int *copy_intp(int value) { 229 | int *obj = (int *) calloc(1,sizeof(int)); 230 | *obj = value; 231 | return obj; 232 | } 233 | 234 | static void delete_intp(int *obj) { 235 | if (obj) free(obj); 236 | } 237 | 238 | static void intp_assign(int *obj, int value) { 239 | *obj = value; 240 | } 241 | 242 | static int intp_value(int *obj) { 243 | return *obj; 244 | } 245 | 246 | #ifdef __cplusplus 247 | extern "C" { 248 | #endif 249 | 250 | void _wrap_Swig_free_example_94bf2401246d4292(void *_swig_go_0) { 251 | void *arg1 = (void *) 0 ; 252 | 253 | arg1 = *(void **)&_swig_go_0; 254 | 255 | Swig_free(arg1); 256 | 257 | } 258 | 259 | 260 | void *_wrap_Swig_malloc_example_94bf2401246d4292(intgo _swig_go_0) { 261 | int arg1 ; 262 | void *result = 0 ; 263 | void *_swig_go_result; 264 | 265 | arg1 = (int)_swig_go_0; 266 | 267 | result = (void *)Swig_malloc(arg1); 268 | *(void **)&_swig_go_result = (void *)result; 269 | return _swig_go_result; 270 | } 271 | 272 | 273 | void _wrap_add_example_94bf2401246d4292(intgo *_swig_go_0, intgo *_swig_go_1, intgo *_swig_go_2) { 274 | int *arg1 = (int *) 0 ; 275 | int *arg2 = (int *) 0 ; 276 | int *arg3 = (int *) 0 ; 277 | 278 | arg1 = *(int **)&_swig_go_0; 279 | arg2 = *(int **)&_swig_go_1; 280 | arg3 = *(int **)&_swig_go_2; 281 | 282 | add(arg1,arg2,arg3); 283 | 284 | } 285 | 286 | 287 | intgo *_wrap_new_intp_example_94bf2401246d4292() { 288 | int *result = 0 ; 289 | intgo *_swig_go_result; 290 | 291 | 292 | result = (int *)new_intp(); 293 | *(int **)&_swig_go_result = (int *)result; 294 | return _swig_go_result; 295 | } 296 | 297 | 298 | intgo *_wrap_copy_intp_example_94bf2401246d4292(intgo _swig_go_0) { 299 | int arg1 ; 300 | int *result = 0 ; 301 | intgo *_swig_go_result; 302 | 303 | arg1 = (int)_swig_go_0; 304 | 305 | result = (int *)copy_intp(arg1); 306 | *(int **)&_swig_go_result = (int *)result; 307 | return _swig_go_result; 308 | } 309 | 310 | 311 | void _wrap_delete_intp_example_94bf2401246d4292(intgo *_swig_go_0) { 312 | int *arg1 = (int *) 0 ; 313 | 314 | arg1 = *(int **)&_swig_go_0; 315 | 316 | delete_intp(arg1); 317 | 318 | } 319 | 320 | 321 | void _wrap_intp_assign_example_94bf2401246d4292(intgo *_swig_go_0, intgo _swig_go_1) { 322 | int *arg1 = (int *) 0 ; 323 | int arg2 ; 324 | 325 | arg1 = *(int **)&_swig_go_0; 326 | arg2 = (int)_swig_go_1; 327 | 328 | intp_assign(arg1,arg2); 329 | 330 | } 331 | 332 | 333 | intgo _wrap_intp_value_example_94bf2401246d4292(intgo *_swig_go_0) { 334 | int *arg1 = (int *) 0 ; 335 | int result; 336 | intgo _swig_go_result; 337 | 338 | arg1 = *(int **)&_swig_go_0; 339 | 340 | result = (int)intp_value(arg1); 341 | _swig_go_result = result; 342 | return _swig_go_result; 343 | } 344 | 345 | 346 | void _wrap_sub_example_94bf2401246d4292(intgo _swig_go_0, intgo _swig_go_1, _goslice_ _swig_go_2) { 347 | int *arg1 = (int *) 0 ; 348 | int *arg2 = (int *) 0 ; 349 | int *arg3 = (int *) 0 ; 350 | int temp3 ; 351 | 352 | arg1 = (int *)&_swig_go_0; 353 | arg2 = (int *)&_swig_go_1; 354 | { 355 | if (_swig_go_2.len == 0) { 356 | _swig_gopanic("array must contain at least 1 element"); 357 | } 358 | arg3 = &temp3; 359 | } 360 | 361 | sub(arg1,arg2,arg3); 362 | 363 | 364 | 365 | { 366 | int* a = (int *) _swig_go_2.array; 367 | a[0] = temp3; 368 | } 369 | 370 | 371 | 372 | } 373 | 374 | 375 | intgo _wrap_divide_example_94bf2401246d4292(intgo _swig_go_0, intgo _swig_go_1, _goslice_ _swig_go_2) { 376 | int arg1 ; 377 | int arg2 ; 378 | int *arg3 = (int *) 0 ; 379 | int temp3 ; 380 | int result; 381 | intgo _swig_go_result; 382 | 383 | arg1 = (int)_swig_go_0; 384 | arg2 = (int)_swig_go_1; 385 | { 386 | if (_swig_go_2.len == 0) { 387 | _swig_gopanic("array must contain at least 1 element"); 388 | } 389 | arg3 = &temp3; 390 | } 391 | 392 | result = (int)divide(arg1,arg2,arg3); 393 | _swig_go_result = result; 394 | { 395 | int* a = (int *) _swig_go_2.array; 396 | a[0] = temp3; 397 | } 398 | 399 | return _swig_go_result; 400 | } 401 | 402 | 403 | #ifdef __cplusplus 404 | } 405 | #endif 406 | 407 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /basic/class/example/example.go: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | package example 14 | 15 | /* 16 | #define intgo swig_intgo 17 | typedef void *swig_voidp; 18 | 19 | #include 20 | 21 | 22 | typedef long long intgo; 23 | typedef unsigned long long uintgo; 24 | 25 | 26 | 27 | typedef struct { char *p; intgo n; } _gostring_; 28 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 29 | 30 | 31 | extern void _wrap_Swig_free_example_ce26c1f9f9997e3a(uintptr_t arg1); 32 | extern uintptr_t _wrap_Swig_malloc_example_ce26c1f9f9997e3a(swig_intgo arg1); 33 | extern void _wrap_delete_Shape_example_ce26c1f9f9997e3a(uintptr_t arg1); 34 | extern void _wrap_Shape_x_set_example_ce26c1f9f9997e3a(uintptr_t arg1, double arg2); 35 | extern double _wrap_Shape_x_get_example_ce26c1f9f9997e3a(uintptr_t arg1); 36 | extern void _wrap_Shape_y_set_example_ce26c1f9f9997e3a(uintptr_t arg1, double arg2); 37 | extern double _wrap_Shape_y_get_example_ce26c1f9f9997e3a(uintptr_t arg1); 38 | extern void _wrap_Shape_move_example_ce26c1f9f9997e3a(uintptr_t arg1, double arg2, double arg3); 39 | extern double _wrap_Shape_area_example_ce26c1f9f9997e3a(uintptr_t arg1); 40 | extern double _wrap_Shape_perimeter_example_ce26c1f9f9997e3a(uintptr_t arg1); 41 | extern void _wrap_Shape_nshapes_set_example_ce26c1f9f9997e3a(swig_intgo arg1); 42 | extern swig_intgo _wrap_Shape_nshapes_get_example_ce26c1f9f9997e3a(void); 43 | extern uintptr_t _wrap_new_Circle_example_ce26c1f9f9997e3a(double arg1); 44 | extern double _wrap_Circle_area_example_ce26c1f9f9997e3a(uintptr_t arg1); 45 | extern double _wrap_Circle_perimeter_example_ce26c1f9f9997e3a(uintptr_t arg1); 46 | extern void _wrap_delete_Circle_example_ce26c1f9f9997e3a(uintptr_t arg1); 47 | extern void _wrap_SetCircle_X_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1); 48 | extern double _wrap_GetCircle_X_example_ce26c1f9f9997e3a(uintptr_t _swig_base); 49 | extern void _wrap_SetCircle_Y_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1); 50 | extern double _wrap_GetCircle_Y_example_ce26c1f9f9997e3a(uintptr_t _swig_base); 51 | extern void _wrap_Circle_move_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1, double arg2); 52 | extern uintptr_t _wrap_new_Square_example_ce26c1f9f9997e3a(double arg1); 53 | extern double _wrap_Square_area_example_ce26c1f9f9997e3a(uintptr_t arg1); 54 | extern double _wrap_Square_perimeter_example_ce26c1f9f9997e3a(uintptr_t arg1); 55 | extern void _wrap_delete_Square_example_ce26c1f9f9997e3a(uintptr_t arg1); 56 | extern void _wrap_SetSquare_X_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1); 57 | extern double _wrap_GetSquare_X_example_ce26c1f9f9997e3a(uintptr_t _swig_base); 58 | extern void _wrap_SetSquare_Y_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1); 59 | extern double _wrap_GetSquare_Y_example_ce26c1f9f9997e3a(uintptr_t _swig_base); 60 | extern void _wrap_Square_move_example_ce26c1f9f9997e3a(uintptr_t _swig_base, double arg1, double arg2); 61 | #undef intgo 62 | */ 63 | import "C" 64 | 65 | import "unsafe" 66 | import _ "runtime/cgo" 67 | import "sync" 68 | 69 | 70 | type _ unsafe.Pointer 71 | 72 | 73 | 74 | var Swig_escape_always_false bool 75 | var Swig_escape_val interface{} 76 | 77 | 78 | type _swig_fnptr *byte 79 | type _swig_memberptr *byte 80 | 81 | 82 | type _ sync.Mutex 83 | 84 | func Swig_free(arg1 uintptr) { 85 | _swig_i_0 := arg1 86 | C._wrap_Swig_free_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0)) 87 | } 88 | 89 | func Swig_malloc(arg1 int) (_swig_ret uintptr) { 90 | var swig_r uintptr 91 | _swig_i_0 := arg1 92 | swig_r = (uintptr)(C._wrap_Swig_malloc_example_ce26c1f9f9997e3a(C.swig_intgo(_swig_i_0))) 93 | return swig_r 94 | } 95 | 96 | type SwigcptrShape uintptr 97 | 98 | func (p SwigcptrShape) Swigcptr() uintptr { 99 | return (uintptr)(p) 100 | } 101 | 102 | func (p SwigcptrShape) SwigIsShape() { 103 | } 104 | 105 | func DeleteShape(arg1 Shape) { 106 | _swig_i_0 := arg1.Swigcptr() 107 | C._wrap_delete_Shape_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0)) 108 | } 109 | 110 | func (arg1 SwigcptrShape) SetX(arg2 float64) { 111 | _swig_i_0 := arg1 112 | _swig_i_1 := arg2 113 | C._wrap_Shape_x_set_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0), C.double(_swig_i_1)) 114 | } 115 | 116 | func (arg1 SwigcptrShape) GetX() (_swig_ret float64) { 117 | var swig_r float64 118 | _swig_i_0 := arg1 119 | swig_r = (float64)(C._wrap_Shape_x_get_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 120 | return swig_r 121 | } 122 | 123 | func (arg1 SwigcptrShape) SetY(arg2 float64) { 124 | _swig_i_0 := arg1 125 | _swig_i_1 := arg2 126 | C._wrap_Shape_y_set_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0), C.double(_swig_i_1)) 127 | } 128 | 129 | func (arg1 SwigcptrShape) GetY() (_swig_ret float64) { 130 | var swig_r float64 131 | _swig_i_0 := arg1 132 | swig_r = (float64)(C._wrap_Shape_y_get_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 133 | return swig_r 134 | } 135 | 136 | func (arg1 SwigcptrShape) Move(arg2 float64, arg3 float64) { 137 | _swig_i_0 := arg1 138 | _swig_i_1 := arg2 139 | _swig_i_2 := arg3 140 | C._wrap_Shape_move_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0), C.double(_swig_i_1), C.double(_swig_i_2)) 141 | } 142 | 143 | func (arg1 SwigcptrShape) Area() (_swig_ret float64) { 144 | var swig_r float64 145 | _swig_i_0 := arg1 146 | swig_r = (float64)(C._wrap_Shape_area_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 147 | return swig_r 148 | } 149 | 150 | func (arg1 SwigcptrShape) Perimeter() (_swig_ret float64) { 151 | var swig_r float64 152 | _swig_i_0 := arg1 153 | swig_r = (float64)(C._wrap_Shape_perimeter_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 154 | return swig_r 155 | } 156 | 157 | func SetShapeNshapes(arg1 int) { 158 | _swig_i_0 := arg1 159 | C._wrap_Shape_nshapes_set_example_ce26c1f9f9997e3a(C.swig_intgo(_swig_i_0)) 160 | } 161 | 162 | func GetShapeNshapes() (_swig_ret int) { 163 | var swig_r int 164 | swig_r = (int)(C._wrap_Shape_nshapes_get_example_ce26c1f9f9997e3a()) 165 | return swig_r 166 | } 167 | 168 | type Shape interface { 169 | Swigcptr() uintptr 170 | SwigIsShape() 171 | SetX(arg2 float64) 172 | GetX() (_swig_ret float64) 173 | SetY(arg2 float64) 174 | GetY() (_swig_ret float64) 175 | Move(arg2 float64, arg3 float64) 176 | Area() (_swig_ret float64) 177 | Perimeter() (_swig_ret float64) 178 | } 179 | 180 | type SwigcptrCircle uintptr 181 | 182 | func (p SwigcptrCircle) Swigcptr() uintptr { 183 | return (uintptr)(p) 184 | } 185 | 186 | func (p SwigcptrCircle) SwigIsCircle() { 187 | } 188 | 189 | func NewCircle(arg1 float64) (_swig_ret Circle) { 190 | var swig_r Circle 191 | _swig_i_0 := arg1 192 | swig_r = (Circle)(SwigcptrCircle(C._wrap_new_Circle_example_ce26c1f9f9997e3a(C.double(_swig_i_0)))) 193 | return swig_r 194 | } 195 | 196 | func (arg1 SwigcptrCircle) Area() (_swig_ret float64) { 197 | var swig_r float64 198 | _swig_i_0 := arg1 199 | swig_r = (float64)(C._wrap_Circle_area_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 200 | return swig_r 201 | } 202 | 203 | func (arg1 SwigcptrCircle) Perimeter() (_swig_ret float64) { 204 | var swig_r float64 205 | _swig_i_0 := arg1 206 | swig_r = (float64)(C._wrap_Circle_perimeter_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 207 | return swig_r 208 | } 209 | 210 | func DeleteCircle(arg1 Circle) { 211 | _swig_i_0 := arg1.Swigcptr() 212 | C._wrap_delete_Circle_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0)) 213 | } 214 | 215 | func (_swig_base SwigcptrCircle) SetX(arg1 float64) { 216 | _swig_i_0 := arg1 217 | C._wrap_SetCircle_X_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0)) 218 | } 219 | 220 | func (_swig_base SwigcptrCircle) GetX() (_swig_ret float64) { 221 | var swig_r float64 222 | swig_r = (float64)(C._wrap_GetCircle_X_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base))) 223 | return swig_r 224 | } 225 | 226 | func (_swig_base SwigcptrCircle) SetY(arg1 float64) { 227 | _swig_i_0 := arg1 228 | C._wrap_SetCircle_Y_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0)) 229 | } 230 | 231 | func (_swig_base SwigcptrCircle) GetY() (_swig_ret float64) { 232 | var swig_r float64 233 | swig_r = (float64)(C._wrap_GetCircle_Y_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base))) 234 | return swig_r 235 | } 236 | 237 | func (_swig_base SwigcptrCircle) Move(arg1 float64, arg2 float64) { 238 | _swig_i_0 := arg1 239 | _swig_i_1 := arg2 240 | C._wrap_Circle_move_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0), C.double(_swig_i_1)) 241 | } 242 | 243 | func (p SwigcptrCircle) SwigIsShape() { 244 | } 245 | 246 | func (p SwigcptrCircle) SwigGetShape() Shape { 247 | return SwigcptrShape(p.Swigcptr()) 248 | } 249 | 250 | type Circle interface { 251 | Swigcptr() uintptr 252 | SwigIsCircle() 253 | Area() (_swig_ret float64) 254 | Perimeter() (_swig_ret float64) 255 | SetX(arg1 float64) 256 | GetX() (_swig_ret float64) 257 | SetY(arg1 float64) 258 | GetY() (_swig_ret float64) 259 | Move(arg1 float64, arg2 float64) 260 | SwigIsShape() 261 | SwigGetShape() Shape 262 | } 263 | 264 | type SwigcptrSquare uintptr 265 | 266 | func (p SwigcptrSquare) Swigcptr() uintptr { 267 | return (uintptr)(p) 268 | } 269 | 270 | func (p SwigcptrSquare) SwigIsSquare() { 271 | } 272 | 273 | func NewSquare(arg1 float64) (_swig_ret Square) { 274 | var swig_r Square 275 | _swig_i_0 := arg1 276 | swig_r = (Square)(SwigcptrSquare(C._wrap_new_Square_example_ce26c1f9f9997e3a(C.double(_swig_i_0)))) 277 | return swig_r 278 | } 279 | 280 | func (arg1 SwigcptrSquare) Area() (_swig_ret float64) { 281 | var swig_r float64 282 | _swig_i_0 := arg1 283 | swig_r = (float64)(C._wrap_Square_area_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 284 | return swig_r 285 | } 286 | 287 | func (arg1 SwigcptrSquare) Perimeter() (_swig_ret float64) { 288 | var swig_r float64 289 | _swig_i_0 := arg1 290 | swig_r = (float64)(C._wrap_Square_perimeter_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0))) 291 | return swig_r 292 | } 293 | 294 | func DeleteSquare(arg1 Square) { 295 | _swig_i_0 := arg1.Swigcptr() 296 | C._wrap_delete_Square_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_i_0)) 297 | } 298 | 299 | func (_swig_base SwigcptrSquare) SetX(arg1 float64) { 300 | _swig_i_0 := arg1 301 | C._wrap_SetSquare_X_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0)) 302 | } 303 | 304 | func (_swig_base SwigcptrSquare) GetX() (_swig_ret float64) { 305 | var swig_r float64 306 | swig_r = (float64)(C._wrap_GetSquare_X_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base))) 307 | return swig_r 308 | } 309 | 310 | func (_swig_base SwigcptrSquare) SetY(arg1 float64) { 311 | _swig_i_0 := arg1 312 | C._wrap_SetSquare_Y_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0)) 313 | } 314 | 315 | func (_swig_base SwigcptrSquare) GetY() (_swig_ret float64) { 316 | var swig_r float64 317 | swig_r = (float64)(C._wrap_GetSquare_Y_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base))) 318 | return swig_r 319 | } 320 | 321 | func (_swig_base SwigcptrSquare) Move(arg1 float64, arg2 float64) { 322 | _swig_i_0 := arg1 323 | _swig_i_1 := arg2 324 | C._wrap_Square_move_example_ce26c1f9f9997e3a(C.uintptr_t(_swig_base), C.double(_swig_i_0), C.double(_swig_i_1)) 325 | } 326 | 327 | func (p SwigcptrSquare) SwigIsShape() { 328 | } 329 | 330 | func (p SwigcptrSquare) SwigGetShape() Shape { 331 | return SwigcptrShape(p.Swigcptr()) 332 | } 333 | 334 | type Square interface { 335 | Swigcptr() uintptr 336 | SwigIsSquare() 337 | Area() (_swig_ret float64) 338 | Perimeter() (_swig_ret float64) 339 | SetX(arg1 float64) 340 | GetX() (_swig_ret float64) 341 | SetY(arg1 float64) 342 | GetY() (_swig_ret float64) 343 | Move(arg1 float64, arg2 float64) 344 | SwigIsShape() 345 | SwigGetShape() Shape 346 | } 347 | 348 | 349 | -------------------------------------------------------------------------------- /basic/reference/example/example_wrap.cxx: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | #define SWIGMODULE example 14 | 15 | #ifdef __cplusplus 16 | /* SwigValueWrapper is described in swig.swg */ 17 | template class SwigValueWrapper { 18 | struct SwigMovePointer { 19 | T *ptr; 20 | SwigMovePointer(T *p) : ptr(p) { } 21 | ~SwigMovePointer() { delete ptr; } 22 | SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } 23 | } pointer; 24 | SwigValueWrapper& operator=(const SwigValueWrapper& rhs); 25 | SwigValueWrapper(const SwigValueWrapper& rhs); 26 | public: 27 | SwigValueWrapper() : pointer(0) { } 28 | SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } 29 | operator T&() const { return *pointer.ptr; } 30 | T *operator&() { return pointer.ptr; } 31 | }; 32 | 33 | template T SwigValueInit() { 34 | return T(); 35 | } 36 | #endif 37 | 38 | /* ----------------------------------------------------------------------------- 39 | * This section contains generic SWIG labels for method/variable 40 | * declarations/attributes, and other compiler dependent labels. 41 | * ----------------------------------------------------------------------------- */ 42 | 43 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 44 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 45 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 46 | # define SWIGTEMPLATEDISAMBIGUATOR template 47 | # elif defined(__HP_aCC) 48 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 49 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 50 | # define SWIGTEMPLATEDISAMBIGUATOR template 51 | # else 52 | # define SWIGTEMPLATEDISAMBIGUATOR 53 | # endif 54 | #endif 55 | 56 | /* inline attribute */ 57 | #ifndef SWIGINLINE 58 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 59 | # define SWIGINLINE inline 60 | # else 61 | # define SWIGINLINE 62 | # endif 63 | #endif 64 | 65 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 66 | #ifndef SWIGUNUSED 67 | # if defined(__GNUC__) 68 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 69 | # define SWIGUNUSED __attribute__ ((__unused__)) 70 | # else 71 | # define SWIGUNUSED 72 | # endif 73 | # elif defined(__ICC) 74 | # define SWIGUNUSED __attribute__ ((__unused__)) 75 | # else 76 | # define SWIGUNUSED 77 | # endif 78 | #endif 79 | 80 | #ifndef SWIG_MSC_UNSUPPRESS_4505 81 | # if defined(_MSC_VER) 82 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 83 | # endif 84 | #endif 85 | 86 | #ifndef SWIGUNUSEDPARM 87 | # ifdef __cplusplus 88 | # define SWIGUNUSEDPARM(p) 89 | # else 90 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 91 | # endif 92 | #endif 93 | 94 | /* internal SWIG method */ 95 | #ifndef SWIGINTERN 96 | # define SWIGINTERN static SWIGUNUSED 97 | #endif 98 | 99 | /* internal inline SWIG method */ 100 | #ifndef SWIGINTERNINLINE 101 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 102 | #endif 103 | 104 | /* exporting methods */ 105 | #if defined(__GNUC__) 106 | # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 107 | # ifndef GCC_HASCLASSVISIBILITY 108 | # define GCC_HASCLASSVISIBILITY 109 | # endif 110 | # endif 111 | #endif 112 | 113 | #ifndef SWIGEXPORT 114 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 115 | # if defined(STATIC_LINKED) 116 | # define SWIGEXPORT 117 | # else 118 | # define SWIGEXPORT __declspec(dllexport) 119 | # endif 120 | # else 121 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 122 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 123 | # else 124 | # define SWIGEXPORT 125 | # endif 126 | # endif 127 | #endif 128 | 129 | /* calling conventions for Windows */ 130 | #ifndef SWIGSTDCALL 131 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 132 | # define SWIGSTDCALL __stdcall 133 | # else 134 | # define SWIGSTDCALL 135 | # endif 136 | #endif 137 | 138 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 139 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 140 | # define _CRT_SECURE_NO_DEPRECATE 141 | #endif 142 | 143 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 144 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 145 | # define _SCL_SECURE_NO_DEPRECATE 146 | #endif 147 | 148 | /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ 149 | #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) 150 | # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 151 | #endif 152 | 153 | /* Intel's compiler complains if a variable which was never initialised is 154 | * cast to void, which is a common idiom which we use to indicate that we 155 | * are aware a variable isn't used. So we just silence that warning. 156 | * See: https://github.com/swig/swig/issues/192 for more discussion. 157 | */ 158 | #ifdef __INTEL_COMPILER 159 | # pragma warning disable 592 160 | #endif 161 | 162 | 163 | #include 164 | #include 165 | #include 166 | #include 167 | #include 168 | 169 | 170 | 171 | typedef long long intgo; 172 | typedef unsigned long long uintgo; 173 | 174 | 175 | # if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__)) 176 | # define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__)) 177 | # else 178 | # define SWIGSTRUCTPACKED __attribute__((__packed__)) 179 | # endif 180 | 181 | 182 | 183 | typedef struct { char *p; intgo n; } _gostring_; 184 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 185 | 186 | 187 | 188 | 189 | #define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; 190 | #define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) 191 | 192 | swiggo_size_assert(char, 1) 193 | swiggo_size_assert(short, 2) 194 | swiggo_size_assert(int, 4) 195 | typedef long long swiggo_long_long; 196 | swiggo_size_assert(swiggo_long_long, 8) 197 | swiggo_size_assert(float, 4) 198 | swiggo_size_assert(double, 8) 199 | 200 | #ifdef __cplusplus 201 | extern "C" { 202 | #endif 203 | extern void crosscall2(void (*fn)(void *, int), void *, int); 204 | extern char* _cgo_topofstack(void) __attribute__ ((weak)); 205 | extern void _cgo_allocate(void *, int); 206 | extern void _cgo_panic(void *, int); 207 | #ifdef __cplusplus 208 | } 209 | #endif 210 | 211 | static char *_swig_topofstack() { 212 | if (_cgo_topofstack) { 213 | return _cgo_topofstack(); 214 | } else { 215 | return 0; 216 | } 217 | } 218 | 219 | static void _swig_gopanic(const char *p) { 220 | struct { 221 | const char *p; 222 | } SWIGSTRUCTPACKED a; 223 | a.p = p; 224 | crosscall2(_cgo_panic, &a, (int) sizeof a); 225 | } 226 | 227 | 228 | 229 | 230 | #define SWIG_contract_assert(expr, msg) \ 231 | if (!(expr)) { _swig_gopanic(msg); } else 232 | 233 | 234 | static _gostring_ Swig_AllocateString(const char *p, size_t l) { 235 | _gostring_ ret; 236 | ret.p = (char*)malloc(l); 237 | memcpy(ret.p, p, l); 238 | ret.n = l; 239 | return ret; 240 | } 241 | 242 | 243 | static void Swig_free(void* p) { 244 | free(p); 245 | } 246 | 247 | static void* Swig_malloc(int c) { 248 | return malloc(c); 249 | } 250 | 251 | 252 | #include "example.h" 253 | 254 | 255 | Vector addv(Vector &a, Vector &b) { 256 | return a+b; 257 | } 258 | 259 | SWIGINTERN Vector &VectorArray_get(VectorArray *self,int index){ 260 | return (*self)[index]; 261 | } 262 | SWIGINTERN void VectorArray_set(VectorArray *self,int index,Vector &a){ 263 | (*self)[index] = a; 264 | } 265 | #ifdef __cplusplus 266 | extern "C" { 267 | #endif 268 | 269 | void _wrap_Swig_free_example_7c6d0b865a722e37(void *_swig_go_0) { 270 | void *arg1 = (void *) 0 ; 271 | 272 | arg1 = *(void **)&_swig_go_0; 273 | 274 | Swig_free(arg1); 275 | 276 | } 277 | 278 | 279 | void *_wrap_Swig_malloc_example_7c6d0b865a722e37(intgo _swig_go_0) { 280 | int arg1 ; 281 | void *result = 0 ; 282 | void *_swig_go_result; 283 | 284 | arg1 = (int)_swig_go_0; 285 | 286 | result = (void *)Swig_malloc(arg1); 287 | *(void **)&_swig_go_result = (void *)result; 288 | return _swig_go_result; 289 | } 290 | 291 | 292 | Vector *_wrap_new_Vector_example_7c6d0b865a722e37(double _swig_go_0, double _swig_go_1, double _swig_go_2) { 293 | double arg1 ; 294 | double arg2 ; 295 | double arg3 ; 296 | Vector *result = 0 ; 297 | Vector *_swig_go_result; 298 | 299 | arg1 = (double)_swig_go_0; 300 | arg2 = (double)_swig_go_1; 301 | arg3 = (double)_swig_go_2; 302 | 303 | result = (Vector *)new Vector(arg1,arg2,arg3); 304 | *(Vector **)&_swig_go_result = (Vector *)result; 305 | return _swig_go_result; 306 | } 307 | 308 | 309 | void _wrap_delete_Vector_example_7c6d0b865a722e37(Vector *_swig_go_0) { 310 | Vector *arg1 = (Vector *) 0 ; 311 | 312 | arg1 = *(Vector **)&_swig_go_0; 313 | 314 | delete arg1; 315 | 316 | } 317 | 318 | 319 | _gostring_ _wrap_Vector_print_example_7c6d0b865a722e37(Vector *_swig_go_0) { 320 | Vector *arg1 = (Vector *) 0 ; 321 | char *result = 0 ; 322 | _gostring_ _swig_go_result; 323 | 324 | arg1 = *(Vector **)&_swig_go_0; 325 | 326 | result = (char *)(arg1)->print(); 327 | _swig_go_result = Swig_AllocateString((char*)result, result ? strlen((char*)result) : 0); 328 | return _swig_go_result; 329 | } 330 | 331 | 332 | Vector *_wrap_addv_example_7c6d0b865a722e37(Vector *_swig_go_0, Vector *_swig_go_1) { 333 | Vector *arg1 = 0 ; 334 | Vector *arg2 = 0 ; 335 | SwigValueWrapper< Vector > result; 336 | Vector *_swig_go_result; 337 | 338 | arg1 = *(Vector **)&_swig_go_0; 339 | arg2 = *(Vector **)&_swig_go_1; 340 | 341 | result = addv(*arg1,*arg2); 342 | *(Vector **)&_swig_go_result = new Vector(result); 343 | return _swig_go_result; 344 | } 345 | 346 | 347 | VectorArray *_wrap_new_VectorArray_example_7c6d0b865a722e37(intgo _swig_go_0) { 348 | int arg1 ; 349 | VectorArray *result = 0 ; 350 | VectorArray *_swig_go_result; 351 | 352 | arg1 = (int)_swig_go_0; 353 | 354 | result = (VectorArray *)new VectorArray(arg1); 355 | *(VectorArray **)&_swig_go_result = (VectorArray *)result; 356 | return _swig_go_result; 357 | } 358 | 359 | 360 | void _wrap_delete_VectorArray_example_7c6d0b865a722e37(VectorArray *_swig_go_0) { 361 | VectorArray *arg1 = (VectorArray *) 0 ; 362 | 363 | arg1 = *(VectorArray **)&_swig_go_0; 364 | 365 | delete arg1; 366 | 367 | } 368 | 369 | 370 | intgo _wrap_VectorArray_size_example_7c6d0b865a722e37(VectorArray *_swig_go_0) { 371 | VectorArray *arg1 = (VectorArray *) 0 ; 372 | int result; 373 | intgo _swig_go_result; 374 | 375 | arg1 = *(VectorArray **)&_swig_go_0; 376 | 377 | result = (int)(arg1)->size(); 378 | _swig_go_result = result; 379 | return _swig_go_result; 380 | } 381 | 382 | 383 | Vector *_wrap_VectorArray_get_example_7c6d0b865a722e37(VectorArray *_swig_go_0, intgo _swig_go_1) { 384 | VectorArray *arg1 = (VectorArray *) 0 ; 385 | int arg2 ; 386 | Vector *result = 0 ; 387 | Vector *_swig_go_result; 388 | 389 | arg1 = *(VectorArray **)&_swig_go_0; 390 | arg2 = (int)_swig_go_1; 391 | 392 | result = (Vector *) &VectorArray_get(arg1,arg2); 393 | *(Vector **)&_swig_go_result = result; 394 | return _swig_go_result; 395 | } 396 | 397 | 398 | void _wrap_VectorArray_set_example_7c6d0b865a722e37(VectorArray *_swig_go_0, intgo _swig_go_1, Vector *_swig_go_2) { 399 | VectorArray *arg1 = (VectorArray *) 0 ; 400 | int arg2 ; 401 | Vector *arg3 = 0 ; 402 | 403 | arg1 = *(VectorArray **)&_swig_go_0; 404 | arg2 = (int)_swig_go_1; 405 | arg3 = *(Vector **)&_swig_go_2; 406 | 407 | VectorArray_set(arg1,arg2,*arg3); 408 | 409 | } 410 | 411 | 412 | #ifdef __cplusplus 413 | } 414 | #endif 415 | 416 | -------------------------------------------------------------------------------- /basic/class/example/example_wrap.cxx: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 3.0.12 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | // source: example.i 12 | 13 | #define SWIGMODULE example 14 | 15 | #ifdef __cplusplus 16 | /* SwigValueWrapper is described in swig.swg */ 17 | template class SwigValueWrapper { 18 | struct SwigMovePointer { 19 | T *ptr; 20 | SwigMovePointer(T *p) : ptr(p) { } 21 | ~SwigMovePointer() { delete ptr; } 22 | SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } 23 | } pointer; 24 | SwigValueWrapper& operator=(const SwigValueWrapper& rhs); 25 | SwigValueWrapper(const SwigValueWrapper& rhs); 26 | public: 27 | SwigValueWrapper() : pointer(0) { } 28 | SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; } 29 | operator T&() const { return *pointer.ptr; } 30 | T *operator&() { return pointer.ptr; } 31 | }; 32 | 33 | template T SwigValueInit() { 34 | return T(); 35 | } 36 | #endif 37 | 38 | /* ----------------------------------------------------------------------------- 39 | * This section contains generic SWIG labels for method/variable 40 | * declarations/attributes, and other compiler dependent labels. 41 | * ----------------------------------------------------------------------------- */ 42 | 43 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 44 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 45 | # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) 46 | # define SWIGTEMPLATEDISAMBIGUATOR template 47 | # elif defined(__HP_aCC) 48 | /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ 49 | /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ 50 | # define SWIGTEMPLATEDISAMBIGUATOR template 51 | # else 52 | # define SWIGTEMPLATEDISAMBIGUATOR 53 | # endif 54 | #endif 55 | 56 | /* inline attribute */ 57 | #ifndef SWIGINLINE 58 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 59 | # define SWIGINLINE inline 60 | # else 61 | # define SWIGINLINE 62 | # endif 63 | #endif 64 | 65 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 66 | #ifndef SWIGUNUSED 67 | # if defined(__GNUC__) 68 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 69 | # define SWIGUNUSED __attribute__ ((__unused__)) 70 | # else 71 | # define SWIGUNUSED 72 | # endif 73 | # elif defined(__ICC) 74 | # define SWIGUNUSED __attribute__ ((__unused__)) 75 | # else 76 | # define SWIGUNUSED 77 | # endif 78 | #endif 79 | 80 | #ifndef SWIG_MSC_UNSUPPRESS_4505 81 | # if defined(_MSC_VER) 82 | # pragma warning(disable : 4505) /* unreferenced local function has been removed */ 83 | # endif 84 | #endif 85 | 86 | #ifndef SWIGUNUSEDPARM 87 | # ifdef __cplusplus 88 | # define SWIGUNUSEDPARM(p) 89 | # else 90 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 91 | # endif 92 | #endif 93 | 94 | /* internal SWIG method */ 95 | #ifndef SWIGINTERN 96 | # define SWIGINTERN static SWIGUNUSED 97 | #endif 98 | 99 | /* internal inline SWIG method */ 100 | #ifndef SWIGINTERNINLINE 101 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 102 | #endif 103 | 104 | /* exporting methods */ 105 | #if defined(__GNUC__) 106 | # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 107 | # ifndef GCC_HASCLASSVISIBILITY 108 | # define GCC_HASCLASSVISIBILITY 109 | # endif 110 | # endif 111 | #endif 112 | 113 | #ifndef SWIGEXPORT 114 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 115 | # if defined(STATIC_LINKED) 116 | # define SWIGEXPORT 117 | # else 118 | # define SWIGEXPORT __declspec(dllexport) 119 | # endif 120 | # else 121 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 122 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 123 | # else 124 | # define SWIGEXPORT 125 | # endif 126 | # endif 127 | #endif 128 | 129 | /* calling conventions for Windows */ 130 | #ifndef SWIGSTDCALL 131 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 132 | # define SWIGSTDCALL __stdcall 133 | # else 134 | # define SWIGSTDCALL 135 | # endif 136 | #endif 137 | 138 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 139 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 140 | # define _CRT_SECURE_NO_DEPRECATE 141 | #endif 142 | 143 | /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ 144 | #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) 145 | # define _SCL_SECURE_NO_DEPRECATE 146 | #endif 147 | 148 | /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */ 149 | #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES) 150 | # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0 151 | #endif 152 | 153 | /* Intel's compiler complains if a variable which was never initialised is 154 | * cast to void, which is a common idiom which we use to indicate that we 155 | * are aware a variable isn't used. So we just silence that warning. 156 | * See: https://github.com/swig/swig/issues/192 for more discussion. 157 | */ 158 | #ifdef __INTEL_COMPILER 159 | # pragma warning disable 592 160 | #endif 161 | 162 | 163 | #include 164 | #include 165 | #include 166 | #include 167 | #include 168 | 169 | 170 | 171 | typedef long long intgo; 172 | typedef unsigned long long uintgo; 173 | 174 | 175 | # if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__)) 176 | # define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__)) 177 | # else 178 | # define SWIGSTRUCTPACKED __attribute__((__packed__)) 179 | # endif 180 | 181 | 182 | 183 | typedef struct { char *p; intgo n; } _gostring_; 184 | typedef struct { void* array; intgo len; intgo cap; } _goslice_; 185 | 186 | 187 | 188 | 189 | #define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; 190 | #define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n) 191 | 192 | swiggo_size_assert(char, 1) 193 | swiggo_size_assert(short, 2) 194 | swiggo_size_assert(int, 4) 195 | typedef long long swiggo_long_long; 196 | swiggo_size_assert(swiggo_long_long, 8) 197 | swiggo_size_assert(float, 4) 198 | swiggo_size_assert(double, 8) 199 | 200 | #ifdef __cplusplus 201 | extern "C" { 202 | #endif 203 | extern void crosscall2(void (*fn)(void *, int), void *, int); 204 | extern char* _cgo_topofstack(void) __attribute__ ((weak)); 205 | extern void _cgo_allocate(void *, int); 206 | extern void _cgo_panic(void *, int); 207 | #ifdef __cplusplus 208 | } 209 | #endif 210 | 211 | static char *_swig_topofstack() { 212 | if (_cgo_topofstack) { 213 | return _cgo_topofstack(); 214 | } else { 215 | return 0; 216 | } 217 | } 218 | 219 | static void _swig_gopanic(const char *p) { 220 | struct { 221 | const char *p; 222 | } SWIGSTRUCTPACKED a; 223 | a.p = p; 224 | crosscall2(_cgo_panic, &a, (int) sizeof a); 225 | } 226 | 227 | 228 | 229 | 230 | #define SWIG_contract_assert(expr, msg) \ 231 | if (!(expr)) { _swig_gopanic(msg); } else 232 | 233 | 234 | static void Swig_free(void* p) { 235 | free(p); 236 | } 237 | 238 | static void* Swig_malloc(int c) { 239 | return malloc(c); 240 | } 241 | 242 | 243 | #include "example.h" 244 | 245 | #ifdef __cplusplus 246 | extern "C" { 247 | #endif 248 | 249 | void _wrap_Swig_free_example_ce26c1f9f9997e3a(void *_swig_go_0) { 250 | void *arg1 = (void *) 0 ; 251 | 252 | arg1 = *(void **)&_swig_go_0; 253 | 254 | Swig_free(arg1); 255 | 256 | } 257 | 258 | 259 | void *_wrap_Swig_malloc_example_ce26c1f9f9997e3a(intgo _swig_go_0) { 260 | int arg1 ; 261 | void *result = 0 ; 262 | void *_swig_go_result; 263 | 264 | arg1 = (int)_swig_go_0; 265 | 266 | result = (void *)Swig_malloc(arg1); 267 | *(void **)&_swig_go_result = (void *)result; 268 | return _swig_go_result; 269 | } 270 | 271 | 272 | void _wrap_delete_Shape_example_ce26c1f9f9997e3a(Shape *_swig_go_0) { 273 | Shape *arg1 = (Shape *) 0 ; 274 | 275 | arg1 = *(Shape **)&_swig_go_0; 276 | 277 | delete arg1; 278 | 279 | } 280 | 281 | 282 | void _wrap_Shape_x_set_example_ce26c1f9f9997e3a(Shape *_swig_go_0, double _swig_go_1) { 283 | Shape *arg1 = (Shape *) 0 ; 284 | double arg2 ; 285 | 286 | arg1 = *(Shape **)&_swig_go_0; 287 | arg2 = (double)_swig_go_1; 288 | 289 | if (arg1) (arg1)->x = arg2; 290 | 291 | } 292 | 293 | 294 | double _wrap_Shape_x_get_example_ce26c1f9f9997e3a(Shape *_swig_go_0) { 295 | Shape *arg1 = (Shape *) 0 ; 296 | double result; 297 | double _swig_go_result; 298 | 299 | arg1 = *(Shape **)&_swig_go_0; 300 | 301 | result = (double) ((arg1)->x); 302 | _swig_go_result = result; 303 | return _swig_go_result; 304 | } 305 | 306 | 307 | void _wrap_Shape_y_set_example_ce26c1f9f9997e3a(Shape *_swig_go_0, double _swig_go_1) { 308 | Shape *arg1 = (Shape *) 0 ; 309 | double arg2 ; 310 | 311 | arg1 = *(Shape **)&_swig_go_0; 312 | arg2 = (double)_swig_go_1; 313 | 314 | if (arg1) (arg1)->y = arg2; 315 | 316 | } 317 | 318 | 319 | double _wrap_Shape_y_get_example_ce26c1f9f9997e3a(Shape *_swig_go_0) { 320 | Shape *arg1 = (Shape *) 0 ; 321 | double result; 322 | double _swig_go_result; 323 | 324 | arg1 = *(Shape **)&_swig_go_0; 325 | 326 | result = (double) ((arg1)->y); 327 | _swig_go_result = result; 328 | return _swig_go_result; 329 | } 330 | 331 | 332 | void _wrap_Shape_move_example_ce26c1f9f9997e3a(Shape *_swig_go_0, double _swig_go_1, double _swig_go_2) { 333 | Shape *arg1 = (Shape *) 0 ; 334 | double arg2 ; 335 | double arg3 ; 336 | 337 | arg1 = *(Shape **)&_swig_go_0; 338 | arg2 = (double)_swig_go_1; 339 | arg3 = (double)_swig_go_2; 340 | 341 | (arg1)->move(arg2,arg3); 342 | 343 | } 344 | 345 | 346 | double _wrap_Shape_area_example_ce26c1f9f9997e3a(Shape *_swig_go_0) { 347 | Shape *arg1 = (Shape *) 0 ; 348 | double result; 349 | double _swig_go_result; 350 | 351 | arg1 = *(Shape **)&_swig_go_0; 352 | 353 | result = (double)(arg1)->area(); 354 | _swig_go_result = result; 355 | return _swig_go_result; 356 | } 357 | 358 | 359 | double _wrap_Shape_perimeter_example_ce26c1f9f9997e3a(Shape *_swig_go_0) { 360 | Shape *arg1 = (Shape *) 0 ; 361 | double result; 362 | double _swig_go_result; 363 | 364 | arg1 = *(Shape **)&_swig_go_0; 365 | 366 | result = (double)(arg1)->perimeter(); 367 | _swig_go_result = result; 368 | return _swig_go_result; 369 | } 370 | 371 | 372 | void _wrap_Shape_nshapes_set_example_ce26c1f9f9997e3a(intgo _swig_go_0) { 373 | int arg1 ; 374 | 375 | arg1 = (int)_swig_go_0; 376 | 377 | Shape::nshapes = arg1; 378 | 379 | } 380 | 381 | 382 | intgo _wrap_Shape_nshapes_get_example_ce26c1f9f9997e3a() { 383 | int result; 384 | intgo _swig_go_result; 385 | 386 | 387 | result = (int)Shape::nshapes; 388 | _swig_go_result = result; 389 | return _swig_go_result; 390 | } 391 | 392 | 393 | Circle *_wrap_new_Circle_example_ce26c1f9f9997e3a(double _swig_go_0) { 394 | double arg1 ; 395 | Circle *result = 0 ; 396 | Circle *_swig_go_result; 397 | 398 | arg1 = (double)_swig_go_0; 399 | 400 | result = (Circle *)new Circle(arg1); 401 | *(Circle **)&_swig_go_result = (Circle *)result; 402 | return _swig_go_result; 403 | } 404 | 405 | 406 | double _wrap_Circle_area_example_ce26c1f9f9997e3a(Circle *_swig_go_0) { 407 | Circle *arg1 = (Circle *) 0 ; 408 | double result; 409 | double _swig_go_result; 410 | 411 | arg1 = *(Circle **)&_swig_go_0; 412 | 413 | result = (double)(arg1)->area(); 414 | _swig_go_result = result; 415 | return _swig_go_result; 416 | } 417 | 418 | 419 | double _wrap_Circle_perimeter_example_ce26c1f9f9997e3a(Circle *_swig_go_0) { 420 | Circle *arg1 = (Circle *) 0 ; 421 | double result; 422 | double _swig_go_result; 423 | 424 | arg1 = *(Circle **)&_swig_go_0; 425 | 426 | result = (double)(arg1)->perimeter(); 427 | _swig_go_result = result; 428 | return _swig_go_result; 429 | } 430 | 431 | 432 | void _wrap_delete_Circle_example_ce26c1f9f9997e3a(Circle *_swig_go_0) { 433 | Circle *arg1 = (Circle *) 0 ; 434 | 435 | arg1 = *(Circle **)&_swig_go_0; 436 | 437 | delete arg1; 438 | 439 | } 440 | 441 | 442 | void _wrap_SetCircle_X_example_ce26c1f9f9997e3a(Circle *_swig_go_0, double _swig_go_1) { 443 | Circle *arg1 = (Circle *) 0 ; 444 | double arg2 ; 445 | 446 | arg1 = *(Circle **)&_swig_go_0; 447 | arg2 = (double)_swig_go_1; 448 | 449 | Shape *swig_b0 = (Shape *)arg1; 450 | if (swig_b0) (swig_b0)->x = arg2; 451 | 452 | } 453 | 454 | 455 | double _wrap_GetCircle_X_example_ce26c1f9f9997e3a(Circle *_swig_go_0) { 456 | Circle *arg1 = (Circle *) 0 ; 457 | double result; 458 | double _swig_go_result; 459 | 460 | arg1 = *(Circle **)&_swig_go_0; 461 | 462 | Shape *swig_b0 = (Shape *)arg1; 463 | result = (double) ((swig_b0)->x); 464 | _swig_go_result = result; 465 | return _swig_go_result; 466 | } 467 | 468 | 469 | void _wrap_SetCircle_Y_example_ce26c1f9f9997e3a(Circle *_swig_go_0, double _swig_go_1) { 470 | Circle *arg1 = (Circle *) 0 ; 471 | double arg2 ; 472 | 473 | arg1 = *(Circle **)&_swig_go_0; 474 | arg2 = (double)_swig_go_1; 475 | 476 | Shape *swig_b0 = (Shape *)arg1; 477 | if (swig_b0) (swig_b0)->y = arg2; 478 | 479 | } 480 | 481 | 482 | double _wrap_GetCircle_Y_example_ce26c1f9f9997e3a(Circle *_swig_go_0) { 483 | Circle *arg1 = (Circle *) 0 ; 484 | double result; 485 | double _swig_go_result; 486 | 487 | arg1 = *(Circle **)&_swig_go_0; 488 | 489 | Shape *swig_b0 = (Shape *)arg1; 490 | result = (double) ((swig_b0)->y); 491 | _swig_go_result = result; 492 | return _swig_go_result; 493 | } 494 | 495 | 496 | void _wrap_Circle_move_example_ce26c1f9f9997e3a(Circle *_swig_go_0, double _swig_go_1, double _swig_go_2) { 497 | Circle *arg1 = (Circle *) 0 ; 498 | double arg2 ; 499 | double arg3 ; 500 | 501 | arg1 = *(Circle **)&_swig_go_0; 502 | arg2 = (double)_swig_go_1; 503 | arg3 = (double)_swig_go_2; 504 | 505 | Shape *swig_b0 = (Shape *)arg1; 506 | (swig_b0)->move(arg2,arg3); 507 | 508 | } 509 | 510 | 511 | Square *_wrap_new_Square_example_ce26c1f9f9997e3a(double _swig_go_0) { 512 | double arg1 ; 513 | Square *result = 0 ; 514 | Square *_swig_go_result; 515 | 516 | arg1 = (double)_swig_go_0; 517 | 518 | result = (Square *)new Square(arg1); 519 | *(Square **)&_swig_go_result = (Square *)result; 520 | return _swig_go_result; 521 | } 522 | 523 | 524 | double _wrap_Square_area_example_ce26c1f9f9997e3a(Square *_swig_go_0) { 525 | Square *arg1 = (Square *) 0 ; 526 | double result; 527 | double _swig_go_result; 528 | 529 | arg1 = *(Square **)&_swig_go_0; 530 | 531 | result = (double)(arg1)->area(); 532 | _swig_go_result = result; 533 | return _swig_go_result; 534 | } 535 | 536 | 537 | double _wrap_Square_perimeter_example_ce26c1f9f9997e3a(Square *_swig_go_0) { 538 | Square *arg1 = (Square *) 0 ; 539 | double result; 540 | double _swig_go_result; 541 | 542 | arg1 = *(Square **)&_swig_go_0; 543 | 544 | result = (double)(arg1)->perimeter(); 545 | _swig_go_result = result; 546 | return _swig_go_result; 547 | } 548 | 549 | 550 | void _wrap_delete_Square_example_ce26c1f9f9997e3a(Square *_swig_go_0) { 551 | Square *arg1 = (Square *) 0 ; 552 | 553 | arg1 = *(Square **)&_swig_go_0; 554 | 555 | delete arg1; 556 | 557 | } 558 | 559 | 560 | void _wrap_SetSquare_X_example_ce26c1f9f9997e3a(Square *_swig_go_0, double _swig_go_1) { 561 | Square *arg1 = (Square *) 0 ; 562 | double arg2 ; 563 | 564 | arg1 = *(Square **)&_swig_go_0; 565 | arg2 = (double)_swig_go_1; 566 | 567 | Shape *swig_b0 = (Shape *)arg1; 568 | if (swig_b0) (swig_b0)->x = arg2; 569 | 570 | } 571 | 572 | 573 | double _wrap_GetSquare_X_example_ce26c1f9f9997e3a(Square *_swig_go_0) { 574 | Square *arg1 = (Square *) 0 ; 575 | double result; 576 | double _swig_go_result; 577 | 578 | arg1 = *(Square **)&_swig_go_0; 579 | 580 | Shape *swig_b0 = (Shape *)arg1; 581 | result = (double) ((swig_b0)->x); 582 | _swig_go_result = result; 583 | return _swig_go_result; 584 | } 585 | 586 | 587 | void _wrap_SetSquare_Y_example_ce26c1f9f9997e3a(Square *_swig_go_0, double _swig_go_1) { 588 | Square *arg1 = (Square *) 0 ; 589 | double arg2 ; 590 | 591 | arg1 = *(Square **)&_swig_go_0; 592 | arg2 = (double)_swig_go_1; 593 | 594 | Shape *swig_b0 = (Shape *)arg1; 595 | if (swig_b0) (swig_b0)->y = arg2; 596 | 597 | } 598 | 599 | 600 | double _wrap_GetSquare_Y_example_ce26c1f9f9997e3a(Square *_swig_go_0) { 601 | Square *arg1 = (Square *) 0 ; 602 | double result; 603 | double _swig_go_result; 604 | 605 | arg1 = *(Square **)&_swig_go_0; 606 | 607 | Shape *swig_b0 = (Shape *)arg1; 608 | result = (double) ((swig_b0)->y); 609 | _swig_go_result = result; 610 | return _swig_go_result; 611 | } 612 | 613 | 614 | void _wrap_Square_move_example_ce26c1f9f9997e3a(Square *_swig_go_0, double _swig_go_1, double _swig_go_2) { 615 | Square *arg1 = (Square *) 0 ; 616 | double arg2 ; 617 | double arg3 ; 618 | 619 | arg1 = *(Square **)&_swig_go_0; 620 | arg2 = (double)_swig_go_1; 621 | arg3 = (double)_swig_go_2; 622 | 623 | Shape *swig_b0 = (Shape *)arg1; 624 | (swig_b0)->move(arg2,arg3); 625 | 626 | } 627 | 628 | 629 | #ifdef __cplusplus 630 | } 631 | #endif 632 | 633 | --------------------------------------------------------------------------------