update swig on windows
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
CXXSRCS = example.cxx
|
||||
|
||||
include $(SRCDIR)../example.mk
|
||||
@@ -0,0 +1,45 @@
|
||||
/* File : example.cxx */
|
||||
|
||||
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
|
||||
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
|
||||
# define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include "example.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Vector operator+(const Vector &a, const Vector &b) {
|
||||
Vector r;
|
||||
r.x = a.x + b.x;
|
||||
r.y = a.y + b.y;
|
||||
r.z = a.z + b.z;
|
||||
return r;
|
||||
}
|
||||
|
||||
char *Vector::print() {
|
||||
static char temp[512];
|
||||
sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z);
|
||||
return temp;
|
||||
}
|
||||
|
||||
VectorArray::VectorArray(int size) {
|
||||
items = new Vector[size];
|
||||
maxsize = size;
|
||||
}
|
||||
|
||||
VectorArray::~VectorArray() {
|
||||
delete [] items;
|
||||
}
|
||||
|
||||
Vector &VectorArray::operator[](int index) {
|
||||
if ((index < 0) || (index >= maxsize)) {
|
||||
printf("Panic! Array index out of bounds.\n");
|
||||
exit(1);
|
||||
}
|
||||
return items[index];
|
||||
}
|
||||
|
||||
int VectorArray::size() {
|
||||
return maxsize;
|
||||
}
|
||||
22
winx64/bin/swigwin-4.0.0/Examples/octave/reference/example.h
Normal file
22
winx64/bin/swigwin-4.0.0/Examples/octave/reference/example.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* File : example.h */
|
||||
|
||||
class Vector {
|
||||
private:
|
||||
double x,y,z;
|
||||
public:
|
||||
Vector() : x(0), y(0), z(0) { }
|
||||
Vector(double x, double y, double z) : x(x), y(y), z(z) { }
|
||||
friend Vector operator+(const Vector &a, const Vector &b);
|
||||
char *print();
|
||||
};
|
||||
|
||||
class VectorArray {
|
||||
private:
|
||||
Vector *items;
|
||||
int maxsize;
|
||||
public:
|
||||
VectorArray(int maxsize);
|
||||
~VectorArray();
|
||||
Vector &operator[](int);
|
||||
int size();
|
||||
};
|
||||
46
winx64/bin/swigwin-4.0.0/Examples/octave/reference/example.i
Normal file
46
winx64/bin/swigwin-4.0.0/Examples/octave/reference/example.i
Normal file
@@ -0,0 +1,46 @@
|
||||
/* File : example.i */
|
||||
|
||||
/* This file has a few "typical" uses of C++ references. */
|
||||
|
||||
%module swigexample
|
||||
|
||||
%feature("autodoc", 1);
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%rename(cprint) print;
|
||||
|
||||
class Vector {
|
||||
public:
|
||||
Vector(double x, double y, double z);
|
||||
~Vector();
|
||||
char *print();
|
||||
};
|
||||
|
||||
/* This helper function calls an overloaded operator */
|
||||
%inline %{
|
||||
Vector addv(Vector &a, Vector &b) {
|
||||
return a+b;
|
||||
}
|
||||
%}
|
||||
|
||||
/* Wrapper around an array of vectors class */
|
||||
|
||||
class VectorArray {
|
||||
public:
|
||||
VectorArray(int maxsize);
|
||||
~VectorArray();
|
||||
int size();
|
||||
|
||||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
65
winx64/bin/swigwin-4.0.0/Examples/octave/reference/runme.m
Normal file
65
winx64/bin/swigwin-4.0.0/Examples/octave/reference/runme.m
Normal file
@@ -0,0 +1,65 @@
|
||||
# do not dump Octave core
|
||||
if exist("crash_dumps_octave_core", "builtin")
|
||||
crash_dumps_octave_core(0);
|
||||
endif
|
||||
|
||||
# This file illustrates the manipulation of C++ references in Octave
|
||||
|
||||
swigexample
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
printf("Creating some objects:\n");
|
||||
a = swigexample.Vector(3,4,5)
|
||||
b = swigexample.Vector(10,11,12)
|
||||
|
||||
printf(" Created %s\n",a.cprint());
|
||||
printf(" Created %s\n",b.cprint());
|
||||
|
||||
# ----- Call an overloaded operator -----
|
||||
|
||||
# This calls the wrapper we placed around
|
||||
#
|
||||
# operator+(const Vector &a, const Vector &)
|
||||
#
|
||||
# It returns a new allocated object.
|
||||
|
||||
printf("Adding a+b\n");
|
||||
c = swigexample.addv(a,b);
|
||||
printf(" a+b = %s\n", c.cprint());
|
||||
|
||||
clear c
|
||||
|
||||
# ----- Create a vector array -----
|
||||
|
||||
# Note: Using the high-level interface here
|
||||
printf("Creating an array of vectors\n");
|
||||
va = swigexample.VectorArray(10)
|
||||
|
||||
# ----- Set some values in the array -----
|
||||
|
||||
# These operators copy the value of $a and $b to the vector array
|
||||
va.set(0,a);
|
||||
va.set(1,b);
|
||||
|
||||
va.set(2,swigexample.addv(a,b))
|
||||
|
||||
# Get some values from the array
|
||||
|
||||
printf("Getting some array values\n");
|
||||
for i=0:4,
|
||||
printf(" va(%d) = %s\n",i,va.get(i).cprint());
|
||||
end;
|
||||
|
||||
# Watch under resource meter to check on this
|
||||
printf("Making sure we don't leak memory.\n");
|
||||
for i=0:1000000-1,
|
||||
c = va.get(mod(i,10));
|
||||
end
|
||||
|
||||
# ----- Clean up -----
|
||||
printf("Cleaning up\n");
|
||||
|
||||
clear va
|
||||
clear a
|
||||
clear b
|
||||
Reference in New Issue
Block a user