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:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
2
SWIG/Examples/ruby/operator/.cvsignore
Normal file
2
SWIG/Examples/ruby/operator/.cvsignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
example_wrap.cxx
|
||||
example.dll
|
||||
20
SWIG/Examples/ruby/operator/Makefile
Normal file
20
SWIG/Examples/ruby/operator/Makefile
Normal 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)' ruby_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myruby' INTERFACE='$(INTERFACE)' ruby_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile ruby_clean
|
||||
|
||||
check: all
|
||||
36
SWIG/Examples/ruby/operator/example.h
Normal file
36
SWIG/Examples/ruby/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; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
23
SWIG/Examples/ruby/operator/example.i
Normal file
23
SWIG/Examples/ruby/operator/example.i
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* 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 */
|
||||
|
||||
/* 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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
25
SWIG/Examples/ruby/operator/runme.rb
Normal file
25
SWIG/Examples/ruby/operator/runme.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Operator overloading example
|
||||
require 'example'
|
||||
|
||||
include Example
|
||||
|
||||
a = Complex.new(2, 3)
|
||||
b = Complex.new(-5, 10)
|
||||
|
||||
puts "a = #{a}"
|
||||
puts "b = #{b}"
|
||||
|
||||
c = a + b
|
||||
puts "c = #{c}"
|
||||
puts "a*b = #{a*b}"
|
||||
puts "a-c = #{a-c}"
|
||||
|
||||
# This should invoke Complex's copy constructor
|
||||
e = Complex.new(a-c)
|
||||
e = a - c
|
||||
puts "e = #{e}"
|
||||
|
||||
# Big expression
|
||||
f = ((a+b)*(c+b*e)) + (-a)
|
||||
puts "f = #{f}"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue