提升python导出单例(Boost python export singleton)

编程入门 行业动态 更新时间:2024-10-17 23:34:49
提升python导出单例(Boost python export singleton)

我有一个单例(来自boost :: serialization):

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

以及获取实例的包装器:

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

将此绑定到boost.python模块的正确方法是什么?

我试过了:

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

结果 - 在控制台中出现了很多难看的错误文本。 怎么了?

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?

最满意答案

除了在第二个参数中使用base bases<...>作为Autopulated指出,我想你也想要指定boost::noncopyable作为第三个模板参数,例如

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

编辑 :此外,您需要为列出的任何基类提供类声明,例如

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

或者,如果您不需要访问基类并且不会导出boost::serialization::singleton<LogManager>任何其他子项,那么您可以省略首先指定基类。 也就是说,如果你想要做的就是暴露LogManager类,那么下面的声明就可以了:

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

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)

更多推荐

本文发布于:2023-07-16 13:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Boost   python   singleton   export

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!