range with virtual functions
Hello, I have yet another "problem" :] I want to expose a begin_foo and end_foo functions as an iterable object like: .add_property("foo", range(&Blah:begin_foo, &Blah::end_foo)) How can I do it when begin_foo and end_foo are virtual functions? I am interested in both cases, when they are pure virtual and virtual with default implementation. TIA for help! -- Best Regards, Piotr Jaroszynski
On 3/28/07, Piotr Jaroszynski <p.jaroszynski@gmail.com> wrote:
Hello,
I have yet another "problem" :] I want to expose a begin_foo and end_foo functions as an iterable object like: .add_property("foo", range(&Blah:begin_foo, &Blah::end_foo))
How can I do it when begin_foo and end_foo are virtual functions? I am interested in both cases, when they are pure virtual and virtual with default implementation.
I am not sure whether range takes references to [pure]virtual functions, but you can use same trick as in your previous question: define 2 static functions, which take reference to your class instance and return relevant iterator. Than expose these functions. This should work. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/
On Wednesday 28 of March 2007 22:50:44 Roman Yakovenko wrote:
I am not sure whether range takes references to [pure]virtual functions, but you can use same trick as in your previous question: define 2 static functions, which take reference to your class instance and return relevant iterator. Than expose these functions. This should work.
I basically get the idea, but I don't know how to implement these static functions to return the relevant iterator. When just wrapping non-pure virtuals I do: struct FooWrapper (...) iterator begin_foo() { if (override begin_foo = this->get_override("begin_foo")) return begin_foo(); return Foo::begin_foo(); } iterator default_begin_foo() { return this->Foo::begin_foo(); } and then .def("begin_foo", &Foo::begin_foo, &FooWrapper::defualt_begin_foo). So I suppose I need to somehow emulate what's def doing here in the static functions, but how? P.S. I always wondered why .def is not taking the &FooWrapper::begin_foo, but the default_begin_foo and the "original" begin_foo from Foo. -- Best Regards, Piotr Jaroszynski
on Wed Mar 28 2007, Piotr Jaroszynski <p.jaroszynski-AT-gmail.com> wrote:
Hello,
I have yet another "problem" :] I want to expose a begin_foo and end_foo functions as an iterable object like: .add_property("foo", range(&Blah:begin_foo, &Blah::end_foo))
How can I do it when begin_foo and end_foo are virtual functions? I am interested in both cases, when they are pure virtual and virtual with default implementation.
TIA for help!
You don't need to do anything special. Just expose them as above. Boost Consulting www.boost-consulting.com Don't Miss BoostCon 2007! ==> http://www.boostcon.com
participants (3)
-
David Abrahams -
Piotr Jaroszynski -
Roman Yakovenko