From: Steve T. <Ste...@us...> - 2010-01-19 19:59:34
|
Hello, I am currently using swig to wrap a C++ library for use in JAVA. We use std::string extensively and swig wraps the function call with jresult = jenv->NewStringUTF(result->c_str()); I now have 4 functions that require an extended character set. Is there some way to have swig return the following code for these 4 functions: jbyteArray bytes = 0; int len = strlen(result->c_str ()); bytes = jenv->NewByteArray(len); if (bytes != NULL) { jenv->SetByteArrayRegion (bytes, 0 , len, (jbyte *)result->c_str()); jclass clazz = jenv->FindClass("java/lang/String"); jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V"); if (mid != 0) { jresult = (jstring) jenv->NewObject(clazz, mid, bytes); jenv->DeleteLocalRef(bytes); } } Thanks, Steve ********************************************************************** This communication and all information (including, but not limited to, market prices/levels and data) contained therein (the "Information") is for informational purposes only, is confidential, may be legally privileged and is the intellectual property of ICAP plc and its affiliates ("ICAP") or third parties. No confidentiality or privilege is waived or lost by any mistransmission. The Information is not, and should not be construed as, an offer, bid or solicitation in relation to any financial instrument or as an official confirmation of any transaction. The Information is not warranted, including, but not limited, as to completeness, timeliness or accuracy and is subject to change without notice. ICAP assumes no liability for use or misuse of the Information. All representations and warranties are expressly disclaimed. The Information does not necessarily reflect the views of ICAP. Access to the Information by anyone else other than the recipient is unauthorized and any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it is prohibited. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. ********************************************************************** |
From: William S F. <ws...@fu...> - 2010-01-28 06:57:44
|
Steve Troiano wrote: > Hello, > > > > I am currently using swig to wrap a C++ library for use in > JAVA. We use std::string extensively and swig wraps the function call > with jresult = jenv->NewStringUTF(result->c_str()); > > > > I now have 4 functions that require an extended character set. Is there > some way to have swig return the following code for these 4 functions: > > > > jbyteArray bytes = 0; > > int len = strlen(result->c_str ()); > > bytes = jenv->NewByteArray(len); > > if (bytes != NULL) > > { > > jenv->SetByteArrayRegion (bytes, 0 , len, (jbyte *)result->c_str()); > > > > jclass clazz = jenv->FindClass("java/lang/String"); > > > > jmethodID mid = jenv->GetMethodID(clazz, "<init>", "([B)V"); > > > > if (mid != 0) > > { > > jresult = (jstring) jenv->NewObject(clazz, mid, bytes); > > jenv->DeleteLocalRef(bytes); > > } > > } > Read up about typemaps. You probably need to override the typemap that comes in std_string.i: namespace std { %typemap(out) string %{ $result = jenv->NewStringUTF($1.c_str()); %} } With your own containing the code you want. There is a typemap example in Examples/java/typemap. William |