我需要存储一个类成员列表,以后再暴露给Python。
我想从:
struct Toto {
int one;
double two;
};
BOOST_PYTHON_MODULE(PythonExport)
{
using namespace boost::python;
class_<Toto>("Toto")
.def_read("one", &Toto::one)
.def_read("groot", &Toto::two);
}
收件人:
BOOST_PYTHON_MODULE(PythonExport)
{
using namespace boost::python;
std::map<std::string, ???> fieldList;
fieldList.push_back("one", &Toto::one);
fieldList.push_back("two", &Toto::two);
RegisterFields(class_<Toto>("Toto"), fieldList);
}
template <class T>
void RegisterFields(class_<T> aClass, std::map<std::string, ...> fieldList) {
for(fields : fieldList) {
aClass.def_read(fieldList.first, fieldList.second);
}
}
我唯一的限制是它必须可存储在容器(地图)中。可以根据需要将其存储在接口下的模板化类中,但是我想避免这种情况(性能)