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
9
Examples/tcl/operator/.cvsignore
Normal file
9
Examples/tcl/operator/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
example.dll
|
||||
example.dsw
|
||||
example.ncb
|
||||
example.opt
|
||||
example.plg
|
||||
Release
|
||||
Debug
|
||||
19
Examples/tcl/operator/Makefile
Normal file
19
Examples/tcl/operator/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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)' tcl_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mytclsh' INTERFACE='$(INTERFACE)' tclsh_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile tcl_clean
|
||||
|
||||
check: all
|
||||
36
Examples/tcl/operator/example.h
Normal file
36
Examples/tcl/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/tcl/operator/example.i
Normal file
28
Examples/tcl/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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
31
Examples/tcl/operator/runme.tcl
Normal file
31
Examples/tcl/operator/runme.tcl
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Operator overloading example
|
||||
|
||||
catch { load ./example.so example}
|
||||
catch { load ./example.dll example} ;# Windows
|
||||
|
||||
set a [Complex -args 2 3]
|
||||
set b [Complex -args -5 10]
|
||||
|
||||
puts "a = $a [$a str]"
|
||||
puts "b = $b [$b str]"
|
||||
|
||||
set c [$a + $b]
|
||||
Complex -this $c
|
||||
puts "c = $c [$c str]"
|
||||
|
||||
set d [$a * $b]
|
||||
Complex -this $d
|
||||
puts "a*b = [$d str]"
|
||||
|
||||
# Alternative calling convention
|
||||
set e [Complex_- $a $c]
|
||||
puts "a-c = [Complex_str $e]"
|
||||
|
||||
set f [new_ComplexCopy $e]
|
||||
Complex -this $f
|
||||
puts "f = [$f str]"
|
||||
|
||||
# Call assignment operator
|
||||
$c = $f
|
||||
puts "c = [$c str]"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue