All Downloads are FREE. Search and download functionalities are using the official Maven repository.

icoudot.java4cpp.java4cpp-templates.1.0.2.source-code.base-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">
	<globalTemplates>
		<globalTemplate>include-template.ftl</globalTemplate>
		<globalTemplate>exception-template.ftl</globalTemplate>
	</globalTemplates>
	<datatypes>
		<fallback>
			<sourceTemplates>
				<sourceTemplate>header-template.ftl</sourceTemplate>
				<sourceTemplate>source-template.ftl</sourceTemplate>
			</sourceTemplates>
			<cppType>const ${class.type.cppFullName}&amp;</cppType>
			<cppReturnType>${class.type.cppFullName}</cppReturnType>
			<dependencies>${class.type.addDependencies(class.type.javaName)}</dependencies>
			<functions>
				<function name="java2cpp">${class.type.cppFullName} ${arg2} = ${class.type.cppFullName}(${arg1});
				javaEnv->DeleteLocalRef(${arg1});
				</function>
				<function name="cpp2java">${class.type.jniSignature} ${arg2} = ${arg1}.getJavaObject();
				</function>
			</functions>
		</fallback>
		<array>
			<cppType>const std::vector&lt;${class.type.innerType.type.cppReturnType} &gt;&amp;</cppType>
			<cppReturnType>std::vector&lt;${class.type.innerType.type.cppReturnType} &gt;</cppReturnType>
			<dependencies>${class.type.addIncludes("&lt;vector&gt;")}${class.type.addDependencies(class.type.finalInnerType.type.dependencies)}${class.type.addIncludes(class.type.finalInnerType.type.includes)}</dependencies>
			<functions>
				<function name="java2cpp">&lt;#if class.type.innerType.type.jniMethodName == "Object"&gt;
				std::vector&lt;${class.type.innerType.type.cppReturnType} &gt; ${arg2};
				jsize ${arg1}size = javaEnv->GetArrayLength((jobjectArray)${arg1});
				for(int i = 0; i &lt; ${arg1}size; ++i) {
				jobject ${arg1}elem = javaEnv->GetObjectArrayElement((jobjectArray)${arg1}, i);
				${class.type.innerType.type.functions.java2cpp("${arg1}elem", "${arg2}tmp")}
				${arg2}.push_back(${arg2}tmp);
				javaEnv->DeleteLocalRef(${arg1}elem);
				}
				javaEnv->DeleteLocalRef(${arg1});
				&lt;#else&gt;
				${class.type.innerType.type.cppReturnType}* ${arg2}values = (${class.type.innerType.type.cppReturnType}*)javaEnv->Get${class.type.innerType.type.jniMethodName}ArrayElements((${class.type.jniSignature})${arg1}, NULL);
				std::vector&lt;${class.type.innerType.type.cppReturnType} &gt; ${arg2}(${arg2}values, ${arg2}values+javaEnv->GetArrayLength((${class.type.jniSignature})${arg1}));
				javaEnv->Release${class.type.innerType.type.jniMethodName}ArrayElements((${class.type.jniSignature})${arg1}, (${class.type.innerType.type.jniSignature}*)${arg2}values, JNI_ABORT);
				javaEnv->DeleteLocalRef(${arg1});
				&lt;/#if&gt; </function>
				<function name="cpp2java">&lt;#if class.type.innerType.type.jniMethodName == "Object"&gt;
				jclass ${arg2}cls = Java4CppRuntime::getClass(javaEnv, "${class.type.innerType.type.javaName?replace('.', '/')}");
				jobjectArray ${arg2} = javaEnv->NewObjectArray((jsize)${arg1}.size(), ${arg2}cls, NULL);
				for(jsize ${arg2}idx = 0; ${arg2}idx &lt; (jsize)${arg1}.size(); ++${arg2}idx) {
					${class.type.innerType.type.functions.cpp2java("${arg1}[${arg2}idx]", "${arg2}elem")}
					javaEnv->SetObjectArrayElement(${arg2}, ${arg2}idx, ${arg2}elem);
					&lt;#if class.type.innerType.type.functions.cpp2javaClean??&gt;${class.type.innerType.type.functions.cpp2javaClean("${arg2}elem")}&lt;/#if&gt;
				}
				&lt;#elseif class.type.innerType.type.jniMethodName == "Boolean"&gt;
				${class.type.jniSignature} ${arg2} = javaEnv->New${class.type.innerType.type.jniMethodName}Array((jsize)${arg1}.size());
				for(jsize ${arg2}idx = 0; ${arg2}idx &lt; (jsize)${arg1}.size(); ++${arg2}idx) {
					${class.type.innerType.type.functions.cpp2java("${arg1}[${arg2}idx]", "${arg2}elem")}
					javaEnv->Set${class.type.innerType.type.jniMethodName}ArrayRegion(${arg2}, ${arg2}idx, 1, (${class.type.innerType.type.jniSignature}*)&amp;${arg2}elem);
					&lt;#if class.type.innerType.type.functions.cpp2javaClean??&gt;${class.type.innerType.type.functions.cpp2javaClean("${arg2}elem")};&lt;/#if&gt;
				}
				&lt;#else&gt;
				${class.type.jniSignature} ${arg2} = javaEnv->New${class.type.innerType.type.jniMethodName}Array((jsize)${arg1}.size());
				javaEnv->Set${class.type.innerType.type.jniMethodName}ArrayRegion(${arg2}, 0, (jsize)${arg1}.size(), (${class.type.innerType.type.jniSignature}*)&amp;${arg1}[0]);
				&lt;/#if&gt; </function>
				<function name="cpp2javaClean">javaEnv->DeleteLocalRef(${arg1});
				</function>
			</functions>
		</array>
		<enum>
			<sourceTemplates>
				<sourceTemplate>enum-template.ftl</sourceTemplate>
				<sourceTemplate>header-template.ftl</sourceTemplate>
				<sourceTemplate>source-template.ftl</sourceTemplate>
			</sourceTemplates>
			<cppType>${class.type.cppFullName}&lt;#if !class.type.isInnerClass&gt;Enum&lt;/#if&gt;::${class.type.cppShortName}Enum</cppType>
			<dependencies>${class.type.addDependencies(class.type.javaName)}</dependencies>
			<functions>
				<function name="java2cpp">${class.type.cppFullName}&lt;#if !class.type.isInnerClass&gt;Enum&lt;/#if&gt;::${class.type.cppShortName}Enum ${arg2} = ${class.type.cppFullName}&lt;#if !class.type.isInnerClass&gt;Enum&lt;/#if&gt;::${class.type.cppShortName}Enum::NULL_VALUE;
				if( ${arg1} ) {
					jclass enumcls = Java4CppRuntime::getClass(javaEnv, "${class.type.javaName?replace('.', '/')}");
					jmethodID ordinal = Java4CppRuntime::getMethodID(javaEnv, enumcls, "ordinal", "()I");
					${arg2} = (${class.type.cppFullName}&lt;#if !class.type.isInnerClass&gt;Enum&lt;/#if&gt;::${class.type.cppShortName}Enum)javaEnv->CallIntMethod(${arg1}, ordinal);
					javaEnv->DeleteLocalRef(${arg1});
				}</function>
				<function name="cpp2java">jobject ${arg2} = NULL;
				if( ${arg1} != ${class.type.cppFullName}&lt;#if !class.type.isInnerClass&gt;Enum&lt;/#if&gt;::${class.type.cppShortName}Enum::NULL_VALUE ) {
					jclass ${arg2}cls = Java4CppRuntime::getClass(javaEnv, "${class.type.javaName?replace('.', '/')}");
					jmethodID ${arg2}values = Java4CppRuntime::getStaticMethodID(javaEnv, ${arg2}cls, "values", "()[${class.type.javaSignature}");
      				jobjectArray ${arg2}array = (jobjectArray)javaEnv->CallStaticObjectMethod(${arg2}cls, ${arg2}values);
      				${arg2} = javaEnv->GetObjectArrayElement(${arg2}array, (jsize)${arg1});
      				javaEnv->DeleteLocalRef(${arg2}array);
				}</function>
				<function name="cpp2javaClean">javaEnv->DeleteLocalRef(${arg1});
				</function>
			</functions>
		</enum>
		<templates>
			<template class="void">
				<cppType>void</cppType>
			</template>
			<template class="boolean">
				<cppType>bool</cppType>
				<functions>
					<function name="java2cpp">bool ${arg2} = ${arg1} == JNI_TRUE;</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="byte">
				<cppType>unsigned char</cppType>
				<functions>
					<function name="java2cpp">unsigned char ${arg2} = (unsigned char)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="char">
				<cppType>char</cppType>
				<functions>
					<function name="java2cpp">char ${arg2} = (char)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="double">
				<cppType>double</cppType>
				<functions>
					<function name="java2cpp">double ${arg2} = (double)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="float">
				<cppType>float</cppType>
				<functions>
					<function name="java2cpp">float ${arg2} = (float)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="int">
				<cppType>int</cppType>
				<functions>
					<function name="java2cpp">int ${arg2} = (int)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="long">
				<cppType>long long</cppType>
				<functions>
					<function name="java2cpp">long long ${arg2} = (long long)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
			<template class="short">
				<cppType>short</cppType>
				<functions>
					<function name="java2cpp">short ${arg2} = (short)${arg1};</function>
					<function name="cpp2java">${class.type.jniSignature} ${arg2} = (${class.type.jniSignature})${arg1};</function>
				</functions>
			</template>
		</templates>
	</datatypes>
	<copyFiles>
		<copyFile>java4cpp_runtime.h</copyFile>
		<copyFile>java4cpp_runtime.cpp</copyFile>
		<copyFile>java_exceptions.h</copyFile>
		<copyFile>jvm_launcher.h</copyFile>
		<copyFile>jvm_launcher.cpp</copyFile>
	</copyFiles>
</templates>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy