mirror of https://github.com/swig/swig
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
|
@ -33,10 +33,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*self)[index] = a;
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
|||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return self->get(index);
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
self->set(index,val);
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,10 +33,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*self)[index] = a;
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
|||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return self->get(index);
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
self->set(index,val);
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,10 +33,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
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 */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
printf("VectorArray extended get: %p %d\n",self,index);
|
||||
return (*self)[index];
|
||||
printf("VectorArray extended get: %p %d\n",$self,index);
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*self)[index] = a;
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
|||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return self->get(index);
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
self->set(index,val);
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
%extend Complex {
|
||||
char *__str__() {
|
||||
static char temp[512];
|
||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
||||
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,10 +35,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*self)[index] = a;
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
|||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return self->get(index);
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
self->set(index,val);
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
%extend Complex {
|
||||
char *__str__() {
|
||||
static char temp[512];
|
||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
||||
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -33,10 +33,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
void set(int index, Vector &a) {
|
||||
(*self)[index] = a;
|
||||
(*$self)[index] = a;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,10 +21,10 @@ template<class T> class vector {
|
|||
#ifdef SWIG
|
||||
%extend {
|
||||
T getitem(int index) {
|
||||
return self->get(index);
|
||||
return $self->get(index);
|
||||
}
|
||||
void setitem(int index, T val) {
|
||||
self->set(index,val);
|
||||
$self->set(index,val);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
%extend Complex {
|
||||
char *str() {
|
||||
static char temp[512];
|
||||
sprintf(temp,"(%g,%g)", self->re(), self->im());
|
||||
sprintf(temp,"(%g,%g)", $self->re(), $self->im());
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -33,10 +33,10 @@ public:
|
|||
/* This wrapper provides an alternative to the [] operator */
|
||||
%extend {
|
||||
Vector &get(int index) {
|
||||
return (*self)[index];
|
||||
return (*$self)[index];
|
||||
}
|
||||
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
|
||||
{
|
||||
return self->getFooBar();
|
||||
return $self->getFooBar();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
%extend Foo {
|
||||
Foo(int a) { return new Foo(); }
|
||||
~Foo() { delete self;}
|
||||
~Foo() { delete $self;}
|
||||
int spam(int x) { return x; }
|
||||
int spam(int x, int y) { return x + y ; }
|
||||
int spam(int x, int y,int z) { return x + y ; }
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
%extend Bar {
|
||||
Bar(int a) { return new Bar(); }
|
||||
~Bar() { delete self;}
|
||||
~Bar() { delete $self;}
|
||||
int spam() { return 1}
|
||||
int spam(int x) { return x; }
|
||||
int spam(int x, int y) { return x + y ; }
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
%extend FooT {
|
||||
FooT(int a) { return new FooT<T>(); }
|
||||
~FooT() { delete self;}
|
||||
~FooT() { delete $self;}
|
||||
int spam(int x) { return x; }
|
||||
int spam(int x, int y) { return x + y ; }
|
||||
int spam(int x, int y,int z) { return x + y ; }
|
||||
|
@ -96,7 +96,7 @@ public:
|
|||
|
||||
%extend BarT {
|
||||
BarT(int a) { return new BarT<T>(); }
|
||||
~BarT() { delete self;}
|
||||
~BarT() { delete $self;}
|
||||
int spam() { return 1}
|
||||
int spam(int x) { return x; }
|
||||
int spam(int x, int y) { return x + y ; }
|
||||
|
|
|
@ -41,7 +41,7 @@ void do_stuff(Foo *f) {
|
|||
|
||||
%extend Foo {
|
||||
~Foo() {
|
||||
free((void *) self);
|
||||
free((void *) $self);
|
||||
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
|
||||
// to make the friends & non members part of the class
|
||||
%extend Op{
|
||||
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 &&(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
|
||||
// this allows it to be converted to a string (so it can be printed)
|
||||
const char* __str__()
|
||||
{
|
||||
static char buffer[255];
|
||||
sprintf(buffer,"Op(%d)",self->i);
|
||||
sprintf(buffer,"Op(%d)",$self->i);
|
||||
return buffer;
|
||||
}
|
||||
// to get the [] operator working correctly we need to extend with two function
|
||||
// __getitem__ & __setitem__
|
||||
int __getitem__(unsigned i)
|
||||
{ return (*self)[i]; }
|
||||
{ return (*$self)[i]; }
|
||||
void __setitem__(unsigned i,int v)
|
||||
{ (*self)[i]=v; }
|
||||
{ (*$self)[i]=v; }
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -40,14 +40,14 @@ struct Foo {
|
|||
return new Bar();
|
||||
}
|
||||
~Bar() {
|
||||
if (self) delete self;
|
||||
delete $self;
|
||||
}
|
||||
#else
|
||||
Bar() {
|
||||
return (Bar *) malloc(sizeof(Bar));
|
||||
}
|
||||
~Bar() {
|
||||
if (self) free(self);
|
||||
free($self);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue