Re: [pygccxml-development] Proper overload resolution
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2010-05-17 17:23:55
|
On Mon, May 17, 2010 at 6:23 PM, Benoit Leveau
<ben...@mo...> wrote:
> Hello,
>
> Consider the following class:
>
> struct MyClass
> {
> void setBool(bool a);
> void setInt(int a);
> };
>
> Because of the way the overloading resolution works currently in boost
> python, if you're trying to bind these two functions to __setitem__,
> only one of these functions (the last one bound actually) will always be
> called, no matter if you call __setitem__ with a bool or an int (for
> more information of the why, please take a look at the cplusplus-sig
> thread mentioned below).
>
> The only way I could find to bind these two methods to __setitem__ and
> have them called "correctly" is to bind them as two separate functions,
> and then define a __setitem__ function in python at runtime, by adding
> something like that in the __init__.py file:
>
> def custom_set_item(a):
> if isinstanceof(a, bool):
> ...
> ...
>
> MyClass.__setitem__ = custom_set_item
>
> Maybe there's a way to do that by binding a setitem which would take a
> bp::object and test the type in C++, I haven't tried.
You can do this in C++ too, but why bother? You can generate that code
from Py++ :-)
> It looks like Troy D. Straszheim came with a better implementation of
> the overloading mechanism (which is much closer to what we expect):
> http://mail.python.org/pipermail/cplusplus-sig/2009-December/015047.html
>
> It is apparently considered for addition in boost, but looks like
> they're waiting for the new langbinding integration:
> http://www.boost.org/doc/libs/1_43_0/libs/python/todo.html
>
> Any chance one of you have tried Troy's modification, or have any
> suggestion for this problem?
Yes, I do. Please take a look on the following document(
http://language-binding.net/pyplusplus/documentation/functions/registration_order.html
) and let me know whether it solved your problem or not.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|