You are not logged in.
In my painful journey as a noob through the Python/C++ bindings land, I found myself stuck again, so I need some help from above...
I'm trying to expose a member function which returns an iterator to elements of a boost::unordered_map; this is the map definition:
typedef boost::unordered_map<string, LogDetData> LogDetMap;
where LogDetData is a simple struct with no function members. The function I want to expose is defined as:
LogDetMap::iterator GetLogDet(const string &logDetName);
Using BOOST.Python framework, I wrote bindings for LogDetMap and the function (which belogs to GCDGeoNavigator class) as:
class_<GCDGeoNavigator> ("GCDGeoNavigator", init<string> ()) //
.def("GetLogDet", &GCDGeoNavigator::GetLogDet);
class_<LogDetData> ("LogDetData") //
.def_readwrite("logVol", &LogDetData::logVol); // + many other members...
class_<LogDetMap> ("LogDetMap") //
.def("__iter__", boost::python::iterator<LogDetMap>()); // I want to export only the iterator
The code compiles but when invoking the function in the python shell I get:
>>> k = geonav.GetLogDet("CSSX")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: No to_python (by-value) converter found for C++ type: boost::unordered_detail::hash_iterator<std::allocator<std::pair<std::string const, LogDetData> >, boost::unordered_detail::ungrouped>
I really can't figure out if the problem is due to an error made by myself (very likely) or instead related to the hash_iterator reported in the error message. I googled around but I didn't found any "for dummies" information about this (maybe writing python bindings is not a task "for dummies", but I have to deal with it at work...).
I would be thankful to anyone who would shed some light on my blinded brain...
Offline