David Beazley | 3 May 2002 00:07
Favicon

Namespace fun

William S Fulton writes:
 > 
 > 
 > Dave
 > 
 > Some more namespace problems/queries 'cause I know you love them :).
 > 
 > What am I doing wrong here?
 > 
 > namespace std {
 >     %typemap(jni) string "jstring"
 >     %typemap(jtype) string "String"
 >     %typemap(jstype) string "String"
 > 
 >     %typemap(in) string
 >     %{ if($input) {
 >         char *p = (char *)jenv->GetStringUTFChars($input, 0);
 >         $1 =  std::string(p);
 >         jenv->ReleaseStringUTFChars($input, p);
 >       } %}
 > 
 >     %typemap(out) string
 >     %{ $result = jenv->NewStringUTF($1.c_str()); %}
 > }
 > 

I'm a little jet-lagged (just got back), but in order for this to work 
as intended, you need to tell SWIG that "string" is a typename defined 
in the namespace.  Just use a forward class definition.

namespace std {
   class string;
   %typemap() ....
}

Cheers,

Dave


Gmane