use $self special variable instead of self in %extend
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9533 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
80f1901570
commit
65c52f7c06
20 changed files with 52 additions and 52 deletions
|
|
@ -33,10 +33,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return self->get(index);
|
return $self->get(index);
|
||||||
}
|
}
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return self->get(index);
|
return $self->get(index);
|
||||||
}
|
}
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
printf("VectorArray extended get: %p %d\n",self,index);
|
printf("VectorArray extended get: %p %d\n",$self,index);
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return self->get(index);
|
return $self->get(index);
|
||||||
}
|
}
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
%extend Complex {
|
%extend Complex {
|
||||||
char *__str__() {
|
char *__str__() {
|
||||||
static char temp[512];
|
static char temp[512];
|
||||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return self->get(index);
|
return $self->get(index);
|
||||||
}
|
}
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
%extend Complex {
|
%extend Complex {
|
||||||
char *__str__() {
|
char *__str__() {
|
||||||
static char temp[512];
|
static char temp[512];
|
||||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
||||||
#ifdef SWIG
|
#ifdef SWIG
|
||||||
%extend {
|
%extend {
|
||||||
T getitem(int index) {
|
T getitem(int index) {
|
||||||
return self->get(index);
|
return $self->get(index);
|
||||||
}
|
}
|
||||||
void setitem(int index, T val) {
|
void setitem(int index, T val) {
|
||||||
self->set(index,val);
|
$self->set(index,val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
%extend Complex {
|
%extend Complex {
|
||||||
char *str() {
|
char *str() {
|
||||||
static char temp[512];
|
static char temp[512];
|
||||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ public:
|
||||||
/* This wrapper provides an alternative to the [] operator */
|
/* This wrapper provides an alternative to the [] operator */
|
||||||
%extend {
|
%extend {
|
||||||
Vector &get(int index) {
|
Vector &get(int index) {
|
||||||
return (*self)[index];
|
return (*$self)[index];
|
||||||
}
|
}
|
||||||
void set(int index, Vector &a) {
|
void set(int index, Vector &a) {
|
||||||
(*self)[index] = a;
|
(*$self)[index] = a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
virtual int dummy() // Had to remove virtual to work
|
virtual int dummy() // Had to remove virtual to work
|
||||||
{
|
{
|
||||||
return self->getFooBar();
|
return $self->getFooBar();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
%extend Foo {
|
%extend Foo {
|
||||||
Foo(int a) { return new Foo(); }
|
Foo(int a) { return new Foo(); }
|
||||||
~Foo() { delete self;}
|
~Foo() { delete $self;}
|
||||||
int spam(int x) { return x; }
|
int spam(int x) { return x; }
|
||||||
int spam(int x, int y) { return x + y ; }
|
int spam(int x, int y) { return x + y ; }
|
||||||
int spam(int x, int y,int z) { return x + y ; }
|
int spam(int x, int y,int z) { return x + y ; }
|
||||||
|
|
@ -41,7 +41,7 @@ public:
|
||||||
|
|
||||||
%extend Bar {
|
%extend Bar {
|
||||||
Bar(int a) { return new Bar(); }
|
Bar(int a) { return new Bar(); }
|
||||||
~Bar() { delete self;}
|
~Bar() { delete $self;}
|
||||||
int spam() { return 1}
|
int spam() { return 1}
|
||||||
int spam(int x) { return x; }
|
int spam(int x) { return x; }
|
||||||
int spam(int x, int y) { return x + y ; }
|
int spam(int x, int y) { return x + y ; }
|
||||||
|
|
@ -56,7 +56,7 @@ public:
|
||||||
|
|
||||||
%extend FooT {
|
%extend FooT {
|
||||||
FooT(int a) { return new FooT<T>(); }
|
FooT(int a) { return new FooT<T>(); }
|
||||||
~FooT() { delete self;}
|
~FooT() { delete $self;}
|
||||||
int spam(int x) { return x; }
|
int spam(int x) { return x; }
|
||||||
int spam(int x, int y) { return x + y ; }
|
int spam(int x, int y) { return x + y ; }
|
||||||
int spam(int x, int y,int z) { return x + y ; }
|
int spam(int x, int y,int z) { return x + y ; }
|
||||||
|
|
@ -96,7 +96,7 @@ public:
|
||||||
|
|
||||||
%extend BarT {
|
%extend BarT {
|
||||||
BarT(int a) { return new BarT<T>(); }
|
BarT(int a) { return new BarT<T>(); }
|
||||||
~BarT() { delete self;}
|
~BarT() { delete $self;}
|
||||||
int spam() { return 1}
|
int spam() { return 1}
|
||||||
int spam(int x) { return x; }
|
int spam(int x) { return x; }
|
||||||
int spam(int x, int y) { return x + y ; }
|
int spam(int x, int y) { return x + y ; }
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ void do_stuff(Foo *f) {
|
||||||
|
|
||||||
%extend Foo {
|
%extend Foo {
|
||||||
~Foo() {
|
~Foo() {
|
||||||
free((void *) self);
|
free((void *) $self);
|
||||||
g_fooCount--;
|
g_fooCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,36 +167,36 @@ inline bool operator>=(const Op& a,const Op& b){return a.i>=b.i;}
|
||||||
// we need to extend the class
|
// we need to extend the class
|
||||||
// to make the friends & non members part of the class
|
// to make the friends & non members part of the class
|
||||||
%extend Op{
|
%extend Op{
|
||||||
Op operator &&(const Op& b){return Op(self->i&&b.i);}
|
Op operator &&(const Op& b){return Op($self->i&&b.i);}
|
||||||
Op operator or(const Op& b){return Op(self->i||b.i);}
|
Op operator or(const Op& b){return Op($self->i||b.i);}
|
||||||
|
|
||||||
Op operator+(const Op& b){return Op(self->i+b.i);}
|
Op operator+(const Op& b){return Op($self->i+b.i);}
|
||||||
Op operator-(const Op& b){return Op(self->i-b.i);}
|
Op operator-(const Op& b){return Op($self->i-b.i);}
|
||||||
Op operator*(const Op& b){return Op(self->i*b.i);}
|
Op operator*(const Op& b){return Op($self->i*b.i);}
|
||||||
Op operator/(const Op& b){return Op(self->i/b.i);}
|
Op operator/(const Op& b){return Op($self->i/b.i);}
|
||||||
Op operator%(const Op& b){return Op(self->i%b.i);}
|
Op operator%(const Op& b){return Op($self->i%b.i);}
|
||||||
|
|
||||||
bool operator==(const Op& b){return self->i==b.i;}
|
bool operator==(const Op& b){return $self->i==b.i;}
|
||||||
bool operator!=(const Op& b){return self->i!=b.i;}
|
bool operator!=(const Op& b){return $self->i!=b.i;}
|
||||||
bool operator< (const Op& b){return self->i<b.i;}
|
bool operator< (const Op& b){return $self->i<b.i;}
|
||||||
bool operator<=(const Op& b){return self->i<=b.i;}
|
bool operator<=(const Op& b){return $self->i<=b.i;}
|
||||||
bool operator> (const Op& b){return self->i>b.i;}
|
bool operator> (const Op& b){return $self->i>b.i;}
|
||||||
bool operator>=(const Op& b){return self->i>=b.i;}
|
bool operator>=(const Op& b){return $self->i>=b.i;}
|
||||||
|
|
||||||
// we also add the __str__() fn to the class
|
// we also add the __str__() fn to the class
|
||||||
// this allows it to be converted to a string (so it can be printed)
|
// this allows it to be converted to a string (so it can be printed)
|
||||||
const char* __str__()
|
const char* __str__()
|
||||||
{
|
{
|
||||||
static char buffer[255];
|
static char buffer[255];
|
||||||
sprintf(buffer,"Op(%d)",self->i);
|
sprintf(buffer,"Op(%d)",$self->i);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
// to get the [] operator working correctly we need to extend with two function
|
// to get the [] operator working correctly we need to extend with two function
|
||||||
// __getitem__ & __setitem__
|
// __getitem__ & __setitem__
|
||||||
int __getitem__(unsigned i)
|
int __getitem__(unsigned i)
|
||||||
{ return (*self)[i]; }
|
{ return (*$self)[i]; }
|
||||||
void __setitem__(unsigned i,int v)
|
void __setitem__(unsigned i,int v)
|
||||||
{ (*self)[i]=v; }
|
{ (*$self)[i]=v; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,14 @@ struct Foo {
|
||||||
return new Bar();
|
return new Bar();
|
||||||
}
|
}
|
||||||
~Bar() {
|
~Bar() {
|
||||||
if (self) delete self;
|
delete $self;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Bar() {
|
Bar() {
|
||||||
return (Bar *) malloc(sizeof(Bar));
|
return (Bar *) malloc(sizeof(Bar));
|
||||||
}
|
}
|
||||||
~Bar() {
|
~Bar() {
|
||||||
if (self) free(self);
|
free($self);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue