[C++-sig] Problems using wrapper.hpp to override virtual functions
Roman Yakovenko
roman.yakovenko at gmail.com
Thu Jan 17 10:44:26 CET 2008
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, x):
> 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, x):
print 'handle python'
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list