Initial commit of Octave module.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2008-03-01 23:35:44 +00:00
commit 393391965c
275 changed files with 14004 additions and 5 deletions

View file

@ -0,0 +1,21 @@
TOP = ../..
SWIG = $(TOP)/../preinst-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)' octave_cpp
static::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
clean::
$(MAKE) -f $(TOP)/Makefile octave_clean
rm -f $(TARGET).m
check: all

View file

@ -0,0 +1,36 @@
/* File : example.h */
#include <math.h>
class ComplexVal {
private:
double rpart, ipart;
public:
ComplexVal(double r = 0, double i = 0) : rpart(r), ipart(i) { }
ComplexVal(const ComplexVal &c) : rpart(c.rpart), ipart(c.ipart) { }
ComplexVal &operator=(const ComplexVal &c) {
rpart = c.rpart;
ipart = c.ipart;
return *this;
}
ComplexVal operator+(const ComplexVal &c) const {
return ComplexVal(rpart+c.rpart, ipart+c.ipart);
}
ComplexVal operator-(const ComplexVal &c) const {
return ComplexVal(rpart-c.rpart, ipart-c.ipart);
}
ComplexVal operator*(const ComplexVal &c) const {
return ComplexVal(rpart*c.rpart - ipart*c.ipart,
rpart*c.ipart + c.rpart*ipart);
}
ComplexVal operator-() const {
return ComplexVal(-rpart, -ipart);
}
double re() const { return rpart; }
double im() const { return ipart; }
};

View file

@ -0,0 +1,24 @@
/* File : example.i */
%module example
#pragma SWIG nowarn=SWIGWARN_IGNORE_OPERATOR_EQ
%{
#include "example.h"
%}
/* Now grab the original header file */
%include "example.h"
/* An output method that turns a complex into a short string */
%extend ComplexVal {
char *__str() {
static char temp[512];
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
return temp;
}
ComplexVal __paren(int j) {
return ComplexVal($self->re()*j,$self->im()*j);
}
};

View file

@ -0,0 +1,24 @@
# Operator overloading example
example
a = example.ComplexVal(2,3);
b = example.ComplexVal(-5,10);
printf("a = %s\n",a);
printf("b = %s\n",b);
c = a + b;
printf("c = %s\n",c);
printf("a*b = %s\n",a*b);
printf("a-c = %s\n",a-c);
e = example.ComplexVal(a-c);
printf("e = %s\n",e);
# Big expression
f = ((a+b)*(c+b*e)) + (-a);
printf("f = %s\n",f);
# paren overloading
printf("a(3)= %s\n",a(3));