Iterating over std::map in PHP with SWIG

房东的猫 提交于 2019-12-04 21:55:38

问题


I am using SWIG to wrap a function that returns an std::map in PHP.

In the PHP code, I need to iterate over the elements of the map.

Thw SWIG library provides support for std::map with the std_map.i interface file, but only the following methods are wrapped:

 clear()
 del($key)
 get($key)
 has_key($key)
 is_empty()
 set($key, $x)
 size()

How can I iterate over the elements of the map? Would I need to extend the std_map.i file with some sort of wrappers for iterators and begin() and end()?


回答1:


As @awoodland said you will have to implement the iterator interface.

Here is another question on stackoverflow. Although it is java it can give you a better idea of what you are looking for:

No iterator for Java when using SWIG with C++'s std::map



来源:https://stackoverflow.com/questions/10577075/iterating-over-stdmap-in-php-with-swig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!