List Info

Thread: Re: Boost Python: Howto wrap "out" arguments of a methode




Re: Boost Python: Howto wrap "out" arguments of a methode
country flaguser name
United States
2007-06-05 14:45:02
on Mon Jun 04 2007, Alexander Eisenhuth
<newsuser-AT-stacom-software.de> wrote:

> How to wrap methode Get with Boost.Python?

First, I suggest you take your question to the C++-sig
(
http://www.boost.org/more/mailing_lists.htm#cplussig).


>
>       class MyClass {
>       public:
>           MyClass();
>
>           void GetX(double &pos_x);
> [...]
>
>
> I'v tried it with:
>
>           .def(
>               "GetX"
>               , &::MyClass::GetX
>               , bp::arg("")
>               ,
bp::return_value_policy<bp::return_arg<1>() >()
>
> But when I try it in python:
>
> Boost.Python.ArgumentError: Python argument types in
>       MyClass.GetX(MyClass, int)
> did not match C++ signature:
>       GetX(class MyClass::LedPosition_C , int
 )
>
> Any ideas?

return_value_policy is only good for telling Boost.Python
how to
handle the actual (non-void) return value of your C++
function.  In
your case, create a thin wrapper function:

     double GetX2(MyClass& self, double pos_x) 
     { self.GetX(pos_x); return pos_x; }

and wrap that instead of GetX:

           .def("GetX", GetX2)




-- 
Dave Abrahams
Boost Consulting
http://www.boost-cons
ulting.com

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

Re: Boost Python: Howto wrap "out" arguments of a methode
country flaguser name
Germany
2007-06-06 01:02:27
David Abrahams schrieb:
> on Mon Jun 04 2007, Alexander Eisenhuth
<newsuser-AT-stacom-software.de> wrote:
> 
>> How to wrap methode Get with Boost.Python?
> 
> First, I suggest you take your question to the C++-sig
> (
http://www.boost.org/more/mailing_lists.htm#cplussig).
> 
> 
>>       class MyClass {
>>       public:
>>           MyClass();
>>
>>           void GetX(double &pos_x);
>> [...]
>>
>>
>> I'v tried it with:
>>
>>           .def(
>>               "GetX"
>>               , &::MyClass::GetX
>>               , bp::arg("")
>>               ,
bp::return_value_policy<bp::return_arg<1>() >()
>>
>> But when I try it in python:
>>
>> Boost.Python.ArgumentError: Python argument types
in
>>       MyClass.GetX(MyClass, int)
>> did not match C++ signature:
>>       GetX(class MyClass::LedPosition_C ,
int  )
>>
>> Any ideas?
> 
> return_value_policy is only good for telling
Boost.Python how to
> handle the actual (non-void) return value of your C++
function.  In
> your case, create a thin wrapper function:

Ok, thanks for that hint.

> 
>      double GetX2(MyClass& self, double pos_x) 
>      { self.GetX(pos_x); return pos_x; }
> 
> and wrap that instead of GetX:
> 
>            .def("GetX", GetX2)
> 

So boost.python doesn't have a mechanism to transform in the
wrapper code a call 
by reference into return value?

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )