views:

89

answers:

1

I'm currently trying to expose a c++ Interface (pure virtual class) to Python using Boost::Python. The c++ interface is:

Agent.hpp

#include "Tab.hpp"
class Agent
{
    virtual void start(const Tab& t) = 0;
    virtual void stop() = 0;
};

And, by reading the "official" tutorial, I managed to write and build the next Python wrapper:

Agent.cpp

#include <boost/python.hpp>
#include <Tabl.hpp>
#include <Agent.hpp>
using namespace boost::python;

struct AgentWrapper: Agent, wrapper<Agent>
{
    public:
    void start(const Tab& t)
    {
        this->get_override("start")();
    }
    void stop()
    {
        this->get_override("stop")();
    }
};

BOOST_PYTHON_MODULE(PythonWrapper)
{
    class_<AgentWrapper, boost::noncopyable>("Agent")
        .def("start", pure_virtual(&Agent::start) )
        .def("stop", pure_virtual(&Agent::stop) )
    ;
}

Note that I have no problems while building it. What concerns me, though, is that as you can see AgentWrapper::start doesn't seem to pass any argument to Agent::start in:

void start(const Tab& t)
{
    this->get_override("start")();
}

How will the python wrapper know "start" recieves one argument? How can i do so?

+1  A: 

The get_override functions returns an an object of type override which has a number of overloads for differing number of arguments. So you should be able to just do this:

void start(const Tab& t)
{
    this->get_override("start")(t);
}

Did you try this?

zdan
I already did it that way. And it seems to work. Thanks a lot.
Fabzter