From 19f72587d9bfc29e0e60b901cf1cf409f3dd08c0 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Mon, 4 Sep 2000 15:30:20 +0000 Subject: [PATCH] new example git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@840 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/python/class/example.h | 9 +++++++++ SWIG/Examples/python/class/example.i | 3 +++ SWIG/Examples/python/funcptr/Makefile | 18 ++++++++++++++++++ SWIG/Examples/python/funcptr/example.c | 17 +++++++++++++++++ SWIG/Examples/python/index.html | 1 + 5 files changed, 48 insertions(+) create mode 100644 SWIG/Examples/python/funcptr/Makefile create mode 100644 SWIG/Examples/python/funcptr/example.c diff --git a/SWIG/Examples/python/class/example.h b/SWIG/Examples/python/class/example.h index 849071dd3..b01e8bb0a 100644 --- a/SWIG/Examples/python/class/example.h +++ b/SWIG/Examples/python/class/example.h @@ -9,9 +9,11 @@ public: nshapes--; }; double x, y; + char foo[256]; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; + char *name() { return "Shape"; } static int nshapes; }; @@ -24,6 +26,13 @@ public: virtual double perimeter(); }; +class XCircle : public Circle { + public: + XCircle(double r) : Circle(r) { }; + virtual double area(); + char *name() { return "XCircle"; } +}; + class Square : public Shape { private: double width; diff --git a/SWIG/Examples/python/class/example.i b/SWIG/Examples/python/class/example.i index 23ee8a822..3cd206c26 100644 --- a/SWIG/Examples/python/class/example.i +++ b/SWIG/Examples/python/class/example.i @@ -6,6 +6,9 @@ %} /* Let's just grab the original header file here */ +%typemap(memberin) char [ANY] { + strncpy($target,$source,$dim0); +} %include "example.h" diff --git a/SWIG/Examples/python/funcptr/Makefile b/SWIG/Examples/python/funcptr/Makefile new file mode 100644 index 000000000..e495cfa9a --- /dev/null +++ b/SWIG/Examples/python/funcptr/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_static + +clean:: + rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core + +check: all diff --git a/SWIG/Examples/python/funcptr/example.c b/SWIG/Examples/python/funcptr/example.c new file mode 100644 index 000000000..99583b72e --- /dev/null +++ b/SWIG/Examples/python/funcptr/example.c @@ -0,0 +1,17 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} diff --git a/SWIG/Examples/python/index.html b/SWIG/Examples/python/index.html index c11247421..fcf607895 100644 --- a/SWIG/Examples/python/index.html +++ b/SWIG/Examples/python/index.html @@ -21,6 +21,7 @@ certain C declarations are turned into constants.
  • class. Wrapping a simple C++ class.
  • reference. C++ references.
  • pointer. Simple pointer handling. +
  • funcptr. Pointers to functions.

    Compilation Issues