Question on creating ResultConverters
Michael Fabbri <[email protected]> Tue, 25 Jan 2011 23:48:59 -0800 (PST)
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
--===============3575880115819681524==
Content-Type: multipart/alternative; boundary="0-2019348693-1296028139=:44251"
--0-2019348693-1296028139=:44251
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
I am trying to map some existing C++ interface functions Python so that pyt=
hon =0Aprogrammers can use a existing C++ product.=0AI am dealing with a co=
nnect function that internally creates a connection =0Aobject, but returns =
it as void* to the caller effectively making the returned =0Aobject opaque.=
=0A=0AThe compiler is failing with the error: =0A=0AIn static member functi=
on =E2=80=98static const PyTypeObject* =0Aboost::python::detail::converter_=
target_type<ResultConverter>::get_pytype() =0A[with ResultConverter =3D =0A=
boost::python::detail::specify_a_return_value_policy_to_wrap_functions_retu=
rning<void*>]=E2=80=99=0A=0A=0A=E2=80=98struct boost::python::detail::calle=
r_arity<3u>::impl<F, Policies, =0ASig>::operator()(PyObject*, PyObject*) [w=
ith F =3D void* =0A(namespace::type::*)(const std::string&, uint16_t)const,=
Policies =3D =0Aboost::python::default_call_policies, Sig =3D boost::mpl::=
vector4<void*, =0Anamespace::RemoteConnect&, const std::string&, short unsi=
gned =0Aint>]::result_converter=E2=80=99 has no member named =E2=80=98get_p=
ytype=E2=80=99=0A=0ABasically, it cannot convert the connection object to v=
oid*. The specific =0Adetails are shown below. I have experimented with cal=
l policies, but they do not =0Aseem appropriate for the job. I have seen t=
he ResultConverter Concepts page =0A(http://www.boost.org/doc/libs/1_45_0/l=
ibs/python/doc/v2/CallPolicies.html#CallPolicies-concept)=0A which implies =
an expression of form G::apply::type can be applied.=0A=0AThe question is: =
Is this trivially doable using some type of call policy =0Aconcatenated wit=
h a ResultConverter expression or must I use C python interface =0Afunction=
s to build a converter? A pointer to an example would be useful. The =0Asp=
ecific code is show below. =0A=0A=0AConsider the following:=0A=0AIn a .h f=
ile to be included by a C++ program wishing to connect to the product I =0A=
have the following definition:=0A class type {=0A public:=0A =
virtual void* connect( const std::string& connectionString =
=3D =0A"localhost", uint16_t port =3D 1239) const =3D 0=0A .=0A =
.=0A } //end class type=0A=0A const type& getConnector();=
=0A=0A=0AIn the .cpp file implementing the interface I have:=0A clas=
s RemoteConnect: public namespace::type {=0A public:=0A void*=
connect(const std::string& connectionString, uint16_t port) const=0A =
{=0A BaseConnection* connection =3D new =
=0ABaseConnection(ioService);=0A connection->connect=
(connectionString, port);=0A return (void*) connecti=
on;=0A }=0A .=0A .=0A .=0A } _c=
onnector; //end of RemoteConnect Class=0A=0A const type& getConnecto=
r()=0A {=0A return _connector;=0A }=0A=0AThe C=
++ programmer is expected to call getConnector and then use _connector to =
=0Aconnect (e.g. _connector.connect(....);=0A=0AMy boost:python class defin=
ition is as follows:=0A=0A BOOST_PYTHON_MODULE(connectPy)=0A =
class_<RemoteConnect>("RemoteConnect",no_init)=0A .def("conn=
ect", &RemoteConnect::connect) // this cause the =0Acompiler error report t=
he conversion of void cannot be done.=0A .=0A =
.=0A ;=0A} //end BOOST_PYTHON_MODULE=0A=0AThank you,=0AMike=
Fabbri=0A=0A=0A
--0-2019348693-1296028139=:44251
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
<html><head><style type=3D"text/css"><!-- DIV {margin:0px;} --></style></he=
ad><body><div style=3D"font-family:arial,helvetica,sans-serif;font-size:12p=
t;color:#000000;">I am trying to map some existing C++ interface functions =
Python so that python programmers can use a existing C++ product.<br>I am d=
ealing with a connect function that internally creates a connection object,=
but returns it as void* to the caller effectively making the returned obje=
ct opaque.<br><br>The compiler is failing with the error: <br><div style=3D=
"margin-left: 40px;">In static member function =E2=80=98static const PyType=
Object* boost::python::detail::converter_target_type<ResultConverter>=
::get_pytype() [with ResultConverter =3D boost::python::detail::specify_a_r=
eturn_value_policy_to_wrap_functions_returning<void*>]=E2=80=99<br><b=
r>=E2=80=98struct boost::python::detail::caller_arity<3u>::impl<F,=
Policies, Sig>::operator()(PyObject*, PyObject*) [with F =3D void*
(namespace::type::*)(const std::string&, uint16_t)const, Policies =3D =
boost::python::default_call_policies, Sig =3D boost::mpl::vector4<void*,=
namespace::RemoteConnect&, const std::string&, short unsigned int&=
gt;]::result_converter=E2=80=99 has no member named =E2=80=98get_pytype=E2=
=80=99<br></div><br><span>Basically, it cannot convert the connection objec=
t to void*. The specific details are shown below. I have experimented with =
call policies, but they do not seem appropriate for the job. I have s=
een the ResultConverter Concepts page (<a target=3D"_blank" href=3D"http://=
www.boost.org/doc/libs/1_45_0/libs/python/doc/v2/CallPolicies.html#CallPoli=
cies-concept">http://www.boost.org/doc/libs/1_45_0/libs/python/doc/v2/CallP=
olicies.html#CallPolicies-concept</a>) which implies an expression of form =
G::apply<r>::type can be applied.</r></span><br><br><span style=3D"font-wei=
ght: bold;">The question is:</span> Is this trivially doable using some typ=
e of call policy
concatenated with a ResultConverter expression or must I use C python inte=
rface functions to build a converter? A pointer to an example would be usef=
ul. The specific code is show below. <br><br>Consider the follo=
wing:<br><br>In a .h file to be included by a C++ program wishing to connec=
t to the product I have the following definition:<br> &nbs=
p; class type {<br> &n=
bsp; public:<br>  =
; virtual void* connect( const std::string&am=
p; connectionString =3D "localhost", uint16_t port =3D 1239) const =3D 0<br=
> .<br> &n=
bsp; .<br> } //end cl=
ass type<br><br> const type& =
getConnector();<br><br><br>In the .cpp file implementing the interface I
have:<br> class RemoteConnect: p=
ublic namespace::type {<br> publi=
c:<br> void* connect(const std::s=
tring& connectionString, uint16_t port) const<br> &nbs=
p; {<br>&=
nbsp; &nbs=
p; BaseConnecti=
on* connection =3D new BaseConnection(ioService);<br> &nbs=
p; &=
nbsp; connection->connect(conn=
ectionString, port);<br> &nb=
sp; =
return (void*)
connection;<br>  =
; }<br> &n=
bsp; .<br> .<br>  =
; .<br> }=
_connector; //end of RemoteConnect Class<br><br> &n=
bsp; const type& getConnector()<br> =
{<br> &nb=
sp; return _connector;<br> &=
nbsp; }<br><br>The C++ programmer is expected=
to call getConnector and then use _connector to connect (e.g. _conne=
ctor.connect(....);<br><br>My boost:python class definition is as follows:<=
br><br> BOOST_PYTHON_MODULE(conne=
ctPy)<br>
class_<RemoteConnect>("RemoteConnect",no_init)<br> =
.d=
ef("connect", &RemoteConnect::connect) // this cause the compiler error=
report the conversion of void cannot be done.<br> &=
nbsp; .<br>&nbs=
p; &=
nbsp; .<br> &nbs=
p; ;<br>} //end BOOST_PYTHON_MODULE<br><br>Th=
ank you,<br>Mike Fabbri<br><div><br></div>=0A</div><br>=0A=0A=0A=0A=0A=0A=
=0A=0A </body></html>
--0-2019348693-1296028139=:44251--
--===============3575880115819681524==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
--===============3575880115819681524==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Boost-langbinding mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-langbinding
--===============3575880115819681524==--