add 'attribute' macros for python

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5777 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-03-20 00:08:36 +00:00
commit e83c226741
3 changed files with 198 additions and 0 deletions

View file

@ -0,0 +1,50 @@
%module attributetest
%include attribute.i
%attribute(A, int, a, get_a, set_a);
%attribute_ref(A, int, b);
%attribute(A, int, c, get_c); /* read-only */
%attribute_ref(A, int, d, b); /* different attribute name 'd' */
%inline
{
struct A
{
A(int a, int b, int c) : _a(a), _b(b), _c(c)
{
}
int get_a() const
{
return _a;
}
void set_a(int aa)
{
_a = aa;
}
const int& b() const
{
return _b;
}
int& b()
{
return _b;
}
int get_c() const
{
return _c;
}
private:
int _a;
int _b;
int _c;
};
}

View file

@ -0,0 +1,27 @@
import attributetest
aa = attributetest.A(1,2,3)
if aa.a != 1:
raise RuntimeError
aa.a = 3
if aa.a != 3:
raise RuntimeError
if aa.b != 2:
raise RuntimeError
aa.b = 5
if aa.b != 5:
raise RuntimeError
if aa.d != aa.b:
raise RuntimeError
if aa.c != 3:
raise RuntimeError
#aa.c = 5
#if aa.c != 3:
# raise RuntimeError