Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost python export singleton

I have a singleton (from boost::serialization):

class LogManager : public boost::serialization::singleton<LogManager> { ... };

And wrapper for getting instance:

inline LogManager &logManager() { return LogManager::get_mutable_instance(); }

What's the right way to bind this into boost.python module?

I tried:

class_< LogManager, boost::serialization::singleton<LogManager> >("LogManager", no_init)
    ...
;

As a result - a lot of ugly error text in console. What's wrong?

like image 482
Max Frai Avatar asked Dec 06 '25 03:12

Max Frai


1 Answers

In addition to using bases<...> in the second argument as Autopulated pointed out, I think you also want to specifiy boost::noncopyable as the third template argument, e.g.

bp::class_<LogManager, bp::bases<boost::serialization::singleton<LogManager> >, boost::noncopyable>("LogManager", bp::no_init)

Edit: Also, you need have a class declaration for any base classes listed, e.g.

bp::class_<boost::serialization::singleton<LogManager>, boost::noncopyable>("Singleton", bp::no_init)

Or, if you don't need access to the base class and won't be exporting any other children of boost::serialization::singleton<LogManager>, then you can omit specifying the base classes in the first place. That is, the following declaration is just fine if all you want to do is expose the LogManager class:

bp::class_<LogManager, boost::noncopyable>("LogManager", bp::no_init)
like image 155
Ray Avatar answered Dec 08 '25 16:12

Ray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!