The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
131 changed files with 125431 additions and 43485 deletions

View file

@ -0,0 +1,23 @@
# see top-level Makefile.in
class
constants
enum
exceptshadow
funcattr
funcptr
funcptr2
functor
import
import
template
mpointer
multimap
operator
pointer
reference
shadow
simple
smartptr
template
value
variables

View file

@ -0,0 +1,9 @@
*_wrap.c
*_wrap.cxx
*.dll
*.dsw
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -14,6 +14,7 @@ static::
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean::
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py
check: all

View file

@ -1,7 +1,7 @@
/* File : example.c */
#include "example.h"
#include <math.h>
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
int Shape::nshapes = 0;
double Circle::area() {
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter() {
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area() {
double Square::area(void) {
return width*width;
}
double Square::perimeter() {
double Square::perimeter(void) {
return 4*width;
}

View file

@ -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 odbc32.lib odbccp32.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 odbc32.lib odbccp32.lib "$(PYTHON_LIB)" /nologo /dll /debug /machine:I386 /out:"_example.dll" /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 odbc32.lib odbccp32.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 odbc32.lib odbccp32.lib "$(PYTHON_LIB)" /nologo /dll /machine:I386 /out:"_example.dll"
!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 -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 -c++ -python $(InputPath)
# End Custom Build
!ENDIF
# End Source File
# End Target
# End Project

View file

@ -10,8 +10,8 @@ public:
};
double x, y;
void move(double dx, double dy);
virtual double area() = 0;
virtual double perimeter() = 0;
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
@ -20,17 +20,17 @@ private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area();
virtual double perimeter();
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area();
virtual double perimeter();
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -1,67 +0,0 @@
# file: example.py
# This file illustrates the low-level C++ interface
# created by SWIG. In this case, all of our C++ classes
# get converted into function calls.
import example
# ----- Object creation -----
print "Creating some objects:"
c = example.new_Circle(10)
print " Created circle", c
s = example.new_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
example.Shape_x_set(c, 20)
example.Shape_y_set(c, 30)
example.Shape_x_set(s,-10)
example.Shape_y_set(s,5)
print "\nHere is their current position:"
print " Circle = (%f, %f)" % (example.Shape_x_get(c), example.Shape_y_get(c))
print " Square = (%f, %f)" % (example.Shape_x_get(s), example.Shape_y_get(s))
# ----- Call some methods -----
print "\nHere are some properties of the shapes:"
for o in [c,s]:
print " ", o
print " area = ", example.Shape_area(o)
print " perimeter = ", example.Shape_perimeter(o)
# Notice how the Shape_area() and Shape_perimeter() functions really
# invoke the appropriate virtual method on each object.
# ----- Try to cause a type error -----
print "\nI'm going to try and break the type system"
try:
# Bad script!
Square_area(c) # Try to invoke Square method on a Circle
print " Bad bad SWIG!"
except:
print " Well, it didn't work. Good SWIG."
# ----- Delete everything -----
print "\nGuess I'll clean up now"
# Note: this invokes the virtual destructor
example.delete_Shape(c)
example.delete_Shape(s)
print example.cvar.Shape_nshapes,"shapes remain"
print "Goodbye"

View file

@ -109,14 +109,14 @@ For example:
<blockquote>
<pre>
example.Circle_x_set(c,15) # Set member data
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 base class or the derived class can be
used in the function name as shown above. Of course, it would probably be more
proper to just use the base class version such as <tt>Shape_x_get()</tt>
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
@ -164,13 +164,14 @@ example.cvar.Shapes_nshapes = 13 # Set a static data member
<h2>General Comments</h2>
<ul>
<li>This low-level interface is not the only way to handle C++ code. Shadow classes
provide a much higher-level interface.
<li>This low-level interface is not the only way to handle C++ code.
Shadow 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.
<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
@ -206,28 +207,6 @@ to write a helper function. For example:
<p>
<li>Namespaces. Not supported at all. Won't be supported until SWIG2.0 (if at all).
<p>
<li>Templates. Not supported at all. SWIG throws out anything that looks like a template.
You can work around the problem by aliasing a template class behind a typedef however.
For example:
<blockquote>
<pre>
%{
typedef vector<int> IntVector;
%}
class IntVector {
public:
... methods ...
};
</pre>
</blockquote>
</ul>
<p>
<li>There is no guarantee that an extremely complex C++ application will be able to compile
as a Python extension. Sorry.
<p>
<li>Dave's snide remark: Like a large bottle of strong Tequilla, it's better to
use C++ in moderation.

View file

@ -0,0 +1,51 @@
# file: runme.py
# This file illustrates the shadow-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"

View file

@ -0,0 +1,9 @@
*_wrap.c
*_wrap.cxx
*.dll
*.dsw
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -13,6 +13,7 @@ static::
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
clean::
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py
check: all

View file

@ -19,19 +19,9 @@
/* Neither should this (BAR isn't defined) */
#define FOO (ICONST + BAR)
/* The following statements also produce constants */
const int iconst = 37;
const double fconst = 3.14;
%constant(double) PI = 3.14159;
/* Test address of operator */
%{
static double blah = 1.2345;
%}
%constant(double *) blahptr = &blah;
/* The following directives also produce constants */
%constant int iconst = 37;
%constant double fconst = 3.14;

View file

@ -0,0 +1,27 @@
# file: example.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)"

View file

@ -0,0 +1,9 @@
*_wrap.c
*_wrap.cxx
*.dll
*.dsw
*.ncb
*.opt
*.plg
Release
Debug

View file

@ -14,6 +14,7 @@ static::
TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean::
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
$(MAKE) -f $(TOP)/Makefile python_clean
rm -f $(TARGET).py
check: all

View file

@ -1,30 +0,0 @@
# file: example.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.new_Foo()
example.Foo_enum_test(f,example.Foo_IMPULSE)
example.Foo_enum_test(f,example.Foo_WARP)
example.Foo_enum_test(f,example.Foo_LUDICROUS)

View file

@ -0,0 +1,31 @@
# file: example.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)

View file

@ -0,0 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../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

View file

@ -0,0 +1,37 @@
/* File : example.h */
#include <string>
class Exc {
public:
Exc(int c, const char *m) {
code = c;
strncpy(msg,m,256);
}
int code;
char msg[256];
};
class Test {
public:
int simple() throw(int) {
throw(37);
}
int message() throw(const char *) {
throw("I died.");
}
int hosed() throw(Exc) {
throw(Exc(42,"Hosed"));
}
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"));
}
};

View file

@ -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"

Some files were not shown because too many files have changed in this diff Show more