/// @brief Get the class object for a wrapped type that has been exposed
/// through Boost.Python.
template <typename T>
boost::python::object get_instance_class()
{
// Query into the registry for type T.
namespace python = boost::python;
python::type_info type = python::type_id<T>();
const python::converter::registration* registration =
python::converter::registry::query(type);
// If the class is not registered, return None.
if (!registration) return python::object();
python::handle<PyTypeObject> handle(python::borrowed(
registration->get_class_object()));
return python::object(handle);
}
给定C++类型^ {CD1>},可以创建一个^{} 对象,然后查询到Boost.Python注册信息登记处。如果在注册表中找到一个条目,那么可以使用它来获取为类型
T
创建的Python类的句柄:下面是一个完整的示例demonstrating在Boost.Python注册表:
^{pr2}$输出:
有关更多与类型相关的功能,例如接受类型对象、
is
和issubclass
,请参阅this答案。在相关问题 更多 >
编程相关推荐