<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Since I didn't find any solution when using map_indexing_suite, I wrote a simple wrapping that works in my case :<div><br></div><div>==============</div><div><div><font class="Apple-style-span" face="Courier">#include &lt;map&gt;</font></div><div><font class="Apple-style-span" face="Courier">#include &lt;boost/python.hpp&gt;</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">namespace myProject {</font></div><div><font class="Apple-style-span" face="Courier">template&lt;class Key, class Val&gt;</font></div><div><font class="Apple-style-span" face="Courier">struct map_item {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;typedef std::map&lt;Key,Val&gt; Map;</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static Val get(Map &amp; self, const Key idx) {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp;if (self.find(idx) == self.end()) {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PyErr_SetString(PyExc_KeyError,"Map key not found");</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;throw_error_already_set();</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp;}</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp;return self[idx];</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static void set(Map&amp; self, const Key idx, const Val val) { self[idx]=val; }</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static void del(Map&amp; self, const Key n) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ self.erase(n); }</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static bool in (Map const&amp; self, const Key n) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ return self.find(n) != self.end(); }</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static list keys(Map const&amp; self) {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;list t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(typename Map::const_iterator it = self.begin() ; it!=self.end() ; ++it)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t.append(it-&gt;first);</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static list values(Map const&amp; self) {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;list t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(typename Map::const_iterator it=self.begin(); it!=self.end(); ++it)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t.append(it-&gt;second);</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;static list items(Map const&amp; self) {</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;list t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(typename Map::const_iterator it=self.begin(); it!=self.end(); ++it)</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;t.append( make_tuple(it-&gt;first, it-&gt;second) );</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return t;</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;}</font></div><div><font class="Apple-style-span" face="Courier">};</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">#define STL_MAP_WRAPPING_PTR(KEY_TYPE, VALUE_TYPE, PYTHON_TYPE_NAME) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;class_&lt;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt; &gt;((std::string(PYTHON_TYPE_NAME)+std::string("DATA")).c_str()) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def_readonly ("key" &nbsp;, &amp;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt;::first ) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def_readwrite("value", &amp;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt;::second) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;class_&lt;std::map&lt;KEY_TYPE, VALUE_TYPE&gt; &gt;(PYTHON_TYPE_NAME) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__len__" &nbsp; &nbsp; , &amp;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;::size) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__iter__" &nbsp; &nbsp;, boost::python::iterator&lt;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;, return_internal_reference&lt;&gt; &gt;()) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__getitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().get, return_internal_reference&lt;&gt;()) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__setitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().set &nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__delitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().del &nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__contains__", &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().in &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("clear" &nbsp; &nbsp; &nbsp; , &amp;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;::clear &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("has_key" &nbsp; &nbsp; , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().in &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("keys" &nbsp; &nbsp; &nbsp; &nbsp;, &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().keys &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("values" &nbsp; &nbsp; &nbsp;, &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().values) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("items" &nbsp; &nbsp; &nbsp; , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().items ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;;</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">#define STL_MAP_WRAPPING(KEY_TYPE, VALUE_TYPE, PYTHON_TYPE_NAME) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;class_&lt;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt; &gt;((std::string(PYTHON_TYPE_NAME)+std::string("DATA")).c_str()) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def_readonly ("key" &nbsp;, &amp;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt;::first ) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def_readwrite("value", &amp;std::pair&lt;const KEY_TYPE, VALUE_TYPE&gt;::second) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;class_&lt;std::map&lt;KEY_TYPE, VALUE_TYPE&gt; &gt;(PYTHON_TYPE_NAME) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__len__" &nbsp; &nbsp; , &amp;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;::size) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__iter__" &nbsp; &nbsp;, boost::python::iterator&lt;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;, return_internal_reference&lt;&gt; &gt;()) \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__getitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().get &nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__setitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().set &nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__delitem__" , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().del &nbsp; ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("__contains__", &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().in &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("clear" &nbsp; &nbsp; &nbsp; , &amp;std::map&lt;KEY_TYPE, VALUE_TYPE&gt;::clear &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("has_key" &nbsp; &nbsp; , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().in &nbsp; &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("keys" &nbsp; &nbsp; &nbsp; &nbsp;, &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().keys &nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("values" &nbsp; &nbsp; &nbsp;, &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().values) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;.def("items" &nbsp; &nbsp; &nbsp; , &amp;map_item&lt;KEY_TYPE, VALUE_TYPE&gt;().items ) &nbsp; &nbsp; &nbsp; &nbsp; \</font></div><div><font class="Apple-style-span" face="Courier">&nbsp;&nbsp; &nbsp;;</font></div><div><font class="Apple-style-span" face="Courier"><br></font></div><div><font class="Apple-style-span" face="Courier">} // namespace</font></div><div>=================</div><div><br></div><div><br></div><div><br></div><div>Simply use STL_MAP_WRAPPING_PTR(KeyClass, ClassA*, "ClassAMap")&nbsp;to bind a map&lt;KeyClass, ClassA*&gt;</div><div>or STL_MAP_WRAPPING(KeyClass, ClassB, "ClassBMap") to bind a map&lt;KeyClass, ClassB&gt;</div><div><br></div><div>This code works in my case, fell free to correct or complete any error / missing.</div><div><br></div><div><div>-------------------------------</div><div>Damien Dupuis</div></div><div><br></div><div><div><div>Le 12 juil. 2010 à 09:13, Pentix a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>Hi, Damien!<br><br>I've got exactly the same problem... Have you got any achievements?<br><br><br><br>Damien Dupuis wrote:<br><blockquote type="cite"><br></blockquote><blockquote type="cite">error: no match for call to ‘(const<br></blockquote><blockquote type="cite">boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning&lt;X*&gt;)<br></blockquote><blockquote type="cite">(X*)‘<br></blockquote><blockquote type="cite"><br></blockquote><br>-- <br>View this message in context: <a href="http://old.nabble.com/Problem-with-map_indexing_suite-tp28925347p29135982.html">http://old.nabble.com/Problem-with-map_indexing_suite-tp28925347p29135982.html</a><br>Sent from the Python - c++-sig mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>Cplusplus-sig mailing list<br><a href="mailto:Cplusplus-sig@python.org">Cplusplus-sig@python.org</a><br>http://mail.python.org/mailman/listinfo/cplusplus-sig<br><br></div></blockquote></div><br><div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div><br></div><div><br></div></div><br class="Apple-interchange-newline"></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<br></div></div></body></html>