开发者

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?


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)


You want bp::bases< boost::serialization::singleton<LogManager> > as the second template parameter instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜