logo       

SWIG: std::string returned as reference - solution: msg#00130

programming.swig

Subject: SWIG: std::string returned as reference - solution

Nair, Sanjay S writes:
>
> I've written the following typemap to support returning string as
> reference from c++ to perl.
>
> %typemap(in) std::string*, std::string& ($basetype string_temp) {
> if (!SvPOK($input)) {
> croak("Argument $argnum is not a string");
> }
> $1 = &string_temp;
> argvi++;
> }
>
> %typemap(argout) std::string& OUTPUT {
> sv_setpv( $input, (*$1).c_str() );
> }
>
> %apply std::string& OUTPUT { std::string& };
>
> I've tested it under windows OS and Active perl. This seem to work fine.
> Any one see any issue with this implementation please let me know?
>

This is different than most OUTPUT typemaps which do not modify their
arguments. Use std::string &REFERENCE if you're going to do that (to
be consistent with other typemaps that behave in the same way).

-- Dave

_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise