eud*_*xos 9 converter boost-python
我有几个模块为一些简单类型定义转换器(例如int的列表std::vector<int>); 它们是独立模块的一部分,但有时它们都用在一个脚本中,这导致了
RuntimeWarning: to-Python converter for std::vector<int, std::allocator<int> > already registered; second conversion method ignored.
Run Code Online (Sandbox Code Playgroud)
如何检查某种类型的转换器是否已定义并跳过第二次注册?
小智 8
boost::python::type_info info = boost::python::type_id<YourType>();
const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
if (reg == NULL) {
//register YourType
} else if ((*reg).m_to_python == NULL) {
//register YourType
}
Run Code Online (Sandbox Code Playgroud)
请注意,您还需要检查((*reg).m_to_python == NULL)是否存在风险,在某些体系结构中,注册不会作为默认构造函数发生,因为已调用注册为YourType分配NULL转换器.在这种情况下,查询(info)确实返回空注册的地址.
你可以查询注册表,所以像这样(未经测试)..
#include <boost/python/converter/registry.hpp>
boost::python::type_info info = boost::python::type_id<YourType>();
boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
if (reg == NULL)
{
//registry YourType
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3355 次 |
| 最近记录: |