The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5fcae5eb66
commit
12a43edc2d
1508 changed files with 125983 additions and 44037 deletions
10
Examples/python/operator/.cvsignore
Normal file
10
Examples/python/operator/.cvsignore
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
example.py
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
21
Examples/python/operator/Makefile
Normal file
21
Examples/python/operator/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
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)' 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
|
||||
36
Examples/python/operator/example.h
Normal file
36
Examples/python/operator/example.h
Normal file
|
|
@ -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; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
28
Examples/python/operator/example.i
Normal file
28
Examples/python/operator/example.i
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
21
Examples/python/operator/runme.py
Normal file
21
Examples/python/operator/runme.py
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue