director typemaps added

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7109 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2005-03-29 20:51:58 +00:00
commit 070993e828
7 changed files with 238 additions and 2 deletions

View file

@ -15,6 +15,9 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}
%typemap(directorout) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
@ -40,6 +43,7 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"

View file

@ -15,6 +15,9 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}
%typemap(directorout) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(javadirectorin) const enum SWIGTYPE & "$jniinput"
%typemap(javadirectorout) const enum SWIGTYPE & "$javacall"
@ -40,6 +43,7 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$jniinput"
%typemap(javadirectorout) enum SWIGTYPE "$javacall"

View file

@ -14,6 +14,9 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}
%typemap(directorout) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin, descriptor="L$packagepath/$*javaclassname;") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(javadirectorin) const enum SWIGTYPE & "$*javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) const enum SWIGTYPE & "($javacall).swigValue()"
@ -38,6 +41,7 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin, descriptor="L$packagepath/$javaclassname;") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$javaclassname.swigToEnum($jniinput)"
%typemap(javadirectorout) enum SWIGTYPE "($javacall).swigValue()"

View file

@ -15,6 +15,9 @@
$1 = &temp; %}
%typemap(out) const enum SWIGTYPE & %{ $result = (jint)*$1; %}
%typemap(directorout) const enum SWIGTYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin, descriptor="I") const enum SWIGTYPE & "$input = (jint)$1_name;"
%typemap(javadirectorin) const enum SWIGTYPE & "$jniinput"
%typemap(javadirectorout) const enum SWIGTYPE & "$javacall"
@ -40,6 +43,7 @@
%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(out) enum SWIGTYPE %{ $result = (jint)$1; %}
%typemap(directorout) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
%typemap(directorin, descriptor="I") enum SWIGTYPE "$input = (jint) $1;"
%typemap(javadirectorin) enum SWIGTYPE "$jniinput"
%typemap(javadirectorout) enum SWIGTYPE "$javacall"

View file

@ -154,6 +154,9 @@
%typemap(in) bool
%{ $1 = $input ? true : false; %}
%typemap(directorout) bool
%{ $1 = $input ? true : false; %}
%typemap(javadirectorin) bool "$jniinput"
%typemap(javadirectorout) bool "$javacall"
@ -171,6 +174,20 @@
double
%{ $1 = ($1_ltype)$input; %}
%typemap(directorout) char,
signed char,
unsigned char,
short,
unsigned short,
int,
unsigned int,
long,
unsigned long,
long long,
float,
double
%{ $1 = ($1_ltype)$input; %}
%typemap(directorin, descriptor="Z") bool "$input = (jboolean) $1;"
%typemap(directorin, descriptor="C") char "$input = (jint) $1;"
%typemap(directorin, descriptor="B") signed char "$input = (jbyte) $1;"
@ -260,6 +277,38 @@
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
}
%typemap(directorout) unsigned long long {
jclass clazz;
jmethodID mid;
jbyteArray ba;
jbyte* bae;
jsize sz;
int i;
if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
return $null;
}
clazz = JCALL1(GetObjectClass, jenv, $input);
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
sz = JCALL1(GetArrayLength, jenv, ba);
$1 = 0;
if (bae[0] == 0) {
for(i=sz-1; i>0; i-- ) {
$1 = ($1 << 8) | (unsigned char)bae[sz-i];
}
}
else {
for(i=sz; i>=0; i-- ) {
$1 = ($1 << 8) | (unsigned char)bae[sz-1-i];
}
}
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
}
/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
%typemap(out) unsigned long long {
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
@ -310,6 +359,14 @@
}
}
%typemap(directorout) char * {
$1 = 0;
if ($input) {
$1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
if (!$1) return $null;
}
}
%typemap(directorin, descriptor="Ljava/lang/String;") char * {
$input = 0;
if ($1) {
@ -333,6 +390,10 @@
%{ temp = $input ? true : false;
$1 = &temp; %}
%typemap(directorout) const bool & (bool temp)
%{ temp = $input ? true : false;
$1 = &temp; %}
%typemap(javadirectorin) const bool & "$jniinput"
%typemap(javadirectorout) const bool & "$javacall"
@ -351,6 +412,21 @@
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorout) const char & (char temp),
const signed char & (signed char temp),
const unsigned char & (unsigned char temp),
const short & (short temp),
const unsigned short & (unsigned short temp),
const int & (int temp),
const unsigned int & (unsigned int temp),
const long & (long temp),
const unsigned long & (unsigned long temp),
const long long & ($*1_ltype temp),
const float & (float temp),
const double & (double temp)
%{ temp = ($*1_ltype)$input;
$1 = &temp; %}
%typemap(directorin, descriptor="Z") const bool & "$input = (jboolean)$1_name;"
%typemap(directorin, descriptor="C") const char & "$input = (jchar)$1_name;"
%typemap(directorin, descriptor="B") const signed char & "$input = (jbyte)$1_name;"
@ -442,6 +518,38 @@
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
}
%typemap(directorout) const unsigned long long & ($*1_ltype temp) {
jclass clazz;
jmethodID mid;
jbyteArray ba;
jbyte* bae;
jsize sz;
int i;
if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
return $null;
}
clazz = JCALL1(GetObjectClass, jenv, $input);
mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
sz = JCALL1(GetArrayLength, jenv, ba);
$1 = &temp;
temp = 0;
if (bae[0] == 0) {
for(i=sz-1; i>0; i-- ) {
temp = (temp << 8) | (unsigned char)bae[sz-i];
}
}
else {
for(i=sz; i>=0; i-- ) {
temp = (temp << 8) | (unsigned char)bae[sz-1-i];
}
}
JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
}
%typemap(out) const unsigned long long & {
jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
@ -472,6 +580,14 @@
}
$1 = *argp; %}
%typemap(directorout) SWIGTYPE ($&1_type argp)
%{ argp = *($&1_ltype*)&$input;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
$1 = *argp; %}
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{*($&1_ltype*)&$result = new $1_ltype(($1_ltype &)$1); %}
@ -499,6 +615,8 @@
%typemap(out) SWIGTYPE &
%{ *($&1_ltype)&$result = $1; %}
%typemap(directorout) SWIGTYPE *, SWIGTYPE (CLASS::*)
%{ $1 = *($&1_ltype)&$input; %}
%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE *, SWIGTYPE (CLASS::*)
%{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
@ -522,6 +640,14 @@
}
}
%typemap(directorout) char[ANY], char[] {
$1 = 0;
if ($input) {
$1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
if (!$1) return $null;
}
}
%typemap(directorin, descriptor="Ljava/lang/String;") char[ANY], char[] {
$input = 0;
if ($1) {
@ -558,6 +684,27 @@
jobjectArray
%{ $1 = $input; %}
%typemap(directorout) jboolean,
jchar,
jbyte,
jshort,
jint,
jlong,
jfloat,
jdouble,
jstring,
jobject,
jbooleanArray,
jcharArray,
jbyteArray,
jshortArray,
jintArray,
jlongArray,
jfloatArray,
jdoubleArray,
jobjectArray
%{ $1 = $input; %}
%typemap(out) jboolean,
jchar,
jbyte,

View file

@ -41,6 +41,16 @@ class string;
$1 = std::string($1_pstr);
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorout) string
%{if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
if (!$1_pstr) return $null;
$1 = std::string($1_pstr);
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") string
%{ $input = jenv->NewStringUTF($1.c_str()); %}
@ -78,6 +88,18 @@ class string;
$1 = &$1_str;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorout,warning="470:Possible thread/reentrant unsafe wrapping, consider using a plain 'const string' or 'string' return type instead.") const string &
%{if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string");
return $null;
}
const char *$1_pstr = (const char *)jenv->GetStringUTFChars($input, 0);
if (!$1_pstr) return $null;
/* possible thread/reentrant code problem */
static std::string $1_str($1_pstr);
$1 = &$1_str;
jenv->ReleaseStringUTFChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const string &
%{ $input = jenv->NewStringUTF($1.c_str()); %}
@ -144,6 +166,25 @@ class wstring;
jenv->ReleaseStringChars($input, $1_pstr);
%}
%typemap(directorout) wstring
%{if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
return $null;
}
const jchar *$1_pstr = jenv->GetStringChars($input, 0);
if (!$1_pstr) return $null;
jsize $1_len = jenv->GetStringLength($input);
if ($1_len) {
wchar_t *conv_buf = new wchar_t[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = $1_pstr[i];
}
$1 = std::wstring(conv_buf, $1_len);
delete [] conv_buf;
}
jenv->ReleaseStringChars($input, $1_pstr);
%}
%typemap(directorin,descriptor="Ljava/lang/String;") wstring
%{jsize $1_len = $1.length();
jchar *conv_buf = new jchar[$1_len];
@ -175,7 +216,27 @@ class wstring;
%typemap(javadirectorin) const wstring & "$jniinput"
%typemap(javadirectorout) const wstring & "$javacall"
%typemap(in) const wstring &
%typemap(directorout,warning="470:Possible thread/reentrant unsafe wrapping, consider using a plain 'const wstring' or 'wstring' return type instead.") const wstring &
%{if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
return $null;
}
const jchar *$1_pstr = jenv->GetStringChars($input, 0);
if (!$1_pstr) return $null;
jsize $1_len = jenv->GetStringLength($input);
static std::wstring $1_str;
if ($1_len) {
wchar_t *conv_buf = new wchar_t[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = $1_pstr[i];
}
$1_str = std::wstring(conv_buf, $1_len);
delete [] conv_buf;
}
$1 = &$1_str;
jenv->ReleaseStringChars($input, $1_pstr); %}
%typemap(directorout) const wstring &
%{if(!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::wstring");
return $null;

View file

@ -73,7 +73,10 @@ There are no char *INPUT typemaps, however you can apply the signed char * typem
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(directorin,descriptor=JNIDESC) CYTPE &INPUT
%typemap(directorout) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
%typemap(directorin,descriptor=JNIDESC) TYPE &INPUT
%{ *(($&1_ltype) $input) = (JNITYPE *) &$1; %}
%typemap(directorin,descriptor=JNIDESC) TYPE *INPUT
@ -216,6 +219,11 @@ There are no char *OUTPUT typemaps, however you can apply the signed char * type
$1 = &temp;
}
%typemap(directorout) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp)
{
#error "Need to provide OUTPUT directorout typemap
}
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT
%{ *(($&1_ltype) $input = &$1; %}
@ -352,6 +360,10 @@ There are no char *INOUT typemaps, however you can apply the signed char * typem
$1 = ($1_ltype) JCALL2(Get##JAVATYPE##ArrayElements, jenv, $input, 0);
}
%typemap(directorout) TYPE *INOUT, TYPE &INOUT {
#error "Need to provide INOUT directorout typemap
}
%typemap(directorin,descriptor=JNIDESC) TYPE &INOUT
%{ *(($&1_ltype)&$input) = &$1; %}