Hi All,
I use
- Visual Studio 2013
- boost 1.58 with NuGet
- 64 bit Intel
I have a class (called Log::FileSink)
that I want to instantiate via a boost::shared_ptr. This class is derived
from an abstract interface (Log::ISink) which is wrapped (Log::ISinkRealizer)
boost::python::class_<Log::ISinkRealizer,
boost::shared_ptr<Log::ISinkRealizer>,
boost::noncopyable>("ISink",
boost::python::no_init)
.def("AddEntry",
boost::python::pure_virtual(&Log::ISinkRealizer::AddEntry))
.def("ShallLog",
boost::python::pure_virtual(&Log::ISinkRealizer::ShallLog));
boost::python::class_<Log::FileSink,
boost::shared_ptr<Log::FileSink>,
boost::python::bases<Log::ISink>,
boost::noncopyable>
("FileSink",
boost::python::init<const
std::string&>())
.def("AddDomain",
&Log::FileSink::AddDomain):
When I create a python instance from
the FileSink and I pass it to the constructor of another class inside the
same module then it works fine.
>>> import DiagnsoticsPy
>>> logFile = DiagnsoticsPy.FileSink("system.log");
>>> logFile.AddDomain("Sensor.SensorController",
DiagnsoticsPy.Severity.VerboseAndAbove);
>>> logFile.AddDomain("Python.DI",
DiagnsoticsPy.Severity.VerboseAndAbove);
>>> logSource = DiagnsoticsPy.Source("Python.DI",
logFile)
boost::python::class_<Log::Source,
boost::shared_ptr<Log::Source>>("Source",
boost::python::init<const
std::string&>())
.def(boost::python::init<const
std::string&,
boost::shared_ptr<Log::ISink>>());
class
DIAGNOSTICS_API
Source
{
public:
Source(const
std::string&
name, boost::shared_ptr<Log::ISink>
sink);
};
However when I want to pass the same
"logFile" instance to a method which is defined in another python
module then the conversion between python and C++ fails.
boost::python::class_<Sensor::SensorController,
boost::shared_ptr<Sensor::SensorController>,
boost::noncopyable>("SensorController",
boost::python::init<boost::shared_ptr<Log::ISink>>());
class
SENSORCONTROL_API
SensorController
: public
boost::enable_shared_from_this<SensorController>
{
public:
explicit
SensorController(boost::shared_ptr<Log::ISink>
logSink);
};
>>> import
SensorControlPy
>>> sensorController = SensorControlPy.SensorController(logFile);
Python argument types in
SensorController.__init__(SensorController,
FileSink)
did not match C++ signature:
__init__(struct _object * __ptr64,
class boost::shared_ptr<class Log::ISink>)
If I put the all the Python bindings (also the
SensorController) into the same python module then the call to the SensorController
constructor works.