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
1508 changed files with 125983 additions and 44037 deletions

View file

@ -0,0 +1,13 @@
# see top-level Makefile.in
class
constants
constants2
funcptr
import
multimap
pointer
reference
shadow
simple
value
variables

View file

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

View file

@ -14,6 +14,6 @@ static::
TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static
clean::
rm -f *_wrap* *.o *~ *.so myperl *.pyc .~* core
$(MAKE) -f $(TOP)/Makefile perl5_clean
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,150 @@
# 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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -c++ -perl5 $(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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -c++ -perl5 $(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,8 +20,8 @@ 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 {
@ -29,8 +29,8 @@ 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

@ -20,12 +20,12 @@ print "\nA total of $example::Shape_nshapes shapes were created\n";
# ----- Member data access -----
# Set the location of the object
# Set the location of the object.
# Note: methods in the base class Shape are used since
# x and y are defined there.
example::Shape_x_set($c, 20);
example::Shape_y_set($c, 30);
# Now use the same functions in the base class
example::Shape_x_set($s,-10);
example::Shape_y_set($s,5);

View file

@ -109,14 +109,13 @@ 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 data member is defined is used. For example <tt>Shape_x_get()</tt>.
<p>
<li>To invoke a member function, you simply do this
@ -204,28 +203,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.
</ul>
<hr>

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -19,8 +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;
/* The following directives also produce constants */
%constant int iconst = 37;
%constant double fconst = 3.14;

View file

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

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIG = $(TOP)/../swig
SRCS =
TARGET = example
INTERFACE = example.i
SWIGOPT = -const
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

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

View file

@ -0,0 +1,16 @@
# file: example.pl
use example;
print "ICONST = ", example::ICONST, " (should be 42)\n";
print "FCONST = ", example::FCONST, " (should be 2.1828)\n";
print "CCONST = ", example::CCONST, " (should be 'x')\n";
print "CCONST2 = ", example::CCONST2," (this should be on a new line)\n";
print "SCONST = ", example::SCONST, " (should be 'Hello World')\n";
print "SCONST2 = ", example::SCONST2, " (should be '\"Hello World\"')\n";
print "EXPR = ", example::EXPR, " (should be 48.5484)\n";
print "iconst = ", example::iconst, " (should be 37)\n";
print "fconst = ", example::fconst, " (should be 3.14)\n";

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -15,3 +15,5 @@ int sub(int a, int b) {
int mul(int a, int b) {
return a*b;
}
int (*funcvar)(int,int) = add;

View file

@ -8,8 +8,9 @@
extern int do_op(int a, int b, int (*op)(int, int));
/* Now install a bunch of "ops" as constants */
%constant(int (*)(int,int)) ADD = add;
%constant(int (*)(int,int)) SUB = sub;
%constant(int (*)(int,int)) MUL = mul;
%constant int (*ADD)(int,int) = add;
%constant int (*SUB)(int,int) = sub;
%constant int (*MUL)(int,int) = mul;
extern int (*funcvar)(int,int);

View file

@ -0,0 +1,14 @@
baseclass.pm
example.pm
foo.pm
bar.pm
spam.pm
*_wrap.c
*_wrap.cxx
example.dll
example.dsw
example.ncb
example.opt
example.plg
Release
Debug

View file

@ -0,0 +1,21 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIGOPT = -c -shadow
#If your system requires linking with the runtime libraries then set the directory location here
RUNTIMEDIR =
all::
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='baseclass' INTERFACE='base.i' perl5_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='foo' INTERFACE='foo.i' perl5_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='bar' INTERFACE='bar.i' perl5_multi_cpp
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
RUNTIMEDIR='$(RUNTIMEDIR)' TARGET='spam' INTERFACE='spam.i' perl5_multi_cpp
clean::
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -0,0 +1,28 @@
This example tests the SWIG run-time libraries and use of the
%import directive to work with multiple modules.
Use 'perl runme.pl' 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 used %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 working correctly, all of the modules will load
correctly and type checking will work correctly. The
example requires the use of the SWIG run-time libraries
which must be built and properly installed.

View file

@ -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);
}
};

View file

@ -0,0 +1,9 @@
%module bar
%{
#include "bar.h"
%}
%import base.i
%include "bar.h"

View file

@ -0,0 +1,18 @@
#include <stdio.h>
class Base {
public:
Base() { };
~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);
}
};

View file

@ -0,0 +1,6 @@
%module baseclass
%{
#include "base.h"
%}
%include base.h

View file

@ -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);
}
};

View file

@ -0,0 +1,8 @@
%module foo
%{
#include "foo.h"
%}
%import base.i
%include "foo.h"

View file

@ -0,0 +1,116 @@
# file: runme.pl
# Test various properties of classes defined in separate modules
print "Testing the %import directive\n";
use baseclass;
use foo;
use bar;
use spam;
# Create some objects
print "Creating some objects\n";
$a = new baseclass::Base();
$b = new foo::Foo();
$c = new bar::Bar();
$d = new spam::Spam();
# Try calling some methods
print "Testing some methods\n";
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";
$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\n";
} else {
print "good swig\n";
}
print " Spam -> Base -> Bar : ";
$y = bar::Bar_fromBase($x);
if ($y) {
print "good swig\n";
} else {
print "bad swig\n";
}
print " Spam -> Base -> Spam : ";
$y = spam::Spam_fromBase($x);
if ($y) {
print "good swig\n";
} else {
print "bad swig\n";
}
print " Foo -> Spam : ";
#print $b;
$y = spam::Spam_fromBase($b);
print $y;
if ($y) {
print "bad swig\n";
} else {
print "good swig\n";
}

View file

@ -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);
}
};

View file

@ -0,0 +1,9 @@
%module spam
%{
#include "spam.h"
%}
%import bar.i
%include "spam.h"

View file

@ -66,7 +66,8 @@ The examples have been extensively tested on the following platforms:
<li>Solaris
</ul>
<p>
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>
The most recent version of Perl used for testing is as follows:
<blockquote>

View file

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

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIG = $(TOP)/../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)' perl5
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -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] = 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);
}
}

View file

@ -0,0 +1,146 @@
# 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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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.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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -perl5 $(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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -perl5 $(InputPath)
# End Custom Build
!ENDIF
# End Source File
# End Target
# End Project

View file

@ -0,0 +1,81 @@
/* File : example.i */
%module example
%include exception.i
%include typemaps.i
extern int gcd(int x, int y);
%typemap(perl5,in) (int argc, char *argv[]) {
AV *tempav;
SV **tv;
I32 len;
int i;
if (!SvROK($input)) {
SWIG_exception(SWIG_ValueError,"$input is not an array.");
}
if (SvTYPE(SvRV($input)) != SVt_PVAV) {
SWIG_exception(SWIG_ValueError,"$input is not an array.");
}
tempav = (AV*)SvRV($input);
len = av_len(tempav);
$1 = (int) len+1;
$2 = (char **) malloc($1*sizeof(char *));
for (i = 0; i < $1; i++) {
tv = av_fetch(tempav, i, 0);
$2[i] = (char *) SvPV(*tv,PL_na);
}
$2[i] = 0;
}
%typemap(perl5,freearg) (int argc, char *argv[]) {
free($2);
}
extern int gcdmain(int argc, char *argv[]);
%typemap(perl5,in) (char *bytes, int len) {
unsigned int temp;
$1 = (char *) SvPV($input, temp);
$2 = (int) temp;
}
extern int count(char *bytes, int len, char c);
/* This example shows how to wrap a function that mutates a string */
%typemap(perl5,in) (char *str, int len) {
unsigned int templen;
char *temp;
temp = (char *) SvPV($input,templen);
$2 = (int) templen;
$1 = (char *) malloc($2+1);
memmove($1,temp,$2);
}
/* Return the mutated string as a new object. */
%typemap(perl5,argout) (char *str, int len) {
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setpvn((SV*)ST(argvi++),$1,$2);
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);

View file

@ -0,0 +1,28 @@
# file: example.pl
use example;
# Call our gcd() function
$x = 42;
$y = 105;
$g = example::gcd($x,$y);
print "The gcd of $x and $y is $g\n";
# Call the gcdmain() function
@a = ("gcdmain","42","105");
example::gcdmain(\@a);
# Call the count function
print example::count("Hello World", "l"),"\n";
# Call the capitize function
print example::capitalize("hello world"),"\n";

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -6,7 +6,8 @@
/* First we'll use the pointer library */
extern void add(int *x, int *y, int *result);
%include pointer.i
%include cpointer.i
%pointer_functions(int, intp);
/* Next we'll use some typemaps */

View file

@ -4,9 +4,11 @@ use example;
# First create some objects using the pointer library.
print "Testing the pointer library\n";
$a = example::ptrcreate("int",37);
$b = example::ptrcreate("int",42);
$c = example::ptrcreate("int");
$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\n";
print " b = $b\n";
@ -16,13 +18,13 @@ print " c = $c\n";
example::add($a,$b,$c);
# Now get the result
$r = example::ptrvalue($c);
$r = example::intp_value($c);
print " 37 + 42 = $r\n";
# Clean up the pointers
example::ptrfree($a);
example::ptrfree($b);
example::ptrfree($c);
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

View file

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

View file

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

View file

@ -31,7 +31,7 @@ public:
int size();
/* This wrapper provides an alternative to the [] operator */
%addmethods {
%extend {
Vector &get(int index) {
return (*self)[index];
}

View file

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

View file

@ -15,6 +15,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static
clean::
rm -f *_wrap* *.o *~ *.so myperl *.pyc .~* core
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

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

@ -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,8 +20,9 @@ private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area();
virtual double perimeter();
~Circle() { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
@ -29,8 +30,9 @@ private:
double width;
public:
Square(double w) : width(w) { };
virtual double area();
virtual double perimeter();
~Square() { }
virtual double area(void);
virtual double perimeter(void);
};

View file

@ -16,18 +16,18 @@ print " Created square $s\n";
# ----- Access a static member -----
print "\nA total of $example::Shape_nshapes shapes were created\n";
print "\nA total of $example::Shape::nshapes shapes were created\n";
# ----- Member data access -----
# Set the location of the object
# Set the location of the object.
# Note: methods in the base class Shape are used since
# x and y are defined there.
$c->{'x'} = 20;
$c->{'y'} = 30;
# Now use the same functions in the base class
$s->{'x'} = -10;
$s->{'y'} = 5;
$c->{x} = 20;
$c->{y} = 30;
$s->{x} = -10;
$s->{y} = 5;
print "\nHere is their current position:\n";
print " Circle = (",$c->{x},",", $c->{y},")\n";
@ -41,17 +41,16 @@ foreach $o ($c,$s) {
print " area = ", $o->area(), "\n";
print " perimeter = ", $o->perimeter(), "\n";
}
# Notice how the Shape_area() and Shape_perimeter() functions really
# invoke the appropriate virtual method on each object.
# ----- Delete everything -----
print "\nGuess I'll clean up now\n";
# Note: this invokes the virtual destructor
$c->DESTROY();
$s->DESTROY();
print $example::Shape_nshapes," shapes remain\n";
print $example::Shape::nshapes," shapes remain\n";
print "Goodbye\n";

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -0,0 +1,146 @@
# 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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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 "$(PERL5_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 $(PERL5_INCLUDE)/perl.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.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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -perl5 $(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 PERL5_INCLUDE: %PERL5_INCLUDE%
echo on
..\..\..\swig -perl5 $(InputPath)
# End Custom Build
!ENDIF
# End Source File
# End Target
# End Project

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

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

View file

@ -13,6 +13,6 @@ static::
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
clean::
rm -f *_wrap* *.o core *~ *.so *.pm myperl
$(MAKE) -f $(TOP)/Makefile perl5_clean
check: all

View file

@ -27,10 +27,10 @@ extern Point pt;
/* Some read-only variables */
%readonly {
%immutable;
extern int status;
extern char path[256];
}
%mutable;
/* Some helper functions to make it easier to test */
extern void print_vars();

View file

@ -27,21 +27,21 @@ Click <a href="example.pl">here</a> to see a script that updates and prints some
<h2>Creating read-only variables</h2>
The <tt>%readonly</tt> and <tt>%readwrite</tt> directives can be used to
The <tt>%immutable</tt> and <tt>%mutable</tt> directives can be used to
specify a collection of read-only variables. For example:
<blockquote>
<pre>
%readonly
%immutable;
int status;
double blah;
...
%readwrite
%mutable;
</pre>
</blockquote>
The <tt>%readonly</tt> directive remains in effect until it is explicitly disabled
using the <tt>%readwrite</tt> directive.
The <tt>%immutable</tt> directive remains in effect until it is explicitly disabled
using the <tt>%mutable</tt> directive.
<h2>Notes:</h2>