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,8 @@
# see top-level Makefile.in
class
constants
enum
operator
overload
simple
template

View file

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

View file

@ -0,0 +1,19 @@
TOP = ../..
SWIG = $(TOP)/../swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
all:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
static:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

@ -0,0 +1,48 @@
/* File : example.c */
#include "example.h"
#include <stdio.h>
#define M_PI 3.14159265358979323846
// Static member initializer
int Shape::nshapes = 0;
// Constructor
Shape::Shape() {
// printf("Shape::Shape(), this = 0x%08x\n", this);
nshapes++;
}
// Move the shape to a new location
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
// Destructor
Shape::~Shape() {
// printf("Shape::~Shape(), this = 0x%08x\n", this);
nshapes--;
}
// Circle area
double Circle::area() {
return M_PI*radius*radius;
}
// Circle perimeter
double Circle::perimeter() {
return 2*M_PI*radius;
}
// Square area
double Square::area() {
return width*width;
}
// Square perimeter
double Square::perimeter() {
return 4*width;
}

View file

@ -0,0 +1,35 @@
/* File : example.h */
class Shape {
public:
Shape();
virtual ~Shape();
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);
};

View file

@ -0,0 +1,10 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,61 @@
import .example;
int main()
{
// ----- Object creation -----
write("Creating some objects:\n");
Circle c = Circle(10.0);
// write(" Created circle " + (string) c + ".\n");
write(" Created circle.\n");
Square s = Square(10.0);
// write(" Created square " + (string) s + ".\n");
write(" Created square.\n");
// ----- Access a static member -----
// write("\nA total of " + Shape->nshapes + " shapes were created\n");
// ----- Member data access -----
// Set the location of the object
// c->x = 20.0;
// c->y = 30.0;
c->x_set(20.0);
c->y_set(30.0);
// s->x = -10.0;
// s->y = 5.0;
s->x_set(-10.0);
s->y_set(5.0);
write("\nHere is their current position:\n");
// write(sprintf(" Circle = (%f, %f)\n", c->x, c->y));
// write(sprintf(" Square = (%f, %f)\n", s->x, s->y));
write(sprintf(" Circle = (%f, %f)\n", c->x_get(), c->y_get()));
write(sprintf(" Square = (%f, %f)\n", s->x_get(), s->y_get()));
// ----- Call some methods -----
write("\nHere are some properties of the shapes:\n");
write(" The circle:\n");
write(sprintf(" area = %f.\n", c->area()));
write(sprintf(" perimeter = %f.\n", c->perimeter()));
// write(" " + (string) s + ".\n");
write(" The square:\n");
write(sprintf(" area = %f.\n", s->area()));
write(sprintf(" perimeter = %f.\n", s->perimeter()));
write("\nGuess I'll clean up now\n");
// Note: this invokes the virtual destructor
// del c;
// del s;
// s = 3;
// write(sprintf("%d shapes remain\n", Shape->nshapes));
write("Goodbye\n");
return 0;
}

View file

@ -0,0 +1,9 @@
*_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
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static
clean::
$(MAKE) -f $(TOP)/Makefile pike_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,24 @@
int main()
{
write(sprintf("ICONST = %d (should be 42)\n", .example.ICONST));
write(sprintf("FCONST = %f (should be 2.1828)\n", .example.FCONST));
write(sprintf("CCONST = %c (should be 'x')\n", .example.CCONST));
write(sprintf("CCONST2 = %c (this should be on a new line)\n", .example.CCONST2));
write(sprintf("SCONST = %s (should be 'Hello World')\n", .example.SCONST));
write(sprintf("SCONST2 = %s (should be '\"Hello World\"')\n", .example.SCONST2));
write(sprintf("EXPR = %f (should be 48.5484)\n", .example.EXPR));
write(sprintf("iconst = %d (should be 37)\n", .example.iconst));
write(sprintf("fconst = %f (should be 3.14)\n", .example.fconst));
if (search(indices(.example), "EXTERN") == -1)
write("EXTERN isn't defined (good)\n");
else
write("EXTERN is defined (bad)\n");
if (search(indices(.example), "FOO") == -1)
write("FOO isn't defined (good)\n");
else
write("FOO is defined (bad)\n");
return 0;
}

View file

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

View file

@ -0,0 +1,19 @@
TOP = ../..
SWIG = $(TOP)/../swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lm
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
static::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

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

View file

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

View file

@ -0,0 +1,11 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,27 @@
int main()
{
write("*** color ***\n");
write(" RED = " + .example.RED + "\n");
write(" BLUE = " + .example.BLUE + "\n");
write(" GREEN = " + .example.GREEN + "\n");
write("\n*** Foo::speed ***\n");
write(" Foo_IMPULSE = " + .example.Foo.IMPULSE + "\n");
write(" Foo_WARP = " + .example.Foo.WARP + "\n");
write(" Foo_LUDICROUS = " + .example.Foo.LUDICROUS + "\n");
write("\nTesting use of enums with functions\n\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);
write("\nTesting use of enum with class method\n");
.example.Foo f = .example.Foo();
f->enum_test(.example.Foo.IMPULSE);
f->enum_test(.example.Foo.WARP);
f->enum_test(.example.Foo.LUDICROUS);
return 0;
}

View file

@ -0,0 +1,4 @@
example.o
example.so
example_wrap.cxx
example_wrap.o

View file

@ -0,0 +1,19 @@
TOP = ../..
SWIG = $(TOP)/../swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i
LIBS = -lstdc++ -lm
all::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike_cpp
static::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

@ -0,0 +1,115 @@
#include <iostream>
#include "example.h"
// Overloaded constructors for class Bar
Bar::Bar() {
std::cout << "Called Bar::Bar()" << std::endl;
}
Bar::Bar(const Bar&) {
std::cout << "Called Bar::Bar(const Bar&)" << std::endl;
}
Bar::Bar(double x) {
std::cout << "Called Bar::Bar(double) with x = " << x << std::endl;
}
Bar::Bar(double x, char *y) {
std::cout << "Called Bar::Bar(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}
Bar::Bar(int x, int y) {
std::cout << "Called Bar::Bar(int, int) with x, y = " << x << ", " << y << std::endl;
}
Bar::Bar(char *x) {
std::cout << "Called Bar::Bar(char *) with x = \"" << x << "\"" << std::endl;
}
Bar::Bar(int x) {
std::cout << "Called Bar::Bar(int) with x = " << x << std::endl;
}
Bar::Bar(long x) {
std::cout << "Called Bar::Bar(long) with x = " << x << std::endl;
}
Bar::Bar(Bar *x) {
std::cout << "Called Bar::Bar(Bar *) with x = " << x << std::endl;
}
// Overloaded member functions
void Bar::foo(const Bar& x) {
std::cout << "Called Bar::foo(const Bar&) with &x = " << &x << std::endl;
}
void Bar::foo(double x) {
std::cout << "Called Bar::foo(double) with x = " << x << std::endl;
}
void Bar::foo(double x, char *y) {
std::cout << "Called Bar::foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}
void Bar::foo(int x, int y) {
std::cout << "Called Bar::foo(int, int) with x, y = " << x << ", " << y << std::endl;
}
void Bar::foo(char *x) {
std::cout << "Called Bar::foo(char *) with x = \"" << x << "\"" << std::endl;
}
void Bar::foo(int x) {
std::cout << "Called Bar::foo(int) with x = " << x << std::endl;
}
void Bar::foo(long x) {
std::cout << "Called Bar::foo(long) with x = " << x << std::endl;
}
void Bar::foo(Bar *x) {
std::cout << "Called Bar::foo(Bar *) with x = " << x << std::endl;
}
void Bar::spam(int x, int y, int z) {
std::cout << "Called Bar::spam(int, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
}
void Bar::spam(double x, int y, int z) {
std::cout << "Called Bar::spam(double, int, int) with x, y, z = " << x << ", " << y << ", " << z << std::endl;
}
// Overloaded global methods
void foo(const Bar& x) {
std::cout << "Called foo(const Bar& x) with &x = " << &x << std::endl;
}
void foo(double x) {
std::cout << "Called foo(double) with x = " << x << std::endl;
}
void foo(double x, char *y) {
std::cout << "Called foo(double, char *) with x, y = " << x << ", \"" << y << "\"" << std::endl;
}
void foo(int x, int y) {
std::cout << "Called foo(int, int) with x, y = " << x << ", " << y << std::endl;
}
void foo(char *x) {
std::cout << "Called foo(char *) with x = \"" << x << "\"" << std::endl;
}
void foo(int x) {
std::cout << "Called foo(int) with x = " << x << std::endl;
}
void foo(long x) {
std::cout << "Called foo(long) with x = " << x << std::endl;
}
void foo(Bar *x) {
std::cout << "Called foo(Bar *) with x = " << x << std::endl;
}

View file

@ -0,0 +1,41 @@
#ifndef EXAMPLE_H
#define EXAMPLE_H
class Bar {
public:
Bar();
Bar(const Bar&);
Bar(double);
Bar(double, char *);
Bar(int, int);
Bar(char *);
Bar(long);
Bar(int);
Bar(Bar *);
void foo(const Bar&);
void foo(double);
void foo(double, char *);
void foo(int, int);
void foo(char *);
void foo(long);
void foo(int);
void foo(Bar *);
void spam(int x, int y=2, int z=3);
void spam(double x, int y=2, int z=3);
};
void foo(const Bar&);
void foo(double);
void foo(double, char *);
void foo(int, int);
void foo(char *);
void foo(int);
void foo(long);
void foo(Bar *);
void spam(int x, int y=2, int z=3);
void spam(double x, int y=2, int z=3);
#endif

View file

@ -0,0 +1,28 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/**
* These overloaded declarations conflict with other overloads (as far as
* SWIG's Ruby module's implementation for overloaded methods is concerned).
* One option is use the %rename directive to rename the conflicting methods;
* here, we're just using %ignore to avoid wrapping some of the overloaded
* functions altogether.
*/
%ignore Bar;
%ignore Bar::Bar(Bar *);
%ignore Bar::Bar(long);
%ignore Bar::foo(const Bar&);
%ignore Bar::foo(long);
%ignore ::foo(const Bar&);
%ignore ::foo(int);
/* Let's just grab the original header file here */
%include "example.h"

View file

@ -0,0 +1,83 @@
// import .example;
int main()
{
// This should invoke foo(double)
.example.foo(3.14159);
// This should invoke foo(double, char *)
.example.foo(3.14159, "Pi");
// This should invoke foo(int, int)
.example.foo(3, 4);
// This should invoke foo(char *)
.example.foo("This is a test");
// This should invoke foo(long)
.example.foo(42);
/*
// This should invoke Bar::Bar() followed by foo(Bar *)
foo(Bar.new);
// Skip a line
write("\n");
// This should invoke Bar::Bar(double)
Bar.new(3.14159);
// This should invoke Bar::Bar(double, char *)
Bar.new(3.14159, "Pi");
// This should invoke Bar::Bar(int, int)
Bar.new(3, 4);
// This should invoke Bar::Bar(char *)
Bar.new("This is a test");
// This should invoke Bar::Bar(int)
Bar.new(42);
// This should invoke Bar::Bar() for the input argument,
// followed by Bar::Bar(const Bar&).
Bar.new(Bar.new);
// Skip a line
write("\n");
*/
// Construct a new Bar instance (invokes Bar::Bar())
/*
bar = Bar.new;
// This should invoke Bar::foo(double)
bar.foo(3.14159);
// This should invoke Bar::foo(double, char *)
bar.foo(3.14159, "Pi");
// This should invoke Bar::foo(int, int)
bar.foo(3, 4);
// This should invoke Bar::foo(char *)
bar.foo("This is a test");
// This should invoke Bar::foo(int)
bar.foo(42);
// This should invoke Bar::Bar() to construct the input
// argument, followed by Bar::foo(Bar *).
bar.foo(Example::Bar.new);
// This should invoke Bar::spam(int x, int y, int z)
bar.spam(1);
// This should invoke Bar::spam(double x, int y, int z)
bar.spam(3.14159);
*/
write("Goodbye\n");
return 0;
}

View file

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

View file

@ -0,0 +1,18 @@
TOP = ../..
SWIG = $(TOP)/../swig
SRCS = example.c
TARGET = example
INTERFACE = example.i
all::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' pike
static::
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='mypike' INTERFACE='$(INTERFACE)' pike_static
clean::
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

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

View file

@ -0,0 +1,5 @@
/* File : example.i */
%module example
extern int gcd(int x, int y);
/* extern double Foo; */

View file

@ -0,0 +1,20 @@
int main()
{
/* Call our gcd() function */
int x = 42;
int y = 105;
int g = .example.gcd(x, y);
write(sprintf("The gcd of %d and %d is %d\n", x, y, g));
/* Manipulate the Foo global variable */
/* Output its current value */
/* write(sprintf("Foo = %f\n", .example.Foo_get())); */
/* Change its value */
/* .example.Foo_set(3.1415926); */
/* See if the change took effect */
/* write(sprintf("Foo = %f\n", .example.Foo_get())); */
return 0;
}

View file

@ -0,0 +1 @@
example_wrap.cxx

View file

@ -0,0 +1,20 @@
TOP = ../..
SWIG = $(TOP)/../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)' pike_cpp
static:
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='mypike' INTERFACE='$(INTERFACE)' pike_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile pike_clean
check: all

View file

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

View file

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

View file

@ -0,0 +1,33 @@
int main()
{
// Call some templated functions
write(sprintf("%d\n", .example.maxint(3, 7)));
write(sprintf("%f\n", .example.maxdouble(3.14, 2.18)));
// Create some objects
.example.vecint iv = .example.vecint(100);
.example.vecdouble dv = .example.vecdouble(1000);
for (int i = 0; i < 100; i++) {
iv->setitem(i, 2*i);
}
for (int i = 0; i < 1000; i++) {
dv->setitem(i, 1.0/(i+1));
}
int isum = 0;
for (int i = 0; i < 100; i++) {
isum += iv->getitem(i);
}
write(sprintf("%d\n", isum));
float fsum = 0.0;
for (int i = 0; i < 1000; i++) {
fsum += dv->getitem(i);
}
write(sprintf("%f\n", fsum));
return 0;
}