summaryrefslogtreecommitdiff
path: root/Examples/python
diff options
context:
space:
mode:
Diffstat (limited to 'Examples/python')
-rw-r--r--Examples/python/callback/Makefile22
-rw-r--r--Examples/python/callback/example.cxx4
-rw-r--r--Examples/python/callback/example.h22
-rw-r--r--Examples/python/callback/example.i13
-rw-r--r--Examples/python/callback/index.html19
-rw-r--r--Examples/python/callback/runme.py56
-rw-r--r--Examples/python/check.list29
-rw-r--r--Examples/python/class/Makefile21
-rw-r--r--Examples/python/class/example.cxx28
-rw-r--r--Examples/python/class/example.dsp152
-rw-r--r--Examples/python/class/example.h39
-rw-r--r--Examples/python/class/example.i10
-rw-r--r--Examples/python/class/index.html216
-rw-r--r--Examples/python/class/runme.py51
-rw-r--r--Examples/python/constants/Makefile20
-rw-r--r--Examples/python/constants/example.i27
-rw-r--r--Examples/python/constants/index.html67
-rw-r--r--Examples/python/constants/runme.py27
-rw-r--r--Examples/python/contract/Makefile20
-rw-r--r--Examples/python/contract/example.c23
-rw-r--r--Examples/python/contract/example.dsp148
-rw-r--r--Examples/python/contract/example.i21
-rw-r--r--Examples/python/contract/runme.py30
-rw-r--r--Examples/python/docstrings/Makefile24
-rw-r--r--Examples/python/docstrings/example.cxx4
-rw-r--r--Examples/python/docstrings/example.h4
-rw-r--r--Examples/python/docstrings/example.i14
-rw-r--r--Examples/python/docstrings/runme.py6
-rw-r--r--Examples/python/enum/Makefile21
-rw-r--r--Examples/python/enum/example.cxx37
-rw-r--r--Examples/python/enum/example.h13
-rw-r--r--Examples/python/enum/example.i11
-rw-r--r--Examples/python/enum/index.html35
-rw-r--r--Examples/python/enum/runme.py31
-rw-r--r--Examples/python/exception/Makefile21
-rw-r--r--Examples/python/exception/example.h53
-rw-r--r--Examples/python/exception/example.i12
-rw-r--r--Examples/python/exception/runme.py36
-rw-r--r--Examples/python/exceptproxy/Makefile22
-rw-r--r--Examples/python/exceptproxy/example.h54
-rw-r--r--Examples/python/exceptproxy/example.i114
-rw-r--r--Examples/python/exceptproxy/runme.py45
-rw-r--r--Examples/python/extend/Makefile22
-rw-r--r--Examples/python/extend/example.cxx4
-rw-r--r--Examples/python/extend/example.h56
-rw-r--r--Examples/python/extend/example.i15
-rw-r--r--Examples/python/extend/index.html19
-rw-r--r--Examples/python/extend/runme.py81
-rw-r--r--Examples/python/funcptr/Makefile20
-rw-r--r--Examples/python/funcptr/example.c19
-rw-r--r--Examples/python/funcptr/example.h9
-rw-r--r--Examples/python/funcptr/example.i16
-rw-r--r--Examples/python/funcptr/index.html90
-rw-r--r--Examples/python/funcptr/runme.py20
-rw-r--r--Examples/python/funcptr2/Makefile20
-rw-r--r--Examples/python/funcptr2/example.c19
-rw-r--r--Examples/python/funcptr2/example.h9
-rw-r--r--Examples/python/funcptr2/example.i18
-rw-r--r--Examples/python/funcptr2/runme.py24
-rw-r--r--Examples/python/functor/Makefile22
-rw-r--r--Examples/python/functor/example.i29
-rw-r--r--Examples/python/functor/runme.py17
-rw-r--r--Examples/python/import/Makefile22
-rw-r--r--Examples/python/import/README39
-rw-r--r--Examples/python/import/bar.dsp144
-rw-r--r--Examples/python/import/bar.h22
-rw-r--r--Examples/python/import/bar.i9
-rw-r--r--Examples/python/import/base.dsp144
-rw-r--r--Examples/python/import/base.h18
-rw-r--r--Examples/python/import/base.i6
-rw-r--r--Examples/python/import/example.dsw65
-rw-r--r--Examples/python/import/foo.dsp144
-rw-r--r--Examples/python/import/foo.h21
-rw-r--r--Examples/python/import/foo.i8
-rw-r--r--Examples/python/import/runme.py111
-rw-r--r--Examples/python/import/spam.dsp144
-rw-r--r--Examples/python/import/spam.h24
-rw-r--r--Examples/python/import/spam.i9
-rw-r--r--Examples/python/import_template/Makefile22
-rw-r--r--Examples/python/import_template/README30
-rw-r--r--Examples/python/import_template/bar.h22
-rw-r--r--Examples/python/import_template/bar.i11
-rw-r--r--Examples/python/import_template/base.h18
-rw-r--r--Examples/python/import_template/base.i7
-rw-r--r--Examples/python/import_template/foo.h21
-rw-r--r--Examples/python/import_template/foo.i10
-rw-r--r--Examples/python/import_template/runme.py111
-rw-r--r--Examples/python/import_template/spam.h24
-rw-r--r--Examples/python/import_template/spam.i10
-rw-r--r--Examples/python/index.html112
-rw-r--r--Examples/python/java/Example.java29
-rw-r--r--Examples/python/java/Makefile25
-rw-r--r--Examples/python/java/example.i9
-rw-r--r--Examples/python/java/runme.py16
-rw-r--r--Examples/python/libffi/Makefile20
-rw-r--r--Examples/python/libffi/example.i176
-rw-r--r--Examples/python/multimap/Makefile20
-rw-r--r--Examples/python/multimap/example.c53
-rw-r--r--Examples/python/multimap/example.dsp148
-rw-r--r--Examples/python/multimap/example.i121
-rw-r--r--Examples/python/multimap/runme.py27
-rw-r--r--Examples/python/operator/Makefile22
-rw-r--r--Examples/python/operator/example.h36
-rw-r--r--Examples/python/operator/example.i28
-rw-r--r--Examples/python/operator/runme.py21
-rw-r--r--Examples/python/pointer/Makefile20
-rw-r--r--Examples/python/pointer/example.c16
-rw-r--r--Examples/python/pointer/example.i30
-rw-r--r--Examples/python/pointer/index.html171
-rw-r--r--Examples/python/pointer/runme.py44
-rw-r--r--Examples/python/reference/Makefile21
-rw-r--r--Examples/python/reference/example.cxx46
-rw-r--r--Examples/python/reference/example.h26
-rw-r--r--Examples/python/reference/example.i48
-rw-r--r--Examples/python/reference/index.html147
-rw-r--r--Examples/python/reference/runme.py63
-rw-r--r--Examples/python/simple/Makefile20
-rw-r--r--Examples/python/simple/example.c18
-rw-r--r--Examples/python/simple/example.dsp148
-rw-r--r--Examples/python/simple/example.i7
-rw-r--r--Examples/python/simple/index.html97
-rw-r--r--Examples/python/simple/runme.py30
-rw-r--r--Examples/python/smartptr/Makefile22
-rw-r--r--Examples/python/smartptr/example.cxx31
-rw-r--r--Examples/python/smartptr/example.h39
-rw-r--r--Examples/python/smartptr/example.i20
-rw-r--r--Examples/python/smartptr/runme.py55
-rw-r--r--Examples/python/smartptr/smartptr.h13
-rw-r--r--Examples/python/std_map/Makefile25
-rw-r--r--Examples/python/std_map/example.h17
-rw-r--r--Examples/python/std_map/example.i27
-rw-r--r--Examples/python/std_map/runme.py82
-rw-r--r--Examples/python/std_vector/Makefile22
-rw-r--r--Examples/python/std_vector/example.h25
-rw-r--r--Examples/python/std_vector/example.i17
-rw-r--r--Examples/python/std_vector/runme.py36
-rw-r--r--Examples/python/swigrun/Makefile25
-rw-r--r--Examples/python/swigrun/example.cxx20
-rw-r--r--Examples/python/swigrun/example.h58
-rw-r--r--Examples/python/swigrun/example.i15
-rw-r--r--Examples/python/swigrun/runme.py28
-rw-r--r--Examples/python/template/Makefile22
-rw-r--r--Examples/python/template/example.h32
-rw-r--r--Examples/python/template/example.i17
-rw-r--r--Examples/python/template/runme.py34
-rw-r--r--Examples/python/varargs/Makefile20
-rw-r--r--Examples/python/varargs/example.i65
-rw-r--r--Examples/python/varargs/runme.py34
-rw-r--r--Examples/python/variables/Makefile20
-rw-r--r--Examples/python/variables/example.c91
-rw-r--r--Examples/python/variables/example.h6
-rw-r--r--Examples/python/variables/example.i51
-rw-r--r--Examples/python/variables/index.html100
-rw-r--r--Examples/python/variables/runme.py75
-rw-r--r--Examples/python/weave/Makefile22
-rw-r--r--Examples/python/weave/README25
-rw-r--r--Examples/python/weave/example.h18
-rw-r--r--Examples/python/weave/example.i15
-rw-r--r--Examples/python/weave/runme.py72
-rw-r--r--Examples/python/weave/swigptr2.py3556
160 files changed, 10034 insertions, 0 deletions
diff --git a/Examples/python/callback/Makefile b/Examples/python/callback/Makefile
new file mode 100644
index 0000000..a29276e
--- /dev/null
+++ b/Examples/python/callback/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/callback/example.cxx b/Examples/python/callback/example.cxx
new file mode 100644
index 0000000..450d756
--- /dev/null
+++ b/Examples/python/callback/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/python/callback/example.h b/Examples/python/callback/example.h
new file mode 100644
index 0000000..2a01949
--- /dev/null
+++ b/Examples/python/callback/example.h
@@ -0,0 +1,22 @@
+/* File : example.h */
+
+#include <iostream>
+
+class Callback {
+public:
+ virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
+ virtual void run() { std::cout << "Callback::run()" << std::endl; }
+};
+
+
+class Caller {
+private:
+ Callback *_callback;
+public:
+ Caller(): _callback(0) {}
+ ~Caller() { delCallback(); }
+ void delCallback() { delete _callback; _callback = 0; }
+ void setCallback(Callback *cb) { delCallback(); _callback = cb; }
+ void call() { if (_callback) _callback->run(); }
+};
+
diff --git a/Examples/python/callback/example.i b/Examples/python/callback/example.i
new file mode 100644
index 0000000..90beda0
--- /dev/null
+++ b/Examples/python/callback/example.i
@@ -0,0 +1,13 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* turn on director wrapping Callback */
+%feature("director") Callback;
+
+%include "example.h"
+
diff --git a/Examples/python/callback/index.html b/Examples/python/callback/index.html
new file mode 100644
index 0000000..e2017ec
--- /dev/null
+++ b/Examples/python/callback/index.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>SWIG:Examples:python:callback</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/extend/</tt>
+<hr>
+
+<H2>Implementing C++ callbacks in Python</H2>
+
+<p>
+This example illustrates how to use directors to implement C++ callbacks in Python.
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/callback/runme.py b/Examples/python/callback/runme.py
new file mode 100644
index 0000000..026e952
--- /dev/null
+++ b/Examples/python/callback/runme.py
@@ -0,0 +1,56 @@
+# file: runme.py
+
+# This file illustrates the cross language polymorphism using directors.
+
+import example
+
+
+class PyCallback(example.Callback):
+ def __init__(self):
+ example.Callback.__init__(self)
+ def run(self):
+ print "PyCallback.run()"
+
+# Create an Caller instance
+
+caller = example.Caller()
+
+# Add a simple C++ callback (caller owns the callback, so
+# we disown it first by clearing the .thisown flag).
+
+print "Adding and calling a normal C++ callback"
+print "----------------------------------------"
+
+callback = example.Callback()
+callback.thisown = 0
+caller.setCallback(callback)
+caller.call()
+caller.delCallback();
+
+print
+print "Adding and calling a Python callback"
+print "------------------------------------"
+
+# Add a Python callback (caller owns the callback, so we
+# disown it first by calling __disown__).
+
+caller.setCallback(PyCallback().__disown__())
+caller.call()
+caller.delCallback()
+
+print
+print "Adding and calling another Python callback"
+print "------------------------------------------"
+
+# Lets do the same but use the weak reference this time.
+
+callback = PyCallback().__disown__()
+caller.setCallback(callback)
+caller.call()
+caller.delCallback()
+
+# All done.
+
+print
+print "python exit"
+
diff --git a/Examples/python/check.list b/Examples/python/check.list
new file mode 100644
index 0000000..7cfe437
--- /dev/null
+++ b/Examples/python/check.list
@@ -0,0 +1,29 @@
+# see top-level Makefile.in
+callback
+class
+constants
+contract
+docstrings
+enum
+exception
+exceptproxy
+extend
+funcptr
+funcptr2
+functor
+import
+import_template
+java
+#libffi
+multimap
+operator
+pointer
+reference
+simple
+smartptr
+std_vector
+std_map
+swigrun
+template
+varargs
+variables
diff --git a/Examples/python/class/Makefile b/Examples/python/class/Makefile
new file mode 100644
index 0000000..74625b9
--- /dev/null
+++ b/Examples/python/class/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/class/example.cxx b/Examples/python/class/example.cxx
new file mode 100644
index 0000000..1e8e203
--- /dev/null
+++ b/Examples/python/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/python/class/example.dsp b/Examples/python/class/example.dsp
new file mode 100644
index 0000000..fd7bf8c
--- /dev/null
+++ b/Examples/python/class/example.dsp
@@ -0,0 +1,152 @@
+# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=example - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "example - Win32 Debug"
+# Name "example - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\example.cxx
+# End Source File
+# Begin Source File
+
+SOURCE=.\example_wrap.cxx
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\example.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\example.i
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/class/example.h b/Examples/python/class/example.h
new file mode 100644
index 0000000..46d9013
--- /dev/null
+++ b/Examples/python/class/example.h
@@ -0,0 +1,39 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+
+
+
+
diff --git a/Examples/python/class/example.i b/Examples/python/class/example.i
new file mode 100644
index 0000000..75700b3
--- /dev/null
+++ b/Examples/python/class/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/python/class/index.html b/Examples/python/class/index.html
new file mode 100644
index 0000000..12c5ede
--- /dev/null
+++ b/Examples/python/class/index.html
@@ -0,0 +1,216 @@
+<html>
+<head>
+<title>SWIG:Examples:python:class</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/class/</tt>
+<hr>
+
+<H2>Wrapping a simple C++ class</H2>
+
+<p>
+This example illustrates the most primitive form of C++ class wrapping performed
+by SWIG. In this case, C++ classes are simply transformed into a collection of
+C-style functions that provide access to class members.
+
+<h2>The C++ Code</h2>
+
+Suppose you have some C++ classes described by the following (and admittedly lame)
+header file:
+
+<blockquote>
+<pre>
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area() = 0;
+ virtual double perimeter() = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area();
+ virtual double perimeter();
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area();
+ virtual double perimeter();
+};
+</pre>
+</blockquote>
+
+<h2>The SWIG interface</h2>
+
+A simple SWIG interface for this can be built by simply grabbing the header file
+like this:
+
+<blockquote>
+<pre>
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+</pre>
+</blockquote>
+
+Note: when creating a C++ extension, you must run SWIG with the <tt>-c++</tt> option like this:
+<blockquote>
+<pre>
+% swig -c++ -python example.i
+</pre>
+</blockquote>
+
+<h2>A sample Python script</h2>
+
+Click <a href="example.py">here</a> to see a script that calls the C++ functions from Python.
+
+<h2>Key points</h2>
+
+<ul>
+<li>To create a new object, you call a constructor like this:
+
+<blockquote>
+<pre>
+c = example.new_Circle(10.0)
+</pre>
+</blockquote>
+
+<p>
+<li>To access member data, a pair of accessor functions are used.
+For example:
+
+<blockquote>
+<pre>
+example.Shape_x_set(c,15) # Set member data
+x = example.Shape_x_get(c) # Get member data
+</pre>
+</blockquote>
+
+Note: when accessing member data, the name of the class in which
+the member data was must be used. In this case, <tt>Shape_x_get()</tt>
+and <tt>Shape_x_set()</tt> are used since 'x' was defined in Shape.
+
+<p>
+<li>To invoke a member function, you simply do this
+
+<blockquote>
+<pre>
+print "The area is ", example.Shape_area(c)
+</pre>
+</blockquote>
+
+<p>
+<li>Type checking knows about the inheritance structure of C++. For example:
+
+<blockquote>
+<pre>
+example.Shape_area(c) # Works (c is a Shape)
+example.Circle_area(c) # Works (c is a Circle)
+example.Square_area(c) # Fails (c is definitely not a Square)
+</pre>
+</blockquote>
+
+<p>
+<li>To invoke a destructor, simply do this
+
+<blockquote>
+<pre>
+example.delete_Shape(c) # Deletes a shape
+</pre>
+</blockquote>
+
+(Note: destructors are currently not inherited. This might change later).
+
+<p>
+<li>Static member variables are wrapped as C global variables. For example:
+
+<blockquote>
+<pre>
+n = example.cvar.Shape_nshapes # Get a static data member
+example.cvar.Shapes_nshapes = 13 # Set a static data member
+</pre>
+</blockquote>
+
+</ul>
+
+<h2>General Comments</h2>
+
+<ul>
+<li>This low-level interface is not the only way to handle C++ code.
+Proxy classes provide a much higher-level interface.
+
+<p>
+<li>SWIG *does* know how to properly perform upcasting of objects in
+an inheritance hierarchy (including multiple inheritance). Therefore
+it is perfectly safe to pass an object of a derived class to any
+function involving a base class.
+
+<p>
+<li>A wide variety of C++ features are not currently supported by SWIG. Here is the
+short and incomplete list:
+
+<p>
+<ul>
+<li>Overloaded methods and functions. SWIG wrappers don't know how to resolve name
+conflicts so you must give an alternative name to any overloaded method name using the
+%name directive like this:
+
+<blockquote>
+<pre>
+void foo(int a);
+%name(foo2) void foo(double a, double b);
+</pre>
+</blockquote>
+
+<p>
+<li>Overloaded operators. Not supported at all. The only workaround for this is
+to write a helper function. For example:
+
+<blockquote>
+<pre>
+%inline %{
+ Vector *vector_add(Vector *a, Vector *b) {
+ ... whatever ...
+ }
+%}
+</pre>
+</blockquote>
+
+<p>
+<li>Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all).
+
+<p>
+<li>Dave's snide remark: Like a large bottle of strong Tequilla, it's better to
+use C++ in moderation.
+
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/class/runme.py b/Examples/python/class/runme.py
new file mode 100644
index 0000000..f1272ae
--- /dev/null
+++ b/Examples/python/class/runme.py
@@ -0,0 +1,51 @@
+# file: runme.py
+
+# This file illustrates the proxy class C++ interface generated
+# by SWIG.
+
+import example
+
+# ----- Object creation -----
+
+print "Creating some objects:"
+c = example.Circle(10)
+print " Created circle", c
+s = example.Square(10)
+print " Created square", s
+
+# ----- Access a static member -----
+
+print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
+
+# ----- Member data access -----
+
+# Set the location of the object
+
+c.x = 20
+c.y = 30
+
+s.x = -10
+s.y = 5
+
+print "\nHere is their current position:"
+print " Circle = (%f, %f)" % (c.x,c.y)
+print " Square = (%f, %f)" % (s.x,s.y)
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:"
+for o in [c,s]:
+ print " ", o
+ print " area = ", o.area()
+ print " perimeter = ", o.perimeter()
+
+print "\nGuess I'll clean up now"
+
+# Note: this invokes the virtual destructor
+del c
+del s
+
+s = 3
+print example.cvar.Shape_nshapes,"shapes remain"
+print "Goodbye"
+
diff --git a/Examples/python/constants/Makefile b/Examples/python/constants/Makefile
new file mode 100644
index 0000000..1420b4e
--- /dev/null
+++ b/Examples/python/constants/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/constants/example.i b/Examples/python/constants/example.i
new file mode 100644
index 0000000..4f7b1a4
--- /dev/null
+++ b/Examples/python/constants/example.i
@@ -0,0 +1,27 @@
+/* File : example.i */
+%module example
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+/* The following directives also produce constants */
+
+%constant int iconst = 37;
+%constant double fconst = 3.14;
+
+
diff --git a/Examples/python/constants/index.html b/Examples/python/constants/index.html
new file mode 100644
index 0000000..35cc0d7
--- /dev/null
+++ b/Examples/python/constants/index.html
@@ -0,0 +1,67 @@
+<html>
+<head>
+<title>SWIG:Examples:python:constants</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+<tt>SWIG/Examples/python/constants/</tt>
+<hr>
+
+<H2>Wrapping C Constants</H2>
+
+<p>
+When SWIG encounters C preprocessor macros and C declarations that look like constants,
+it creates Python variables with an identical value. Click <a href="example.i">here</a>
+to see a SWIG interface with some constant declarations in it.
+
+<h2>Accessing Constants from Python</h2>
+
+Click <a href="example.py">here</a> to see a script that prints out the values
+of the constants contained in the above file.
+
+<h2>Key points</h2>
+
+<ul>
+<li>The values of preprocessor macros are converted into Python constants.
+<li>Types are inferred by syntax (e.g., "3" is an integer and "3.5" is a float).
+<li>Character constants such as 'x' are converted into Python strings.
+<li>C string literals such as "Hello World" are converted into Python strings.
+<li>Macros that are not fully defined are simply ignored. For example:
+<blockquote>
+<pre>
+#define EXTERN extern
+</pre>
+</blockquote>
+is ignored because SWIG has no idea what type of variable this would be.
+
+<p>
+<li>Expressions are allowed provided that all of their components are defined. Otherwise, the constant is ignored.
+
+<li>Certain C declarations involving 'const' are also turned into Python constants.
+<li>The Python variables that SWIG creates are not protected from modification. For example,
+even if you had this:
+<blockquote>
+<pre>
+#define FOO 73
+</pre>
+</blockquote>
+a user could come along in a script and type
+<blockquote>
+<pre>
+example.FOO = 13
+</pre>
+</blockquote>
+Unfortunately, there's no easy way to prevent this.
+
+<p>
+<li>The constants that appear in a SWIG interface file do not have to appear in any sort
+of matching C source file since the creation of a constant does not require linkage
+to a stored value (i.e., a value held in a C global variable or memory location).
+</ul>
+
+<hr>
+
+
+</body>
+</html>
diff --git a/Examples/python/constants/runme.py b/Examples/python/constants/runme.py
new file mode 100644
index 0000000..8d25b87
--- /dev/null
+++ b/Examples/python/constants/runme.py
@@ -0,0 +1,27 @@
+# file: runme.py
+
+import example
+
+print "ICONST =", example.ICONST, "(should be 42)"
+print "FCONST =", example.FCONST, "(should be 2.1828)"
+print "CCONST =", example.CCONST, "(should be 'x')"
+print "CCONST2 =", example.CCONST2, "(this should be on a new line)"
+print "SCONST =", example.SCONST, "(should be 'Hello World')"
+print "SCONST2 =", example.SCONST2, "(should be '\"Hello World\"')"
+print "EXPR =", example.EXPR, "(should be 48.5484)"
+print "iconst =", example.iconst, "(should be 37)"
+print "fconst =", example.fconst, "(should be 3.14)"
+
+try:
+ print "EXTERN = ", example.EXTERN, "(Arg! This shouldn't print anything)"
+except AttributeError:
+ print "EXTERN isn't defined (good)"
+
+try:
+ print "FOO = ", example.FOO, "(Arg! This shouldn't print anything)"
+except AttributeError:
+ print "FOO isn't defined (good)"
+
+
+
+
diff --git a/Examples/python/contract/Makefile b/Examples/python/contract/Makefile
new file mode 100644
index 0000000..77fe94b
--- /dev/null
+++ b/Examples/python/contract/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+SWIGOPT =
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
+
+static::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/contract/example.c b/Examples/python/contract/example.c
new file mode 100644
index 0000000..1a64454
--- /dev/null
+++ b/Examples/python/contract/example.c
@@ -0,0 +1,23 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+int fact(int n) {
+ if (n <= 0) return 1;
+ return n*fact(n-1);
+}
+
+
diff --git a/Examples/python/contract/example.dsp b/Examples/python/contract/example.dsp
new file mode 100644
index 0000000..32845e0
--- /dev/null
+++ b/Examples/python/contract/example.dsp
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=example - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "example - Win32 Debug"
+# Name "example - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\example.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\example_wrap.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\example.i
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/contract/example.i b/Examples/python/contract/example.i
new file mode 100644
index 0000000..8fd1a80
--- /dev/null
+++ b/Examples/python/contract/example.i
@@ -0,0 +1,21 @@
+/* File : example.i */
+%module example
+
+%contract gcd(int x, int y) {
+require:
+ x >= 0;
+ y >= 0;
+}
+
+%contract fact(int n) {
+require:
+ n >= 0;
+ensure:
+ fact >= 1;
+}
+
+%inline %{
+extern int gcd(int x, int y);
+extern int fact(int n);
+extern double Foo;
+%}
diff --git a/Examples/python/contract/runme.py b/Examples/python/contract/runme.py
new file mode 100644
index 0000000..d484ae9
--- /dev/null
+++ b/Examples/python/contract/runme.py
@@ -0,0 +1,30 @@
+# file: runme.py
+
+import example
+
+# Call our gcd() function
+
+x = 42
+y = 105
+g = example.gcd(x,y)
+print "The gcd of %d and %d is %d" % (x,y,g)
+
+# Manipulate the Foo global variable
+
+# Output its current value
+print "Foo = ", example.cvar.Foo
+
+# Change its value
+example.cvar.Foo = 3.1415926
+
+# See if the change took effect
+print "Foo = ", example.cvar.Foo
+
+
+
+
+
+
+
+
+
diff --git a/Examples/python/docstrings/Makefile b/Examples/python/docstrings/Makefile
new file mode 100644
index 0000000..f25450c
--- /dev/null
+++ b/Examples/python/docstrings/Makefile
@@ -0,0 +1,24 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT = -O
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/docstrings/example.cxx b/Examples/python/docstrings/example.cxx
new file mode 100644
index 0000000..93e6542
--- /dev/null
+++ b/Examples/python/docstrings/example.cxx
@@ -0,0 +1,4 @@
+#include "example.h"
+
+void Foo::bar() {}
+
diff --git a/Examples/python/docstrings/example.h b/Examples/python/docstrings/example.h
new file mode 100644
index 0000000..f44dbc4
--- /dev/null
+++ b/Examples/python/docstrings/example.h
@@ -0,0 +1,4 @@
+class Foo {
+ public:
+ void bar();
+};
diff --git a/Examples/python/docstrings/example.i b/Examples/python/docstrings/example.i
new file mode 100644
index 0000000..15e08e6
--- /dev/null
+++ b/Examples/python/docstrings/example.i
@@ -0,0 +1,14 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* %feature("docstring") has to come before the declaration of the method to
+ * SWIG. */
+%feature("docstring") Foo::bar "No comment"
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/python/docstrings/runme.py b/Examples/python/docstrings/runme.py
new file mode 100644
index 0000000..b6c95e6
--- /dev/null
+++ b/Examples/python/docstrings/runme.py
@@ -0,0 +1,6 @@
+# file: runme.py
+
+import example
+
+print "example.Foo.bar.__doc__ =", repr(example.Foo.bar.__doc__), "(Should be 'No comment')"
+
diff --git a/Examples/python/enum/Makefile b/Examples/python/enum/Makefile
new file mode 100644
index 0000000..74625b9
--- /dev/null
+++ b/Examples/python/enum/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/enum/example.cxx b/Examples/python/enum/example.cxx
new file mode 100644
index 0000000..6785e57
--- /dev/null
+++ b/Examples/python/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.c */
+
+#include "example.h"
+#include <stdio.h>
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ if (s == Foo::IMPULSE) {
+ printf("speed = IMPULSE speed\n");
+ } else if (s == Foo::WARP) {
+ printf("speed = WARP speed\n");
+ } else if (s == Foo::LUDICROUS) {
+ printf("speed = LUDICROUS speed\n");
+ } else {
+ printf("speed = Unknown speed!\n");
+ }
+}
diff --git a/Examples/python/enum/example.h b/Examples/python/enum/example.h
new file mode 100644
index 0000000..525d62a
--- /dev/null
+++ b/Examples/python/enum/example.h
@@ -0,0 +1,13 @@
+/* File : example.h */
+
+enum color { RED, BLUE, GREEN };
+
+class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE, WARP, LUDICROUS };
+ void enum_test(speed s);
+};
+
+void enum_test(color c, Foo::speed s);
+
diff --git a/Examples/python/enum/example.i b/Examples/python/enum/example.i
new file mode 100644
index 0000000..23ee8a8
--- /dev/null
+++ b/Examples/python/enum/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/python/enum/index.html b/Examples/python/enum/index.html
new file mode 100644
index 0000000..776030f
--- /dev/null
+++ b/Examples/python/enum/index.html
@@ -0,0 +1,35 @@
+<html>
+<head>
+<title>SWIG:Examples:python:enum</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/enum/</tt>
+<hr>
+
+<H2>Wrapping enumerations</H2>
+
+<p>
+This example tests SWIG's ability to wrap enumerations. By default, SWIG
+converts enumeration specifications into integer constants. Further use
+of enumerated types are handled as integers.
+
+<ul>
+<li><a href="example.h">example.h</a>. Header file containing some enums.
+<li><a href="example.i">example.i</a>. Interface file.
+<li><a href="example.py">example.py</a>. Sample Python script.
+</ul>
+
+<h2>Notes</h2>
+
+<ul>
+<li>SWIG allows arbitrary integers to be passed as enum values. However,
+the result of passing an integer not corresponding to any of the values
+specified in the <tt>enum</tt> specification is undefined.
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/enum/runme.py b/Examples/python/enum/runme.py
new file mode 100644
index 0000000..10c4a26
--- /dev/null
+++ b/Examples/python/enum/runme.py
@@ -0,0 +1,31 @@
+# file: runme.py
+
+import example
+
+# ----- Object creation -----
+
+# Print out the value of some enums
+print "*** color ***"
+print " RED =", example.RED
+print " BLUE =", example.BLUE
+print " GREEN =", example.GREEN
+
+print "\n*** Foo::speed ***"
+print " Foo_IMPULSE =", example.Foo.IMPULSE
+print " Foo_WARP =", example.Foo.WARP
+print " Foo_LUDICROUS =", example.Foo.LUDICROUS
+
+print "\nTesting use of enums with functions\n"
+
+example.enum_test(example.RED, example.Foo.IMPULSE)
+example.enum_test(example.BLUE, example.Foo.WARP)
+example.enum_test(example.GREEN, example.Foo.LUDICROUS)
+example.enum_test(1234,5678)
+
+print "\nTesting use of enum with class method"
+f = example.Foo()
+
+f.enum_test(example.Foo.IMPULSE)
+f.enum_test(example.Foo.WARP)
+f.enum_test(example.Foo.LUDICROUS)
+
diff --git a/Examples/python/exception/Makefile b/Examples/python/exception/Makefile
new file mode 100644
index 0000000..7dbdde9
--- /dev/null
+++ b/Examples/python/exception/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/exception/example.h b/Examples/python/exception/example.h
new file mode 100644
index 0000000..8f9a977
--- /dev/null
+++ b/Examples/python/exception/example.h
@@ -0,0 +1,53 @@
+/* File : example.h */
+
+#include <string>
+#ifndef SWIG
+struct A {
+};
+#endif
+
+class Exc {
+public:
+ Exc(int c, const char *m) {
+ code = c;
+ strncpy(msg,m,256);
+ }
+ int code;
+ char msg[256];
+};
+
+#if defined(_MSC_VER)
+ #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
+class Test {
+public:
+ int simple() throw(int) {
+ throw(37);
+ return 1;
+ }
+ int message() throw(const char *) {
+ throw("I died.");
+ return 1;
+ }
+ int hosed() throw(Exc) {
+ throw(Exc(42,"Hosed"));
+ return 1;
+ }
+ int unknown() throw(A*) {
+ static A a;
+ throw &a;
+ return 1;
+ }
+ int multi(int x) throw(int, const char *, Exc) {
+ if (x == 1) throw(37);
+ if (x == 2) throw("Bleah!");
+ if (x == 3) throw(Exc(42,"No-go-diggy-die"));
+ return 1;
+ }
+};
+
+#if defined(_MSC_VER)
+ #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
diff --git a/Examples/python/exception/example.i b/Examples/python/exception/example.i
new file mode 100644
index 0000000..08672c3
--- /dev/null
+++ b/Examples/python/exception/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/python/exception/runme.py b/Examples/python/exception/runme.py
new file mode 100644
index 0000000..7187078
--- /dev/null
+++ b/Examples/python/exception/runme.py
@@ -0,0 +1,36 @@
+# file: runme.py
+
+# Throw a lot of exceptions
+
+import example
+
+t = example.Test()
+try:
+ t.unknown()
+except RuntimeError,e:
+ print "incomplete type", e.args[0]
+
+try:
+ t.simple()
+except RuntimeError,e:
+ print e.args[0]
+
+try:
+ t.message()
+except RuntimeError,e:
+ print e.args[0]
+
+try:
+ t.hosed()
+except example.Exc,e:
+ print e.code, e.msg
+
+for i in range(1,4):
+ try:
+ t.multi(i)
+ except RuntimeError,e:
+ print e.args[0]
+ except example.Exc,e:
+ print e.code, e.msg
+
+
diff --git a/Examples/python/exceptproxy/Makefile b/Examples/python/exceptproxy/Makefile
new file mode 100644
index 0000000..ba5c798
--- /dev/null
+++ b/Examples/python/exceptproxy/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/exceptproxy/example.h b/Examples/python/exceptproxy/example.h
new file mode 100644
index 0000000..ec7107a
--- /dev/null
+++ b/Examples/python/exceptproxy/example.h
@@ -0,0 +1,54 @@
+/* File : example.h */
+
+// A simple exception
+class EmptyError { };
+class FullError {
+ public:
+ int maxsize;
+ FullError(int m) : maxsize(m) { }
+};
+
+#if defined(_MSC_VER)
+ #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
+template<typename T> class Queue {
+ int maxsize;
+ T *items;
+ int nitems;
+ int last;
+ public:
+ Queue(int size) {
+ maxsize = size;
+ items = new T[size];
+ nitems = 0;
+ last = 0;
+ }
+ ~Queue() {
+ delete [] items;
+ }
+ void enqueue(T x) throw(FullError) {
+ if (nitems == maxsize) {
+ throw FullError(maxsize);
+ }
+ items[last] = x;
+ last = (last + 1) % maxsize;
+ nitems++;
+ }
+ T dequeue() {
+ T x;
+ if (nitems == 0) throw EmptyError();
+ x = items[(last + maxsize - nitems) % maxsize];
+ nitems--;
+ return x;
+ }
+ int length() {
+ return nitems;
+ }
+};
+
+
+#if defined(_MSC_VER)
+ #pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
+#endif
+
diff --git a/Examples/python/exceptproxy/example.i b/Examples/python/exceptproxy/example.i
new file mode 100644
index 0000000..4a1e0ba
--- /dev/null
+++ b/Examples/python/exceptproxy/example.i
@@ -0,0 +1,114 @@
+/* This is a rather sophisticated example that illustrates exception handling,
+ templates, and proxy classes.
+
+ (i) The %exception directive is used to attach exception handlers
+ to specific methods.
+
+ (ii) Exception classes are automatically converted to proxy class
+ objects.
+
+ (iii) The %template directive is used to expand the templates
+*/
+
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Define some exception handlers for specific methods. In
+ the header file, the enqueue method throws FullError and
+ the dequeue method throws EmptyError. Since we don't
+ want to define an exception handler for everything, we
+ simply write a handler each method individually.
+
+ Note: the *::enqueue syntax means that we simply define
+ the handler for any class with this method defined.
+*/
+
+/*
+ First we need to 'disable' the default swig throw mechanism for the
+ FullError class. We do this by rethrowing the exception.
+
+ Note that this is necessary since the class appears in a throw
+ declaration:
+
+
+ void enqueue(T x) throw(FullError);
+
+ hence, swig recognizes it as an exception class and it will generate
+ the necessary code to catch it and rethrow it to the python side.
+
+*/
+%typemap(throws) FullError "(void)$1; throw;";
+
+
+%exception *::enqueue {
+ try {
+ $action
+ } catch(FullError& e) {
+ FullError *ecopy = new FullError(e);
+ PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_FullError, 1);
+ PyErr_SetObject(SWIG_Python_ExceptionType(SWIGTYPE_p_FullError), err);
+ SWIG_fail;
+ }
+}
+
+/* Some notes about the code above:
+
+ (0) $action gets replaced with the actual method call.
+
+ (1) We are going to return a copy of the exception object (FullError)
+ to pass back to the Python interpreter. This is why the copy
+ constructor is being called.
+
+ (2) The SWIG_NewPointerObj() call automatically wraps the exception object
+ into a proxy class. The SWIGTYPE_p_FullError is the type-descriptor
+ used for type checking. The "1" indicates that Python will have
+ ownership of the resulting object.
+
+ (3) The PyErr_SetObject call sets the Python exception. However,
+ the SWIGTYPE_p_FullError->clientdata reference may not be
+ obvious. This is actually the Python proxy class object
+ for FullError. Recall that in Python, exceptions are defined
+ as classes. Therefore, this works perfectly as the argument to
+ PyErr_SetObject()! A neat trick perhaps.
+*/
+
+/*
+ Now, the EmpytError doesn't appear in a throw declaration, and hence
+ we need to 'mark' it as an exception class. In python, classes that
+ are used as exception are 'special', and need to be wrapped as
+ 'classic' ones.
+
+ This is a python issue, and if you don't mark the class, you will
+ see 'interesting' behaviours at the python side.
+
+
+*/
+%exceptionclass EmptyError;
+%exceptionclass FullError;
+
+%exception *::dequeue {
+ try {
+ $action
+ } catch(EmptyError& e) {
+ EmptyError *ecopy = new EmptyError(e);
+ PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_EmptyError, 1);
+ PyErr_SetObject(SWIG_Python_ExceptionType(SWIGTYPE_p_EmptyError), err);
+ SWIG_fail;
+ }
+}
+
+/* Grab the original header file */
+%include "example.h"
+
+/* Instantiate a few templates */
+
+%template(intQueue) Queue<int>;
+%template(doubleQueue) Queue<double>;
+
+
+
+
+
diff --git a/Examples/python/exceptproxy/runme.py b/Examples/python/exceptproxy/runme.py
new file mode 100644
index 0000000..a2ae555
--- /dev/null
+++ b/Examples/python/exceptproxy/runme.py
@@ -0,0 +1,45 @@
+# file: runme.py
+import example
+
+q = example.intQueue(10)
+
+print "Inserting items into intQueue"
+
+try:
+ for i in range(0,100):
+ q.enqueue(i)
+except example.FullError,e:
+ print "Maxsize is", e.maxsize
+
+print "Removing items"
+
+try:
+ while 1:
+ q.dequeue()
+except example.EmptyError,e:
+ pass
+
+
+q = example.doubleQueue(1000)
+
+print "Inserting items into doubleQueue"
+
+try:
+ for i in range(0,10000):
+ q.enqueue(i*1.5)
+except example.FullError,e:
+ print "Maxsize is", e.maxsize
+
+print "Removing items"
+
+try:
+ while 1:
+ q.dequeue()
+except example.EmptyError,e:
+ pass
+
+
+
+
+
+
diff --git a/Examples/python/extend/Makefile b/Examples/python/extend/Makefile
new file mode 100644
index 0000000..a29276e
--- /dev/null
+++ b/Examples/python/extend/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/extend/example.cxx b/Examples/python/extend/example.cxx
new file mode 100644
index 0000000..450d756
--- /dev/null
+++ b/Examples/python/extend/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/python/extend/example.h b/Examples/python/extend/example.h
new file mode 100644
index 0000000..b27ab97
--- /dev/null
+++ b/Examples/python/extend/example.h
@@ -0,0 +1,56 @@
+/* File : example.h */
+
+#include <cstdio>
+#include <iostream>
+#include <vector>
+#include <string>
+#include <cmath>
+
+class Employee {
+private:
+ std::string name;
+public:
+ Employee(const char* n): name(n) {}
+ virtual std::string getTitle() { return getPosition() + " " + getName(); }
+ virtual std::string getName() { return name; }
+ virtual std::string getPosition() const { return "Employee"; }
+ virtual ~Employee() { printf("~Employee() @ %p\n", this); }
+};
+
+
+class Manager: public Employee {
+public:
+ Manager(const char* n): Employee(n) {}
+ virtual std::string getPosition() const { return "Manager"; }
+};
+
+
+class EmployeeList {
+ std::vector<Employee*> list;
+public:
+ EmployeeList() {
+ list.push_back(new Employee("Bob"));
+ list.push_back(new Employee("Jane"));
+ list.push_back(new Manager("Ted"));
+ }
+ void addEmployee(Employee *p) {
+ list.push_back(p);
+ std::cout << "New employee added. Current employees are:" << std::endl;
+ std::vector<Employee*>::iterator i;
+ for (i=list.begin(); i!=list.end(); i++) {
+ std::cout << " " << (*i)->getTitle() << std::endl;
+ }
+ }
+ const Employee *get_item(int i) {
+ return list[i];
+ }
+ ~EmployeeList() {
+ std::vector<Employee*>::iterator i;
+ std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
+ for (i=list.begin(); i!=list.end(); i++) {
+ delete *i;
+ }
+ std::cout << "~EmployeeList empty." << std::endl;
+ }
+};
+
diff --git a/Examples/python/extend/example.i b/Examples/python/extend/example.i
new file mode 100644
index 0000000..c8ec32e
--- /dev/null
+++ b/Examples/python/extend/example.i
@@ -0,0 +1,15 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_vector.i"
+%include "std_string.i"
+
+/* turn on director wrapping for Manager */
+%feature("director") Employee;
+%feature("director") Manager;
+
+%include "example.h"
+
diff --git a/Examples/python/extend/index.html b/Examples/python/extend/index.html
new file mode 100644
index 0000000..959e8c6
--- /dev/null
+++ b/Examples/python/extend/index.html
@@ -0,0 +1,19 @@
+<html>
+<head>
+<title>SWIG:Examples:python:extend</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/extend/</tt>
+<hr>
+
+<H2>Extending a simple C++ class in Python</H2>
+
+<p>
+This example illustrates the extending of a C++ class with cross language polymorphism.
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/extend/runme.py b/Examples/python/extend/runme.py
new file mode 100644
index 0000000..240b098
--- /dev/null
+++ b/Examples/python/extend/runme.py
@@ -0,0 +1,81 @@
+# file: runme.py
+
+# This file illustrates the cross language polymorphism using directors.
+
+import example
+
+
+# CEO class, which overrides Employee::getPosition().
+
+class CEO(example.Manager):
+ def __init__(self, name):
+ example.Manager.__init__(self, name)
+ def getPosition(self):
+ return "CEO"
+
+
+# Create an instance of our employee extension class, CEO. The calls to
+# getName() and getPosition() are standard, the call to getTitle() uses
+# the director wrappers to call CEO.getPosition. e = CEO("Alice")
+
+e = CEO("Alice")
+print e.getName(), "is a", e.getPosition()
+print "Just call her \"%s\"" % e.getTitle()
+print "----------------------"
+
+
+# Create a new EmployeeList instance. This class does not have a C++
+# director wrapper, but can be used freely with other classes that do.
+
+list = example.EmployeeList()
+
+# EmployeeList owns its items, so we must surrender ownership of objects
+# we add. This involves first calling the __disown__ method to tell the
+# C++ director to start reference counting. We reassign the resulting
+# weakref.proxy to e so that no hard references remain. This can also be
+# done when the object is constructed, as in: e =
+# CEO("Alice").__disown__()
+
+e = e.__disown__()
+list.addEmployee(e)
+print "----------------------"
+
+# Now we access the first four items in list (three are C++ objects that
+# EmployeeList's constructor adds, the last is our CEO). The virtual
+# methods of all these instances are treated the same. For items 0, 1, and
+# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls
+# getPosition which resolves in Python. The call to getPosition is
+# slightly different, however, from the e.getPosition() call above, since
+# now the object reference has been "laundered" by passing through
+# EmployeeList as an Employee*. Previously, Python resolved the call
+# immediately in CEO, but now Python thinks the object is an instance of
+# class Employee (actually EmployeePtr). So the call passes through the
+# Employee proxy class and on to the C wrappers and C++ director,
+# eventually ending up back at the CEO implementation of getPosition().
+# The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+# method, which in turn calls getPosition(). This virtual method call
+# passes down through the C++ director class to the Python implementation
+# in CEO. All this routing takes place transparently.
+
+print "(position, title) for items 0-3:"
+
+print " %s, \"%s\"" % (list.get_item(0).getPosition(), list.get_item(0).getTitle())
+print " %s, \"%s\"" % (list.get_item(1).getPosition(), list.get_item(1).getTitle())
+print " %s, \"%s\"" % (list.get_item(2).getPosition(), list.get_item(2).getTitle())
+print " %s, \"%s\"" % (list.get_item(3).getPosition(), list.get_item(3).getTitle())
+print "----------------------"
+
+# Time to delete the EmployeeList, which will delete all the Employee*
+# items it contains. The last item is our CEO, which gets destroyed as its
+# reference count goes to zero. The Python destructor runs, and is still
+# able to call self.getName() since the underlying C++ object still
+# exists. After this destructor runs the remaining C++ destructors run as
+# usual to destroy the object.
+
+del list
+print "----------------------"
+
+# All done.
+
+print "python exit"
+
diff --git a/Examples/python/funcptr/Makefile b/Examples/python/funcptr/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/funcptr/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/funcptr/example.c b/Examples/python/funcptr/example.c
new file mode 100644
index 0000000..5c4a3da
--- /dev/null
+++ b/Examples/python/funcptr/example.c
@@ -0,0 +1,19 @@
+/* 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;
+}
+
+int (*funcvar)(int,int) = add;
diff --git a/Examples/python/funcptr/example.h b/Examples/python/funcptr/example.h
new file mode 100644
index 0000000..9936e24
--- /dev/null
+++ b/Examples/python/funcptr/example.h
@@ -0,0 +1,9 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/python/funcptr/example.i b/Examples/python/funcptr/example.i
new file mode 100644
index 0000000..8b3bef6
--- /dev/null
+++ b/Examples/python/funcptr/example.i
@@ -0,0 +1,16 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+/* Now install a bunch of "ops" as constants */
+%constant int (*ADD)(int,int) = add;
+%constant int (*SUB)(int,int) = sub;
+%constant int (*MUL)(int,int) = mul;
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/python/funcptr/index.html b/Examples/python/funcptr/index.html
new file mode 100644
index 0000000..e41e0db
--- /dev/null
+++ b/Examples/python/funcptr/index.html
@@ -0,0 +1,90 @@
+<html>
+<head>
+<title>SWIG:Examples:python:funcptr</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/funcptr/</tt>
+<hr>
+
+<H2>Pointers to Functions</H2>
+
+<p>
+Okay, just what in the heck does SWIG do with a declaration like this?
+
+<blockquote>
+<pre>
+int do_op(int a, int b, int (*op)(int, int));
+</pre>
+</blockquote>
+
+Well, it creates a wrapper as usual. Of course, that does raise some
+questions about the third argument (the pointer to a function).
+
+<p>
+In this case, SWIG will wrap the function pointer as it does for all other
+pointers. However, in order to actually call this function from a script,
+you will need to pass some kind of C function pointer object. In C,
+this is easy, you just supply a function name as an argument like this:
+
+<blockquote>
+<pre>
+/* Some callback function */
+int add(int a, int b) {
+ return a+b;
+}
+...
+int r = do_op(x,y,add);
+</pre>
+</blockquote>
+
+To make this work with SWIG, you will need to do a little extra work. Specifically,
+you need to create some function pointer objects using the %constant directive like this:
+
+<blockquote>
+<pre>
+%constant(int (*)(int,int)) ADD = add;
+</pre>
+</blockquote>
+
+Now, in a script, you would do this:
+
+<blockquote>
+<pre>
+r = do_op(x,y, ADD)
+</pre>
+</blockquote>
+
+<h2>An Example</h2>
+
+Here are some files that illustrate this with a simple example:
+
+<ul>
+<li><a href="example.c">example.c</a>
+<li><a href="example.h">example.h</a>
+<li><a href="example.i">example.i</a> (SWIG interface)
+<li><a href="example.py">example.py</a> (Sample script)
+</ul>
+
+<h2>Notes</h2>
+
+<ul>
+<li>The value of a function pointer must correspond to a function written in C or C++.
+It is not possible to pass an arbitrary Python function object in as a substitute for a C
+function pointer.
+
+<p>
+<li>A python function can be used as a C/C++ callback if you write some
+clever typemaps and are very careful about how you create your extension.
+This is an advanced topic not covered here.
+</ul>
+
+<hr>
+</body>
+</html>
+
+
+
+
diff --git a/Examples/python/funcptr/runme.py b/Examples/python/funcptr/runme.py
new file mode 100644
index 0000000..bce0650
--- /dev/null
+++ b/Examples/python/funcptr/runme.py
@@ -0,0 +1,20 @@
+# file: runme.py
+
+import example
+
+a = 37
+b = 42
+
+# Now call our C function with a bunch of callbacks
+
+print "Trying some C callback functions"
+print " a =", a
+print " b =", b
+print " ADD(a,b) =", example.do_op(a,b,example.ADD)
+print " SUB(a,b) =", example.do_op(a,b,example.SUB)
+print " MUL(a,b) =", example.do_op(a,b,example.MUL)
+
+print "Here is what the C callback function objects look like in Python"
+print " ADD =", example.ADD
+print " SUB =", example.SUB
+print " MUL =", example.MUL
diff --git a/Examples/python/funcptr2/Makefile b/Examples/python/funcptr2/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/funcptr2/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/funcptr2/example.c b/Examples/python/funcptr2/example.c
new file mode 100644
index 0000000..5c4a3da
--- /dev/null
+++ b/Examples/python/funcptr2/example.c
@@ -0,0 +1,19 @@
+/* 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;
+}
+
+int (*funcvar)(int,int) = add;
diff --git a/Examples/python/funcptr2/example.h b/Examples/python/funcptr2/example.h
new file mode 100644
index 0000000..9936e24
--- /dev/null
+++ b/Examples/python/funcptr2/example.h
@@ -0,0 +1,9 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/python/funcptr2/example.i b/Examples/python/funcptr2/example.i
new file mode 100644
index 0000000..681775a
--- /dev/null
+++ b/Examples/python/funcptr2/example.i
@@ -0,0 +1,18 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+/* Now install a bunch of "ops" as constants */
+%callback("%(upper)s");
+int add(int, int);
+int sub(int, int);
+int mul(int, int);
+%nocallback;
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/python/funcptr2/runme.py b/Examples/python/funcptr2/runme.py
new file mode 100644
index 0000000..bd58fb6
--- /dev/null
+++ b/Examples/python/funcptr2/runme.py
@@ -0,0 +1,24 @@
+# file: runme.py
+
+import example
+
+a = 37
+b = 42
+
+# Now call our C function with a bunch of callbacks
+
+print "Trying some C callback functions"
+print " a =", a
+print " b =", b
+print " ADD(a,b) =", example.do_op(a,b,example.ADD)
+print " SUB(a,b) =", example.do_op(a,b,example.SUB)
+print " MUL(a,b) =", example.do_op(a,b,example.MUL)
+
+print "Here is what the C callback function objects look like in Python"
+print " ADD =", example.ADD
+print " SUB =", example.SUB
+print " MUL =", example.MUL
+
+print "Call the functions directly..."
+print " add(a,b) =", example.add(a,b)
+print " sub(a,b) =", example.sub(a,b)
diff --git a/Examples/python/functor/Makefile b/Examples/python/functor/Makefile
new file mode 100644
index 0000000..fe38975
--- /dev/null
+++ b/Examples/python/functor/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/functor/example.i b/Examples/python/functor/example.i
new file mode 100644
index 0000000..2fd3817
--- /dev/null
+++ b/Examples/python/functor/example.i
@@ -0,0 +1,29 @@
+/* File : example.i */
+%module example
+
+
+%inline %{
+// From B. Strousjoup, "The C++ Programming Language, Third Edition", p. 514
+template<class T> class Sum {
+ T res;
+public:
+ Sum(T i = 0) : res(i) { }
+ void operator() (T x) { res += x; }
+ T result() const { return res; }
+};
+
+%}
+
+// Rename the application operator to __call__ for python.
+// Note: this is normally automatic, but if you had to do it yourself
+// you would use this directive:
+//
+// %rename(__call__) *::operator();
+
+// Instantiate a few versions
+%template(intSum) Sum<int>;
+%template(doubleSum) Sum<double>;
+
+
+
+
diff --git a/Examples/python/functor/runme.py b/Examples/python/functor/runme.py
new file mode 100644
index 0000000..8fc0f2f
--- /dev/null
+++ b/Examples/python/functor/runme.py
@@ -0,0 +1,17 @@
+# Operator overloading example
+import example
+import math
+
+a = example.intSum(0)
+b = example.doubleSum(100.0)
+
+# Use the objects. They should be callable just like a normal
+# python function.
+
+for i in range(0,100):
+ a(i) # Note: function call
+ b(math.sqrt(i)) # Note: function call
+
+print a.result()
+print b.result()
+
diff --git a/Examples/python/import/Makefile b/Examples/python/import/Makefile
new file mode 100644
index 0000000..74d4f88
--- /dev/null
+++ b/Examples/python/import/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SWIGOPT =
+LIBS =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp
+
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ @rm -f foo.py bar.py spam.py base.py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/import/README b/Examples/python/import/README
new file mode 100644
index 0000000..5679dbb
--- /dev/null
+++ b/Examples/python/import/README
@@ -0,0 +1,39 @@
+This example tests the %import directive and working with multiple modules.
+
+Use 'python runme.py' to run a test.
+
+Overview:
+---------
+
+The example defines 4 different extension modules--each wrapping
+a separate C++ class.
+
+ base.i - Base class
+ foo.i - Foo class derived from Base
+ bar.i - Bar class derived from Base
+ spam.i - Spam class derived from Bar
+
+Each module uses %import to refer to another module. For
+example, the 'foo.i' module uses '%import base.i' to get
+definitions for its base class.
+
+If everything is okay, all of the modules will load properly and
+type checking will work correctly. Caveat: Some compilers, for example
+gcc-3.2.x, generate broken vtables with the inline methods in this test.
+This is not a SWIG problem and can usually be solved with non-inlined
+destructors compiled into separate shared objects/DLLs.
+
+Unix:
+-----
+- Run make
+- Run the test as described above
+
+Windows:
+--------
+- Use the Visual C++ 6 workspace file (example.dsw). Build the runtime
+ project DLL first followed by the other 4 DLLs as they all have a
+ dependency on the runtime DLL. The Batch build option in the Build menu
+ is usually the easiest way to do this. Only use the Release builds not
+ the Debug builds.
+- Run the test as described above
+
diff --git a/Examples/python/import/bar.dsp b/Examples/python/import/bar.dsp
new file mode 100644
index 0000000..17b05cc
--- /dev/null
+++ b/Examples/python/import/bar.dsp
@@ -0,0 +1,144 @@
+# Microsoft Developer Studio Project File - Name="bar" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=bar - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "bar.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "bar.mak" CFG="bar - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "bar - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "bar - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "bar - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_bar.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "bar - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BAR_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_bar.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "bar - Win32 Debug"
+# Name "bar - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\bar_wrap.cxx
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\bar.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\bar.i
+
+!IF "$(CFG)" == "bar - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\bar.i
+InputName=bar
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "bar - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\bar.i
+InputName=bar
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/import/bar.h b/Examples/python/import/bar.h
new file mode 100644
index 0000000..fa4185f
--- /dev/null
+++ b/Examples/python/import/bar.h
@@ -0,0 +1,22 @@
+#include "base.h"
+
+class Bar : public Base {
+ public:
+ Bar() { }
+ ~Bar() { }
+ virtual void A() {
+ printf("I'm Bar::A\n");
+ }
+ void B() {
+ printf("I'm Bar::B\n");
+ }
+ virtual Base *toBase() {
+ return static_cast<Base *>(this);
+ }
+ static Bar *fromBase(Base *b) {
+ return dynamic_cast<Bar *>(b);
+ }
+
+};
+
+
diff --git a/Examples/python/import/bar.i b/Examples/python/import/bar.i
new file mode 100644
index 0000000..5816cbe
--- /dev/null
+++ b/Examples/python/import/bar.i
@@ -0,0 +1,9 @@
+%module bar
+%{
+#include "bar.h"
+%}
+
+%import base.i
+%include "bar.h"
+
+
diff --git a/Examples/python/import/base.dsp b/Examples/python/import/base.dsp
new file mode 100644
index 0000000..2bc9736
--- /dev/null
+++ b/Examples/python/import/base.dsp
@@ -0,0 +1,144 @@
+# Microsoft Developer Studio Project File - Name="base" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=base - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "base.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "base.mak" CFG="base - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "base - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "base - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "base - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_base.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "base - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BASE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_base.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "base - Win32 Debug"
+# Name "base - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\base_wrap.cxx
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\base.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\base.i
+
+!IF "$(CFG)" == "base - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\base.i
+InputName=base
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "base - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\base.i
+InputName=base
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/import/base.h b/Examples/python/import/base.h
new file mode 100644
index 0000000..5a266f6
--- /dev/null
+++ b/Examples/python/import/base.h
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+class Base {
+ public:
+ Base() { };
+ virtual ~Base() { };
+ virtual void A() {
+ printf("I'm Base::A\n");
+ }
+ void B() {
+ printf("I'm Base::B\n");
+ }
+ virtual Base *toBase() {
+ return static_cast<Base *>(this);
+ }
+};
+
+
diff --git a/Examples/python/import/base.i b/Examples/python/import/base.i
new file mode 100644
index 0000000..f6e19ef
--- /dev/null
+++ b/Examples/python/import/base.i
@@ -0,0 +1,6 @@
+%module base
+%{
+#include "base.h"
+%}
+
+%include base.h
diff --git a/Examples/python/import/example.dsw b/Examples/python/import/example.dsw
new file mode 100644
index 0000000..d395d46
--- /dev/null
+++ b/Examples/python/import/example.dsw
@@ -0,0 +1,65 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "bar"=.\bar.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "base"=.\base.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "foo"=.\foo.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "spam"=.\spam.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Examples/python/import/foo.dsp b/Examples/python/import/foo.dsp
new file mode 100644
index 0000000..9a92c4b
--- /dev/null
+++ b/Examples/python/import/foo.dsp
@@ -0,0 +1,144 @@
+# Microsoft Developer Studio Project File - Name="foo" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=foo - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "foo.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "foo.mak" CFG="foo - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "foo - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "foo - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "foo - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_foo.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "foo - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "FOO_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_foo.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "foo - Win32 Debug"
+# Name "foo - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\foo_wrap.cxx
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\foo.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\foo.i
+
+!IF "$(CFG)" == "foo - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\foo.i
+InputName=foo
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "foo - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\foo.i
+InputName=foo
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/import/foo.h b/Examples/python/import/foo.h
new file mode 100644
index 0000000..dd51840
--- /dev/null
+++ b/Examples/python/import/foo.h
@@ -0,0 +1,21 @@
+#include "base.h"
+
+class Foo : public Base {
+ public:
+ Foo() { }
+ ~Foo() { }
+ virtual void A() {
+ printf("I'm Foo::A\n");
+ }
+ void B() {
+ printf("I'm Foo::B\n");
+ }
+ virtual Base *toBase() {
+ return static_cast<Base *>(this);
+ }
+ static Foo *fromBase(Base *b) {
+ return dynamic_cast<Foo *>(b);
+ }
+};
+
+
diff --git a/Examples/python/import/foo.i b/Examples/python/import/foo.i
new file mode 100644
index 0000000..27feb2e
--- /dev/null
+++ b/Examples/python/import/foo.i
@@ -0,0 +1,8 @@
+%module foo
+%{
+#include "foo.h"
+%}
+
+%import base.i
+%include "foo.h"
+
diff --git a/Examples/python/import/runme.py b/Examples/python/import/runme.py
new file mode 100644
index 0000000..6b800ec
--- /dev/null
+++ b/Examples/python/import/runme.py
@@ -0,0 +1,111 @@
+# file: runme.py
+# Test various properties of classes defined in separate modules
+
+print "Testing the %import directive"
+import base
+import foo
+import bar
+import spam
+
+# Create some objects
+
+print "Creating some objects"
+
+a = base.Base()
+b = foo.Foo()
+c = bar.Bar()
+d = spam.Spam()
+
+# Try calling some methods
+print "Testing some methods"
+print "",
+print "Should see 'Base::A' ---> ",
+a.A()
+print "Should see 'Base::B' ---> ",
+a.B()
+
+print "Should see 'Foo::A' ---> ",
+b.A()
+print "Should see 'Foo::B' ---> ",
+b.B()
+
+print "Should see 'Bar::A' ---> ",
+c.A()
+print "Should see 'Bar::B' ---> ",
+c.B()
+
+print "Should see 'Spam::A' ---> ",
+d.A()
+print "Should see 'Spam::B' ---> ",
+d.B()
+
+# Try some casts
+
+print "\nTesting some casts\n"
+print "",
+
+x = a.toBase()
+print "Should see 'Base::A' ---> ",
+x.A()
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = b.toBase()
+print "Should see 'Foo::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = c.toBase()
+print "Should see 'Bar::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = d.toBase()
+print "Should see 'Spam::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = d.toBar()
+print "Should see 'Bar::B' ---> ",
+x.B()
+
+print "\nTesting some dynamic casts\n"
+x = d.toBase()
+
+print " Spam -> Base -> Foo : ",
+y = foo.Foo_fromBase(x)
+if y:
+ print "bad swig"
+else:
+ print "good swig"
+
+print " Spam -> Base -> Bar : ",
+y = bar.Bar_fromBase(x)
+if y:
+ print "good swig"
+else:
+ print "bad swig"
+
+print " Spam -> Base -> Spam : ",
+y = spam.Spam_fromBase(x)
+if y:
+ print "good swig"
+else:
+ print "bad swig"
+
+print " Foo -> Spam : ",
+y = spam.Spam_fromBase(b)
+if y:
+ print "bad swig"
+else:
+ print "good swig"
+
+
+
+
diff --git a/Examples/python/import/spam.dsp b/Examples/python/import/spam.dsp
new file mode 100644
index 0000000..0a6595b
--- /dev/null
+++ b/Examples/python/import/spam.dsp
@@ -0,0 +1,144 @@
+# Microsoft Developer Studio Project File - Name="spam" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=spam - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "spam.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "spam.mak" CFG="spam - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "spam - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "spam - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "spam - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GR /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_spam.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "spam - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GR /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SPAM_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_spam.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "spam - Win32 Debug"
+# Name "spam - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\spam_wrap.cxx
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\spam.h
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\spam.i
+
+!IF "$(CFG)" == "spam - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\spam.i
+InputName=spam
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "spam - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\spam.i
+InputName=spam
+
+"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -c++ -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/import/spam.h b/Examples/python/import/spam.h
new file mode 100644
index 0000000..b4e7a26
--- /dev/null
+++ b/Examples/python/import/spam.h
@@ -0,0 +1,24 @@
+#include "bar.h"
+
+class Spam : public Bar {
+ public:
+ Spam() { }
+ ~Spam() { }
+ virtual void A() {
+ printf("I'm Spam::A\n");
+ }
+ void B() {
+ printf("I'm Spam::B\n");
+ }
+ virtual Base *toBase() {
+ return static_cast<Base *>(this);
+ }
+ virtual Bar *toBar() {
+ return static_cast<Bar *>(this);
+ }
+ static Spam *fromBase(Base *b) {
+ return dynamic_cast<Spam *>(b);
+ }
+};
+
+
diff --git a/Examples/python/import/spam.i b/Examples/python/import/spam.i
new file mode 100644
index 0000000..d3d9121
--- /dev/null
+++ b/Examples/python/import/spam.i
@@ -0,0 +1,9 @@
+%module spam
+%{
+#include "spam.h"
+%}
+
+%import bar.i
+%include "spam.h"
+
+
diff --git a/Examples/python/import_template/Makefile b/Examples/python/import_template/Makefile
new file mode 100644
index 0000000..ee47e99
--- /dev/null
+++ b/Examples/python/import_template/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SWIGOPT =
+LIBS =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' python_cpp
+ $(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
+ LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' python_cpp
+
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ @rm -f foo.py bar.py spam.py base.py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/import_template/README b/Examples/python/import_template/README
new file mode 100644
index 0000000..f8cf02d
--- /dev/null
+++ b/Examples/python/import_template/README
@@ -0,0 +1,30 @@
+This example tests the %import directive and working with multiple modules.
+
+Use 'python runme.py' to run a test.
+
+Overview:
+---------
+
+The example defines 4 different extension modules--each wrapping
+a separate C++ class.
+
+ base.i - Base class
+ foo.i - Foo class derived from Base
+ bar.i - Bar class derived from Base
+ spam.i - Spam class derived from Bar
+
+Each module uses %import to refer to another module. For
+example, the 'foo.i' module uses '%import base.i' to get
+definitions for its base class.
+
+If everything is okay, all of the modules will load properly and
+type checking will work correctly. Caveat: Some compilers, for example
+gcc-3.2.x, generate broken vtables with the inline methods in this test.
+This is not a SWIG problem and can usually be solved with non-inlined
+destructors compiled into separate shared objects/DLLs.
+
+Unix:
+-----
+- Run make
+- Run the test as described above
+
diff --git a/Examples/python/import_template/bar.h b/Examples/python/import_template/bar.h
new file mode 100644
index 0000000..500b67a
--- /dev/null
+++ b/Examples/python/import_template/bar.h
@@ -0,0 +1,22 @@
+#include "base.h"
+
+template<class T> class Bar : public Base<T> {
+ public:
+ Bar() { }
+ ~Bar() { }
+ virtual void A() {
+ printf("I'm Bar::A\n");
+ }
+ void B() {
+ printf("I'm Bar::B\n");
+ }
+ virtual Base<T> *toBase() {
+ return static_cast<Base<T> *>(this);
+ }
+ static Bar<T> *fromBase(Base<T> *b) {
+ return dynamic_cast<Bar<T> *>(b);
+ }
+
+};
+
+
diff --git a/Examples/python/import_template/bar.i b/Examples/python/import_template/bar.i
new file mode 100644
index 0000000..155c08d
--- /dev/null
+++ b/Examples/python/import_template/bar.i
@@ -0,0 +1,11 @@
+%module bar
+%{
+#include "bar.h"
+%}
+
+%import base.i
+%include "bar.h"
+
+%template(intBar) Bar<int>;
+
+
diff --git a/Examples/python/import_template/base.h b/Examples/python/import_template/base.h
new file mode 100644
index 0000000..c755a6f
--- /dev/null
+++ b/Examples/python/import_template/base.h
@@ -0,0 +1,18 @@
+#include <stdio.h>
+
+template<class T> class Base {
+ public:
+ Base() { };
+ virtual ~Base() { };
+ virtual void A() {
+ printf("I'm Base::A\n");
+ }
+ void B() {
+ printf("I'm Base::B\n");
+ }
+ virtual Base<T> *toBase() {
+ return static_cast<Base<T> *>(this);
+ }
+};
+
+
diff --git a/Examples/python/import_template/base.i b/Examples/python/import_template/base.i
new file mode 100644
index 0000000..a6da063
--- /dev/null
+++ b/Examples/python/import_template/base.i
@@ -0,0 +1,7 @@
+%module base
+%{
+#include "base.h"
+%}
+
+%include base.h
+%template(intBase) Base<int>;
diff --git a/Examples/python/import_template/foo.h b/Examples/python/import_template/foo.h
new file mode 100644
index 0000000..3df13d2
--- /dev/null
+++ b/Examples/python/import_template/foo.h
@@ -0,0 +1,21 @@
+#include "base.h"
+
+template<class T> class Foo : public Base<T> {
+ public:
+ Foo() { }
+ ~Foo() { }
+ virtual void A() {
+ printf("I'm Foo::A\n");
+ }
+ void B() {
+ printf("I'm Foo::B\n");
+ }
+ virtual Base<T> *toBase() {
+ return static_cast<Base<T> *>(this);
+ }
+ static Foo<T> *fromBase(Base<T> *b) {
+ return dynamic_cast<Foo<T> *>(b);
+ }
+};
+
+
diff --git a/Examples/python/import_template/foo.i b/Examples/python/import_template/foo.i
new file mode 100644
index 0000000..e271672
--- /dev/null
+++ b/Examples/python/import_template/foo.i
@@ -0,0 +1,10 @@
+%module foo
+%{
+#include "foo.h"
+%}
+
+%import base.i
+%include "foo.h"
+
+%template(intFoo) Foo<int>;
+
diff --git a/Examples/python/import_template/runme.py b/Examples/python/import_template/runme.py
new file mode 100644
index 0000000..0d5aded
--- /dev/null
+++ b/Examples/python/import_template/runme.py
@@ -0,0 +1,111 @@
+# file: runme.py
+# Test various properties of classes defined in separate modules
+
+print "Testing the %import directive with templates"
+import base
+import foo
+import bar
+import spam
+
+# Create some objects
+
+print "Creating some objects"
+
+a = base.intBase()
+b = foo.intFoo()
+c = bar.intBar()
+d = spam.intSpam()
+
+# Try calling some methods
+print "Testing some methods"
+print "",
+print "Should see 'Base::A' ---> ",
+a.A()
+print "Should see 'Base::B' ---> ",
+a.B()
+
+print "Should see 'Foo::A' ---> ",
+b.A()
+print "Should see 'Foo::B' ---> ",
+b.B()
+
+print "Should see 'Bar::A' ---> ",
+c.A()
+print "Should see 'Bar::B' ---> ",
+c.B()
+
+print "Should see 'Spam::A' ---> ",
+d.A()
+print "Should see 'Spam::B' ---> ",
+d.B()
+
+# Try some casts
+
+print "\nTesting some casts\n"
+print "",
+
+x = a.toBase()
+print "Should see 'Base::A' ---> ",
+x.A()
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = b.toBase()
+print "Should see 'Foo::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = c.toBase()
+print "Should see 'Bar::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = d.toBase()
+print "Should see 'Spam::A' ---> ",
+x.A()
+
+print "Should see 'Base::B' ---> ",
+x.B()
+
+x = d.toBar()
+print "Should see 'Bar::B' ---> ",
+x.B()
+
+print "\nTesting some dynamic casts\n"
+x = d.toBase()
+
+print " Spam -> Base -> Foo : ",
+y = foo.intFoo_fromBase(x)
+if y:
+ print "bad swig"
+else:
+ print "good swig"
+
+print " Spam -> Base -> Bar : ",
+y = bar.intBar_fromBase(x)
+if y:
+ print "good swig"
+else:
+ print "bad swig"
+
+print " Spam -> Base -> Spam : ",
+y = spam.intSpam_fromBase(x)
+if y:
+ print "good swig"
+else:
+ print "bad swig"
+
+print " Foo -> Spam : ",
+y = spam.intSpam_fromBase(b)
+if y:
+ print "bad swig"
+else:
+ print "good swig"
+
+
+
+
diff --git a/Examples/python/import_template/spam.h b/Examples/python/import_template/spam.h
new file mode 100644
index 0000000..c72f49a
--- /dev/null
+++ b/Examples/python/import_template/spam.h
@@ -0,0 +1,24 @@
+#include "bar.h"
+
+template<class T> class Spam : public Bar<T> {
+ public:
+ Spam() { }
+ ~Spam() { }
+ virtual void A() {
+ printf("I'm Spam::A\n");
+ }
+ void B() {
+ printf("I'm Spam::B\n");
+ }
+ virtual Base<T> *toBase() {
+ return static_cast<Base<T> *>(this);
+ }
+ virtual Bar<T> *toBar() {
+ return static_cast<Bar<T> *>(this);
+ }
+ static Spam<T> *fromBase(Base<T> *b) {
+ return dynamic_cast<Spam<T> *>(b);
+ }
+};
+
+
diff --git a/Examples/python/import_template/spam.i b/Examples/python/import_template/spam.i
new file mode 100644
index 0000000..dd94b03
--- /dev/null
+++ b/Examples/python/import_template/spam.i
@@ -0,0 +1,10 @@
+%module spam
+%{
+#include "spam.h"
+%}
+
+%import bar.i
+%include "spam.h"
+
+%template(intSpam) Spam<int>;
+
diff --git a/Examples/python/index.html b/Examples/python/index.html
new file mode 100644
index 0000000..8443a85
--- /dev/null
+++ b/Examples/python/index.html
@@ -0,0 +1,112 @@
+<html>
+<head>
+<title>SWIG:Examples:python</title>
+</head>
+
+<body bgcolor="#ffffff">
+<H1>SWIG Python Examples</H1>
+
+<p>
+The following examples illustrate the use of SWIG with Python.
+
+<ul>
+<li><a href="simple/index.html">simple</a>. A minimal example showing how SWIG can
+be used to wrap a C function, a global variable, and a constant.
+<li><a href="constants/index.html">constants</a>. This shows how preprocessor macros and
+certain C declarations are turned into constants.
+<li><a href="variables/index.html">variables</a>. An example showing how to access C global variables from Python.
+<li><a href="value/index.html">value</a>. How to pass and return structures by value.
+<li><a href="class/index.html">class</a>. Wrapping a simple C++ class.
+<li><a href="reference/index.html">reference</a>. C++ references.
+<li><a href="pointer/index.html">pointer</a>. Simple pointer handling.
+<li><a href="funcptr/index.html">funcptr</a>. Pointers to functions.
+</ul>
+
+<h2>Compilation Issues</h2>
+
+<ul>
+<li>To create a Python extension, SWIG is run with the following options:
+
+<blockquote>
+<pre>
+% swig -python interface.i
+</pre>
+</blockquote>
+
+<li>
+Please see the <a href="../../Doc/Manual/Windows.html">Windows</a> page in the main manual for information on using the examples on Windows. <p>
+</li>
+
+<li>On Unix the compilation of examples is done using the file <tt>Example/Makefile</tt>. This
+makefile performs a manual module compilation which is platform specific. Typically,
+the steps look like this (Linux):
+
+<blockquote>
+<pre>
+% swig -python interface.i
+% gcc -fpic -c interface_wrap.c -I/usr/local/include/python1.5
+% gcc -shared interface_wrap.o $(OBJS) -o interfacemodule.so
+% python
+Python 1.5.2 (#3, Oct 9 1999, 22:09:34) [GCC 2.95.1 19990816 (release)] on linux2
+Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
+&gt;&gt;&gt; import interface
+&gt;&gt;&gt; interface.blah(...)
+...
+</pre>
+</blockquote>
+
+<li>The politically "correct" way to compile a Python extension is to follow the steps
+described at <a href="http://www.python.org/doc/current/ext/building-on-unix.html">www.python.org</a>
+or in the most excellent (and shamelessly plugged) <a href="http://islab.cs.uchicago.edu/python">Python Essential Reference</a>:
+
+<p>
+<ol>
+<li>Create a file called <tt>Setup</tt> that looks like the following where $(SRCS) is filled
+in with any other source files you need to build the extension:
+
+<blockquote>
+<pre>
+*shared*
+interface interface_wrap.c $(SRCS)
+</pre>
+</blockquote>
+<li>Copy the file <tt>Makefile.pre.in</tt> from the Python distribution. Usually it's located
+in the directory <tt>/usr/local/lib/python1.5/config</tt> on a Unix machine.
+
+<p>
+<li>Type the following to build the extension:
+
+<blockquote>
+<pre>
+% make -f Makefile.pre.in boot
+% make
+</pre>
+</blockquote>
+<li> And that's it. If you are preparing an extension for distribution, you may want
+to look at the <a href="http://www.python.org/sigs/distutils-sig/">distutils</a>.
+</ol>
+</ul>
+
+<h2>Compatibility</h2>
+
+The examples have been extensively tested on the following platforms:
+
+<ul>
+<li>Linux
+<li>Solaris
+</ul>
+
+All of the examples were last tested with the following configuration (9/1/2000):
+
+<ul>
+<li>Sparc Solaris 2.8.
+<li>gcc-2.95.2
+<li>Python 1.6b1.
+</ul>
+
+Your mileage may vary. If you experience a problem, please let us know by
+contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
+</body>
+</html>
+
+
diff --git a/Examples/python/java/Example.java b/Examples/python/java/Example.java
new file mode 100644
index 0000000..91ddb1a
--- /dev/null
+++ b/Examples/python/java/Example.java
@@ -0,0 +1,29 @@
+public class Example {
+ public int mPublicInt;
+
+ public Example() {
+ mPublicInt = 0;
+ }
+
+ public Example(int IntVal) {
+ mPublicInt = IntVal;
+ }
+
+
+ public int Add(int a, int b) {
+ return (a+b);
+ }
+
+ public float Add(float a, float b) {
+ return (a+b);
+ }
+
+ public String Add(String a, String b) {
+ return (a+b);
+ }
+
+ public Example Add(Example a, Example b) {
+ return new Example(a.mPublicInt + b.mPublicInt);
+ }
+}
+
diff --git a/Examples/python/java/Makefile b/Examples/python/java/Makefile
new file mode 100644
index 0000000..326a4da
--- /dev/null
+++ b/Examples/python/java/Makefile
@@ -0,0 +1,25 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+
+all:: Example.class
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXX="gcj" \
+ CXXSHARED="gcj -fpic -shared Example.class" DEFS='' LIBS="-lstdc++" python_cpp
+
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+ rm -f *.class Example.h
+
+check: all
+
+
+Example.class: Example.java
+ gcj -fPIC -C -c -g Example.java
+ gcjh Example
+
diff --git a/Examples/python/java/example.i b/Examples/python/java/example.i
new file mode 100644
index 0000000..13d5b5e
--- /dev/null
+++ b/Examples/python/java/example.i
@@ -0,0 +1,9 @@
+%module example
+%include <cni.i>
+
+%{
+#include "Example.h"
+%}
+
+
+%include Example.h
diff --git a/Examples/python/java/runme.py b/Examples/python/java/runme.py
new file mode 100644
index 0000000..0cec8a7
--- /dev/null
+++ b/Examples/python/java/runme.py
@@ -0,0 +1,16 @@
+from example import *
+
+JvCreateJavaVM(None)
+JvAttachCurrentThread(None, None)
+
+e1 = Example(1)
+e2 = Example(2)
+
+print e1.Add(1,2)
+print e1.Add(1.0,2.0)
+e3 = e1.Add(e1,e2)
+print e3.mPublicInt
+
+print e1.Add("1","2")
+
+JvDetachCurrentThread()
diff --git a/Examples/python/libffi/Makefile b/Examples/python/libffi/Makefile
new file mode 100644
index 0000000..fafb7de
--- /dev/null
+++ b/Examples/python/libffi/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+TARGET = example
+INTERFACE = example.i
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' LIBS='-L/usr/local/lib -lffi' python
+
+static::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/libffi/example.i b/Examples/python/libffi/example.i
new file mode 100644
index 0000000..9a29ec0
--- /dev/null
+++ b/Examples/python/libffi/example.i
@@ -0,0 +1,176 @@
+/* File : example.i */
+%module example
+
+%{
+#include <unistd.h>
+#include <ffi.h>
+%}
+
+/* A wrapper for execlp() using libffi to handle an arbitrary
+ number of arguments */
+
+%typemap(in) (...) {
+ char **argv;
+ int argc;
+ int i;
+
+ argc = PyTuple_Size(varargs);
+ argv = (char **) malloc(sizeof(char *)*(argc+1));
+ for (i = 0; i < argc; i++) {
+ PyObject *o = PyTuple_GetItem(varargs,i);
+ if (!PyString_Check(o)) {
+ PyErr_SetString(PyExc_ValueError,"Expected a string");
+ return NULL;
+ }
+ argv[i] = PyString_AsString(o);
+ }
+ argv[i] = NULL;
+ $1 = (void *) argv;
+}
+
+/* Rewrite the function call, using libffi */
+%feature("action") execlp {
+ int i, vc;
+ ffi_cif cif;
+ ffi_type **types;
+ void **values;
+ char **args;
+
+ vc = PyTuple_Size(varargs);
+ types = (ffi_type **) malloc((vc+3)*sizeof(ffi_type *));
+ values = (void **) malloc((vc+3)*sizeof(void *));
+ args = (char **) arg3;
+
+ /* Set up path parameter */
+ types[0] = &ffi_type_pointer;
+ values[0] = &arg1;
+
+ /* Set up first argument */
+ types[1] = &ffi_type_pointer;
+ values[1] = &arg2;
+
+ /* Set up rest of parameters */
+ for (i = 0; i <= vc; i++) {
+ types[2+i] = &ffi_type_pointer;
+ values[2+i] = &args[i];
+ }
+ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, vc+3,
+ &ffi_type_uint, types) == FFI_OK) {
+ ffi_call(&cif, (void (*)()) execlp, &result, values);
+ } else {
+ PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
+ free(types);
+ free(values);
+ free(arg3);
+ return NULL;
+ }
+ free(types);
+ free(values);
+ free(arg3);
+}
+
+int execlp(const char *path, const char *arg1, ...);
+
+
+/* A wrapper for printf() using libffi */
+
+%{
+ typedef struct {
+ int type;
+ union {
+ int ivalue;
+ double dvalue;
+ void *pvalue;
+ } val;
+ } vtype;
+ enum { VT_INT, VT_DOUBLE, VT_POINTER };
+ %}
+
+%typemap(in) (const char *fmt, ...) {
+ vtype *argv;
+ int argc;
+ int i;
+
+ $1 = PyString_AsString($input);
+
+ argc = PyTuple_Size(varargs);
+ argv = (vtype *) malloc(argc*sizeof(vtype));
+ for (i = 0; i < argc; i++) {
+ PyObject *o = PyTuple_GetItem(varargs,i);
+ if (PyInt_Check(o)) {
+ argv[i].type = VT_INT;
+ argv[i].val.ivalue = PyInt_AsLong(o);
+ } else if (PyFloat_Check(o)) {
+ argv[i].type = VT_DOUBLE;
+ argv[i].val.dvalue = PyFloat_AsDouble(o);
+ } else if (PyString_Check(o)) {
+ argv[i].type = VT_POINTER;
+ argv[i].val.pvalue = (void *) PyString_AsString(o);
+ } else {
+ PyErr_SetString(PyExc_ValueError,"Unsupported argument type");
+ free(argv);
+ return NULL;
+ }
+ }
+
+ $2 = (void *) argv;
+}
+
+/* Rewrite the function call, using libffi */
+%feature("action") printf {
+ int i, vc;
+ ffi_cif cif;
+ ffi_type **types;
+ void **values;
+ vtype *args;
+
+ vc = PyTuple_Size(varargs);
+ types = (ffi_type **) malloc((vc+1)*sizeof(ffi_type *));
+ values = (void **) malloc((vc+1)*sizeof(void *));
+ args = (vtype *) arg2;
+
+ /* Set up fmt parameter */
+ types[0] = &ffi_type_pointer;
+ values[0] = &arg1;
+
+ /* Set up rest of parameters */
+ for (i = 0; i < vc; i++) {
+ switch(args[i].type) {
+ case VT_INT:
+ types[1+i] = &ffi_type_uint;
+ values[1+i] = &args[i].val.ivalue;
+ break;
+ case VT_DOUBLE:
+ types[1+i] = &ffi_type_double;
+ values[1+i] = &args[i].val.dvalue;
+ break;
+ case VT_POINTER:
+ types[1+i] = &ffi_type_pointer;
+ values[1+i] = &args[i].val.pvalue;
+ break;
+ default:
+ abort(); /* Whoa! We're seriously hosed */
+ break;
+ }
+ }
+ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, vc+1,
+ &ffi_type_uint, types) == FFI_OK) {
+ ffi_call(&cif, (void (*)()) printf, &result, values);
+ } else {
+ PyErr_SetString(PyExc_RuntimeError, "Whoa!!!!!");
+ free(types);
+ free(values);
+ free(args);
+ return NULL;
+ }
+ free(types);
+ free(values);
+ free(args);
+}
+
+int printf(const char *fmt, ...);
+
+
+
+
+
diff --git a/Examples/python/multimap/Makefile b/Examples/python/multimap/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/multimap/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/multimap/example.c b/Examples/python/multimap/example.c
new file mode 100644
index 0000000..b8360fa
--- /dev/null
+++ b/Examples/python/multimap/example.c
@@ -0,0 +1,53 @@
+/* File : example.c */
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+int gcdmain(int argc, char *argv[]) {
+ int x,y;
+ if (argc != 3) {
+ printf("usage: gcd x y\n");
+ return -1;
+ }
+ x = atoi(argv[1]);
+ y = atoi(argv[2]);
+ printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
+ return 0;
+}
+
+int count(char *bytes, int len, char c) {
+ int i;
+ int count = 0;
+ for (i = 0; i < len; i++) {
+ if (bytes[i] == c) count++;
+ }
+ return count;
+}
+
+void capitalize(char *str, int len) {
+ int i;
+ for (i = 0; i < len; i++) {
+ str[i] = (char)toupper(str[i]);
+ }
+}
+
+void circle(double x, double y) {
+ double a = x*x + y*y;
+ if (a > 1.0) {
+ printf("Bad points %g, %g\n", x,y);
+ } else {
+ printf("Good points %g, %g\n", x,y);
+ }
+}
diff --git a/Examples/python/multimap/example.dsp b/Examples/python/multimap/example.dsp
new file mode 100644
index 0000000..32845e0
--- /dev/null
+++ b/Examples/python/multimap/example.dsp
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=example - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "example - Win32 Debug"
+# Name "example - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\example.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\example_wrap.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\example.i
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/multimap/example.i b/Examples/python/multimap/example.i
new file mode 100644
index 0000000..f1c4d99
--- /dev/null
+++ b/Examples/python/multimap/example.i
@@ -0,0 +1,121 @@
+/* File : example.i */
+%module example
+
+%{
+extern int gcd(int x, int y);
+extern int gcdmain(int argc, char *argv[]);
+extern int count(char *bytes, int len, char c);
+extern void capitalize (char *str, int len);
+extern void circle (double cx, double cy);
+extern int squareCubed (int n, int *OUTPUT);
+%}
+
+%include exception.i
+%include typemaps.i
+
+extern int gcd(int x, int y);
+
+%typemap(in,fragment="t_output_helper") (int argc, char *argv[]) {
+ int i;
+ if (!PyList_Check($input)) {
+ SWIG_exception(SWIG_ValueError, "Expecting a list");
+ }
+ $1 = PyList_Size($input);
+ if ($1 == 0) {
+ SWIG_exception(SWIG_ValueError, "List must contain at least 1 element");
+ }
+ $2 = (char **) malloc(($1+1)*sizeof(char *));
+ for (i = 0; i < $1; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+%#if PY_VERSION_HEX >= 0x03000000
+ if (!PyUnicode_Check(s))
+%#else
+ if (!PyString_Check(s))
+%#endif
+ {
+ free($2);
+ SWIG_exception(SWIG_ValueError, "List items must be strings");
+ }
+%#if PY_VERSION_HEX >= 0x03000000
+ {
+ int l;
+ $2[i] = PyUnicode_AsStringAndSize(s, &l);
+ }
+%#else
+ $2[i] = PyString_AsString(s);
+%#endif
+
+ }
+ $2[i] = 0;
+}
+
+extern int gcdmain(int argc, char *argv[]);
+
+%typemap(in) (char *bytes, int len) {
+
+%#if PY_VERSION_HEX >= 0x03000000
+ if (!PyUnicode_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"Expected a string");
+ return NULL;
+ }
+ $1 = PyUnicode_AsStringAndSize($input, &$2);
+%#else
+ if (!PyString_Check($input)) {
+ PyErr_SetString(PyExc_ValueError,"Expected a string");
+ return NULL;
+ }
+ $1 = PyString_AsString($input);
+ $2 = PyString_Size($input);
+%#endif
+}
+
+extern int count(char *bytes, int len, char c);
+
+
+/* This example shows how to wrap a function that mutates a string */
+
+/* Since str is modified, we make a copy of the Python object
+ so that we don't violate it's mutability */
+
+%typemap(in) (char *str, int len) {
+%#if PY_VERSION_HEX >= 0x03000000
+ $2 = PyUnicode_GetSize($input);
+ $1 = (char *) malloc($2+1);
+ memmove($1,PyUnicode_AsString($input),$2);
+%#else
+ $2 = PyString_Size($input);
+ $1 = (char *) malloc($2+1);
+ memmove($1,PyString_AsString($input),$2);
+%#endif
+}
+
+/* Return the mutated string as a new object. The t_output_helper
+ function takes an object and appends it to the output object
+ to create a tuple */
+
+%typemap(argout) (char *str, int len) {
+ PyObject *o;
+%#if PY_VERSION_HEX >= 0x03000000
+ o = PyUnicode_FromStringAndSize($1,$2);
+%#else
+ o = PyString_FromStringAndSize($1,$2);
+%#endif
+ $result = t_output_helper($result,o);
+ free($1);
+}
+
+extern void capitalize(char *str, int len);
+
+/* A multi-valued constraint. Force two arguments to lie
+ inside the unit circle */
+
+%typemap(check) (double cx, double cy) {
+ double a = $1*$1 + $2*$2;
+ if (a > 1.0) {
+ SWIG_exception(SWIG_ValueError,"$1_name and $2_name must be in unit circle");
+ }
+}
+
+extern void circle(double cx, double cy);
+
+
diff --git a/Examples/python/multimap/runme.py b/Examples/python/multimap/runme.py
new file mode 100644
index 0000000..f996ab3
--- /dev/null
+++ b/Examples/python/multimap/runme.py
@@ -0,0 +1,27 @@
+# file: runme.py
+
+import example
+
+# Call our gcd() function
+
+x = 42
+y = 105
+g = example.gcd(x,y)
+print "The gcd of %d and %d is %d" % (x,y,g)
+
+# Call the gcdmain() function
+example.gcdmain(["gcdmain","42","105"])
+
+# Call the count function
+print example.count("Hello World", "l")
+
+# Call the capitalize function
+
+print example.capitalize("hello world")
+
+
+
+
+
+
+
diff --git a/Examples/python/operator/Makefile b/Examples/python/operator/Makefile
new file mode 100644
index 0000000..fe38975
--- /dev/null
+++ b/Examples/python/operator/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/operator/example.h b/Examples/python/operator/example.h
new file mode 100644
index 0000000..4da6a23
--- /dev/null
+++ b/Examples/python/operator/example.h
@@ -0,0 +1,36 @@
+/* File : example.h */
+#include <math.h>
+
+class Complex {
+private:
+ double rpart, ipart;
+public:
+ Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
+ Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
+ Complex &operator=(const Complex &c) {
+ rpart = c.rpart;
+ ipart = c.ipart;
+ return *this;
+ }
+ Complex operator+(const Complex &c) const {
+ return Complex(rpart+c.rpart, ipart+c.ipart);
+ }
+ Complex operator-(const Complex &c) const {
+ return Complex(rpart-c.rpart, ipart-c.ipart);
+ }
+ Complex operator*(const Complex &c) const {
+ return Complex(rpart*c.rpart - ipart*c.ipart,
+ rpart*c.ipart + c.rpart*ipart);
+ }
+ Complex operator-() const {
+ return Complex(-rpart, -ipart);
+ }
+
+ double re() const { return rpart; }
+ double im() const { return ipart; }
+};
+
+
+
+
+
diff --git a/Examples/python/operator/example.i b/Examples/python/operator/example.i
new file mode 100644
index 0000000..e37e76b
--- /dev/null
+++ b/Examples/python/operator/example.i
@@ -0,0 +1,28 @@
+/* File : example.i */
+%module example
+#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
+%{
+#include "example.h"
+%}
+
+/* This header file is a little tough to handle because it has overloaded
+ operators and constructors. We're going to try and deal with that here */
+
+/* This turns the copy constructor in a function ComplexCopy() that can
+ be called */
+
+%rename(ComplexCopy) Complex::Complex(Complex const &);
+
+/* Now grab the original header file */
+%include "example.h"
+
+/* An output method that turns a complex into a short string */
+%extend Complex {
+ char *__str__() {
+ static char temp[512];
+ sprintf(temp,"(%g,%g)", $self->re(), $self->im());
+ return temp;
+ }
+};
+
+
diff --git a/Examples/python/operator/runme.py b/Examples/python/operator/runme.py
new file mode 100644
index 0000000..3687a38
--- /dev/null
+++ b/Examples/python/operator/runme.py
@@ -0,0 +1,21 @@
+# Operator overloading example
+import example
+
+a = example.Complex(2,3)
+b = example.Complex(-5,10)
+
+print "a =",a
+print "b =",b
+
+c = a + b
+print "c =",c
+print "a*b =",a*b
+print "a-c =",a-c
+
+e = example.ComplexCopy(a-c)
+print "e =",e
+
+# Big expression
+f = ((a+b)*(c+b*e)) + (-a)
+print "f =",f
+
diff --git a/Examples/python/pointer/Makefile b/Examples/python/pointer/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/pointer/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/pointer/example.c b/Examples/python/pointer/example.c
new file mode 100644
index 0000000..b877d9a
--- /dev/null
+++ b/Examples/python/pointer/example.c
@@ -0,0 +1,16 @@
+/* File : example.c */
+
+void add(int *x, int *y, int *result) {
+ *result = *x + *y;
+}
+
+void sub(int *x, int *y, int *result) {
+ *result = *x - *y;
+}
+
+int divide(int n, int d, int *r) {
+ int q;
+ q = n/d;
+ *r = n - q*d;
+ return q;
+}
diff --git a/Examples/python/pointer/example.i b/Examples/python/pointer/example.i
new file mode 100644
index 0000000..a8ac794
--- /dev/null
+++ b/Examples/python/pointer/example.i
@@ -0,0 +1,30 @@
+/* File : example.i */
+%module example
+
+%{
+extern void add(int *, int *, int *);
+extern void sub(int *, int *, int *);
+extern int divide(int, int, int *);
+%}
+
+/* This example illustrates a couple of different techniques
+ for manipulating C pointers */
+
+/* First we'll use the pointer library */
+extern void add(int *x, int *y, int *result);
+%include cpointer.i
+%pointer_functions(int, intp);
+
+/* Next we'll use some typemaps */
+
+%include typemaps.i
+extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
+
+/* Next we'll use typemaps and the %apply directive */
+
+%apply int *OUTPUT { int *r };
+extern int divide(int n, int d, int *r);
+
+
+
+
diff --git a/Examples/python/pointer/index.html b/Examples/python/pointer/index.html
new file mode 100644
index 0000000..ceef305
--- /dev/null
+++ b/Examples/python/pointer/index.html
@@ -0,0 +1,171 @@
+<html>
+<head>
+<title>SWIG:Examples:python:pointer</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+<tt>SWIG/Examples/python/pointer/</tt>
+<hr>
+
+<H2>Simple Pointer Handling</H2>
+
+<p>
+This example illustrates a couple of techniques for handling
+simple pointers in SWIG. The prototypical example is a C function
+that operates on pointers such as this:
+
+<blockquote>
+<pre>
+void add(int *x, int *y, int *r) {
+ *r = *x + *y;
+}
+</pre>
+</blockquote>
+
+By default, SWIG wraps this function exactly as specified and creates
+an interface that expects pointer objects for arguments. The only
+problem is how does one go about creating these objects from a script?
+
+<h2>Possible Solutions</h2>
+
+<ul>
+<li>Write some helper functions to explicitly create objects. For
+example:
+
+<blockquote>
+<pre>
+int *new_int(int ivalue) {
+ int *i = (int *) malloc(sizeof(ivalue));
+ *i = ivalue;
+ return i;
+}
+int get_int(int *i) {
+ return *i;
+}
+
+void delete_int(int *i) {
+ free(i);
+}
+</pre>
+</blockquote>
+
+Now, in a script you would do this:
+
+<blockquote>
+<pre>
+a = new_int(37)
+b = new_int(42)
+c = new_int(0)
+add(a,b,c)
+r = get_int(c);
+print "Result =",r
+delete_int(a)
+delete_int(b)
+delete_int(c)
+</pre>
+</blockquote>
+
+<p>
+<li>Use the SWIG pointer library. For example, in the interface file
+you would do this:
+
+<blockquote>
+<pre>
+%include "pointer.i"
+</pre>
+</blockquote?
+
+and in a script you would do this:
+
+<blockquote>
+<pre>
+a = ptrcreate("int",37)
+b = ptrcreate("int",42)
+c = ptrcreate("int")
+add(a,b,c)
+r = ptrvalue(c)
+print "Result =",r
+ptrfree(a)
+ptrfree(b)
+ptrfree(c)
+</pre>
+</blockquote>
+
+The advantage to using the pointer library is that it unifies some of the helper
+functions behind a common set of names. For example, the same set of functions work
+with int, double, float, and other fundamental types.
+
+<p>
+<li>Use the SWIG typemap library. This library allows you to completely
+change the way arguments are processed by SWIG. For example:
+
+<blockquote>
+<pre>
+%include "typemaps.i"
+void add(int *INPUT, int *INPUT, int *OUTPUT);
+</pre>
+</blockquote>
+
+And in a script:
+
+<blockquote>
+<pre>
+r = add(37,42)
+print "Result =",r
+</pre>
+</blockquote>
+Needless to say, this is substantially easier.
+
+<p>
+<li>A final alternative is to use the typemaps library in combination
+with the %apply directive. This allows you to change the names of parameters
+that behave as input or output parameters. For example:
+
+<blockquote>
+<pre>
+%include "typemaps.i"
+%apply int *INPUT {int *x, int *y};
+%apply int *OUTPUT {int *r};
+
+void add(int *x, int *y, int *r);
+void sub(int *x, int *y, int *r);
+void mul(int *x, int *y, int *r);
+... etc ...
+</pre>
+</blockquote>
+
+</ul>
+
+<h2>Example</h2>
+
+The following example illustrates the use of these features for pointer
+extraction.
+
+<ul>
+<li> <a href="example.c">example.c</a> (C Source)
+<li> <a href="example.i">example.i</a> (Swig interface)
+<li> <a href="example.py">example.py</a> (Python Script)
+</ul>
+
+<h2>Notes</h2>
+
+<ul>
+<li>Since pointers are used for so many different things (arrays, output values,
+etc...) the complexity of pointer handling can be as complicated as you want to
+make it.
+
+<p>
+<li>More documentation on the typemaps.i and pointer.i library files can be
+found in the SWIG user manual. The files also contain documentation.
+
+<p>
+<li>The pointer.i library is designed primarily for convenience. If you
+are concerned about performance, you probably want to use a different
+approach.
+
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/pointer/runme.py b/Examples/python/pointer/runme.py
new file mode 100644
index 0000000..e38a306
--- /dev/null
+++ b/Examples/python/pointer/runme.py
@@ -0,0 +1,44 @@
+# file: runme.py
+
+import example;
+
+# First create some objects using the pointer library.
+print "Testing the pointer library";
+a = example.new_intp();
+b = example.new_intp();
+c = example.new_intp();
+example.intp_assign(a,37);
+example.intp_assign(b,42);
+
+print " a =",a
+print " b =",b
+print " c =",c
+
+# Call the add() function with some pointers
+example.add(a,b,c)
+
+# Now get the result
+r = example.intp_value(c)
+print " 37 + 42 =",r
+
+# Clean up the pointers
+example.delete_intp(a)
+example.delete_intp(b)
+example.delete_intp(c)
+
+# Now try the typemap library
+# This should be much easier. Now how it is no longer
+# necessary to manufacture pointers.
+
+print "Trying the typemap library";
+r = example.sub(37,42)
+print " 37 - 42 =",r
+
+# Now try the version with multiple return values
+
+print "Testing multiple return values";
+q,r = example.divide(42,37)
+print " 42/37 = %d remainder %d" % (q,r)
+
+
+
diff --git a/Examples/python/reference/Makefile b/Examples/python/reference/Makefile
new file mode 100644
index 0000000..74625b9
--- /dev/null
+++ b/Examples/python/reference/Makefile
@@ -0,0 +1,21 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/reference/example.cxx b/Examples/python/reference/example.cxx
new file mode 100644
index 0000000..8a513bf
--- /dev/null
+++ b/Examples/python/reference/example.cxx
@@ -0,0 +1,46 @@
+/* File : example.cxx */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include "example.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+Vector operator+(const Vector &a, const Vector &b) {
+ Vector r;
+ r.x = a.x + b.x;
+ r.y = a.y + b.y;
+ r.z = a.z + b.z;
+ return r;
+}
+
+char *Vector::print() {
+ static char temp[512];
+ sprintf(temp,"Vector %p (%g,%g,%g)", this, x,y,z);
+ return temp;
+}
+
+VectorArray::VectorArray(int size) {
+ items = new Vector[size];
+ maxsize = size;
+}
+
+VectorArray::~VectorArray() {
+ delete [] items;
+}
+
+Vector &VectorArray::operator[](int index) {
+ if ((index < 0) || (index >= maxsize)) {
+ printf("Panic! Array index out of bounds.\n");
+ exit(1);
+ }
+ return items[index];
+}
+
+int VectorArray::size() {
+ return maxsize;
+}
+
diff --git a/Examples/python/reference/example.h b/Examples/python/reference/example.h
new file mode 100644
index 0000000..4915adb
--- /dev/null
+++ b/Examples/python/reference/example.h
@@ -0,0 +1,26 @@
+/* File : example.h */
+
+class Vector {
+private:
+ double x,y,z;
+public:
+ Vector() : x(0), y(0), z(0) { };
+ Vector(double x, double y, double z) : x(x), y(y), z(z) { };
+ friend Vector operator+(const Vector &a, const Vector &b);
+ char *print();
+};
+
+class VectorArray {
+private:
+ Vector *items;
+ int maxsize;
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ Vector &operator[](int);
+ int size();
+};
+
+
+
+
diff --git a/Examples/python/reference/example.i b/Examples/python/reference/example.i
new file mode 100644
index 0000000..8c95b32
--- /dev/null
+++ b/Examples/python/reference/example.i
@@ -0,0 +1,48 @@
+/* File : example.i */
+
+/* This file has a few "typical" uses of C++ references. */
+
+%module example
+
+%{
+#include "example.h"
+%}
+
+%rename(cprint) print;
+
+class Vector {
+public:
+ Vector(double x, double y, double z);
+ ~Vector();
+ char *print();
+};
+
+/* This helper function calls an overloaded operator */
+%inline %{
+Vector addv(Vector &a, Vector &b) {
+ return a+b;
+}
+%}
+
+/* Wrapper around an array of vectors class */
+
+class VectorArray {
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ int size();
+
+ /* This wrapper provides an alternative to the [] operator */
+ %extend {
+ Vector &get(int index) {
+ return (*$self)[index];
+ }
+ void set(int index, Vector &a) {
+ (*$self)[index] = a;
+ }
+ }
+};
+
+
+
+
diff --git a/Examples/python/reference/index.html b/Examples/python/reference/index.html
new file mode 100644
index 0000000..25d4029
--- /dev/null
+++ b/Examples/python/reference/index.html
@@ -0,0 +1,147 @@
+<html>
+<head>
+<title>SWIG:Examples:python:reference</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/reference/</tt>
+<hr>
+
+<H2>C++ Reference Handling</H2>
+
+<p>
+This example tests SWIG's handling of C++ references. Since C++
+references are closely related to pointers (as both refer to a
+location in memory), SWIG simply collapses all references into
+pointers when creating wrappers.
+
+<h2>Some examples</h2>
+
+References are most commonly used as function parameter. For example,
+you might have an operator like this:
+
+<blockquote>
+<pre>
+Vector operator+(const Vector &amp;a, const Vector &amp;b) {
+ Vector result;
+ result.x = a.x + b.x;
+ result.y = a.y + b.y;
+ result.z = a.z + b.z;
+ return result;
+}
+</pre>
+</blockquote>
+
+or a function:
+
+<blockquote>
+<pre>
+Vector addv(const Vector &amp;a, const Vector &amp;b) {
+ Vector result;
+ result.x = a.x + b.x;
+ result.y = a.y + b.y;
+ result.z = a.z + b.z;
+ return result;
+}
+</pre>
+</blockquote>
+
+In these cases, SWIG transforms everything into a pointer and creates a wrapper
+that looks like this:
+
+<blockquote>
+<pre>
+Vector wrap_addv(Vector *a, Vector *b) {
+ return addv(*a,*b);
+}
+</pre>
+</blockquote>
+
+Occasionally, a reference is used as a return value of a function
+when the return result is to be used as an lvalue in an expression.
+The prototypical example is an operator like this:
+
+<blockquote>
+<pre>
+Vector &amp;operator[](int index);
+</pre>
+</blockquote>
+
+or a method:
+
+<blockquote>
+<pre>
+Vector &amp;get(int index);
+</pre>
+</blockquote>
+
+For functions returning references, a wrapper like this is created:
+
+<blockquote>
+<pre>
+Vector *wrap_Object_get(Object *self, int index) {
+ Vector &amp;result = self-&gt;get(index);
+ return &amp;result;
+}
+</pre>
+</blockquote>
+
+The following <a href="example.h">header file</a> contains some class
+definitions with some operators and use of references.
+
+<h2>SWIG Interface</h2>
+
+SWIG does NOT support overloaded operators so it can not directly build
+an interface to the classes in the above file. However, a number of workarounds
+can be made. For example, an overloaded operator can be stuck behind a function
+call such as the <tt>addv()</tt> function above. Array access can be handled
+with a pair of set/get functions like this:
+
+<blockquote>
+<pre>
+class VectorArray {
+public:
+ ...
+ %addmethods {
+ Vector &amp;get(int index) {
+ return (*self)[index];
+ }
+ void set(int index, Vector &amp;a) {
+ (*self)[index] = a;
+ }
+ }
+ ...
+}
+</pre>
+</blockquote>
+
+Click <a href="example.i">here</a> to see a SWIG interface file with these additions.
+
+<h2>Sample Python script</h2>
+
+Click <a href="example.py">here</a> to see a script that manipulates some C++ references.
+
+<h2>Notes:</h2>
+
+<ul>
+<li>C++ references primarily provide notational convenience for C++
+source code. However, Python only supports the 'x.a'
+notation so it doesn't much matter.
+
+<p>
+<li>When a program returns a reference, a pointer is returned.
+Unlike return by value, memory is not allocated to hold the
+return result.
+
+<p>
+<li>SWIG has particular trouble handling various combinations of references
+and pointers. This is side effect of an old parsing scheme and
+type representation that will be replaced in future versions.
+
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/reference/runme.py b/Examples/python/reference/runme.py
new file mode 100644
index 0000000..a1f5336
--- /dev/null
+++ b/Examples/python/reference/runme.py
@@ -0,0 +1,63 @@
+# file: runme.py
+
+# This file illustrates the manipulation of C++ references in Python
+
+import example
+
+# ----- Object creation -----
+
+print "Creating some objects:"
+a = example.Vector(3,4,5)
+b = example.Vector(10,11,12)
+
+print " Created",a.cprint()
+print " Created",b.cprint()
+
+# ----- Call an overloaded operator -----
+
+# This calls the wrapper we placed around
+#
+# operator+(const Vector &a, const Vector &)
+#
+# It returns a new allocated object.
+
+print "Adding a+b"
+c = example.addv(a,b)
+print " a+b =", c.cprint()
+
+# Note: Unless we free the result, a memory leak will occur
+del c
+
+# ----- Create a vector array -----
+
+# Note: Using the high-level interface here
+print "Creating an array of vectors"
+va = example.VectorArray(10)
+print " va = ",va
+
+# ----- Set some values in the array -----
+
+# These operators copy the value of $a and $b to the vector array
+va.set(0,a)
+va.set(1,b)
+
+va.set(2,example.addv(a,b))
+
+# Get some values from the array
+
+print "Getting some array values"
+for i in range(0,5):
+ print " va(%d) = %s" % (i, va.get(i).cprint())
+
+# Watch under resource meter to check on this
+print "Making sure we don't leak memory."
+for i in xrange(0,1000000):
+ c = va.get(i % 10)
+
+# ----- Clean up -----
+print "Cleaning up"
+
+del va
+del a
+del b
+
diff --git a/Examples/python/simple/Makefile b/Examples/python/simple/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/simple/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/simple/example.c b/Examples/python/simple/example.c
new file mode 100644
index 0000000..1c2af78
--- /dev/null
+++ b/Examples/python/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/python/simple/example.dsp b/Examples/python/simple/example.dsp
new file mode 100644
index 0000000..32845e0
--- /dev/null
+++ b/Examples/python/simple/example.dsp
@@ -0,0 +1,148 @@
+# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=example - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.pyd" /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(PYTHON_INCLUDE)" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.pyd"
+
+!ENDIF
+
+# Begin Target
+
+# Name "example - Win32 Debug"
+# Name "example - Win32 Release"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\example.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\example_wrap.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# Begin Source File
+
+SOURCE=.\example.i
+
+!IF "$(CFG)" == "example - Win32 Debug"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "example - Win32 Release"
+
+# Begin Custom Build
+InputPath=.\example.i
+InputName=example
+
+"$(InputName)_wrap.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ echo In order to function correctly, please ensure the following environment variables are correctly set:
+ echo PYTHON_INCLUDE: %PYTHON_INCLUDE%
+ echo PYTHON_LIB: %PYTHON_LIB%
+ echo on
+ ..\..\..\swig.exe -python $(InputPath)
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/Examples/python/simple/example.i b/Examples/python/simple/example.i
new file mode 100644
index 0000000..24093b9
--- /dev/null
+++ b/Examples/python/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/python/simple/index.html b/Examples/python/simple/index.html
new file mode 100644
index 0000000..dace471
--- /dev/null
+++ b/Examples/python/simple/index.html
@@ -0,0 +1,97 @@
+<html>
+<head>
+<title>SWIG:Examples:python:simple</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/python/simple/</tt>
+<hr>
+
+<H2>Simple Python Example</H2>
+
+<p>
+This example illustrates how you can hook Python to a very simple C program containing
+a function and a global variable.
+
+<h2>The C Code</h2>
+
+Suppose you have the following C code:
+
+<blockquote>
+<pre>
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x &gt; 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+</pre>
+</blockquote>
+
+<h2>The SWIG interface</h2>
+
+Here is a simple SWIG interface file:
+
+<blockquote>
+<pre>
+/* File: example.i */
+%module example
+
+extern int gcd(int x, int y);
+extern double Foo;
+</pre>
+</blockquote>
+
+<h2>Compilation</h2>
+
+<ol>
+<li><tt>swig -python <a href="example.i">example.i</a></tt>
+<p>
+<li>Compile <tt><a href="example_wrap.c">example_wrap.c</a></tt> and <tt><a href="example.c">example.c</a></tt>
+to create the extension <tt>examplemodule.so</tt>.
+</ol>
+
+<h2>Using the extension</h2>
+
+Click <a href="example.py">here</a> to see a script that calls our C functions from Python.
+
+<h2>Key points</h2>
+
+<ul>
+<li>Use the <tt>import</tt> statement to load your extension module from Python. For example:
+<blockquote>
+<pre>
+import example
+</pre>
+</blockquote>
+
+<li>C functions work just like Python functions. For example:
+<blockquote>
+<pre>
+g = example.gcd(42,105)
+</pre>
+</blockquote>
+
+<li>C global variables are accessed through a special variable called 'cvar'. For example:
+<blockquote>
+<pre>
+a = example.cvar.Foo
+</pre>
+</blockquote>
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/python/simple/runme.py b/Examples/python/simple/runme.py
new file mode 100644
index 0000000..d484ae9
--- /dev/null
+++ b/Examples/python/simple/runme.py
@@ -0,0 +1,30 @@
+# file: runme.py
+
+import example
+
+# Call our gcd() function
+
+x = 42
+y = 105
+g = example.gcd(x,y)
+print "The gcd of %d and %d is %d" % (x,y,g)
+
+# Manipulate the Foo global variable
+
+# Output its current value
+print "Foo = ", example.cvar.Foo
+
+# Change its value
+example.cvar.Foo = 3.1415926
+
+# See if the change took effect
+print "Foo = ", example.cvar.Foo
+
+
+
+
+
+
+
+
+
diff --git a/Examples/python/smartptr/Makefile b/Examples/python/smartptr/Makefile
new file mode 100644
index 0000000..f73802a
--- /dev/null
+++ b/Examples/python/smartptr/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/smartptr/example.cxx b/Examples/python/smartptr/example.cxx
new file mode 100644
index 0000000..92a3add
--- /dev/null
+++ b/Examples/python/smartptr/example.cxx
@@ -0,0 +1,31 @@
+/* File : example.c */
+
+#include "example.h"
+#include <math.h>
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area() {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter() {
+ return 2*M_PI*radius;
+}
+
+double Square::area() {
+ return width*width;
+}
+
+double Square::perimeter() {
+ return 4*width;
+}
diff --git a/Examples/python/smartptr/example.h b/Examples/python/smartptr/example.h
new file mode 100644
index 0000000..c0f9b1d
--- /dev/null
+++ b/Examples/python/smartptr/example.h
@@ -0,0 +1,39 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area() = 0;
+ virtual double perimeter() = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area();
+ virtual double perimeter();
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area();
+ virtual double perimeter();
+};
+
+
+
+
+
diff --git a/Examples/python/smartptr/example.i b/Examples/python/smartptr/example.i
new file mode 100644
index 0000000..83da4f1
--- /dev/null
+++ b/Examples/python/smartptr/example.i
@@ -0,0 +1,20 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+#include "smartptr.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
+/* Grab smart pointer template */
+
+%include "smartptr.h"
+
+/* Instantiate smart-pointers */
+
+%template(ShapePtr) SmartPtr<Shape>;
+
+
diff --git a/Examples/python/smartptr/runme.py b/Examples/python/smartptr/runme.py
new file mode 100644
index 0000000..5ea1fb9
--- /dev/null
+++ b/Examples/python/smartptr/runme.py
@@ -0,0 +1,55 @@
+# file: runme.py
+
+# This file illustrates the proxy class C++ interface generated
+# by SWIG.
+
+import example
+
+# ----- Object creation -----
+
+print "Creating some objects:"
+cc = example.Circle(10)
+c = example.ShapePtr(cc)
+print " Created circle", c
+ss = example.Square(10)
+s = example.ShapePtr(ss)
+print " Created square", s
+
+# ----- Access a static member -----
+
+print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
+
+# ----- Member data access -----
+
+# Set the location of the object
+
+c.x = 20
+c.y = 30
+
+s.x = -10
+s.y = 5
+
+print "\nHere is their current position:"
+print " Circle = (%f, %f)" % (c.x,c.y)
+print " Square = (%f, %f)" % (s.x,s.y)
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:"
+for o in [c,s]:
+ print " ", o
+ print " area = ", o.area()
+ print " perimeter = ", o.perimeter()
+
+print "\nGuess I'll clean up now"
+
+# Note: this invokes the virtual destructor
+del c
+del s
+del cc
+del ss
+
+s = 3
+print example.cvar.Shape_nshapes,"shapes remain"
+print "Goodbye"
+
diff --git a/Examples/python/smartptr/smartptr.h b/Examples/python/smartptr/smartptr.h
new file mode 100644
index 0000000..2ffa1ca
--- /dev/null
+++ b/Examples/python/smartptr/smartptr.h
@@ -0,0 +1,13 @@
+template<class T> class SmartPtr {
+public:
+ SmartPtr(T *realPtr = 0) { pointee = realPtr; }
+ T *operator->() const {
+ return pointee;
+ }
+ T &operator*() const {
+ return *pointee;
+ }
+private:
+ T *pointee;
+};
+
diff --git a/Examples/python/std_map/Makefile b/Examples/python/std_map/Makefile
new file mode 100644
index 0000000..5d13da7
--- /dev/null
+++ b/Examples/python/std_map/Makefile
@@ -0,0 +1,25 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+run:
+ python runme.py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/std_map/example.h b/Examples/python/std_map/example.h
new file mode 100644
index 0000000..79ccc64
--- /dev/null
+++ b/Examples/python/std_map/example.h
@@ -0,0 +1,17 @@
+/* File : example.h */
+
+#include <map>
+#include <string>
+
+template<class Key, class Value>
+std::map<Key,Value> half_map(const std::map<Key,Value>& v) {
+ typedef typename std::map<Key,Value>::const_iterator iter;
+ std::map<Key,Value> w;
+ for (iter i = v.begin(); i != v.end(); ++i) {
+ w[i->first] = (i->second)/2;
+ }
+ return w;
+}
+
+
+
diff --git a/Examples/python/std_map/example.i b/Examples/python/std_map/example.i
new file mode 100644
index 0000000..6a7af71
--- /dev/null
+++ b/Examples/python/std_map/example.i
@@ -0,0 +1,27 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include std_string.i
+%include std_pair.i
+%include std_map.i
+
+/* instantiate the required template specializations */
+namespace std {
+ /* remember to instantiate the key,value pair! */
+ %template(DoubleMap) map<std::string,double>;
+ %template() map<std::string,int>;
+}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
+%template(halfd) half_map<std::string,double>;
+%template(halfi) half_map<std::string,int>;
+
+
+%template() std::pair<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;
+%template(pymap) std::map<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;
diff --git a/Examples/python/std_map/runme.py b/Examples/python/std_map/runme.py
new file mode 100644
index 0000000..b521c9c
--- /dev/null
+++ b/Examples/python/std_map/runme.py
@@ -0,0 +1,82 @@
+# file: runme.py
+
+import example
+
+pmap = example.pymap()
+pmap["hi"] = 1
+pmap["hello"] = 2
+
+
+
+
+dmap = {}
+dmap["hello"] = 1.0
+dmap["hi"] = 2.0
+
+print dmap.items()
+print dmap.keys()
+print dmap.values()
+
+print dmap
+hmap = example.halfd(dmap)
+dmap = hmap
+
+print dmap
+for i in dmap.iterkeys():
+ print "key", i
+
+for i in dmap.itervalues():
+ print "val", i
+
+for k,v in dmap.iteritems():
+ print "item", k,v
+
+dmap = example.DoubleMap()
+dmap["hello"] = 1.0
+dmap["hi"] = 2.0
+
+for i in dmap.iterkeys():
+ print "key", i
+
+for i in dmap.itervalues():
+ print "val", i
+
+for k,v in dmap.iteritems():
+ print "item", k,v
+
+
+print dmap.items()
+print dmap.keys()
+print dmap.values()
+
+hmap = example.halfd(dmap)
+print hmap.keys()
+print hmap.values()
+
+
+
+dmap = {}
+dmap["hello"] = 2
+dmap["hi"] = 4
+
+hmap = example.halfi(dmap)
+print hmap
+print hmap.keys()
+print hmap.values()
+
+
+dmap = hmap
+
+for i in dmap.iterkeys():
+ print "key", i
+
+for i in dmap.itervalues():
+ print "val", i
+
+for i in dmap.iteritems():
+ print "item", i
+
+for k,v in dmap.iteritems():
+ print "item", k,v
+
+print dmap
diff --git a/Examples/python/std_vector/Makefile b/Examples/python/std_vector/Makefile
new file mode 100644
index 0000000..ba5c798
--- /dev/null
+++ b/Examples/python/std_vector/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/std_vector/example.h b/Examples/python/std_vector/example.h
new file mode 100644
index 0000000..4f0dac7
--- /dev/null
+++ b/Examples/python/std_vector/example.h
@@ -0,0 +1,25 @@
+/* File : example.h */
+
+#include <vector>
+#include <algorithm>
+#include <functional>
+#include <numeric>
+
+double average(std::vector<int> v) {
+ return std::accumulate(v.begin(),v.end(),0.0)/v.size();
+}
+
+std::vector<double> half(const std::vector<double>& v) {
+ std::vector<double> w(v);
+ for (unsigned int i=0; i<w.size(); i++)
+ w[i] /= 2.0;
+ return w;
+}
+
+void halve_in_place(std::vector<double>& v) {
+ // would you believe this is the same as the above?
+ std::transform(v.begin(),v.end(),v.begin(),
+ std::bind2nd(std::divides<double>(),2.0));
+}
+
+
diff --git a/Examples/python/std_vector/example.i b/Examples/python/std_vector/example.i
new file mode 100644
index 0000000..aa58b66
--- /dev/null
+++ b/Examples/python/std_vector/example.i
@@ -0,0 +1,17 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include stl.i
+/* instantiate the required template specializations */
+namespace std {
+ %template(IntVector) vector<int>;
+ %template(DoubleVector) vector<double>;
+}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/python/std_vector/runme.py b/Examples/python/std_vector/runme.py
new file mode 100644
index 0000000..d248ccb
--- /dev/null
+++ b/Examples/python/std_vector/runme.py
@@ -0,0 +1,36 @@
+# file: runme.py
+
+import example
+
+# Call average with a Python list...
+
+print example.average([1,2,3,4])
+
+# ... or a wrapped std::vector<int>
+
+v = example.IntVector(4)
+for i in range(len(v)):
+ v[i] = i+1
+print example.average(v)
+
+
+# half will return a Python list.
+# Call it with a Python tuple...
+
+print example.half((1.0, 1.5, 2.0, 2.5, 3.0))
+
+# ... or a wrapped std::vector<double>
+
+v = example.DoubleVector()
+for i in [1,2,3,4]:
+ v.append(i)
+print example.half(v)
+
+
+# now halve a wrapped std::vector<double> in place
+
+example.halve_in_place(v)
+for i in range(len(v)):
+ print v[i], "; ",
+print
+
diff --git a/Examples/python/swigrun/Makefile b/Examples/python/swigrun/Makefile
new file mode 100644
index 0000000..2142be5
--- /dev/null
+++ b/Examples/python/swigrun/Makefile
@@ -0,0 +1,25 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(SWIG) -python -external-runtime
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+ rm -f swigpyrun.h
+
+check: all
+
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/swigrun/example.cxx b/Examples/python/swigrun/example.cxx
new file mode 100644
index 0000000..25906a5
--- /dev/null
+++ b/Examples/python/swigrun/example.cxx
@@ -0,0 +1,20 @@
+/* File : example.cxx */
+
+#include <Python.h>
+#include "swigpyrun.h"
+#include "example.h"
+
+
+Manager* convert_to_Manager(PyObject *py_obj)
+{
+ Manager* c_ptr;
+ swig_type_info *ty = SWIG_TypeQuery("Manager *");
+ printf("manager ty %p \n", ty);
+ if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty, 0) == -1) {
+ c_ptr = 0;
+ } else {
+ Py_XINCREF(py_obj);
+ }
+ return c_ptr;
+}
+
diff --git a/Examples/python/swigrun/example.h b/Examples/python/swigrun/example.h
new file mode 100644
index 0000000..69e6fe4
--- /dev/null
+++ b/Examples/python/swigrun/example.h
@@ -0,0 +1,58 @@
+/* File : example.h */
+
+#include <cstdio>
+#include <iostream>
+#include <vector>
+#include <string>
+#include <cmath>
+
+class Employee {
+private:
+ std::string name;
+public:
+ Employee(const char* n): name(n) {}
+ virtual std::string getTitle() { return getPosition() + " " + getName(); }
+ virtual std::string getName() { return name; }
+ virtual std::string getPosition() const { return "Employee"; }
+ virtual ~Employee() { printf("~Employee() @ %p\n", this); }
+};
+
+
+class Manager: public Employee {
+public:
+ Manager(const char* n): Employee(n) {}
+ virtual std::string getPosition() const { return "Manager"; }
+};
+
+
+class EmployeeList {
+ std::vector<Employee*> list;
+public:
+ EmployeeList() {
+ list.push_back(new Employee("Bob"));
+ list.push_back(new Employee("Jane"));
+ list.push_back(new Manager("Ted"));
+ }
+ void addEmployee(Employee *p) {
+ list.push_back(p);
+ std::cout << "New employee added. Current employees are:" << std::endl;
+ std::vector<Employee*>::iterator i;
+ for (i=list.begin(); i!=list.end(); i++) {
+ std::cout << " " << (*i)->getTitle() << std::endl;
+ }
+ }
+ const Employee *get_item(int i) {
+ return list[i];
+ }
+ ~EmployeeList() {
+ std::vector<Employee*>::iterator i;
+ std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
+ for (i=list.begin(); i!=list.end(); i++) {
+ delete *i;
+ }
+ std::cout << "~EmployeeList empty." << std::endl;
+ }
+};
+
+Manager* convert_to_Manager(PyObject *obj);
+
diff --git a/Examples/python/swigrun/example.i b/Examples/python/swigrun/example.i
new file mode 100644
index 0000000..c8ec32e
--- /dev/null
+++ b/Examples/python/swigrun/example.i
@@ -0,0 +1,15 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_vector.i"
+%include "std_string.i"
+
+/* turn on director wrapping for Manager */
+%feature("director") Employee;
+%feature("director") Manager;
+
+%include "example.h"
+
diff --git a/Examples/python/swigrun/runme.py b/Examples/python/swigrun/runme.py
new file mode 100644
index 0000000..abcd964
--- /dev/null
+++ b/Examples/python/swigrun/runme.py
@@ -0,0 +1,28 @@
+# file: runme.py
+
+# This file illustrates the cross language polymorphism using directors.
+
+import example
+
+
+# CEO class, which overrides Employee::getPosition().
+
+class CEO(example.Manager):
+ def __init__(self, name):
+ example.Manager.__init__(self, name)
+ def getPosition(self):
+ return "CEO"
+ def __del__(self):
+ print "CEO.__del__(),", self.getName()
+ # for proxy class extensions that are not "disowned" and
+ # define a __del__ method, it is very important to call the
+ # base class __del__. otherwise the c++ objects will never
+ # be deleted.
+ example.Manager.__del__(self)
+
+
+
+
+e = CEO("Alice")
+m = example.convert_to_Manager(e)
+print m
diff --git a/Examples/python/template/Makefile b/Examples/python/template/Makefile
new file mode 100644
index 0000000..ba5c798
--- /dev/null
+++ b/Examples/python/template/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/template/example.h b/Examples/python/template/example.h
new file mode 100644
index 0000000..7401df6
--- /dev/null
+++ b/Examples/python/template/example.h
@@ -0,0 +1,32 @@
+/* File : example.h */
+
+// Some template definitions
+
+template<class T> T max(T a, T b) { return a>b ? a : b; }
+
+template<class T> class vector {
+ T *v;
+ int sz;
+ public:
+ vector(int _sz) {
+ v = new T[_sz];
+ sz = _sz;
+ }
+ T &get(int index) {
+ return v[index];
+ }
+ void set(int index, T &val) {
+ v[index] = val;
+ }
+#ifdef SWIG
+ %extend {
+ T getitem(int index) {
+ return $self->get(index);
+ }
+ void setitem(int index, T val) {
+ $self->set(index,val);
+ }
+ }
+#endif
+};
+
diff --git a/Examples/python/template/example.i b/Examples/python/template/example.i
new file mode 100644
index 0000000..8f94c4d
--- /dev/null
+++ b/Examples/python/template/example.i
@@ -0,0 +1,17 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
+/* Now instantiate some specific template declarations */
+
+%template(maxint) max<int>;
+%template(maxdouble) max<double>;
+%template(vecint) vector<int>;
+%template(vecdouble) vector<double>;
+
diff --git a/Examples/python/template/runme.py b/Examples/python/template/runme.py
new file mode 100644
index 0000000..05940bc
--- /dev/null
+++ b/Examples/python/template/runme.py
@@ -0,0 +1,34 @@
+# file: runme.py
+
+import example
+
+# Call some templated functions
+print example.maxint(3,7)
+print example.maxdouble(3.14,2.18)
+
+# Create some class
+
+iv = example.vecint(100)
+dv = example.vecdouble(1000)
+
+for i in range(0,100):
+ iv.setitem(i,2*i)
+
+for i in range(0,1000):
+ dv.setitem(i, 1.0/(i+1))
+
+sum = 0
+for i in range(0,100):
+ sum = sum + iv.getitem(i)
+
+print sum
+
+sum = 0.0
+for i in range(0,1000):
+ sum = sum + dv.getitem(i)
+print sum
+
+del iv
+del dv
+
+
diff --git a/Examples/python/varargs/Makefile b/Examples/python/varargs/Makefile
new file mode 100644
index 0000000..1420b4e
--- /dev/null
+++ b/Examples/python/varargs/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS =
+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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/varargs/example.i b/Examples/python/varargs/example.i
new file mode 100644
index 0000000..6cb88f5
--- /dev/null
+++ b/Examples/python/varargs/example.i
@@ -0,0 +1,65 @@
+/* File : example.i */
+%module example
+
+%{
+#include <stdarg.h>
+%}
+
+/* This example illustrates SWIG's handling of varargs functions.
+ By default, variable length arguments are simply ignored. This
+ is generally appropriate for wrapping I/O functions like printf.
+ You can simply format a string in the scripting language, and
+ pass it directly */
+
+int printf(const char *fmt, ...);
+
+/* Since passing a format string might be dangerous. Here is a slightly
+ different way of wrapping a printf style function */
+
+#if 1
+/* Replace ... with char *. */
+%varargs(char *) fprintf;
+
+/* Ignore the format string, but set it to %s */
+%typemap(in,numinputs=0) const char *fmt {
+ $1 = "%s";
+}
+#else
+/* An alternative approach using typemaps */
+%typemap(in) (const char *fmt, ...) {
+ $1 = "%s";
+ $2 = (void *) PyString_AsString($input);
+}
+#endif
+
+/* Typemap just to make the example work */
+%typemap(in) FILE * "$1 = PyFile_AsFile($input);";
+
+int fprintf(FILE *, const char *fmt, ...);
+
+/* Here is somewhat different example. A variable length argument
+ function that takes a NULL-terminated list of arguments. We
+ can use a slightly different form of %varargs that specifies
+ a default value and a maximum number of arguments.
+ */
+
+/* Maximum of 20 arguments with default value NULL */
+
+%varargs(20, char *x = NULL) printv;
+
+%inline %{
+void printv(char *s, ...) {
+ va_list ap;
+ char *x;
+ fputs(s,stdout);
+ fputc(' ',stdout);
+ va_start(ap, s);
+ while ((x = va_arg(ap, char *))) {
+ fputs(x,stdout);
+ fputc(' ',stdout);
+ }
+ va_end(ap);
+ fputc('\n',stdout);
+}
+%}
+
diff --git a/Examples/python/varargs/runme.py b/Examples/python/varargs/runme.py
new file mode 100644
index 0000000..a01cb67
--- /dev/null
+++ b/Examples/python/varargs/runme.py
@@ -0,0 +1,34 @@
+# file: runme.py
+
+import sys
+import example
+
+# Call printf
+example.printf("Hello World. I'm printf\n")
+
+# Note: We call printf, but use *python* string formatting
+for i in range(0,10):
+ example.printf("i is %d\n" % i)
+
+# This will probably be garbled because %d is interpreted by C
+example.printf("The value is %d\n")
+
+# Call fprintf
+example.fprintf(sys.stdout,"Hello World. I'm fprintf\n")
+for i in range(0,10):
+ example.fprintf(sys.stdout,"i is %d\n" % i)
+
+# This won't be garbled since %d is not interpreted
+example.fprintf(sys.stdout,"The value is %d\n")
+
+# This function calls our NULL-terminated function
+
+example.printv("Hello","World","this","is","a","test.")
+
+
+
+
+
+
+
+
diff --git a/Examples/python/variables/Makefile b/Examples/python/variables/Makefile
new file mode 100644
index 0000000..0f4a1e0
--- /dev/null
+++ b/Examples/python/variables/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-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::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/variables/example.c b/Examples/python/variables/example.c
new file mode 100644
index 0000000..aa4ffe9
--- /dev/null
+++ b/Examples/python/variables/example.c
@@ -0,0 +1,91 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "example.h"
+
+int ivar = 0;
+short svar = 0;
+long lvar = 0;
+unsigned int uivar = 0;
+unsigned short usvar = 0;
+unsigned long ulvar = 0;
+signed char scvar = 0;
+unsigned char ucvar = 0;
+char cvar = 0;
+float fvar = 0;
+double dvar = 0;
+char *strvar = 0;
+const char cstrvar[] = "Goodbye";
+int *iptrvar = 0;
+char name[256] = "Dave";
+char path[256] = "/home/beazley";
+
+
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
+/* A debugging function to print out their values */
+
+void print_vars() {
+ printf("ivar = %d\n", ivar);
+ printf("svar = %d\n", svar);
+ printf("lvar = %ld\n", lvar);
+ printf("uivar = %u\n", uivar);
+ printf("usvar = %u\n", usvar);
+ printf("ulvar = %lu\n", ulvar);
+ printf("scvar = %d\n", scvar);
+ printf("ucvar = %u\n", ucvar);
+ printf("fvar = %g\n", fvar);
+ printf("dvar = %g\n", dvar);
+ printf("cvar = %c\n", cvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
+ printf("iptrvar = %p\n", iptrvar);
+ printf("name = %s\n", name);
+ printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
+}
+
+/* A function to create a point */
+
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d,%d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/python/variables/example.h b/Examples/python/variables/example.h
new file mode 100644
index 0000000..0f7e895
--- /dev/null
+++ b/Examples/python/variables/example.h
@@ -0,0 +1,6 @@
+/* File: example.h */
+
+typedef struct {
+ int x,y;
+} Point;
+
diff --git a/Examples/python/variables/example.i b/Examples/python/variables/example.i
new file mode 100644
index 0000000..9d0101c
--- /dev/null
+++ b/Examples/python/variables/example.i
@@ -0,0 +1,51 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+#pragma SWIG nowarn=SWIGWARN_TYPEMAP_SWIGTYPELEAK
+
+/* Some global variable declarations */
+%inline %{
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[256];
+
+extern Point *ptptr;
+extern Point pt;
+%}
+
+
+/* Some read-only variables */
+
+%immutable;
+
+%inline %{
+extern int status;
+extern char path[256];
+%}
+
+%mutable;
+
+/* Some helper functions to make it easier to test */
+%inline %{
+extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
+%}
+
diff --git a/Examples/python/variables/index.html b/Examples/python/variables/index.html
new file mode 100644
index 0000000..2940d8a
--- /dev/null
+++ b/Examples/python/variables/index.html
@@ -0,0 +1,100 @@
+<html>
+<head>
+<title>SWIG:Examples:python:variables</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+<tt>SWIG/Examples/python/variables/</tt>
+<hr>
+
+<H2>Wrapping C Global Variables</H2>
+
+<p>
+When a C global variable appears in an interface file, SWIG tries to
+wrap it using a technique known as "variable linking." The idea is
+pretty simple---we try to create a Python variable that magically
+retrieves or updates the value of the underlying C variable when it is
+accessed. Click <a href="example.i">here</a> to see a SWIG interface with some variable
+declarations in it.
+
+<h2>Manipulating Variables from Python</h2>
+
+Before going any further, it is important to understand some important
+differences between C and Python variables. In C, a variable is
+simply a name that refers to a specific location in memory. For
+example, when you declare a global variable '<tt>double a</tt>' you
+know that somewhere in memory, 8 bytes have been set aside to hold a
+<tt>double</tt> and that <tt>a</tt> is bound to this location for the
+life of the program. In Python, variable creation is nothing more
+than a naming operation. For example, when you say '<tt>a = 3</tt>',
+'a' becomes a name that refers to some object '3'. Later on, if you say
+'<tt>a = 7.5</tt>, the name 'a' is bound to an entirely different object
+containing the value '7.5' (the contents of the original object are not
+changed). The end result of this is that a variable in Python can refer
+to a virtually unlimited number of different objects (memory locations)
+over the lifetime of a program.
+
+<p>
+Because of Python's somewhat unusual variable assignment semantics, it is not
+possible to directly link a C global variable into an equivalent Python variable.
+Instead, all C global variables are accessed as attributes of a special object
+called 'cvar'. For example, if you had a global variable
+
+<blockquote>
+<pre>
+double foo;
+</pre>
+</blockquote>
+
+it will be accessed in the Python module as <tt>cvar.foo</tt>. Click
+<a href="example.py">here</a> to see a script that updates and prints
+out the values of the variables using this technique.
+
+<h2>Key points</h2>
+
+<ul>
+<li>When a global variable has the type "<tt>char *</tt>", SWIG manages it as a character
+string. However, whenever the value of such a variable is set from Python, the old
+value is destroyed using <tt>free()</tt> or <tt>delete</tt> (the choice of which depends
+on whether or not SWIG was run with the -c++ option).
+<li><tt>signed char</tt> and <tt>unsigned char</tt> are handled as small 8-bit integers.
+<li>String array variables such as '<tt>char name[256]</tt>' are managed as Python strings, but
+when setting the value, the result is truncated to the maximum length of the array. Furthermore, the string is assumed to be null-terminated.
+<li>When structures and classes are used as global variables, they are mapped into pointers.
+Getting the "value" returns a pointer to the global variable. Setting the value of a structure results in a memory copy from a pointer to the global.
+</ul>
+
+<h2>Creating read-only variables</h2>
+
+The <tt>%immutable</tt> and <tt>%mutable</tt> directives can be used to
+specify a collection of read-only variables. For example:
+
+<blockquote>
+<pre>
+%immutable;
+int status;
+double blah;
+...
+%mutable;
+</pre>
+</blockquote>
+
+The <tt>%immutable</tt> directive remains in effect until it is explicitly disabled
+using the <tt>%mutable</tt> directive.
+
+<h2>Comments</h2>
+<ul>
+<li>Management of global variables is one of the most problematic aspects
+of C/C++ wrapping because the scripting interface and resulting memory management
+is much trickier than simply creating a wrapper function.
+<p>
+<li>Because of the potential for a namespace conflict, you should not use
+the <tt>from module import *</tt> statement for a SWIG module with global
+variables. Doing so will cause a collision on the 'cvar' object should
+more than one module be loaded in this manner.
+</ul>
+
+</body>
+</html>
+<hr>
diff --git a/Examples/python/variables/runme.py b/Examples/python/variables/runme.py
new file mode 100644
index 0000000..b635b98
--- /dev/null
+++ b/Examples/python/variables/runme.py
@@ -0,0 +1,75 @@
+# file: runme.py
+
+import example
+
+# Try to set the values of some global variables
+
+example.cvar.ivar = 42
+example.cvar.svar = -31000
+example.cvar.lvar = 65537
+example.cvar.uivar = 123456
+example.cvar.usvar = 61000
+example.cvar.ulvar = 654321
+example.cvar.scvar = -13
+example.cvar.ucvar = 251
+example.cvar.cvar = "S"
+example.cvar.fvar = 3.14159
+example.cvar.dvar = 2.1828
+example.cvar.strvar = "Hello World"
+example.cvar.iptrvar= example.new_int(37)
+example.cvar.ptptr = example.new_Point(37,42)
+example.cvar.name = "Bill"
+
+# Now print out the values of the variables
+
+print "Variables (values printed from Python)"
+
+print "ivar =", example.cvar.ivar
+print "svar =", example.cvar.svar
+print "lvar =", example.cvar.lvar
+print "uivar =", example.cvar.uivar
+print "usvar =", example.cvar.usvar
+print "ulvar =", example.cvar.ulvar
+print "scvar =", example.cvar.scvar
+print "ucvar =", example.cvar.ucvar
+print "fvar =", example.cvar.fvar
+print "dvar =", example.cvar.dvar
+print "cvar =", example.cvar.cvar
+print "strvar =", example.cvar.strvar
+print "cstrvar =", example.cvar.cstrvar
+print "iptrvar =", example.cvar.iptrvar
+print "name =", example.cvar.name
+print "ptptr =", example.cvar.ptptr, example.Point_print(example.cvar.ptptr)
+print "pt =", example.cvar.pt, example.Point_print(example.cvar.pt)
+
+print "\nVariables (values printed from C)"
+
+example.print_vars()
+
+print "\nNow I'm going to try and modify some read only variables";
+
+print " Tring to set 'path'";
+try:
+ example.cvar.path = "Whoa!"
+ print "Hey, what's going on?!?! This shouldn't work"
+except:
+ print "Good."
+
+print " Trying to set 'status'";
+try:
+ example.cvar.status = 0
+ print "Hey, what's going on?!?! This shouldn't work"
+except:
+ print "Good."
+
+
+print "\nI'm going to try and update a structure variable.\n"
+
+example.cvar.pt = example.cvar.ptptr
+
+print "The new value is"
+example.pt_print()
+print "You should see the value", example.Point_print(example.cvar.ptptr)
+
+
+
diff --git a/Examples/python/weave/Makefile b/Examples/python/weave/Makefile
new file mode 100644
index 0000000..88f95c0
--- /dev/null
+++ b/Examples/python/weave/Makefile
@@ -0,0 +1,22 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+CXXSRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+all::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
+
+static::
+ $(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile python_clean
+ rm -f $(TARGET).py
+
+check: all
+ $(MAKE) -f $(TOP)/Makefile python_run
diff --git a/Examples/python/weave/README b/Examples/python/weave/README
new file mode 100644
index 0000000..a616a4f
--- /dev/null
+++ b/Examples/python/weave/README
@@ -0,0 +1,25 @@
+This directory contains a simple example to test weave support for
+SWIG wrapped objects.
+
+The weave package provides tools for including C/C++ code in Python
+code. This offers both another level of optimization to those who need
+it, and an easy way to modify and extend any supported extension
+libraries. Weave automatically builds an extension module from the
+given C/C++ code and runs that. This can result in very significant
+speedups (of upto 500x) depending on the problem. Weave also supports
+inlining SWIG-1.3.x wrapped objects.
+
+The example in this directory requires that weave be installed. Weave
+is distributed as part of SciPy (http://www.scipy.org). More
+information on Weave may be had from here:
+
+ http://www.scipy.org/documentation/weave
+
+As of November 22, 2004, this example only works with weave from CVS.
+If there is a more recent release of SciPy after this date, it should
+work fine.
+
+
+Also, you need to replace the weave file swigptr2.py by the one
+provided here.
+
diff --git a/Examples/python/weave/example.h b/Examples/python/weave/example.h
new file mode 100644
index 0000000..d09d608
--- /dev/null
+++ b/Examples/python/weave/example.h
@@ -0,0 +1,18 @@
+#ifndef _EXAMPLE_H
+#define _EXAMPLE_H
+
+class Foo {
+ public:
+ int x;
+};
+
+class Bar {
+ public:
+ int y;
+};
+
+class FooBar : public Foo, public Bar {
+ public:
+ int z;
+};
+#endif
diff --git a/Examples/python/weave/example.i b/Examples/python/weave/example.i
new file mode 100644
index 0000000..5d71eaa
--- /dev/null
+++ b/Examples/python/weave/example.i
@@ -0,0 +1,15 @@
+%module(directors="1") example
+
+%{
+#include "example.h"
+%}
+
+%include "std_vector.i"
+
+%director Foo;
+%director Bar;
+%include "example.h"
+
+
+%template(VectorBar) std::vector<Bar*>;
+%template(VectorFoo) std::vector<Foo*>;
diff --git a/Examples/python/weave/runme.py b/Examples/python/weave/runme.py
new file mode 100644
index 0000000..529b4fc
--- /dev/null
+++ b/Examples/python/weave/runme.py
@@ -0,0 +1,72 @@
+"""
+Test weave support for SWIG wrapped objects.
+
+This example requires that one has weave installed. Weave is
+distributed as part of SciPy (http://www.scipy.org). More information
+on Weave may be had from here:
+
+ http://www.scipy.org/documentation/weave
+
+As of November 22, 2004, this only works with weave from CVS. If
+there is a more recent release of SciPy after this date, it should
+work fine.
+
+"""
+
+import example
+import weave
+from weave import converters
+from weave import swig2_spec
+
+# Weave does not support swig2 by default (yet). So add this to the
+# list of default converters to test.
+converters.default.insert(0, swig2_spec.swig2_converter())
+
+def test():
+ """ A simple test case for weave."""
+ a = example.Foo()
+ a.x = 1
+ b = example.Bar()
+ b.y = 2
+ c = example.FooBar()
+ c.x = 1
+ c.y = 2
+ c.z = 3
+ v = example.VectorBar()
+ v.append(b)
+ v.append(c)
+ d = v[0]
+ e = v[1]
+ v = example.VectorFoo()
+ v.append(a)
+ v.append(c)
+ f = v[0]
+ g = v[1]
+
+ code = """
+ std::cout << a->x << std::endl;
+ assert(a->x == 1);
+ std::cout << b->y << std::endl;
+ assert(b->y == 2);
+ std::cout << c->x << std::endl;
+ std::cout << c->y << std::endl;
+ std::cout << c->z << std::endl;
+ assert(c->x == 1);
+ assert(c->y == 2);
+ assert(c->z == 3);
+ std::cout << d->y << std::endl;
+ assert(d->y == 2);
+ std::cout << e->y << std::endl;
+ assert(e->y == 2);
+ std::cout << f->x << std::endl;
+ assert(f->x == 1);
+ std::cout << g->x << std::endl;
+ assert(g->x == 1);
+ """
+ weave.inline(code, ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
+ include_dirs=['.'],
+ headers=['"example.h"'],
+ verbose=2)
+
+if __name__ == "__main__":
+ test()
diff --git a/Examples/python/weave/swigptr2.py b/Examples/python/weave/swigptr2.py
new file mode 100644
index 0000000..7ffe0fb
--- /dev/null
+++ b/Examples/python/weave/swigptr2.py
@@ -0,0 +1,3556 @@
+# This code allows one to use SWIG wrapped objects from weave. This
+# code is specific to SWIG-1.3 and above where things are different.
+# The code is basically all copied out from the SWIG wrapper code but
+# it has been hand edited for brevity.
+#
+# Prabhu Ramachandran <prabhu@aero.iitm.ernet.in>
+
+######################################################################
+# This is for SWIG-1.3.x where x < 22.
+# Essentially, SWIG_RUNTIME_VERSION was not yet used.
+swigptr2_code_v0 = """
+
+#include "Python.h"
+
+/*************************************************************** -*- c -*-
+ * python/precommon.swg
+ *
+ * Rename all exported symbols from common.swg, to avoid symbol
+ * clashes if multiple interpreters are included
+ *
+ ************************************************************************/
+
+#define SWIG_TypeCheck SWIG_Python_TypeCheck
+#define SWIG_TypeCast SWIG_Python_TypeCast
+#define SWIG_TypeName SWIG_Python_TypeName
+#define SWIG_TypeQuery SWIG_Python_TypeQuery
+#define SWIG_PackData SWIG_Python_PackData
+#define SWIG_UnpackData SWIG_Python_UnpackData
+
+
+/***********************************************************************
+ * common.swg
+ *
+ * This file contains generic SWIG runtime support for pointer
+ * type checking as well as a few commonly used macros to control
+ * external linkage.
+ *
+ * Author : David Beazley (beazley@cs.uchicago.edu)
+ *
+ * Copyright (c) 1999-2000, The University of Chicago
+ *
+ * This file may be freely redistributed without license or fee provided
+ * this copyright message remains intact.
+ ************************************************************************/
+
+#include <string.h>
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(_MSC_VER) || defined(__GNUC__)
+# if defined(STATIC_LINKED)
+# define SWIGEXPORT(a) a
+# define SWIGIMPORT(a) extern a
+# else
+# define SWIGEXPORT(a) __declspec(dllexport) a
+# define SWIGIMPORT(a) extern a
+# endif
+# else
+# if defined(__BORLANDC__)
+# define SWIGEXPORT(a) a _export
+# define SWIGIMPORT(a) a _export
+# else
+# define SWIGEXPORT(a) a
+# define SWIGIMPORT(a) a
+# endif
+# endif
+#else
+# define SWIGEXPORT(a) a
+# define SWIGIMPORT(a) a
+#endif
+
+#ifdef SWIG_GLOBAL
+# define SWIGRUNTIME(a) SWIGEXPORT(a)
+#else
+# define SWIGRUNTIME(a) static a
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *(*swig_converter_func)(void *);
+typedef struct swig_type_info *(*swig_dycast_func)(void **);
+
+typedef struct swig_type_info {
+ const char *name;
+ swig_converter_func converter;
+ const char *str;
+ void *clientdata;
+ swig_dycast_func dcast;
+ struct swig_type_info *next;
+ struct swig_type_info *prev;
+} swig_type_info;
+
+#ifdef SWIG_NOINCLUDE
+
+SWIGIMPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
+SWIGIMPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
+SWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *);
+SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *);
+SWIGIMPORT(char *) SWIG_PackData(char *, void *, int);
+SWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int);
+
+#else
+
+static swig_type_info *swig_type_list = 0;
+
+/* Check the typename */
+SWIGRUNTIME(swig_type_info *)
+SWIG_TypeCheck(char *c, swig_type_info *ty) {
+ swig_type_info *s;
+ if (!ty) return 0; /* Void pointer */
+ s = ty->next; /* First element always just a name */
+ do {
+ if (strcmp(s->name,c) == 0) {
+ if (s == ty->next) return s;
+ /* Move s to the top of the linked list */
+ s->prev->next = s->next;
+ if (s->next) {
+ s->next->prev = s->prev;
+ }
+ /* Insert s as second element in the list */
+ s->next = ty->next;
+ if (ty->next) ty->next->prev = s;
+ ty->next = s;
+ s->prev = ty;
+ return s;
+ }
+ s = s->next;
+ } while (s && (s != ty->next));
+ return 0;
+}
+
+/* Cast a pointer up an inheritance hierarchy */
+SWIGRUNTIME(void *)
+SWIG_TypeCast(swig_type_info *ty, void *ptr) {
+ if ((!ty) || (!ty->converter)) return ptr;
+ return (*ty->converter)(ptr);
+}
+
+/* Return the name associated with this type */
+SWIGRUNTIME(const char *)
+SWIG_TypeName(const swig_type_info *ty) {
+ return ty->name;
+}
+
+/*
+ Compare two type names skipping the space characters, therefore
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
+
+ Return 0 when the two name types are equivalent, as in
+ strncmp, but skipping ' '.
+*/
+static int
+SWIG_TypeNameComp(const char *f1, const char *l1,
+ const char *f2, const char *l2) {
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
+ if (*f1 != *f2) return *f1 - *f2;
+ }
+ return (l1 - f1) - (l2 - f2);
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+*/
+static int
+SWIG_TypeEquiv(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+
+/* Search for a swig_type_info structure */
+SWIGRUNTIME(swig_type_info *)
+SWIG_TypeQuery(const char *name) {
+ swig_type_info *ty = swig_type_list;
+ while (ty) {
+ if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;
+ if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
+ ty = ty->prev;
+ }
+ return 0;
+}
+
+/* Pack binary data into a string */
+SWIGRUNTIME(char *)
+SWIG_PackData(char *c, void *ptr, int sz) {
+ static char hex[17] = "0123456789abcdef";
+ int i;
+ unsigned char *u = (unsigned char *) ptr;
+ register unsigned char uu;
+ for (i = 0; i < sz; i++,u++) {
+ uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+
+/* Unpack binary data from a string */
+SWIGRUNTIME(char *)
+SWIG_UnpackData(char *c, void *ptr, int sz) {
+ register unsigned char uu = 0;
+ register int d;
+ unsigned char *u = (unsigned char *) ptr;
+ int i;
+ for (i = 0; i < sz; i++, u++) {
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ *u = uu;
+ }
+ return c;
+}
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/***********************************************************************
+ * python.swg
+ *
+ * This file contains the runtime support for Python modules
+ * and includes code for managing global variables and pointer
+ * type checking.
+ *
+ * Author : David Beazley (beazley@cs.uchicago.edu)
+ ************************************************************************/
+
+#include "Python.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SWIG_PY_INT 1
+#define SWIG_PY_FLOAT 2
+#define SWIG_PY_STRING 3
+#define SWIG_PY_POINTER 4
+#define SWIG_PY_BINARY 5
+
+/* Flags for pointer conversion */
+
+#define SWIG_POINTER_EXCEPTION 0x1
+#define SWIG_POINTER_DISOWN 0x2
+
+/* Exception handling in wrappers */
+#define SWIG_fail goto fail
+
+/* Constant information structure */
+typedef struct swig_const_info {
+ int type;
+ char *name;
+ long lvalue;
+ double dvalue;
+ void *pvalue;
+ swig_type_info **ptype;
+} swig_const_info;
+
+/* Common SWIG API */
+#define SWIG_ConvertPtr(obj, pp, type, flags) \
+ SWIG_Python_ConvertPtr(obj, pp, type, flags)
+#define SWIG_NewPointerObj(p, type, flags) \
+ SWIG_Python_NewPointerObj(p, type, flags)
+#define SWIG_MustGetPtr(p, type, argnum, flags) \
+ SWIG_Python_MustGetPtr(p, type, argnum, flags)
+
+
+typedef double (*py_objasdbl_conv)(PyObject *obj);
+
+#ifdef SWIG_NOINCLUDE
+
+SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);
+SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);
+SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);
+
+#else
+
+
+/* Convert a pointer value */
+SWIGRUNTIME(int)
+SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
+ swig_type_info *tc;
+ char *c = 0;
+ static PyObject *SWIG_this = 0;
+ int newref = 0;
+ PyObject *pyobj = 0;
+
+ if (!obj) return 0;
+ if (obj == Py_None) {
+ *ptr = 0;
+ return 0;
+ }
+#ifdef SWIG_COBJECT_TYPES
+ if (!(PyCObject_Check(obj))) {
+ if (!SWIG_this)
+ SWIG_this = PyString_FromString("this");
+ pyobj = obj;
+ obj = PyObject_GetAttr(obj,SWIG_this);
+ newref = 1;
+ if (!obj) goto type_error;
+ if (!PyCObject_Check(obj)) {
+ Py_DECREF(obj);
+ goto type_error;
+ }
+ }
+ *ptr = PyCObject_AsVoidPtr(obj);
+ c = (char *) PyCObject_GetDesc(obj);
+ if (newref) Py_DECREF(obj);
+ goto cobject;
+#else
+ if (!(PyString_Check(obj))) {
+ if (!SWIG_this)
+ SWIG_this = PyString_FromString("this");
+ pyobj = obj;
+ obj = PyObject_GetAttr(obj,SWIG_this);
+ newref = 1;
+ if (!obj) goto type_error;
+ if (!PyString_Check(obj)) {
+ Py_DECREF(obj);
+ goto type_error;
+ }
+ }
+ c = PyString_AsString(obj);
+ /* Pointer values must start with leading underscore */
+ if (*c != '_') {
+ *ptr = (void *) 0;
+ if (strcmp(c,"NULL") == 0) {
+ if (newref) { Py_DECREF(obj); }
+ return 0;
+ } else {
+ if (newref) { Py_DECREF(obj); }
+ goto type_error;
+ }
+ }
+ c++;
+ c = SWIG_UnpackData(c,ptr,sizeof(void *));
+ if (newref) { Py_DECREF(obj); }
+#endif
+
+#ifdef SWIG_COBJECT_TYPES
+cobject:
+#endif
+
+ if (ty) {
+ tc = SWIG_TypeCheck(c,ty);
+ if (!tc) goto type_error;
+ *ptr = SWIG_TypeCast(tc,(void*) *ptr);
+ }
+
+ if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
+ PyObject *zero = PyInt_FromLong(0);
+ PyObject_SetAttrString(pyobj,(char*)"thisown",zero);
+ Py_DECREF(zero);
+ }
+ return 0;
+
+type_error:
+ PyErr_Clear();
+ if (flags & SWIG_POINTER_EXCEPTION) {
+ if (ty && c) {
+ PyErr_Format(PyExc_TypeError,
+ "Type error. Got %s, expected %s",
+ c, ty->name);
+ } else {
+ PyErr_SetString(PyExc_TypeError,"Expected a pointer");
+ }
+ }
+ return -1;
+}
+
+/* Convert a pointer value, signal an exception on a type mismatch */
+SWIGRUNTIME(void *)
+SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
+ void *result;
+ SWIG_Python_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION);
+ return result;
+}
+
+/* Create a new pointer object */
+SWIGRUNTIME(PyObject *)
+SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
+ PyObject *robj;
+ if (!ptr) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+#ifdef SWIG_COBJECT_TYPES
+ robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) type->name, NULL);
+#else
+ {
+ char result[1024];
+ char *r = result;
+ *(r++) = '_';
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
+ strcpy(r,type->name);
+ robj = PyString_FromString(result);
+ }
+#endif
+ if (!robj || (robj == Py_None)) return robj;
+ if (type->clientdata) {
+ PyObject *inst;
+ PyObject *args = Py_BuildValue((char*)"(O)", robj);
+ Py_DECREF(robj);
+ inst = PyObject_CallObject((PyObject *) type->clientdata, args);
+ Py_DECREF(args);
+ if (inst) {
+ if (own) {
+ PyObject *n = PyInt_FromLong(1);
+ PyObject_SetAttrString(inst,(char*)"thisown",n);
+ Py_DECREF(n);
+ }
+ robj = inst;
+ }
+ }
+ return robj;
+}
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+"""
+
+
+######################################################################
+# This is for SWIG-1.3.x where x >= 23.
+# SWIG_RUNTIME_VERSION == "1"
+
+# All this does is to include (cut/paste): <swigrun.swg>
+# <python/pyrun.swg> and <runtime.swg>
+swigptr2_code_v1 = """
+/***********************************************************************
+ * swigrun.swg
+ *
+ * This file contains generic CAPI SWIG runtime support for pointer
+ * type checking.
+ *
+ ************************************************************************/
+
+/* This should only be incremented when either the layout of swig_type_info changes,
+ or for whatever reason, the runtime changes incompatibly */
+#define SWIG_RUNTIME_VERSION "1"
+
+/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
+#ifdef SWIG_TYPE_TABLE
+#define SWIG_QUOTE_STRING(x) #x
+#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
+#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
+#else
+#define SWIG_TYPE_TABLE_NAME
+#endif
+
+#include <string.h>
+
+#ifndef SWIGINLINE
+#if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+# define SWIGINLINE inline
+#else
+# define SWIGINLINE
+#endif
+#endif
+
+/*
+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
+ creating a static or dynamic library from the swig runtime code.
+ In 99.9% of the cases, swig just needs to declare them as 'static'.
+
+ But only do this if is strictly necessary, ie, if you have problems
+ with your compiler or so.
+*/
+#ifndef SWIGRUNTIME
+#define SWIGRUNTIME static
+#endif
+#ifndef SWIGRUNTIMEINLINE
+#define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *(*swig_converter_func)(void *);
+typedef struct swig_type_info *(*swig_dycast_func)(void **);
+
+typedef struct swig_type_info {
+ const char *name;
+ swig_converter_func converter;
+ const char *str;
+ void *clientdata;
+ swig_dycast_func dcast;
+ struct swig_type_info *next;
+ struct swig_type_info *prev;
+} swig_type_info;
+
+/*
+ Compare two type names skipping the space characters, therefore
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
+
+ Return 0 when the two name types are equivalent, as in
+ strncmp, but skipping ' '.
+*/
+SWIGRUNTIME int
+SWIG_TypeNameComp(const char *f1, const char *l1,
+ const char *f2, const char *l2) {
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
+ if (*f1 != *f2) return *f1 - *f2;
+ }
+ return (l1 - f1) - (l2 - f2);
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+*/
+SWIGRUNTIME int
+SWIG_TypeEquiv(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = SWIG_TypeNameComp(nb, ne, tb, te) == 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+/*
+ Register a type mapping with the type-checking
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeRegisterTL(swig_type_info **tl, swig_type_info *ti) {
+ swig_type_info *tc, *head, *ret, *next;
+ /* Check to see if this type has already been registered */
+ tc = *tl;
+ while (tc) {
+ /* check simple type equivalence */
+ int typeequiv = (strcmp(tc->name, ti->name) == 0);
+ /* check full type equivalence, resolving typedefs */
+ if (!typeequiv) {
+ /* only if tc is not a typedef (no '|' on it) */
+ if (tc->str && ti->str && !strstr(tc->str,"|")) {
+ typeequiv = SWIG_TypeEquiv(ti->str,tc->str);
+ }
+ }
+ if (typeequiv) {
+ /* Already exists in the table. Just add additional types to the list */
+ if (ti->clientdata) tc->clientdata = ti->clientdata;
+ head = tc;
+ next = tc->next;
+ goto l1;
+ }
+ tc = tc->prev;
+ }
+ head = ti;
+ next = 0;
+
+ /* Place in list */
+ ti->prev = *tl;
+ *tl = ti;
+
+ /* Build linked lists */
+ l1:
+ ret = head;
+ tc = ti + 1;
+ /* Patch up the rest of the links */
+ while (tc->name) {
+ head->next = tc;
+ tc->prev = head;
+ head = tc;
+ tc++;
+ }
+ if (next) next->prev = head;
+ head->next = next;
+
+ return ret;
+}
+
+/*
+ Check the typename
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeCheck(const char *c, swig_type_info *ty) {
+ swig_type_info *s;
+ if (!ty) return 0; /* Void pointer */
+ s = ty->next; /* First element always just a name */
+ do {
+ if (strcmp(s->name,c) == 0) {
+ if (s == ty->next) return s;
+ /* Move s to the top of the linked list */
+ s->prev->next = s->next;
+ if (s->next) {
+ s->next->prev = s->prev;
+ }
+ /* Insert s as second element in the list */
+ s->next = ty->next;
+ if (ty->next) ty->next->prev = s;
+ ty->next = s;
+ s->prev = ty;
+ return s;
+ }
+ s = s->next;
+ } while (s && (s != ty->next));
+ return 0;
+}
+
+/*
+ Cast a pointer up an inheritance hierarchy
+*/
+SWIGRUNTIMEINLINE void *
+SWIG_TypeCast(swig_type_info *ty, void *ptr) {
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
+}
+
+/*
+ Dynamic pointer casting. Down an inheritance hierarchy
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
+ swig_type_info *lastty = ty;
+ if (!ty || !ty->dcast) return ty;
+ while (ty && (ty->dcast)) {
+ ty = (*ty->dcast)(ptr);
+ if (ty) lastty = ty;
+ }
+ return lastty;
+}
+
+/*
+ Return the name associated with this type
+*/
+SWIGRUNTIMEINLINE const char *
+SWIG_TypeName(const swig_type_info *ty) {
+ return ty->name;
+}
+
+/*
+ Return the pretty name associated with this type,
+ that is an unmangled type name in a form presentable to the user.
+*/
+SWIGRUNTIME const char *
+SWIG_TypePrettyName(const swig_type_info *type) {
+ /* The "str" field contains the equivalent pretty names of the
+ type, separated by vertical-bar characters. We choose
+ to print the last name, as it is often (?) the most
+ specific. */
+ if (type->str != NULL) {
+ const char *last_name = type->str;
+ const char *s;
+ for (s = type->str; *s; s++)
+ if (*s == '|') last_name = s+1;
+ return last_name;
+ }
+ else
+ return type->name;
+}
+
+/*
+ Search for a swig_type_info structure
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeQueryTL(swig_type_info *tl, const char *name) {
+ swig_type_info *ty = tl;
+ while (ty) {
+ if (ty->str && (SWIG_TypeEquiv(ty->str,name))) return ty;
+ if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
+ ty = ty->prev;
+ }
+ return 0;
+}
+
+/*
+ Set the clientdata field for a type
+*/
+SWIGRUNTIME void
+SWIG_TypeClientDataTL(swig_type_info *tl, swig_type_info *ti, void *clientdata) {
+ swig_type_info *tc, *equiv;
+ if (ti->clientdata) return;
+ /* if (ti->clientdata == clientdata) return; */
+ ti->clientdata = clientdata;
+ equiv = ti->next;
+ while (equiv) {
+ if (!equiv->converter) {
+ tc = tl;
+ while (tc) {
+ if ((strcmp(tc->name, equiv->name) == 0))
+ SWIG_TypeClientDataTL(tl,tc,clientdata);
+ tc = tc->prev;
+ }
+ }
+ equiv = equiv->next;
+ }
+}
+
+/*
+ Pack binary data into a string
+*/
+SWIGRUNTIME char *
+SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static char hex[17] = "0123456789abcdef";
+ unsigned char *u = (unsigned char *) ptr;
+ const unsigned char *eu = u + sz;
+ register unsigned char uu;
+ for (; u != eu; ++u) {
+ uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+
+/*
+ Unpack binary data from a string
+*/
+SWIGRUNTIME const char *
+SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register int d = *(c++);
+ register unsigned char uu = 0;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+
+/*
+ This function will propagate the clientdata field of type to any new
+ swig_type_info structures that have been added into the list of
+ equivalent types. It is like calling SWIG_TypeClientData(type,
+ clientdata) a second time.
+*/
+SWIGRUNTIME void
+SWIG_PropagateClientDataTL(swig_type_info *tl, swig_type_info *type) {
+ swig_type_info *equiv = type->next;
+ swig_type_info *tc;
+ if (!type->clientdata) return;
+ while (equiv) {
+ if (!equiv->converter) {
+ tc = tl;
+ while (tc) {
+ if ((strcmp(tc->name, equiv->name) == 0) && !tc->clientdata)
+ SWIG_TypeClientDataTL(tl,tc, type->clientdata);
+ tc = tc->prev;
+ }
+ }
+ equiv = equiv->next;
+ }
+}
+
+/*
+ Pack 'void *' into a string buffer.
+*/
+SWIGRUNTIME char *
+SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
+ char *r = buff;
+ if ((2*sizeof(void *) + 2) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
+ strcpy(r,name);
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ *ptr = (void *) 0;
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sizeof(void *));
+}
+
+SWIGRUNTIME char *
+SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
+ char *r = buff;
+ size_t lname = (name ? strlen(name) : 0);
+ if ((2*sz + 2 + lname) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,ptr,sz);
+ if (lname) {
+ strncpy(r,name,lname+1);
+ } else {
+ *r = 0;
+ }
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ memset(ptr,0,sz);
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sz);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/***********************************************************************
+ * pyrun.swg
+ *
+ * This file contains the runtime support for Python modules
+ * and includes code for managing global variables and pointer
+ * type checking.
+ *
+ * Author : David Beazley (beazley@cs.uchicago.edu)
+ ************************************************************************/
+
+/* Common SWIG API */
+#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)
+#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)
+#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)
+
+
+/* Python-specific SWIG API */
+#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
+#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
+
+
+/* -----------------------------------------------------------------------------
+ * Pointer declarations
+ * ----------------------------------------------------------------------------- */
+/*
+ Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
+ C/C++ pointers in the python side. Very useful for debugging, but
+ not always safe.
+*/
+#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)
+# define SWIG_COBJECT_TYPES
+#endif
+
+/* Flags for pointer conversion */
+#define SWIG_POINTER_EXCEPTION 0x1
+#define SWIG_POINTER_DISOWN 0x2
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* -----------------------------------------------------------------------------
+ * Create a new pointer string
+ * ----------------------------------------------------------------------------- */
+
+#ifndef SWIG_BUFFER_SIZE
+#define SWIG_BUFFER_SIZE 1024
+#endif
+
+#if defined(SWIG_COBJECT_TYPES)
+#if !defined(SWIG_COBJECT_PYTHON)
+/* -----------------------------------------------------------------------------
+ * Implements a simple Swig Object type, and use it instead of PyCObject
+ * ----------------------------------------------------------------------------- */
+
+typedef struct {
+ PyObject_HEAD
+ void *ptr;
+ const char *desc;
+} PySwigObject;
+
+/* Declarations for objects of type PySwigObject */
+
+SWIGRUNTIME int
+PySwigObject_print(PySwigObject *v, FILE *fp, int flags)
+{
+ char result[SWIG_BUFFER_SIZE];
+ if (SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result))) {
+ fputs("<Swig Object at ", fp); fputs(result, fp); fputs(">", fp);
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_repr(PySwigObject *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
+ PyString_FromFormat("<Swig Object at %s>", result) : 0;
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_str(PySwigObject *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ return SWIG_PackVoidPtr(result, v->ptr, v->desc, sizeof(result)) ?
+ PyString_FromString(result) : 0;
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_long(PySwigObject *v)
+{
+ return PyLong_FromUnsignedLong((unsigned long) v->ptr);
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_oct(PySwigObject *v)
+{
+ char buf[100];
+ unsigned long x = (unsigned long)v->ptr;
+ if (x == 0)
+ strcpy(buf, "0");
+ else
+ PyOS_snprintf(buf, sizeof(buf), "0%lo", x);
+ return PyString_FromString(buf);
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_hex(PySwigObject *v)
+{
+ char buf[100];
+ PyOS_snprintf(buf, sizeof(buf), "0x%lx", (unsigned long)v->ptr);
+ return PyString_FromString(buf);
+}
+
+SWIGRUNTIME int
+PySwigObject_compare(PySwigObject *v, PySwigObject *w)
+{
+ int c = strcmp(v->desc, w->desc);
+ if (c) {
+ return c;
+ } else {
+ void *i = v->ptr;
+ void *j = w->ptr;
+ return (i < j) ? -1 : (i > j) ? 1 : 0;
+ }
+}
+
+SWIGRUNTIME void
+PySwigObject_dealloc(PySwigObject *self)
+{
+ PyObject_DEL(self);
+}
+
+SWIGRUNTIME PyTypeObject*
+PySwigObject_GetType() {
+ static char PySwigObject_Type__doc__[] =
+ "Swig object carries a C/C++ instance pointer";
+
+ static PyNumberMethods PySwigObject_as_number = {
+ (binaryfunc)0, /*nb_add*/
+ (binaryfunc)0, /*nb_subtract*/
+ (binaryfunc)0, /*nb_multiply*/
+ (binaryfunc)0, /*nb_divide*/
+ (binaryfunc)0, /*nb_remainder*/
+ (binaryfunc)0, /*nb_divmod*/
+ (ternaryfunc)0,/*nb_power*/
+ (unaryfunc)0, /*nb_negative*/
+ (unaryfunc)0, /*nb_positive*/
+ (unaryfunc)0, /*nb_absolute*/
+ (inquiry)0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ (coercion)0, /*nb_coerce*/
+ (unaryfunc)PySwigObject_long, /*nb_int*/
+ (unaryfunc)PySwigObject_long, /*nb_long*/
+ (unaryfunc)0, /*nb_float*/
+ (unaryfunc)PySwigObject_oct, /*nb_oct*/
+ (unaryfunc)PySwigObject_hex, /*nb_hex*/
+#if PY_VERSION_HEX >= 0x02000000
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */
+#endif
+ };
+
+ static PyTypeObject PySwigObject_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "PySwigObject", /*tp_name*/
+ sizeof(PySwigObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)PySwigObject_dealloc, /*tp_dealloc*/
+ (printfunc)PySwigObject_print, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
+ (cmpfunc)PySwigObject_compare, /*tp_compare*/
+ (reprfunc)PySwigObject_repr, /*tp_repr*/
+ &PySwigObject_as_number, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ (hashfunc)0, /*tp_hash*/
+ (ternaryfunc)0, /*tp_call*/
+ (reprfunc)PySwigObject_str, /*tp_str*/
+ /* Space for future expansion */
+ 0L,0L,0L,0L,
+ PySwigObject_Type__doc__, /* Documentation string */
+#if PY_VERSION_HEX >= 0x02000000
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+#endif
+#if PY_VERSION_HEX >= 0x02010000
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+#endif
+#if PY_VERSION_HEX >= 0x02020000
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+#endif
+#if PY_VERSION_HEX >= 0x02030000
+ 0, /* tp_del */
+#endif
+#ifdef COUNT_ALLOCS
+ 0,0,0,0 /* tp_alloc -> tp_next */
+#endif
+ };
+
+ return &PySwigObject_Type;
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_FromVoidPtrAndDesc(void *ptr, const char *desc)
+{
+ PySwigObject *self = PyObject_NEW(PySwigObject, PySwigObject_GetType());
+ if (self == NULL) return NULL;
+ self->ptr = ptr;
+ self->desc = desc;
+ return (PyObject *)self;
+}
+
+SWIGRUNTIMEINLINE void *
+PySwigObject_AsVoidPtr(PyObject *self)
+{
+ return ((PySwigObject *)self)->ptr;
+}
+
+SWIGRUNTIMEINLINE const char *
+PySwigObject_GetDesc(PyObject *self)
+{
+ return ((PySwigObject *)self)->desc;
+}
+
+SWIGRUNTIMEINLINE int
+PySwigObject_Check(PyObject *op) {
+ return ((op)->ob_type == PySwigObject_GetType())
+ || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0);
+}
+
+/* -----------------------------------------------------------------------------
+ * Implements a simple Swig Packed type, and use it instead of string
+ * ----------------------------------------------------------------------------- */
+
+typedef struct {
+ PyObject_HEAD
+ void *pack;
+ const char *desc;
+ size_t size;
+} PySwigPacked;
+
+SWIGRUNTIME int
+PySwigPacked_print(PySwigPacked *v, FILE *fp, int flags)
+{
+ char result[SWIG_BUFFER_SIZE];
+ fputs("<Swig Packed ", fp);
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+ fputs("at ", fp);
+ fputs(result, fp);
+ }
+ fputs(v->desc,fp);
+ fputs(">", fp);
+ return 0;
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_repr(PySwigPacked *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+ return PyString_FromFormat("<Swig Packed at %s%s>", result, v->desc);
+ } else {
+ return PyString_FromFormat("<Swig Packed %s>", v->desc);
+ }
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_str(PySwigPacked *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
+ return PyString_FromFormat("%s%s", result, v->desc);
+ } else {
+ return PyString_FromFormat("%s", v->desc);
+ }
+}
+
+SWIGRUNTIME int
+PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)
+{
+ int c = strcmp(v->desc, w->desc);
+ if (c) {
+ return c;
+ } else {
+ size_t i = v->size;
+ size_t j = w->size;
+ int s = (i < j) ? -1 : (i > j) ? 1 : 0;
+ return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
+ }
+}
+
+SWIGRUNTIME void
+PySwigPacked_dealloc(PySwigPacked *self)
+{
+ free(self->pack);
+ PyObject_DEL(self);
+}
+
+SWIGRUNTIME PyTypeObject*
+PySwigPacked_GetType() {
+ static char PySwigPacked_Type__doc__[] =
+ "Swig object carries a C/C++ instance pointer";
+
+ static PyTypeObject PySwigPacked_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "PySwigPacked", /*tp_name*/
+ sizeof(PySwigPacked), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor)PySwigPacked_dealloc, /*tp_dealloc*/
+ (printfunc)PySwigPacked_print, /*tp_print*/
+ (getattrfunc)0, /*tp_getattr*/
+ (setattrfunc)0, /*tp_setattr*/
+ (cmpfunc)PySwigPacked_compare, /*tp_compare*/
+ (reprfunc)PySwigPacked_repr, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ (hashfunc)0, /*tp_hash*/
+ (ternaryfunc)0, /*tp_call*/
+ (reprfunc)PySwigPacked_str, /*tp_str*/
+ /* Space for future expansion */
+ 0L,0L,0L,0L,
+ PySwigPacked_Type__doc__, /* Documentation string */
+#if PY_VERSION_HEX >= 0x02000000
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+#endif
+#if PY_VERSION_HEX >= 0x02010000
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+#endif
+#if PY_VERSION_HEX >= 0x02020000
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */
+#endif
+#if PY_VERSION_HEX >= 0x02030000
+ 0, /* tp_del */
+#endif
+#ifdef COUNT_ALLOCS
+ 0,0,0,0 /* tp_alloc -> tp_next */
+#endif
+ };
+
+ return &PySwigPacked_Type;
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc)
+{
+ PySwigPacked *self = PyObject_NEW(PySwigPacked, PySwigPacked_GetType());
+ if (self == NULL) {
+ return NULL;
+ } else {
+ void *pack = malloc(size);
+ memcpy(pack, ptr, size);
+ self->pack = pack;
+ self->desc = desc;
+ self->size = size;
+ return (PyObject *) self;
+ }
+}
+
+SWIGRUNTIMEINLINE const char *
+PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)
+{
+ PySwigPacked *self = (PySwigPacked *)obj;
+ if (self->size != size) return 0;
+ memcpy(ptr, self->pack, size);
+ return self->desc;
+}
+
+SWIGRUNTIMEINLINE const char *
+PySwigPacked_GetDesc(PyObject *self)
+{
+ return ((PySwigPacked *)self)->desc;
+}
+
+SWIGRUNTIMEINLINE int
+PySwigPacked_Check(PyObject *op) {
+ return ((op)->ob_type == PySwigPacked_GetType())
+ || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
+}
+
+#else
+/* -----------------------------------------------------------------------------
+ * Use the old Python PyCObject instead of PySwigObject
+ * ----------------------------------------------------------------------------- */
+
+#define PySwigObject_GetDesc(obj) PyCObject_GetDesc(obj)
+#define PySwigObject_Check(obj) PyCObject_Check(obj)
+#define PySwigObject_AsVoidPtr(obj) PyCObject_AsVoidPtr(obj)
+#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL)
+
+#endif
+
+#endif
+
+/* -----------------------------------------------------------------------------
+ * errors manipulation
+ * ----------------------------------------------------------------------------- */
+
+SWIGRUNTIME void
+SWIG_Python_TypeError(const char *type, PyObject *obj)
+{
+ if (type) {
+#if defined(SWIG_COBJECT_TYPES)
+ if (PySwigObject_Check(obj)) {
+ const char *otype = (const char *) PySwigObject_GetDesc(obj);
+ if (otype) {
+ PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received",
+ type, otype);
+ return;
+ }
+ } else
+#endif
+ {
+ const char *otype = (obj ? obj->ob_type->tp_name : 0);
+ if (otype) {
+ PyObject *str = PyObject_Str(obj);
+ const char *cstr = str ? PyString_AsString(str) : 0;
+ if (cstr) {
+ PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
+ type, otype, cstr);
+ } else {
+ PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
+ type, otype);
+ }
+ Py_DECREF(str);
+ return;
+ }
+ }
+ PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
+ } else {
+ PyErr_Format(PyExc_TypeError, "unexpected type is received");
+ }
+}
+
+SWIGRUNTIMEINLINE void
+SWIG_Python_NullRef(const char *type)
+{
+ if (type) {
+ PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received",type);
+ } else {
+ PyErr_Format(PyExc_TypeError, "null reference was received");
+ }
+}
+
+SWIGRUNTIME int
+SWIG_Python_AddErrMesg(const char* mesg, int infront)
+{
+ if (PyErr_Occurred()) {
+ PyObject *type = 0;
+ PyObject *value = 0;
+ PyObject *traceback = 0;
+ PyErr_Fetch(&type, &value, &traceback);
+ if (value) {
+ PyObject *old_str = PyObject_Str(value);
+ Py_XINCREF(type);
+ PyErr_Clear();
+ if (infront) {
+ PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str));
+ } else {
+ PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
+ }
+ Py_DECREF(old_str);
+ }
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+SWIGRUNTIME int
+SWIG_Python_ArgFail(int argnum)
+{
+ if (PyErr_Occurred()) {
+ /* add information about failing argument */
+ char mesg[256];
+ sprintf(mesg, "argument number %d:", argnum);
+ return SWIG_Python_AddErrMesg(mesg, 1);
+ } else {
+ return 0;
+ }
+}
+
+
+/* -----------------------------------------------------------------------------
+ * pointers/data manipulation
+ * ----------------------------------------------------------------------------- */
+
+/* Convert a pointer value */
+SWIGRUNTIME int
+SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
+ swig_type_info *tc;
+ const char *c = 0;
+ static PyObject *SWIG_this = 0;
+ int newref = 0;
+ PyObject *pyobj = 0;
+ void *vptr;
+
+ if (!obj) return 0;
+ if (obj == Py_None) {
+ *ptr = 0;
+ return 0;
+ }
+
+#ifdef SWIG_COBJECT_TYPES
+ if (!(PySwigObject_Check(obj))) {
+ if (!SWIG_this)
+ SWIG_this = PyString_FromString("this");
+ pyobj = obj;
+ obj = PyObject_GetAttr(obj,SWIG_this);
+ newref = 1;
+ if (!obj) goto type_error;
+ if (!PySwigObject_Check(obj)) {
+ Py_DECREF(obj);
+ goto type_error;
+ }
+ }
+ vptr = PySwigObject_AsVoidPtr(obj);
+ c = (const char *) PySwigObject_GetDesc(obj);
+ if (newref) { Py_DECREF(obj); }
+ goto type_check;
+#else
+ if (!(PyString_Check(obj))) {
+ if (!SWIG_this)
+ SWIG_this = PyString_FromString("this");
+ pyobj = obj;
+ obj = PyObject_GetAttr(obj,SWIG_this);
+ newref = 1;
+ if (!obj) goto type_error;
+ if (!PyString_Check(obj)) {
+ Py_DECREF(obj);
+ goto type_error;
+ }
+ }
+ c = PyString_AS_STRING(obj);
+ /* Pointer values must start with leading underscore */
+ c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);
+ if (newref) { Py_DECREF(obj); }
+ if (!c) goto type_error;
+#endif
+
+type_check:
+
+ if (ty) {
+ tc = SWIG_TypeCheck(c,ty);
+ if (!tc) goto type_error;
+ *ptr = SWIG_TypeCast(tc,vptr);
+ }
+
+ if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
+ PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False);
+ }
+ return 0;
+
+type_error:
+ PyErr_Clear();
+ if (pyobj && !obj) {
+ obj = pyobj;
+ if (PyCFunction_Check(obj)) {
+ /* here we get the method pointer for callbacks */
+ char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
+ c = doc ? strstr(doc, "swig_ptr: ") : 0;
+ if (c) {
+ c = SWIG_UnpackVoidPtr(c + 10, &vptr, ty->name);
+ if (!c) goto type_error;
+ goto type_check;
+ }
+ }
+ }
+ if (flags & SWIG_POINTER_EXCEPTION) {
+ if (ty) {
+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+ } else {
+ SWIG_Python_TypeError("C/C++ pointer", obj);
+ }
+ }
+ return -1;
+}
+
+/* Convert a pointer value, signal an exception on a type mismatch */
+SWIGRUNTIME void *
+SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
+ void *result;
+ if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
+ PyErr_Clear();
+ if (flags & SWIG_POINTER_EXCEPTION) {
+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+ SWIG_Python_ArgFail(argnum);
+ }
+ }
+ return result;
+}
+
+/* Convert a packed value value */
+SWIGRUNTIME int
+SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {
+ swig_type_info *tc;
+ const char *c = 0;
+
+#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
+ c = PySwigPacked_UnpackData(obj, ptr, sz);
+#else
+ if ((!obj) || (!PyString_Check(obj))) goto type_error;
+ c = PyString_AS_STRING(obj);
+ /* Pointer values must start with leading underscore */
+ c = SWIG_UnpackDataName(c, ptr, sz, ty->name);
+#endif
+ if (!c) goto type_error;
+ if (ty) {
+ tc = SWIG_TypeCheck(c,ty);
+ if (!tc) goto type_error;
+ }
+ return 0;
+
+type_error:
+ PyErr_Clear();
+ if (flags & SWIG_POINTER_EXCEPTION) {
+ if (ty) {
+ SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
+ } else {
+ SWIG_Python_TypeError("C/C++ packed data", obj);
+ }
+ }
+ return -1;
+}
+
+/* Create a new array object */
+SWIGRUNTIME PyObject *
+SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
+ PyObject *robj = 0;
+ if (!ptr) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+#ifdef SWIG_COBJECT_TYPES
+ robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);
+#else
+ {
+ char result[SWIG_BUFFER_SIZE];
+ robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?
+ PyString_FromString(result) : 0;
+ }
+#endif
+ if (!robj || (robj == Py_None)) return robj;
+ if (type->clientdata) {
+ PyObject *inst;
+ PyObject *args = Py_BuildValue((char*)"(O)", robj);
+ Py_DECREF(robj);
+ inst = PyObject_CallObject((PyObject *) type->clientdata, args);
+ Py_DECREF(args);
+ if (inst) {
+ if (own) {
+ PyObject_SetAttrString(inst,(char*)"thisown",Py_True);
+ }
+ robj = inst;
+ }
+ }
+ return robj;
+}
+
+SWIGRUNTIME PyObject *
+SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
+ PyObject *robj = 0;
+ if (!ptr) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
+ robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);
+#else
+ {
+ char result[SWIG_BUFFER_SIZE];
+ robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?
+ PyString_FromString(result) : 0;
+ }
+#endif
+ return robj;
+}
+
+/* -----------------------------------------------------------------------------*
+ * Get type list
+ * -----------------------------------------------------------------------------*/
+
+#ifdef SWIG_LINK_RUNTIME
+void *SWIG_ReturnGlobalTypeList(void *);
+#endif
+
+SWIGRUNTIME swig_type_info **
+SWIG_Python_GetTypeListHandle() {
+ static void *type_pointer = (void *)0;
+ /* first check if module already created */
+ if (!type_pointer) {
+#ifdef SWIG_LINK_RUNTIME
+ type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
+#else
+ type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
+ (char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ type_pointer = (void *)0;
+ }
+ }
+#endif
+ return (swig_type_info **) type_pointer;
+}
+
+/*
+ Search for a swig_type_info structure
+ */
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_Python_GetTypeList() {
+ swig_type_info **tlh = SWIG_Python_GetTypeListHandle();
+ return tlh ? *tlh : (swig_type_info*)0;
+}
+
+#define SWIG_Runtime_GetTypeList SWIG_Python_GetTypeList
+
+#ifdef __cplusplus
+}
+#endif
+
+/* -----------------------------------------------------------------------------*
+ Standard SWIG API for use inside user code.
+
+ You need to include in your code as follow:
+
+#include <Python.h> // or using your favorite language
+#include <swigrun.swg>
+#include <python/pyrun.swg> // or using your favorite language
+#include <runtime.swg>
+
+ * -----------------------------------------------------------------------------*/
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_Runtime_TypeQuery(const char *name) {
+ swig_type_info *tl = SWIG_Runtime_GetTypeList();
+ return SWIG_TypeQueryTL(tl, name);
+}
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_Runtime_TypeRegister(swig_type_info *ti) {
+ swig_type_info *tl = SWIG_Runtime_GetTypeList();
+ return SWIG_TypeRegisterTL(&tl, ti);
+}
+
+SWIGRUNTIMEINLINE void
+SWIG_Runtime_TypeClientData(swig_type_info *ti, void *clientdata) {
+ swig_type_info *tl = SWIG_Runtime_GetTypeList();
+ SWIG_TypeClientDataTL(tl, ti, clientdata);
+}
+
+SWIGRUNTIMEINLINE void
+SWIG_Runtime_PropagateClientData(swig_type_info *type) {
+ swig_type_info *tl = SWIG_Runtime_GetTypeList();
+ SWIG_PropagateClientDataTL(tl, type);
+}
+
+#define SWIG_GetTypeList() SWIG_Runtime_GetTypeList()
+#define SWIG_TypeQuery(name) SWIG_Runtime_TypeQuery(name)
+#define SWIG_TypeRegister(ti) SWIG_Runtime_TypeRegister(ti)
+#define SWIG_TypeClientData(ti, cd) SWIG_Runtime_TypeClientData(ti, cd)
+#define SWIG_PropagateClientData(ti) SWIG_Runtime_PropagateClientData(ti)
+
+"""
+
+######################################################################
+# This is for SWIG-1.3.x where x >= 25.
+# SWIG_RUNTIME_VERSION == "2"
+
+# All this does is to include the contents of the file generated by
+# this command:
+# swig -python -external-runtime
+swigptr2_code_v2 = """
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.28
+ *
+ * This file is not intended to be easily readable and contains a number of
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+/***********************************************************************
+ *
+ * This section contains generic SWIG labels for method/variable
+ * declarations/attributes, and other compiler dependent labels.
+ *
+ ************************************************************************/
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC)
+# if (__SUNPRO_CC <= 0x560)
+# define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+# else
+# define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+# define SWIGINLINE inline
+# else
+# define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+# elif defined(__ICC)
+# define SWIGUNUSED __attribute__ ((__unused__))
+# else
+# define SWIGUNUSED
+# endif
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+# define SWIGUNUSEDPARM(p)
+# else
+# define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods for Windows DLLs */
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# if defined(STATIC_LINKED)
+# define SWIGEXPORT
+# else
+# define SWIGEXPORT __declspec(dllexport)
+# endif
+# else
+# define SWIGEXPORT
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# define SWIGSTDCALL __stdcall
+# else
+# define SWIGSTDCALL
+# endif
+#endif
+
+
+/* Errors in SWIG */
+#define SWIG_UnknownError -1
+#define SWIG_IOError -2
+#define SWIG_RuntimeError -3
+#define SWIG_IndexError -4
+#define SWIG_TypeError -5
+#define SWIG_DivisionByZero -6
+#define SWIG_OverflowError -7
+#define SWIG_SyntaxError -8
+#define SWIG_ValueError -9
+#define SWIG_SystemError -10
+#define SWIG_AttributeError -11
+#define SWIG_MemoryError -12
+#define SWIG_NullReferenceError -13
+
+
+
+/***********************************************************************
+ * swigrun.swg
+ *
+ * This file contains generic CAPI SWIG runtime support for pointer
+ * type checking.
+ *
+ ************************************************************************/
+
+/* This should only be incremented when either the layout of swig_type_info changes,
+ or for whatever reason, the runtime changes incompatibly */
+#define SWIG_RUNTIME_VERSION "2"
+
+/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */
+#ifdef SWIG_TYPE_TABLE
+# define SWIG_QUOTE_STRING(x) #x
+# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x)
+# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE)
+#else
+# define SWIG_TYPE_TABLE_NAME
+#endif
+
+/*
+ You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for
+ creating a static or dynamic library from the swig runtime code.
+ In 99.9% of the cases, swig just needs to declare them as 'static'.
+
+ But only do this if is strictly necessary, ie, if you have problems
+ with your compiler or so.
+*/
+
+#ifndef SWIGRUNTIME
+# define SWIGRUNTIME SWIGINTERN
+#endif
+
+#ifndef SWIGRUNTIMEINLINE
+# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
+#endif
+
+/* Generic buffer size */
+#ifndef SWIG_BUFFER_SIZE
+# define SWIG_BUFFER_SIZE 1024
+#endif
+
+/* Flags for pointer conversions */
+#define SWIG_POINTER_DISOWN 0x1
+
+/* Flags for new pointer objects */
+#define SWIG_POINTER_OWN 0x1
+
+
+/*
+ Flags/methods for returning states.
+
+ The swig conversion methods, as ConvertPtr, return and integer
+ that tells if the conversion was successful or not. And if not,
+ an error code can be returned (see swigerrors.swg for the codes).
+
+ Use the following macros/flags to set or process the returning
+ states.
+
+ In old swig versions, you usually write code as:
+
+ if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) {
+ // success code
+ } else {
+ //fail code
+ }
+
+ Now you can be more explicit as:
+
+ int res = SWIG_ConvertPtr(obj,vptr,ty.flags);
+ if (SWIG_IsOK(res)) {
+ // success code
+ } else {
+ // fail code
+ }
+
+ that seems to be the same, but now you can also do
+
+ Type *ptr;
+ int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags);
+ if (SWIG_IsOK(res)) {
+ // success code
+ if (SWIG_IsNewObj(res) {
+ ...
+ delete *ptr;
+ } else {
+ ...
+ }
+ } else {
+ // fail code
+ }
+
+ I.e., now SWIG_ConvertPtr can return new objects and you can
+ identify the case and take care of the deallocation. Of course that
+ requires also to SWIG_ConvertPtr to return new result values, as
+
+ int SWIG_ConvertPtr(obj, ptr,...) {
+ if (<obj is ok>) {
+ if (<need new object>) {
+ *ptr = <ptr to new allocated object>;
+ return SWIG_NEWOBJ;
+ } else {
+ *ptr = <ptr to old object>;
+ return SWIG_OLDOBJ;
+ }
+ } else {
+ return SWIG_BADOBJ;
+ }
+ }
+
+ Of course, returning the plain '0(success)/-1(fail)' still works, but you can be
+ more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the
+ swig errors code.
+
+ Finally, if the SWIG_CASTRANK_MODE is enabled, the result code
+ allows to return the 'cast rank', for example, if you have this
+
+ int food(double)
+ int fooi(int);
+
+ and you call
+
+ food(1) // cast rank '1' (1 -> 1.0)
+ fooi(1) // cast rank '0'
+
+ just use the SWIG_AddCast()/SWIG_CheckState()
+
+
+ */
+#define SWIG_OK (0)
+#define SWIG_ERROR (-1)
+#define SWIG_IsOK(r) (r >= 0)
+
+/* The CastRankLimit says how many bits are used for the cast rank */
+#define SWIG_CASTRANKLIMIT (1 << 8)
+/* The NewMask denotes the object was created (using new/malloc) */
+#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1)
+/* The TmpMask is for in/out typemaps that use temporal objects */
+#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1)
+/* Simple returning values */
+#define SWIG_BADOBJ (SWIG_ERROR)
+#define SWIG_OLDOBJ (SWIG_OK)
+#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK)
+#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK)
+/* Check, add and del mask methods */
+#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r)
+#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r)
+#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK))
+#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r)
+#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r)
+#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK))
+
+
+/* Cast-Rank Mode */
+#if defined(SWIG_CASTRANK_MODE)
+# ifndef SWIG_TypeRank
+# define SWIG_TypeRank unsigned long
+# endif
+# ifndef SWIG_MAXCASTRANK /* Default cast allowed */
+# define SWIG_MAXCASTRANK (2)
+# endif
+# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1)
+# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK)
+SWIGINTERNINLINE int SWIG_AddCast(int r) {
+ return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r;
+}
+SWIGINTERNINLINE int SWIG_CheckState(int r) {
+ return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0;
+}
+#else /* no cast-rank mode */
+# define SWIG_AddCast
+# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0)
+#endif
+
+
+
+
+#include <string.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void *(*swig_converter_func)(void *);
+typedef struct swig_type_info *(*swig_dycast_func)(void **);
+
+/* Structure to store inforomation on one type */
+typedef struct swig_type_info {
+ const char *name; /* mangled name of this type */
+ const char *str; /* human readable name of this type */
+ swig_dycast_func dcast; /* dynamic cast function down a hierarchy */
+ struct swig_cast_info *cast; /* linked list of types that can cast into this type */
+ void *clientdata; /* language specific type data */
+ int owndata; /* flag if the structure owns the clientdata */
+} swig_type_info;
+
+/* Structure to store a type and conversion function used for casting */
+typedef struct swig_cast_info {
+ swig_type_info *type; /* pointer to type that is equivalent to this type */
+ swig_converter_func converter; /* function to cast the void pointers */
+ struct swig_cast_info *next; /* pointer to next cast in linked list */
+ struct swig_cast_info *prev; /* pointer to the previous cast */
+} swig_cast_info;
+
+/* Structure used to store module information
+ * Each module generates one structure like this, and the runtime collects
+ * all of these structures and stores them in a circularly linked list.*/
+typedef struct swig_module_info {
+ swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */
+ size_t size; /* Number of types in this module */
+ struct swig_module_info *next; /* Pointer to next element in circularly linked list */
+ swig_type_info **type_initial; /* Array of initially generated type structures */
+ swig_cast_info **cast_initial; /* Array of initially generated casting structures */
+ void *clientdata; /* Language specific module data */
+} swig_module_info;
+
+/*
+ Compare two type names skipping the space characters, therefore
+ "char*" == "char *" and "Class<int>" == "Class<int >", etc.
+
+ Return 0 when the two name types are equivalent, as in
+ strncmp, but skipping ' '.
+*/
+SWIGRUNTIME int
+SWIG_TypeNameComp(const char *f1, const char *l1,
+ const char *f2, const char *l2) {
+ for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) {
+ while ((*f1 == ' ') && (f1 != l1)) ++f1;
+ while ((*f2 == ' ') && (f2 != l2)) ++f2;
+ if (*f1 != *f2) return (int)(*f1 - *f2);
+ }
+ return (l1 - f1) - (l2 - f2);
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+ Return 0 if not equal, 1 if equal
+*/
+SWIGRUNTIME int
+SWIG_TypeEquiv(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+/*
+ Check type equivalence in a name list like <name1>|<name2>|...
+ Return 0 if equal, -1 if nb < tb, 1 if nb > tb
+*/
+SWIGRUNTIME int
+SWIG_TypeCompare(const char *nb, const char *tb) {
+ int equiv = 0;
+ const char* te = tb + strlen(tb);
+ const char* ne = nb;
+ while (!equiv && *ne) {
+ for (nb = ne; *ne; ++ne) {
+ if (*ne == '|') break;
+ }
+ equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0;
+ if (*ne) ++ne;
+ }
+ return equiv;
+}
+
+
+/* think of this as a c++ template<> or a scheme macro */
+#define SWIG_TypeCheck_Template(comparison, ty) \
+ if (ty) { \
+ swig_cast_info *iter = ty->cast; \
+ while (iter) { \
+ if (comparison) { \
+ if (iter == ty->cast) return iter; \
+ /* Move iter to the top of the linked list */ \
+ iter->prev->next = iter->next; \
+ if (iter->next) \
+ iter->next->prev = iter->prev; \
+ iter->next = ty->cast; \
+ iter->prev = 0; \
+ if (ty->cast) ty->cast->prev = iter; \
+ ty->cast = iter; \
+ return iter; \
+ } \
+ iter = iter->next; \
+ } \
+ } \
+ return 0
+
+/*
+ Check the typename
+*/
+SWIGRUNTIME swig_cast_info *
+SWIG_TypeCheck(const char *c, swig_type_info *ty) {
+ SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty);
+}
+
+/* Same as previous function, except strcmp is replaced with a pointer comparison */
+SWIGRUNTIME swig_cast_info *
+SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) {
+ SWIG_TypeCheck_Template(iter->type == from, into);
+}
+
+/*
+ Cast a pointer up an inheritance hierarchy
+*/
+SWIGRUNTIMEINLINE void *
+SWIG_TypeCast(swig_cast_info *ty, void *ptr) {
+ return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr);
+}
+
+/*
+ Dynamic pointer casting. Down an inheritance hierarchy
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) {
+ swig_type_info *lastty = ty;
+ if (!ty || !ty->dcast) return ty;
+ while (ty && (ty->dcast)) {
+ ty = (*ty->dcast)(ptr);
+ if (ty) lastty = ty;
+ }
+ return lastty;
+}
+
+/*
+ Return the name associated with this type
+*/
+SWIGRUNTIMEINLINE const char *
+SWIG_TypeName(const swig_type_info *ty) {
+ return ty->name;
+}
+
+/*
+ Return the pretty name associated with this type,
+ that is an unmangled type name in a form presentable to the user.
+*/
+SWIGRUNTIME const char *
+SWIG_TypePrettyName(const swig_type_info *type) {
+ /* The "str" field contains the equivalent pretty names of the
+ type, separated by vertical-bar characters. We choose
+ to print the last name, as it is often (?) the most
+ specific. */
+ if (!type) return NULL;
+ if (type->str != NULL) {
+ const char *last_name = type->str;
+ const char *s;
+ for (s = type->str; *s; s++)
+ if (*s == '|') last_name = s+1;
+ return last_name;
+ }
+ else
+ return type->name;
+}
+
+/*
+ Set the clientdata field for a type
+*/
+SWIGRUNTIME void
+SWIG_TypeClientData(swig_type_info *ti, void *clientdata) {
+ swig_cast_info *cast = ti->cast;
+ /* if (ti->clientdata == clientdata) return; */
+ ti->clientdata = clientdata;
+
+ while (cast) {
+ if (!cast->converter) {
+ swig_type_info *tc = cast->type;
+ if (!tc->clientdata) {
+ SWIG_TypeClientData(tc, clientdata);
+ }
+ }
+ cast = cast->next;
+ }
+}
+SWIGRUNTIME void
+SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) {
+ SWIG_TypeClientData(ti, clientdata);
+ ti->owndata = 1;
+}
+
+/*
+ Search for a swig_type_info structure only by mangled name
+ Search is a O(log #types)
+
+ We start searching at module start, and finish searching when start == end.
+ Note: if start == end at the beginning of the function, we go all the way around
+ the circular list.
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_MangledTypeQueryModule(swig_module_info *start,
+ swig_module_info *end,
+ const char *name) {
+ swig_module_info *iter = start;
+ do {
+ if (iter->size) {
+ register size_t l = 0;
+ register size_t r = iter->size - 1;
+ do {
+ /* since l+r >= 0, we can (>> 1) instead (/ 2) */
+ register size_t i = (l + r) >> 1;
+ const char *iname = iter->types[i]->name;
+ if (iname) {
+ register int compare = strcmp(name, iname);
+ if (compare == 0) {
+ return iter->types[i];
+ } else if (compare < 0) {
+ if (i) {
+ r = i - 1;
+ } else {
+ break;
+ }
+ } else if (compare > 0) {
+ l = i + 1;
+ }
+ } else {
+ break; /* should never happen */
+ }
+ } while (l <= r);
+ }
+ iter = iter->next;
+ } while (iter != end);
+ return 0;
+}
+
+/*
+ Search for a swig_type_info structure for either a mangled name or a human readable name.
+ It first searches the mangled names of the types, which is a O(log #types)
+ If a type is not found it then searches the human readable names, which is O(#types).
+
+ We start searching at module start, and finish searching when start == end.
+ Note: if start == end at the beginning of the function, we go all the way around
+ the circular list.
+*/
+SWIGRUNTIME swig_type_info *
+SWIG_TypeQueryModule(swig_module_info *start,
+ swig_module_info *end,
+ const char *name) {
+ /* STEP 1: Search the name field using binary search */
+ swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name);
+ if (ret) {
+ return ret;
+ } else {
+ /* STEP 2: If the type hasn't been found, do a complete search
+ of the str field (the human readable name) */
+ swig_module_info *iter = start;
+ do {
+ register size_t i = 0;
+ for (; i < iter->size; ++i) {
+ if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name)))
+ return iter->types[i];
+ }
+ iter = iter->next;
+ } while (iter != end);
+ }
+
+ /* neither found a match */
+ return 0;
+}
+
+/*
+ Pack binary data into a string
+*/
+SWIGRUNTIME char *
+SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static const char hex[17] = "0123456789abcdef";
+ register const unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register unsigned char uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+
+/*
+ Unpack binary data from a string
+*/
+SWIGRUNTIME const char *
+SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register char d = *(c++);
+ register unsigned char uu;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+
+/*
+ Pack 'void *' into a string buffer.
+*/
+SWIGRUNTIME char *
+SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) {
+ char *r = buff;
+ if ((2*sizeof(void *) + 2) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,&ptr,sizeof(void *));
+ if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
+ strcpy(r,name);
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ *ptr = (void *) 0;
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sizeof(void *));
+}
+
+SWIGRUNTIME char *
+SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) {
+ char *r = buff;
+ size_t lname = (name ? strlen(name) : 0);
+ if ((2*sz + 2 + lname) > bsz) return 0;
+ *(r++) = '_';
+ r = SWIG_PackData(r,ptr,sz);
+ if (lname) {
+ strncpy(r,name,lname+1);
+ } else {
+ *r = 0;
+ }
+ return buff;
+}
+
+SWIGRUNTIME const char *
+SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) {
+ if (*c != '_') {
+ if (strcmp(c,"NULL") == 0) {
+ memset(ptr,0,sz);
+ return name;
+ } else {
+ return 0;
+ }
+ }
+ return SWIG_UnpackData(++c,ptr,sz);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/***********************************************************************
+ * pyrun.swg
+ *
+ * This file contains the runtime support for Python modules
+ * and includes code for managing global variables and pointer
+ * type checking.
+ *
+ * Author : David Beazley (beazley@cs.uchicago.edu)
+ ************************************************************************/
+
+/* Common SWIG API */
+
+/* for raw pointers */
+#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
+#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags)
+#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own)
+#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags)
+#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty)
+#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src)
+#define swig_owntype int
+
+/* for raw packed data */
+#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
+#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
+
+/* for class or struct pointers */
+#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
+#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
+
+/* for C or C++ function pointers */
+#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type)
+#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0)
+
+/* for C++ member pointers, ie, member methods */
+#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
+#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
+
+
+/* Runtime API */
+
+#define SWIG_GetModule(clientdata) SWIG_Python_GetModule()
+#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer)
+#define SWIG_NewClientData(obj) PySwigClientData_New(obj)
+
+/* A functor is a function object with one single object argument */
+#if PY_VERSION_HEX >= 0x02020000
+#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL);
+#else
+#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj);
+#endif
+
+/* Error manipulation */
+#define SWIG_SetErrorObj(type, obj) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetObject(type, obj); SWIG_PYTHON_THREAD_END_BLOCK; }
+#define SWIG_SetErrorMsg(type, msg) {SWIG_PYTHON_THREAD_BEGIN_BLOCK; PyErr_SetString(type, msg); SWIG_PYTHON_THREAD_END_BLOCK; }
+#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code)
+#define SWIG_Error(code, msg) SWIG_SetErrorMsg(SWIG_Python_ErrorType(code), msg)
+#define SWIG_fail goto fail
+
+
+/*
+ Helper for static pointer initialization for both C and C++ code, for example
+ static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...);
+*/
+#ifdef __cplusplus
+#define SWIG_STATIC_POINTER(var) var
+#else
+#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var
+#endif
+
+/* -----------------------------------------------------------------------------
+ * Pointer declarations
+ * ----------------------------------------------------------------------------- */
+
+/* Flags for new pointer objects */
+#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1)
+#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN)
+
+#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1)
+
+/* For backward compatibility only */
+#define SWIG_POINTER_EXCEPTION 0
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+} /* cc-mode */
+#endif
+#endif
+
+/* Safe Py_None and Py_Void accessors */
+
+#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+# ifndef SWIG_PYTHON_NO_SAFE_NONE
+# ifndef SWIG_PYTHON_SAFE_NONE
+# define SWIG_PYTHON_SAFE_NONE
+# endif
+# endif
+#endif
+
+#ifdef SWIG_PYTHON_SAFE_NONE
+SWIGRUNTIMEINLINE PyObject *
+_SWIG_Py_None(void)
+{
+ PyObject *none = Py_BuildValue("");
+ Py_DECREF(none);
+ return none;
+}
+SWIGRUNTIME PyObject *
+SWIG_Py_None(void)
+{
+ static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None();
+ return none;
+}
+# ifdef Py_None
+# undef Py_None
+# define Py_None SWIG_Py_None()
+# endif
+#endif
+
+SWIGRUNTIMEINLINE PyObject *
+SWIG_Py_Void(void)
+{
+ PyObject *none = Py_None;
+ Py_INCREF(none);
+ return none;
+}
+
+/* Append a value to the result obj */
+
+SWIGINTERN PyObject*
+SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
+ if (!result) {
+ result = obj;
+ } else if (result == Py_None) {
+ Py_DECREF(result);
+ result = obj;
+ } else {
+ if (!PyList_Check(result)) {
+ PyObject *o2 = result;
+ result = PyList_New(1);
+ PyList_SetItem(result, 0, o2);
+ }
+ PyList_Append(result,obj);
+ Py_DECREF(obj);
+ }
+ return result;
+}
+
+SWIGINTERN int
+SWIG_Python_UnpackTuple(PyObject *args, const char *name, int min, int max, PyObject **objs)
+{
+ if (!PyTuple_Check(args)) {
+ PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple");
+ return 0;
+ } else {
+ register int l = PyTuple_GET_SIZE(args);
+ if (l < min) {
+ PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
+ name, (min == max ? "" : "at least "), min, l);
+ return 0;
+ } else if (l > max) {
+ PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d",
+ name, (min == max ? "" : "at most "), max, l);
+ return 0;
+ } else {
+ register int i;
+ for (i = 0; i < l; ++i) {
+ objs[i] = PyTuple_GET_ITEM(args, i);
+ }
+ for (; l < max; ++l) {
+ objs[l] = 0;
+ }
+ return i + 1;
+ }
+ }
+}
+
+/* PySwigClientData */
+
+typedef struct {
+ PyObject *klass;
+ PyObject *newraw;
+ PyObject *newargs;
+ PyObject *destroy;
+ int delargs;
+ int implicitconv;
+} PySwigClientData;
+
+SWIGRUNTIMEINLINE int
+SWIG_Python_CheckImplicit(swig_type_info *ty)
+{
+ PySwigClientData *data = (PySwigClientData *)ty->clientdata;
+ return data ? data->implicitconv : 0;
+}
+
+
+SWIGRUNTIME PySwigClientData *
+PySwigClientData_New(PyObject* obj)
+{
+ if (!obj) {
+ return 0;
+ } else {
+ PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData));
+ /* the klass element */
+ data->klass = obj;
+ Py_INCREF(obj);
+ /* the newraw method and newargs arguments used to create a new raw instance */
+ if (PyClass_Check(obj)) {
+ data->newraw = 0;
+ data->newargs = obj;
+ Py_INCREF(obj);
+ } else {
+#if (PY_VERSION_HEX < 0x02020000)
+ data->newraw = 0;
+ data->newargs = obj;
+ Py_INCREF(obj);
+#else
+ data->newraw = PyObject_GetAttrString((PyObject*)&PyBaseObject_Type, "__new__");
+ Py_INCREF(data->newraw);
+ data->newargs = PyTuple_New(1);
+ PyTuple_SetItem(data->newargs, 0, obj);
+ Py_INCREF(data->newargs);
+#endif
+ }
+ /* the destroy method, aka as the C++ delete method */
+ data->destroy = PyObject_GetAttrString(data->klass, "__swig_destroy__");
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ data->destroy = 0;
+ }
+ if (data->destroy) {
+ Py_INCREF(data->destroy);
+ int flags = PyCFunction_GET_FLAGS(data->destroy);
+#ifdef METH_O
+ data->delargs = !(flags & (METH_O));
+#else
+ data->delargs = 0;
+#endif
+ } else {
+ data->delargs = 0;
+ }
+ data->implicitconv = 0;
+ return data;
+ }
+}
+
+SWIGRUNTIME void
+PySwigClientData_Del(PySwigClientData* data)
+{
+ Py_XDECREF(data->klass);
+ Py_XDECREF(data->newraw);
+ Py_XDECREF(data->newargs);
+ Py_XDECREF(data->destroy);
+ free(data);
+}
+
+/* =============== PySwigObject =====================*/
+
+typedef struct {
+ PyObject_HEAD
+ void *ptr;
+ swig_type_info *ty;
+ int own;
+ PyObject *next;
+} PySwigObject;
+
+SWIGRUNTIME PyObject *
+PySwigObject_long(PySwigObject *v)
+{
+ return PyLong_FromVoidPtr(v->ptr);
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_format(const char* fmt, PySwigObject *v)
+{
+ PyObject *res = NULL;
+ PyObject *args = PyTuple_New(1);
+ if (args) {
+ if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) {
+ PyObject *ofmt = PyString_FromString(fmt);
+ if (ofmt) {
+ res = PyString_Format(ofmt,args);
+ Py_DECREF(ofmt);
+ }
+ Py_DECREF(args);
+ }
+ }
+ return res;
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_oct(PySwigObject *v)
+{
+ return PySwigObject_format("%o",v);
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_hex(PySwigObject *v)
+{
+ return PySwigObject_format("%x",v);
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_repr(PySwigObject *v)
+{
+ const char *name = SWIG_TypePrettyName(v->ty);
+ PyObject *hex = PySwigObject_hex(v);
+ PyObject *repr = PyString_FromFormat("<Swig Object of type '%s' at 0x%s>", name, PyString_AsString(hex));
+ Py_DECREF(hex);
+ if (v->next) {
+ PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next);
+ PyString_ConcatAndDel(&repr,nrep);
+ }
+ return repr;
+}
+
+SWIGRUNTIME int
+PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags))
+{
+ PyObject *repr = PySwigObject_repr(v);
+ if (repr) {
+ fputs(PyString_AsString(repr), fp);
+ Py_DECREF(repr);
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_str(PySwigObject *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ?
+ PyString_FromString(result) : 0;
+}
+
+SWIGRUNTIME int
+PySwigObject_compare(PySwigObject *v, PySwigObject *w)
+{
+ void *i = v->ptr;
+ void *j = w->ptr;
+ return (i < j) ? -1 : ((i > j) ? 1 : 0);
+}
+
+SWIGRUNTIME PyTypeObject* _PySwigObject_type(void);
+
+SWIGRUNTIME PyTypeObject*
+PySwigObject_type(void) {
+ static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type();
+ return type;
+}
+
+SWIGRUNTIMEINLINE int
+PySwigObject_Check(PyObject *op) {
+ return ((op)->ob_type == PySwigObject_type())
+ || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0);
+}
+
+
+SWIGRUNTIME PyObject *
+PySwigObject_New(void *ptr, swig_type_info *ty, int own);
+
+SWIGRUNTIME void
+PySwigObject_dealloc(PyObject *v)
+{
+ PySwigObject *sobj = (PySwigObject *) v;
+ PyObject *next = sobj->next;
+ if (sobj->own) {
+ swig_type_info *ty = sobj->ty;
+ PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0;
+ PyObject *destroy = data ? data->destroy : 0;
+ if (destroy) {
+ /* destroy is always a VARARGS method */
+ PyObject *res;
+ if (data->delargs) {
+ /* we need to create a temporal object to carry the destroy operation */
+ PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0);
+ res = SWIG_Python_CallFunctor(destroy, tmp);
+ Py_DECREF(tmp);
+ } else {
+ PyCFunction meth = PyCFunction_GET_FUNCTION(destroy);
+ PyObject *mself = PyCFunction_GET_SELF(destroy);
+ res = ((*meth)(mself, v));
+ }
+ Py_XDECREF(res);
+ } else {
+ const char *name = SWIG_TypePrettyName(ty);
+#if (PY_VERSION_HEX >= 0x02020000)
+ PyObject *wrn = PyString_FromFormat("swig/python detected a memory leak of type '%s'.", name);
+ PyErr_Warn(PyExc_RuntimeWarning, PyString_AsString(wrn));
+ Py_DECREF(wrn);
+#else
+ printf("swig/python detected a memory leak of type '%s'.", name);
+#endif
+ }
+ }
+ Py_XDECREF(next);
+ PyObject_DEL(v);
+}
+
+SWIGRUNTIME PyObject*
+PySwigObject_append(PyObject* v, PyObject* next)
+{
+ PySwigObject *sobj = (PySwigObject *) v;
+#ifndef METH_O
+ PyObject *tmp = 0;
+ if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL;
+ next = tmp;
+#endif
+ if (!PySwigObject_Check(next)) {
+ return NULL;
+ }
+ sobj->next = next;
+ Py_INCREF(next);
+ return SWIG_Py_Void();
+}
+
+SWIGRUNTIME PyObject*
+#ifdef METH_NOARGS
+PySwigObject_next(PyObject* v)
+#else
+PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
+#endif
+{
+ PySwigObject *sobj = (PySwigObject *) v;
+ if (sobj->next) {
+ Py_INCREF(sobj->next);
+ return sobj->next;
+ } else {
+ return SWIG_Py_Void();
+ }
+}
+
+SWIGINTERN PyObject*
+#ifdef METH_NOARGS
+PySwigObject_disown(PyObject *v)
+#else
+PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
+#endif
+{
+ PySwigObject *sobj = (PySwigObject *)v;
+ sobj->own = 0;
+ return SWIG_Py_Void();
+}
+
+SWIGINTERN PyObject*
+#ifdef METH_NOARGS
+PySwigObject_acquire(PyObject *v)
+#else
+PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args))
+#endif
+{
+ PySwigObject *sobj = (PySwigObject *)v;
+ sobj->own = SWIG_POINTER_OWN;
+ return SWIG_Py_Void();
+}
+
+SWIGINTERN PyObject*
+PySwigObject_own(PyObject *v, PyObject *args)
+{
+ PyObject *val = 0;
+#if (PY_VERSION_HEX < 0x02020000)
+ if (!PyArg_ParseTuple(args,(char *)"O:own",&val))
+#else
+ if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val))
+#endif
+ {
+ return NULL;
+ }
+ else
+ {
+ PySwigObject *sobj = (PySwigObject *)v;
+ PyObject *obj = sobj->own ? Py_True : Py_False;
+ if (val) {
+#ifdef METH_NOARGS
+ if (PyObject_IsTrue(val)) {
+ PySwigObject_acquire(v);
+ } else {
+ PySwigObject_disown(v);
+ }
+#else
+ if (PyObject_IsTrue(val)) {
+ PySwigObject_acquire(v,args);
+ } else {
+ PySwigObject_disown(v,args);
+ }
+#endif
+ }
+ Py_INCREF(obj);
+ return obj;
+ }
+}
+
+SWIGRUNTIME PyTypeObject*
+_PySwigObject_type(void) {
+ static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer";
+ static PyMethodDef
+#ifdef METH_O
+ swigobject_methods[] = {
+ {"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, "releases ownership of the pointer"},
+ {"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, "aquires ownership of the pointer"},
+ {"own", (PyCFunction)PySwigObject_own, METH_VARARGS, "returns/sets ownership of the pointer"},
+ {"append", (PyCFunction)PySwigObject_append, METH_O, "appends another 'this' object"},
+ {"next", (PyCFunction)PySwigObject_next, METH_NOARGS, "returns the next 'this' object"},
+ {0, 0, 0, 0}
+ };
+#else
+ swigobject_methods[] = {
+ {"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, "releases ownership of the pointer"},
+ {"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, "aquires ownership of the pointer"},
+ {"own", (PyCFunction)PySwigObject_own, METH_VARARGS, "returns/sets ownership of the pointer"},
+ {"append", (PyCFunction)PySwigObject_append, METH_VARARGS, "appends another 'this' object"},
+ {"next", (PyCFunction)PySwigObject_next, METH_VARARGS, "returns the next 'this' object"},
+ {0, 0, 0, 0}
+ };
+#endif
+
+ static PyNumberMethods PySwigObject_as_number = {
+ (binaryfunc)0, /*nb_add*/
+ (binaryfunc)0, /*nb_subtract*/
+ (binaryfunc)0, /*nb_multiply*/
+ (binaryfunc)0, /*nb_divide*/
+ (binaryfunc)0, /*nb_remainder*/
+ (binaryfunc)0, /*nb_divmod*/
+ (ternaryfunc)0,/*nb_power*/
+ (unaryfunc)0, /*nb_negative*/
+ (unaryfunc)0, /*nb_positive*/
+ (unaryfunc)0, /*nb_absolute*/
+ (inquiry)0, /*nb_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
+ (coercion)0, /*nb_coerce*/
+ (unaryfunc)PySwigObject_long, /*nb_int*/
+ (unaryfunc)PySwigObject_long, /*nb_long*/
+ (unaryfunc)0, /*nb_float*/
+ (unaryfunc)PySwigObject_oct, /*nb_oct*/
+ (unaryfunc)PySwigObject_hex, /*nb_hex*/
+#if PY_VERSION_HEX >= 0x02020000
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */
+#elif PY_VERSION_HEX >= 0x02000000
+ 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */
+#endif
+ };
+
+ static PyTypeObject pyswigobject_type;
+ static int type_init = 0;
+ if (!type_init) {
+ const PyTypeObject tmp
+ = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ (char *)"PySwigObject", /* tp_name */
+ sizeof(PySwigObject), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)PySwigObject_dealloc, /* tp_dealloc */
+ (printfunc)PySwigObject_print, /* tp_print */
+ (getattrfunc)0, /* tp_getattr */
+ (setattrfunc)0, /* tp_setattr */
+ (cmpfunc)PySwigObject_compare, /* tp_compare */
+ (reprfunc)PySwigObject_repr, /* tp_repr */
+ &PySwigObject_as_number, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ (hashfunc)0, /* tp_hash */
+ (ternaryfunc)0, /* tp_call */
+ (reprfunc)PySwigObject_str, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ swigobject_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+#if PY_VERSION_HEX >= 0x02020000
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ swigobject_methods, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ PyObject_Del, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+#endif
+#if PY_VERSION_HEX >= 0x02030000
+ 0, /* tp_del */
+#endif
+#ifdef COUNT_ALLOCS
+ 0,0,0,0 /* tp_alloc -> tp_next */
+#endif
+ };
+ pyswigobject_type = tmp;
+ pyswigobject_type.ob_type = &PyType_Type;
+ type_init = 1;
+ }
+ return &pyswigobject_type;
+}
+
+SWIGRUNTIME PyObject *
+PySwigObject_New(void *ptr, swig_type_info *ty, int own)
+{
+ PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type());
+ if (sobj) {
+ sobj->ptr = ptr;
+ sobj->ty = ty;
+ sobj->own = own;
+ sobj->next = 0;
+ }
+ return (PyObject *)sobj;
+}
+
+/* -----------------------------------------------------------------------------
+ * Implements a simple Swig Packed type, and use it instead of string
+ * ----------------------------------------------------------------------------- */
+
+typedef struct {
+ PyObject_HEAD
+ void *pack;
+ swig_type_info *ty;
+ size_t size;
+} PySwigPacked;
+
+SWIGRUNTIME int
+PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags))
+{
+ char result[SWIG_BUFFER_SIZE];
+ fputs("<Swig Packed ", fp);
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+ fputs("at ", fp);
+ fputs(result, fp);
+ }
+ fputs(v->ty->name,fp);
+ fputs(">", fp);
+ return 0;
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_repr(PySwigPacked *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) {
+ return PyString_FromFormat("<Swig Packed at %s%s>", result, v->ty->name);
+ } else {
+ return PyString_FromFormat("<Swig Packed %s>", v->ty->name);
+ }
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_str(PySwigPacked *v)
+{
+ char result[SWIG_BUFFER_SIZE];
+ if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){
+ return PyString_FromFormat("%s%s", result, v->ty->name);
+ } else {
+ return PyString_FromString(v->ty->name);
+ }
+}
+
+SWIGRUNTIME int
+PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w)
+{
+ size_t i = v->size;
+ size_t j = w->size;
+ int s = (i < j) ? -1 : ((i > j) ? 1 : 0);
+ return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size);
+}
+
+SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void);
+
+SWIGRUNTIME PyTypeObject*
+PySwigPacked_type(void) {
+ static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type();
+ return type;
+}
+
+SWIGRUNTIMEINLINE int
+PySwigPacked_Check(PyObject *op) {
+ return ((op)->ob_type == _PySwigPacked_type())
+ || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
+}
+
+SWIGRUNTIME void
+PySwigPacked_dealloc(PyObject *v)
+{
+ if (PySwigPacked_Check(v)) {
+ PySwigPacked *sobj = (PySwigPacked *) v;
+ free(sobj->pack);
+ }
+ PyObject_DEL(v);
+}
+
+SWIGRUNTIME PyTypeObject*
+_PySwigPacked_type(void) {
+ static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer";
+ static PyTypeObject pyswigpacked_type;
+ static int type_init = 0;
+ if (!type_init) {
+ const PyTypeObject tmp
+ = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ (char *)"PySwigPacked", /* tp_name */
+ sizeof(PySwigPacked), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)PySwigPacked_dealloc, /* tp_dealloc */
+ (printfunc)PySwigPacked_print, /* tp_print */
+ (getattrfunc)0, /* tp_getattr */
+ (setattrfunc)0, /* tp_setattr */
+ (cmpfunc)PySwigPacked_compare, /* tp_compare */
+ (reprfunc)PySwigPacked_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ (hashfunc)0, /* tp_hash */
+ (ternaryfunc)0, /* tp_call */
+ (reprfunc)PySwigPacked_str, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ swigpacked_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+#if PY_VERSION_HEX >= 0x02020000
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+ PyObject_Del, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+#endif
+#if PY_VERSION_HEX >= 0x02030000
+ 0, /* tp_del */
+#endif
+#ifdef COUNT_ALLOCS
+ 0,0,0,0 /* tp_alloc -> tp_next */
+#endif
+ };
+ pyswigpacked_type = tmp;
+ pyswigpacked_type.ob_type = &PyType_Type;
+ type_init = 1;
+ }
+ return &pyswigpacked_type;
+}
+
+SWIGRUNTIME PyObject *
+PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty)
+{
+ PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type());
+ if (sobj) {
+ void *pack = malloc(size);
+ if (pack) {
+ memcpy(pack, ptr, size);
+ sobj->pack = pack;
+ sobj->ty = ty;
+ sobj->size = size;
+ } else {
+ PyObject_DEL((PyObject *) sobj);
+ sobj = 0;
+ }
+ }
+ return (PyObject *) sobj;
+}
+
+SWIGRUNTIME swig_type_info *
+PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size)
+{
+ if (PySwigPacked_Check(obj)) {
+ PySwigPacked *sobj = (PySwigPacked *)obj;
+ if (sobj->size != size) return 0;
+ memcpy(ptr, sobj->pack, size);
+ return sobj->ty;
+ } else {
+ return 0;
+ }
+}
+
+/* -----------------------------------------------------------------------------
+ * pointers/data manipulation
+ * ----------------------------------------------------------------------------- */
+
+SWIGRUNTIME PyObject *
+_SWIG_This(void)
+{
+ static PyObject *_this = 0;
+ if (!_this) {
+ _this = PyString_FromString("this");
+ }
+ return _this;
+}
+
+SWIGRUNTIME PyObject *
+SWIG_This(void)
+{
+ static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This();
+ return swig_this;
+}
+
+/* #define SWIG_PYTHON_SLOW_GETSET_THIS */
+
+SWIGRUNTIME PySwigObject *
+SWIG_Python_GetSwigThis(PyObject *pyobj)
+{
+ if (PySwigObject_Check(pyobj)) {
+ return (PySwigObject *) pyobj;
+ } else {
+ PyObject *obj = 0;
+#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && !(PY_VERSION_HEX < 0x02020000))
+ if (PyInstance_Check(pyobj)) {
+ obj = _PyInstance_Lookup(pyobj, SWIG_This());
+ } else {
+ PyObject **dictptr = _PyObject_GetDictPtr(pyobj);
+ if (dictptr != NULL) {
+ PyObject *dict = *dictptr;
+ obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0;
+ }
+#ifdef PyWeakref_CheckProxy
+ else if (PyWeakref_CheckProxy(pyobj)) {
+ PyObject *wobj = PyWeakref_GET_OBJECT(pyobj);
+ return wobj ? SWIG_Python_GetSwigThis(wobj) : 0;
+ }
+#endif
+ if (!obj) {
+ obj = PyObject_GetAttr(pyobj,SWIG_This());
+ if (obj) {
+ Py_DECREF(obj);
+ } else {
+ if (PyErr_Occurred()) PyErr_Clear();
+ return 0;
+ }
+ }
+ }
+#else
+ obj = PyObject_GetAttr(pyobj,SWIG_This());
+ if (obj) {
+ Py_DECREF(obj);
+ } else {
+ if (PyErr_Occurred()) PyErr_Clear();
+ return 0;
+ }
+#endif
+ return (PySwigObject *)obj;
+ }
+}
+
+
+/* Acquire a pointer value */
+
+SWIGRUNTIME int
+SWIG_Python_AcquirePtr(PyObject *obj, int own) {
+ if (own) {
+ PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
+ if (sobj) {
+ int oldown = sobj->own;
+ sobj->own = own;
+ return oldown;
+ }
+ }
+ return 0;
+}
+
+/* Convert a pointer value */
+
+SWIGRUNTIME int
+SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
+ if (!obj) return SWIG_ERROR;
+ if (obj == Py_None) {
+ if (ptr) *ptr = 0;
+ return SWIG_OK;
+ } else {
+ PySwigObject *sobj = SWIG_Python_GetSwigThis(obj);
+ while (sobj) {
+ void *vptr = sobj->ptr;
+ if (ty) {
+ swig_type_info *to = sobj->ty;
+ if (to == ty) {
+ /* no type cast needed */
+ if (ptr) *ptr = vptr;
+ break;
+ } else {
+ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
+ if (!tc) {
+ sobj = (PySwigObject *)sobj->next;
+ } else {
+ if (ptr) *ptr = SWIG_TypeCast(tc,vptr);
+ break;
+ }
+ }
+ } else {
+ if (ptr) *ptr = vptr;
+ break;
+ }
+ }
+ if (sobj) {
+ if (own) *own = sobj->own;
+ if (flags & SWIG_POINTER_DISOWN) {
+ sobj->own = 0;
+ }
+ return SWIG_OK;
+ } else {
+ int res = SWIG_ERROR;
+ if (flags & SWIG_POINTER_IMPLICIT_CONV) {
+ PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0;
+ if (data && !data->implicitconv) {
+ PyObject *klass = data->klass;
+ if (klass) {
+ PyObject *impconv;
+ data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
+ impconv = SWIG_Python_CallFunctor(klass, obj);
+ data->implicitconv = 0;
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ impconv = 0;
+ }
+ if (impconv) {
+ PySwigObject *sobj = SWIG_Python_GetSwigThis(impconv);
+ if (sobj) {
+ void *vptr;
+ res = SWIG_Python_ConvertPtrAndOwn((PyObject*)sobj, &vptr, ty, 0, 0);
+ if (SWIG_IsOK(res)) {
+ if (ptr) {
+ *ptr = vptr;
+ /* transfer the ownership to 'ptr' */
+ sobj->own = 0;
+ res = SWIG_AddNewMask(SWIG_AddCast(res));
+ } else {
+ res = SWIG_AddCast(res);
+ }
+ }
+ }
+ Py_DECREF(impconv);
+ }
+ }
+ }
+ }
+ return res;
+ }
+ }
+}
+
+/* Convert a function ptr value */
+
+SWIGRUNTIME int
+SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
+ if (!PyCFunction_Check(obj)) {
+ return SWIG_ConvertPtr(obj, ptr, ty, 0);
+ } else {
+ void *vptr = 0;
+
+ /* here we get the method pointer for callbacks */
+ char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
+ const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
+ if (desc) {
+ desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
+ if (!desc) return SWIG_ERROR;
+ }
+ if (ty) {
+ swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
+ if (!tc) return SWIG_ERROR;
+ *ptr = SWIG_TypeCast(tc,vptr);
+ } else {
+ *ptr = vptr;
+ }
+ return SWIG_OK;
+ }
+}
+
+/* Convert a packed value value */
+
+SWIGRUNTIME int
+SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) {
+ swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz);
+ if (!to) return SWIG_ERROR;
+ if (ty) {
+ if (to != ty) {
+ /* check type cast? */
+ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
+ if (!tc) return SWIG_ERROR;
+ }
+ }
+ return SWIG_OK;
+}
+
+/* -----------------------------------------------------------------------------
+ * Create a new pointer object
+ * ----------------------------------------------------------------------------- */
+
+/*
+ Create a new instance object, whitout calling __init__, and set the
+ 'this' attribute.
+*/
+
+SWIGRUNTIME PyObject*
+SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this)
+{
+#if (PY_VERSION_HEX >= 0x02020000)
+ PyObject *inst = 0;
+ PyObject *newraw = data->newraw;
+ if (newraw) {
+ inst = PyObject_Call(newraw, data->newargs, NULL);
+ if (inst) {
+#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS)
+ PyObject **dictptr = _PyObject_GetDictPtr(inst);
+ if (dictptr != NULL) {
+ PyObject *dict = *dictptr;
+ if (dict == NULL) {
+ dict = PyDict_New();
+ *dictptr = dict;
+ PyDict_SetItem(dict, SWIG_This(), swig_this);
+ }
+ }
+#else
+ PyObject *key = SWIG_This();
+ PyObject_SetAttr(inst, key, swig_this);
+#endif
+ }
+ } else {
+ PyObject *dict = PyDict_New();
+ PyDict_SetItem(dict, SWIG_This(), swig_this);
+ inst = PyInstance_NewRaw(data->newargs, dict);
+ Py_DECREF(dict);
+ }
+ return inst;
+#else
+ PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
+ if (inst == NULL) {
+ return NULL;
+ }
+ inst->in_class = (PyClassObject *)data->newargs;
+ Py_INCREF(inst->in_class);
+ inst->in_dict = PyDict_New();
+ if (inst->in_dict == NULL) {
+ Py_DECREF(inst);
+ return NULL;
+ }
+ PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this);
+ return (PyObject *) inst;
+#endif
+}
+
+/* Create a new pointer object */
+
+SWIGRUNTIME PyObject *
+SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
+ if (!ptr) {
+ return SWIG_Py_Void();
+ } else {
+ int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
+ PyObject *robj = PySwigObject_New(ptr, type, own);
+ PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0;
+ if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
+ PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
+ if (inst) {
+ Py_DECREF(robj);
+ robj = inst;
+ }
+ }
+ return robj;
+ }
+}
+
+/* Create a new packed object */
+
+SWIGRUNTIMEINLINE PyObject *
+SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
+ return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void();
+}
+
+/* -----------------------------------------------------------------------------*
+ * Get type list
+ * -----------------------------------------------------------------------------*/
+
+#ifdef SWIG_LINK_RUNTIME
+void *SWIG_ReturnGlobalTypeList(void *);
+#endif
+
+SWIGRUNTIME swig_module_info *
+SWIG_Python_GetModule(void) {
+ static void *type_pointer = (void *)0;
+ /* first check if module already created */
+ if (!type_pointer) {
+#ifdef SWIG_LINK_RUNTIME
+ type_pointer = SWIG_ReturnGlobalTypeList((void *)0);
+#else
+ type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
+ (char*)"type_pointer" SWIG_TYPE_TABLE_NAME);
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ type_pointer = (void *)0;
+ }
+#endif
+ }
+ return (swig_module_info *) type_pointer;
+}
+
+#if PY_MAJOR_VERSION < 2
+/* PyModule_AddObject function was introduced in Python 2.0. The following function
+ is copied out of Python/modsupport.c in python version 2.3.4 */
+SWIGINTERN int
+PyModule_AddObject(PyObject *m, char *name, PyObject *o)
+{
+ PyObject *dict;
+ if (!PyModule_Check(m)) {
+ PyErr_SetString(PyExc_TypeError,
+ "PyModule_AddObject() needs module as first arg");
+ return SWIG_ERROR;
+ }
+ if (!o) {
+ PyErr_SetString(PyExc_TypeError,
+ "PyModule_AddObject() needs non-NULL value");
+ return SWIG_ERROR;
+ }
+
+ dict = PyModule_GetDict(m);
+ if (dict == NULL) {
+ /* Internal error -- modules must have a dict! */
+ PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
+ PyModule_GetName(m));
+ return SWIG_ERROR;
+ }
+ if (PyDict_SetItemString(dict, name, o))
+ return SWIG_ERROR;
+ Py_DECREF(o);
+ return SWIG_OK;
+}
+#endif
+
+SWIGRUNTIME void
+SWIG_Python_DestroyModule(void *vptr)
+{
+ swig_module_info *swig_module = (swig_module_info *) vptr;
+ swig_type_info **types = swig_module->types;
+ size_t i;
+ for (i =0; i < swig_module->size; ++i) {
+ swig_type_info *ty = types[i];
+ if (ty->owndata) {
+ PySwigClientData *data = (PySwigClientData *) ty->clientdata;
+ if (data) PySwigClientData_Del(data);
+ ty->clientdata = 0;
+ }
+ }
+ Py_DECREF(SWIG_This());
+}
+
+SWIGRUNTIME void
+SWIG_Python_SetModule(swig_module_info *swig_module) {
+ static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */
+
+ PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION,
+ swig_empty_runtime_method_table);
+ PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule);
+ if (pointer && module) {
+ PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer);
+ } else {
+ Py_XDECREF(pointer);
+ }
+}
+
+#ifdef __cplusplus
+#if 0
+{ /* cc-mode */
+#endif
+}
+#endif
+
+/* -----------------------------------------------------------------------------*
+ Standard SWIG API for use inside user code.
+
+ Don't include this file directly, run the command
+ swig -python -external-runtime
+ Also, read the Modules chapter of the SWIG Manual.
+
+ * -----------------------------------------------------------------------------*/
+
+#ifdef SWIG_MODULE_CLIENTDATA_TYPE
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_TypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name) {
+ swig_module_info *module = SWIG_GetModule(clientdata);
+ return SWIG_TypeQueryModule(module, module, name);
+}
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_MangledTypeQuery(SWIG_MODULE_CLIENTDATA_TYPE clientdata, const char *name) {
+ swig_module_info *module = SWIG_GetModule(clientdata);
+ return SWIG_MangledTypeQueryModule(module, module, name);
+}
+
+#else
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_TypeQuery(const char *name) {
+ swig_module_info *module = SWIG_GetModule(NULL);
+ return SWIG_TypeQueryModule(module, module, name);
+}
+
+SWIGRUNTIMEINLINE swig_type_info *
+SWIG_MangledTypeQuery(const char *name) {
+ swig_module_info *module = SWIG_GetModule(NULL);
+ return SWIG_MangledTypeQueryModule(module, module, name);
+}
+
+#endif
+
+"""