Question on creating ResultConverters

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Question on creating ResultConverters

Michael Fabbri
I am trying to map some existing C++ interface functions Python so that python programmers can use a existing C++ product.
I am dealing with a connect function that internally creates a connection object, but returns it as void* to the caller effectively making the returned object opaque.

The compiler is failing with the error:
In static member function ‘static const PyTypeObject* boost::python::detail::converter_target_type<ResultConverter>::get_pytype() [with ResultConverter = boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning<void*>]’

‘struct boost::python::detail::caller_arity<3u>::impl<F, Policies, Sig>::operator()(PyObject*, PyObject*) [with F = void* (namespace::type::*)(const std::string&, uint16_t)const, Policies = boost::python::default_call_policies, Sig = boost::mpl::vector4<void*, namespace::RemoteConnect&, const std::string&, short unsigned int>]::result_converter’ has no member named ‘get_pytype’

Basically, it cannot convert the connection object 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 seen the ResultConverter Concepts page ( which implies an expression of form G::apply::type can be applied.

The question is: Is this trivially doable using some type of call policy concatenated with a ResultConverter expression or must I use C python interface functions to build a converter? A pointer to an example would be useful.  The specific code is show below. 

Consider the following:

In a .h file to be included by a C++ program wishing to connect to the product I have the following definition:
        class type {
                virtual void* connect( const std::string& connectionString = "localhost", uint16_t port = 1239) const = 0
        } //end class type

        const type& getConnector();

In the .cpp file implementing the interface I have:
        class RemoteConnect: public namespace::type {
        void* connect(const std::string& connectionString, uint16_t port) const
                        BaseConnection* connection = new  BaseConnection(ioService);
                        connection->connect(connectionString, port);
                        return (void*) connection;
        }  _connector; //end of RemoteConnect Class

        const type& getConnector()
                return _connector;

The C++ programmer is expected to call getConnector and then use  _connector to connect (e.g. _connector.connect(....);

My boost:python class definition is as follows:

                .def("connect", &RemoteConnect::connect) // this cause the compiler error report the conversion of void cannot be done.

Thank you,
Mike Fabbri

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!
Boost-langbinding mailing list
[hidden email]