[C++-sig] Problems using wrapper.hpp to override virtual functions

Tim Spens t_spens at yahoo.com
Thu Jan 17 18:14:37 CET 2008


I've added in the __init__ constructor like you suggested but I'm still getting the same error?
I also tried adding in a default forwarding function like in http://www.boost.org/libs/python/doc/tutorial/doc/html/python/exposing.html
I'm using py++ to generate most of my wrapper code, with slight modifications.

void default_handle(client_response const & rsp) 
{
    this->python_client_handler::handle(boost::ref(rsp));
}

..def("handle", &client_handler::handle, &python_client_handler_wrapper::default_handle)

 Traceback (most recent call last):
   File "./test_client.py", line 304, in <module>
     class callback(handler):
 Boost.Python.ArgumentError: Error when calling the metaclass bases
     Python argument types in
     python_client_handler.__init__(python_client_handler, str, tuple,
 dict)
 did not match C++ signature:
     __init__(_object*)

Tim

----- Original Message ----
From: Roman Yakovenko <roman.yakovenko at gmail.com>
To: Development of Python/C++ integration <c++-sig at python.org>
Sent: Thursday, January 17, 2008 2:44:26 AM
Subject: Re: [C++-sig] Problems using wrapper.hpp to override virtual functions


On Jan 17, 2008 1:18 AM, Tim Spens <t_spens at yahoo.com> wrote:
> Here is the simplest example of what I'm trying to do, I hope this is
 enough the complete
> project to quite large.  I'm using wrapper.hpp so that I can use a
 python handler to handle
> callbacks from the c++ code.
>
>
>       //c++ pure virtual function definition
>       virtual void handle(const CLIENT::client_response & rsp) = 0;
>
>       //c++ wrapper for virtual function "handle"
>       virtual void handle(client_response const & rsp)
>       {
>           if(override func_handle = this->get_override("handle")){
>                  //I cannot get this section of code to run, from
 what I understand this would be the callback into python?
>               func_handle(boost::ref(rsp));
>               cout << "here handle in python" << endl;}
>           else{
>                  //I currently have a c++ handler which is called
 here, I would like to use the python handler though.
>               this->python_handler::handle(boost::ref(rsp));
>               cout << "here handle in c++" << endl;}
>       }
>
>       BOOST_PYTHON_MODULE(libclientpy)
>       {
>           class_<python_client_handler_wrapper,
 bases<client_handler>, boost::noncopyable >("python_client_handler", init<>())
>               .def("handle", &client_handler::handle);
>       }
>
> #PYTHON CODE
> import libclientpy
> handler = libclientpy.python_handler()
> client = libclientpy.client(handler, '127.0.0.1', 7900)
>
> class callback(handler):
>     def handle(self):
>         print 'handle python'
>
> azc = addZapCallback()
>
> Traceback (most recent call last):
>   File "./test_client.py", line 304, in <module>
>     class callback(handler):
> Boost.Python.ArgumentError: Error when calling the metaclass bases
>     Python argument types in
>     python_client_handler.__init__(python_client_handler, str, tuple,
 dict)
> did not match C++ signature:
>     __init__(_object*)
>
>
> I am unsure what is happening here.  I cannot even find a __init__
 function in my python_client_handler that has the said arguments?
 __init__(python_client_handler, str, tuple, dict)
>
> Any ideas?

Small complete example helps.

you have to call __init__ method of exposed C++ class


class callback(handler):
    def __init__( self ):
        handler.__init__( self )
    def handle(self):
        print 'handle python'

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig





      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 





More information about the Cplusplus-sig mailing list