Hi all,
I am pretty new to boost.python and I have been getting some problems
wrapping generic getter/setter functions.
Say for eg. we have class like this.
class X{
int a[10];
public:
int geta(int index) throw(some_exception) {
if(index >= 10 || index <0)
throw some_exception;
return a[index];
}
void seta(int index, int val) throw(some_exception) {
if(index >= 10 || index < 0)
throw some_exception;
a[index] = value;
}
};
I want to add attributes like a0, a1, a2,.. a9 in my python class, wherein
a0 corresponds to a[0] , a1 to a[1] and likewise.
In the boost.python docs ( exposing Class properties ), getter/settter
functions are documented for single value only.
Is it possible to do what I want ( i.e add separate attributes using the
single geta()/seta() functions ) or I need to write some kind of wrapper
functions (each for accessing each a[i]) ?
i.e, what I want to do is something like this.
BOOST_PYTHON_MODULE(mymod)
{
using namespace boost::python;
class_<X>("X")
.add_property("a0", &X::geta, &X::seta)
.add_property("a1", &X::geta, &X::seta)
..
..
;
}
and passing the arguments to geta ( i.e 0, 1,.. etc ) in someway.
So, basically what I want is , to avoid unnecessary code bloat.
regards,
vikas
_______________________________________________
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig