Changeset 489:497c72c3ffbe in verona


Ignore:
Timestamp:
May 25, 2012 5:09:59 PM (13 months ago)
Author:
Vadim Lebedev <vadim@…>
Branch:
default
Message:

fix java string to native string conversions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • swig/verona.i

    r488 r489  
    8080} 
    8181 
    82  
     82void make_cxxstr(JNIEnv* jenv, string& st, jstring jst) 
     83{ 
     84   jint len = env->GetStringUTFLength(jst); 
     85   jint jlen = env->GetStringLength(jst); 
     86   st.capacity(len); 
     87   env->GetStringUTFRegion(jenv, jst, 0, jlen, (char*) st.data()); 
     88   st.resize(len);       
     89 
     90} 
    8391%} 
    8492 
     
    93101} 
    94102 
     103%typemap(in) std::string  
     104%{ if(!$input) { 
     105     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); 
     106     return $null; 
     107    }  
     108    std::string $1_cxxstr; 
     109    make_cxxstr(jenv, $1_cxxstr, $input); 
     110    $1 = &$1_cxxstr; // in std::string 
     111%} 
     112 
     113%typemap(in) const std::string&  
     114%{ if(!$input) { 
     115     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); 
     116     return $null; 
     117    }  
     118    std::string $1_cxxstr; 
     119    make_cxxstr(jenv, $1_cxxstr, $input);  
     120    $1 = &$1_cxxstr; // in const std::string& 
     121%} 
     122 
     123 
     124%typemap(directorout) std::string  
     125%{ if(!$input) { 
     126     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); 
     127     return $null; 
     128   }  
     129   make_cxxstr(jenv, $result, $input); // dirout std::string 
     130%} 
     131 
     132%typemap(directorout) const std::string & 
     133%{ if(!$input) { 
     134     SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); 
     135     return $null; 
     136   } 
     137   std::string $1_cxxstr; 
     138   make_cxxstr(jenv, $1_cxxstr, $input);  
     139   $result = &$1_cxxstr; // dirout const std::string& 
     140%} 
     141 
     142 
     143 
     144%typemap(directorin,descriptor="Ljava/lang/String;") std::string  
     145%{ $input = make_jstr(jenv, &$1); %} 
    95146 
    96147%typemap(out) std::string  
    97148%{ $result = make_jstr(jenv, &$1); // out std::string  %} 
    98149 
    99 %typemap(directorin,descriptor="Ljava/lang/String;", noblock=1) const std::string {  
    100   
    101   $input = make_jstr(jenv, &$1);  
    102   TmpJOBJ $1_tmpobj(jenv, (jobject) $input); 
    103  } 
     150%typemap(directorin,descriptor="Ljava/lang/String;") const std::string & 
     151%{ $input = make_jstr(jenv, &$1); %} 
    104152 
    105153%typemap(out) const std::string &  
     
    107155 
    108156 
    109 %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * { 
    110  $input = 0; 
    111   if ($1) { 
    112     $input = JCALL1(NewStringUTF, jenv, (const char *)::as_cstr($1)); 
    113     if (!$input) return $null; 
    114   } 
    115  
    116   TmpJOBJ $1_tmpobj(jenv, (jobject) $input); 
    117  
    118  
    119 %typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) std::string&, std::string { 
    120  $input = 0; 
    121   if ($1) { 
    122     JavaStr js($1.begin(), $1.end()); 
    123     $input = JCALL2(NewString, jenv, js.data(), js.size()); 
    124     if (!$input) return $null; 
    125   } 
    126  
    127   TmpJOBJ $1_tmpobj(jenv, (jobject) $input); 
    128 } 
    129    
    130  
     157%typemap(newfree) std::string * "delete $1;"; 
    131158 
    132159#endif 
Note: See TracChangeset for help on using the changeset viewer.