icoudot.java4cpp.java4cpp-templates.1.0.2.source-code.string-templates.xml Maven / Gradle / Ivy
The newest version!
<?xml version="1.0" encoding="UTF-8"?> <templates xmlns="http://java4cpp.loicoudot.github.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java4cpp.loicoudot.github.com http://raw.github.com/loicoudot/java4cpp-core/master/templates.xsd"> <datatypes> <templates> <template class="java.lang.String"> <needAnalyzing>false</needAnalyzing> <cppType>const std::string&</cppType> <cppReturnType>std::string</cppReturnType> <dependencies>${class.type.addIncludes("<string>")}</dependencies> <functions> <function name="java2cpp">std::string ${arg2}; if( ${arg1} ) { jclass ${arg1}stringCls = Java4CppRuntime::getClass(javaEnv, "java/lang/String"); jmethodID ${arg1}getBytes = Java4CppRuntime::getMethodID(javaEnv, ${arg1}stringCls, "getBytes", "()[B"); jbyteArray ${arg1}bytes = (jbyteArray)javaEnv->CallObjectMethod(${arg1}, ${arg1}getBytes); jsize ${arg1}len = javaEnv->GetArrayLength(${arg1}bytes); ${arg2}.resize(${arg1}len); javaEnv->GetByteArrayRegion(${arg1}bytes, 0, ${arg1}len, (jbyte*)&${arg2}[0]); javaEnv->DeleteLocalRef(${arg1}bytes); javaEnv->DeleteLocalRef(${arg1}); }</function> <function name="cpp2java">jclass ${arg2}stringCls = Java4CppRuntime::getClass(javaEnv, "java/lang/String"); jmethodID ${arg2}ctor = Java4CppRuntime::getMethodID(javaEnv, ${arg2}stringCls, "<init>", "([B)V"); jbyteArray ${arg2}bytes = javaEnv->NewByteArray((jsize)${arg1}.size()); jstring ${arg2} = NULL; if( ${arg2}bytes ) { javaEnv->SetByteArrayRegion(${arg2}bytes, 0, (jsize)${arg1}.size(), (jbyte*)${arg1}.c_str()); ${arg2} = (jstring)javaEnv->NewObject(${arg2}stringCls, ${arg2}ctor, ${arg2}bytes); javaEnv->DeleteLocalRef(${arg2}bytes); }</function> <function name="cpp2javaClean">javaEnv->DeleteLocalRef(${arg1});</function> </functions> </template> </templates> </datatypes> </templates>
© 2015 - 2024 Weber Informatics LLC | Privacy Policy