Iterating over std::map in PHP with SWIG
Asked Answered
R

1

8

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()?

Rorie answered 14/5, 2012 at 3:0 Comment(1)
Challenge accepted. The "right" thing to do is implement PHP's iterator interface but it looks like that might be a bit tricky. I'll have a thinkBankbook
K
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

Kalakalaazar answered 16/5, 2012 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.