| 1 |
#if defined(SWIGJAVA) && defined(__ANDROID__) |
| 2 |
%typemap(out) std::string |
| 3 |
%{ |
| 4 |
jsize $1_len = (jsize)$1.length(); |
| 5 |
jbyteArray $1_bytes = jenv->NewByteArray($1_len); |
| 6 |
jenv->SetByteArrayRegion($1_bytes, 0, $1_len, (jbyte *) $1.c_str()); |
| 7 |
jclass $1_strClass = jenv->FindClass("java/lang/String"); |
| 8 |
jmethodID $1_ctorID = jenv->GetMethodID($1_strClass, "<init>", "([BLjava/lang/String;)V"); |
| 9 |
jstring $1_encoding = jenv->NewStringUTF("UTF-8"); |
| 10 |
jstring $1_jstr = (jstring) jenv->NewObject($1_strClass, $1_ctorID, $1_bytes, $1_encoding); |
| 11 |
jenv->DeleteLocalRef($1_encoding); |
| 12 |
jenv->DeleteLocalRef($1_bytes); |
| 13 |
$result = $1_jstr; |
| 14 |
%} |
| 15 |
|
| 16 |
%typemap(directorin,descriptor="Ljava/lang/String;") std::string |
| 17 |
%{ |
| 18 |
jsize $1_len = (jsize)$1.length(); |
| 19 |
jbyteArray $1_bytes = jenv->NewByteArray($1_len); |
| 20 |
jenv->SetByteArrayRegion($1_bytes, 0, $1_len, (jbyte *) $1.c_str()); |
| 21 |
jclass $1_strClass = jenv->FindClass("java/lang/String"); |
| 22 |
jmethodID $1_ctorID = jenv->GetMethodID($1_strClass, "<init>", "([BLjava/lang/String;)V"); |
| 23 |
jstring $1_encoding = jenv->NewStringUTF("UTF-8"); |
| 24 |
jstring $1_jstr = (jstring) jenv->NewObject($1_strClass, $1_ctorID, $1_bytes, $1_encoding); |
| 25 |
jenv->DeleteLocalRef($1_encoding); |
| 26 |
jenv->DeleteLocalRef($1_bytes); |
| 27 |
$input = $1_jstr; |
| 28 |
%} |
| 29 |
|
| 30 |
%typemap(directorin,descriptor="Ljava/lang/String;") const std::string & |
| 31 |
%{ |
| 32 |
jsize $1_len = (jsize)$1.length(); |
| 33 |
jbyteArray $1_bytes = jenv->NewByteArray($1_len); |
| 34 |
jenv->SetByteArrayRegion($1_bytes, 0, $1_len, (jbyte *) $1.c_str()); |
| 35 |
jclass $1_strClass = jenv->FindClass("java/lang/String"); |
| 36 |
jmethodID $1_ctorID = jenv->GetMethodID($1_strClass, "<init>", "([BLjava/lang/String;)V"); |
| 37 |
jstring $1_encoding = jenv->NewStringUTF("UTF-8"); |
| 38 |
jstring $1_jstr = (jstring) jenv->NewObject($1_strClass, $1_ctorID, $1_bytes, $1_encoding); |
| 39 |
jenv->DeleteLocalRef($1_encoding); |
| 40 |
jenv->DeleteLocalRef($1_bytes); |
| 41 |
$input = $1_jstr; |
| 42 |
%} |
| 43 |
|
| 44 |
%typemap(out) const std::string & |
| 45 |
%{ |
| 46 |
jsize $1_len = (jsize)$1->length(); |
| 47 |
jbyteArray $1_bytes = jenv->NewByteArray($1_len); |
| 48 |
jenv->SetByteArrayRegion($1_bytes, 0, $1_len, (jbyte *) $1->c_str()); |
| 49 |
jclass $1_strClass = jenv->FindClass("java/lang/String"); |
| 50 |
jmethodID $1_ctorID = jenv->GetMethodID($1_strClass, "<init>", "([BLjava/lang/String;)V"); |
| 51 |
jstring $1_encoding = jenv->NewStringUTF("UTF-8"); |
| 52 |
jstring $1_jstr = (jstring) jenv->NewObject($1_strClass, $1_ctorID, $1_bytes, $1_encoding); |
| 53 |
jenv->DeleteLocalRef($1_encoding); |
| 54 |
jenv->DeleteLocalRef($1_bytes); |
| 55 |
$result = $1_jstr; |
| 56 |
%} |
| 57 |
|
| 58 |
%typemap(in) std::string |
| 59 |
%{ if(!$input) { |
| 60 |
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); |
| 61 |
return $null; |
| 62 |
} |
| 63 |
const jclass $1_strClass = jenv->GetObjectClass($input); |
| 64 |
const jmethodID $1_getBytes = jenv->GetMethodID($1_strClass, "getBytes", "(Ljava/lang/String;)[B"); |
| 65 |
const jbyteArray $1_strJbytes = (jbyteArray) jenv->CallObjectMethod($input, $1_getBytes, jenv->NewStringUTF("UTF-8")); |
| 66 |
|
| 67 |
size_t $1_length = (size_t) jenv->GetArrayLength($1_strJbytes); |
| 68 |
jbyte* $1_pBytes = jenv->GetByteArrayElements($1_strJbytes, NULL); |
| 69 |
|
| 70 |
if (!$1_pBytes) return $null; |
| 71 |
$1.assign((char *)$1_pBytes, $1_length); |
| 72 |
jenv->ReleaseByteArrayElements($1_strJbytes, $1_pBytes, JNI_ABORT); |
| 73 |
jenv->DeleteLocalRef($1_strJbytes); |
| 74 |
jenv->DeleteLocalRef($1_strClass); |
| 75 |
%} |
| 76 |
|
| 77 |
%typemap(directorout) std::string |
| 78 |
%{ if(!$input) { |
| 79 |
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); |
| 80 |
return $null; |
| 81 |
} |
| 82 |
const jclass $1_strClass = jenv->GetObjectClass($input); |
| 83 |
const jmethodID $1_getBytes = jenv->GetMethodID($1_strClass, "getBytes", "(Ljava/lang/String;)[B"); |
| 84 |
const jbyteArray $1_strJbytes = (jbyteArray) jenv->CallObjectMethod($input, $1_getBytes, jenv->NewStringUTF("UTF-8")); |
| 85 |
|
| 86 |
size_t $1_length = (size_t) jenv->GetArrayLength($1_strJbytes); |
| 87 |
jbyte* $1_pBytes = jenv->GetByteArrayElements($1_strJbytes, NULL); |
| 88 |
|
| 89 |
if (!$1_pBytes) return $null; |
| 90 |
$result.assign((char *)$1_pBytes, $1_length); |
| 91 |
jenv->ReleaseByteArrayElements($1_strJbytes, $1_pBytes, JNI_ABORT); |
| 92 |
jenv->DeleteLocalRef($1_strJbytes); |
| 93 |
jenv->DeleteLocalRef($1_strClass); |
| 94 |
%} |
| 95 |
|
| 96 |
%typemap(in) const std::string & |
| 97 |
%{ if(!$input) { |
| 98 |
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); |
| 99 |
return $null; |
| 100 |
} |
| 101 |
const jclass $1_strClass = jenv->GetObjectClass($input); |
| 102 |
const jmethodID $1_getBytes = jenv->GetMethodID($1_strClass, "getBytes", "(Ljava/lang/String;)[B"); |
| 103 |
const jbyteArray $1_strJbytes = (jbyteArray) jenv->CallObjectMethod($input, $1_getBytes, jenv->NewStringUTF("UTF-8")); |
| 104 |
|
| 105 |
size_t $1_length = (size_t) jenv->GetArrayLength($1_strJbytes); |
| 106 |
jbyte* $1_pBytes = jenv->GetByteArrayElements($1_strJbytes, NULL); |
| 107 |
|
| 108 |
if (!$1_pBytes) return $null; |
| 109 |
$*1_ltype $1_str((char *)$1_pBytes, $1_length); |
| 110 |
$1 = &$1_str; |
| 111 |
jenv->ReleaseByteArrayElements($1_strJbytes, $1_pBytes, JNI_ABORT); |
| 112 |
jenv->DeleteLocalRef($1_strJbytes); |
| 113 |
jenv->DeleteLocalRef($1_strClass); |
| 114 |
%} |
| 115 |
|
| 116 |
%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const std::string & |
| 117 |
%{ if(!$input) { |
| 118 |
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string"); |
| 119 |
return $null; |
| 120 |
} |
| 121 |
const jclass $1_strClass = jenv->GetObjectClass($input); |
| 122 |
const jmethodID $1_getBytes = jenv->GetMethodID($1_strClass, "getBytes", "(Ljava/lang/String;)[B"); |
| 123 |
const jbyteArray $1_strJbytes = (jbyteArray) jenv->CallObjectMethod($input, $1_getBytes, jenv->NewStringUTF("UTF-8")); |
| 124 |
|
| 125 |
size_t $1_length = (size_t) jenv->GetArrayLength($1_strJbytes); |
| 126 |
jbyte* $1_pBytes = jenv->GetByteArrayElements($1_strJbytes, NULL); |
| 127 |
|
| 128 |
if (!$1_pBytes) return $null; |
| 129 |
/* possible thread/reentrant code problem */ |
| 130 |
static $*1_ltype $1_str; |
| 131 |
$1_str = (char *)$1_pBytes; |
| 132 |
$result = &$1_str; |
| 133 |
jenv->ReleaseByteArrayElements($1_strJbytes, $1_pBytes, JNI_ABORT); |
| 134 |
jenv->DeleteLocalRef($1_strJbytes); |
| 135 |
jenv->DeleteLocalRef($1_strClass); |
| 136 |
%} |
| 137 |
|
| 138 |
#endif |