Re: [C++-sig] Cplusplus-sig Digest, Vol 45, Issue 15
On 17 June 2012 15:45, <cplusplus-sig-request@python.org> wrote:
Send Cplusplus-sig mailing list submissions to cplusplus-sig@python.org
To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request@python.org
You can reach the person managing the list at cplusplus-sig-owner@python.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..."
Today's Topics:
1. wrapping generic getter/setter functions in boost.python (vikas chauhan) 2. Re: wrapping generic getter/setter functions in boost.python (Jonas Wielicki)
----------------------------------------------------------------------
Message: 1 Date: Sat, 16 Jun 2012 21:42:56 +0545 From: vikas chauhan <presentisgood@gmail.com> To: cplusplus-sig@python.org Subject: [C++-sig] wrapping generic getter/setter functions in boost.python Message-ID: <CAG2Q8SbD4CgEH9gx9mNj6XYArEtp5vqL_wUtfo6AiQnZCPR-Eg@mail.gmail.com
Content-Type: text/plain; charset="iso-8859-1"
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
On 17 June 2012 22:16, vikas chauhan <presentisgood@gmail.com> wrote:
On 17 June 2012 15:45, <cplusplus-sig-request@python.org> wrote:
Send Cplusplus-sig mailing list submissions to cplusplus-sig@python.org
To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request@python.org
You can reach the person managing the list at cplusplus-sig-owner@python.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..."
Today's Topics:
1. wrapping generic getter/setter functions in boost.python (vikas chauhan) 2. Re: wrapping generic getter/setter functions in boost.python (Jonas Wielicki)
----------------------------------------------------------------------
Message: 1 Date: Sat, 16 Jun 2012 21:42:56 +0545 From: vikas chauhan <presentisgood@gmail.com> To: cplusplus-sig@python.org Subject: [C++-sig] wrapping generic getter/setter functions in boost.python Message-ID: < CAG2Q8SbD4CgEH9gx9mNj6XYArEtp5vqL_wUtfo6AiQnZCPR-Eg@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1"
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
participants (1)
-
vikas chauhan