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

icoudot.java4cpp.java4cpp-templates.1.0.2.source-code.header-template.ftl Maven / Gradle / Ivy

The newest version!
<#include "common.ftl"/>
<@cppFormatter>
<#if class.parameters??>
<#assign fileName = ''/>
<#else>
<#-- Sets the name of the generated file -->
<#assign fileNameNoExtension><@fileName class/>
<#assign fileName = fileNameNoExtension+'.h'/>
#ifndef ${fileName?replace('.', '_')?upper_case}
#define ${fileName?replace('.', '_')?upper_case}

<#-- Adds includes from the runtime and Java4Cpp -->
<@initIncludes ['"jni.h"']/>
<#if class.type.isThrowable><@addIncludes ['', '']/>
<@addIncludes class.includes/>
<#-- Enumerations need to include theirs values -->
<#if class.type.isEnum && !class.type.isInnerClass><@addInclude '"'+fileNameNoExtension+'Enum.h"'/>
<#-- Try to use forward declaration as much as possible for the class dependencies -->
<#assign forwards = []/>
<#list class.dependencies as dependency>
<#if dependency.type.owner != class>
<#-- ... we include the owner class of the superclass if any -->
<#if class.content.superclass?? && dependency = class.content.superclass><@addInclude '"'+dependency.type.owner.type.cppFullName?replace('::', '_')+'.h"'/>
<#-- ... we include the owner class of enumerations and interfaces -->
<#else><#if dependency.type.isEnum || class.content.interfaces?seq_contains(dependency)><@addInclude '"'+dependency.type.owner.type.cppFullName?replace('::', '_')+'.h"'/>
<#-- ... we include the owner class for inner class dependency -->
<#else><#if dependency.type.isInnerClass><@addInclude '"'+dependency.type.owner.type.cppFullName?replace('::', '_')+'.h"'/>
<#-- ... other dependencies can be declared as forwards -->
<#else><#assign forwards = forwards + [dependency]/>

<@printInclude/>

<#-- Regroups and print forward declaration by namespace -->
<#assign currentNamespace = []/>
<#list forwards?sort_by(["type", "cppFullName"]) as dependency>
<#list dependency.type.cppFullName?split("::") as namespace>
<#if currentNamespace?size > namespace_index && (currentNamespace[namespace_index] != namespace)>
<#list 1..(currentNamespace?size-namespace_index) as decrement>}
<#if currentNamespace?size = 1><#assign currentNamespace = []/>
<#else><#assign currentNamespace = currentNamespace[0..(currentNamespace?size-2)]/>

 
<#if currentNamespace?size <= namespace_index>
<#if namespace_has_next>namespace ${namespace} {<#assign currentNamespace = currentNamespace + [namespace]/><#else>class ${namespace};



<#list currentNamespace as namespace>
}


<#-- Open namespace -->
<#list class.type.cppFullName?split("::") as namespace>
<#if namespace_has_next>namespace ${namespace} {

<#-- Write class definition -->
<@classDefinition class/>

<#-- Close namespace -->
<#list class.type.cppFullName?split("::") as namespace>
<#if namespace_has_next>}

#endif



<#-- Macro for generating class definition (need recursivity)-->
<#macro classDefinition class>
class ${class.type.cppShortName}<#assign separator=": public"/>
<#if class.content.superclass??>${separator} ${class.content.superclass.type.cppFullName}<#assign separator=", public"/><#t/>
<#else><#if class.type.isThrowable>${separator} std::exception<#assign separator=", public"/><#t/>
<#list class.content.interfaces?sort_by(["type", "cppFullName"]) as interface>${separator} ${interface.type.cppFullName}<#assign separator=", public"/><#t/>
{
public:
	<#-- Inner enumerations are declared inside -->
	<#if class.type.isInnerClass && class.type.isEnum>
	typedef enum {
		NULL_VALUE = -1,
		<#list class.content.enumKeys as key>
		${key}<#if key_has_next>,
		
	} ${class.type.cppShortName}Enum;
   
	
	<#-- Generate nested enumarations -->
	<#list class.content.nestedClass?sort_by(["type", "cppFullName"]) as nestedClass>
	<#if nestedClass.type.isEnum><@classDefinition nestedClass/>
	
	
	
	<#-- Generate nested classes -->
	<#list class.content.nestedClass?sort_by(["type", "cppFullName"]) as nestedClass>
	<#if !nestedClass.type.isEnum><@classDefinition nestedClass/>
	
	
	
	<#-- Generate getters for static fields -->
	<#list class.content.staticFields?sort_by("cppName") as field>
	static ${field.type.type.cppReturnType} get${field.cppName?cap_first}();
	
	jobject getJavaObject() const;
	void setJavaObject(jobject obj);

	<#-- Generate contructors -->
	<@sortConstructors class/>
	<#list constructorList?keys?sort as constructor>
	explicit ${class.type.cppShortName}(${constructor});
	
	explicit ${class.type.cppShortName}(jobject obj);
	<#if class.type.isEnum>explicit ${class.type.cppShortName}(${class.type.cppType} arg1);
	${class.type.cppShortName}(const ${class.type.cppFullName}& other);
	${class.type.cppFullName}& operator=(const ${class.type.cppFullName}& other);
	virtual ~${class.type.cppShortName}()<#if class.type.isThrowable> throw();
	<#if class.type.isThrowable>virtual const char* what() const throw();
	<#if class.type.isCloneable>${class.type.cppReturnType} clone();
public:
	<#-- Generate methods -->
	<@sortMethods class/>
	<#list methodList?keys?sort as method>
	<#if methodList[method].isStatic>static<#else>virtual ${methodList[method].returnType.type.cppReturnType} ${method};
	
	<#-- Generate enumerations helpers -->
	<#if class.type.isEnum>
	static const char* getEnumString(${class.type.cppType} arg1);
	${class.type.cppType} toEnum();
	
private:
	static jclass j4c_getClass();
	
	jobject _obj;
	<#if class.type.isThrowable>mutable std::string _msg;
};






© 2015 - 2024 Weber Informatics LLC | Privacy Policy