[Xapian-discuss] Swig on matchspy

Olly Betts olly at survex.com
Wed Dec 10 01:18:53 GMT 2008


On Mon, Dec 08, 2008 at 06:46:03PM +0100, Yann ROBIN wrote:
> I'm currently testing the trunk version of Xapian using CSharp.
> And i needed to test the CategorySelectMatchSpy.

I should probably note that I'm not totally happy with the API for this
so it may change if we can think of a better one...

> So i change a little bit the xapian.i file to generate the needed
> class and learn on the way how to use swig.
> 
> For the get_value of ValueCountMatchSpy i have now a class that wrap
> the std::map<std::string, Xapian::doccount> class but i don't have any
> method to get the iterator.
> So i added an extension
> 
> %extend std::map {
>    std::map<K, T>::iterator get_begin_iterator() {
>      return (*self).begin();
>    }
> }
> 
> but it seems that there is no mapping for the iterator so it generates
> an "empty" class.

SWIG can actually wrap std::map, but I think you would do better to
convert the returned std::map to a native C# equivalent.

So you want to %extend ValueCountMatchSpy with a new method which calls
get_values() and then uses C#'s C API to build the appropriate C# object
and return it.  If you call the new method GetValues() you can then
%ignore the C++ get_values() method.

I don't know a lot about C# though, so I don't know the details of how
this is done there.

Cheers,
    Olly



More information about the Xapian-discuss mailing list