diff options
Diffstat (limited to 'langs/cpp/tools.tpl')
-rw-r--r-- | langs/cpp/tools.tpl | 223 |
1 files changed, 154 insertions, 69 deletions
diff --git a/langs/cpp/tools.tpl b/langs/cpp/tools.tpl index a0df9f9..0a89664 100644 --- a/langs/cpp/tools.tpl +++ b/langs/cpp/tools.tpl @@ -1,5 +1,9 @@ <#function scopedCppName type shortname=false> - <#local name = "::" + type?replace( ".", "::" )> + <#local name = ""> + <#if !type?starts_with( "::" )> + <#local name = "::"> + </#if> + <#local name = name + type?replace( ".", "::" )> <#if shortname> <#local name = name?replace( "::com::sun::star", "css" )> </#if> @@ -49,57 +53,68 @@ <#return flags> </#function> -<#function cppType unotype> - <#local cpp = unotype> - <#if unotype?is_string > - <#-- Handle UNO simple types --> - <#if unotype == "string"> - <#local cpp = "::rtl::OUString"> - <#elseif unotype == "char"> - <#local cpp = "::sal_Unicode"> - <#elseif unotype == "any"> - <#local cpp = "::com::sun::star::uno::Any"> - <#elseif unotype == "type"> - <#local cpp = "::com::sun::star::uno::Type"> - <#elseif unotype == "boolean"> - <#local cpp = "::sal_Bool"> - <#elseif unotype == "byte"> - <#local cpp = "::sal_Int8"> - <#elseif unotype == "short"> - <#local cpp = "::sal_Int16"> - <#elseif unotype == "unsigned short"> - <#local cpp = "::sal_uInt16"> - <#elseif unotype == "long"> - <#local cpp = "::sal_Int32"> - <#elseif unotype == "unsigned long"> - <#local cpp = "::sal_uInt32"> - <#elseif unotype == "hyper"> - <#local cpp = "::sal_Int64"> - <#elseif unotype == "unsigned hyper"> - <#local cpp = "::sal_uInt64"> - </#if> - <#elseif unotype?is_hash> - <#-- Handle UNO complex types --> - <#local cpp = ""> - <#local levels = (unotype["nested_levels"] - 1)> - <#if (levels > 0)> - <#list 0..levels as i> - <#local cpp = cpp + "::com::sun::star::uno::Sequence< "> - </#list> - </#if> - <#if unotype["type"] == "interface"> - <#local cpp = cpp + "::com::sun::star::uno::Reference< " + scopedCppName( unotype["name"] ) + " >"> - </#if> - <#if (levels > 0)> - <#list 0..levels as i> - <#local cpp = cpp + " >"> - </#list> +<#function cppType unotype shortname=false> + <#local cpp = unotype["name"]> + + <#-- Remove UNO sequence markers as we have the nested levels --> + <#local cpp = cpp?replace( "[]", "" )> + + <#if unotype["type"] == "simple" > + <#if ( cpp != "void" ) && ( cpp != "double" ) && ( cpp != "float" )> + <#local cpp = cpp?replace( "string", "::rtl::OUString" )> + <#local cpp = cpp?replace( "char", "::sal_Unicode" )> + <#local cpp = cpp?replace( "any", "::com::sun::star::uno::Any" )> + <#local cpp = cpp?replace( "type", "::com::sun::star::uno::Type" )> + <#local cpp = cpp?replace( "boolean", "::sal_Bool" )> + <#local cpp = cpp?replace( "byte", "::sal_Int8" )> + <#local cpp = cpp?replace( "unsigned short", "::sal_uInt16" )> + <#local cpp = cpp?replace( "short", "::sal_Int16" )> + <#local cpp = cpp?replace( "unsigned long", "::sal_uInt32" )> + <#local cpp = cpp?replace( "long", "::sal_Int32" )> + <#local cpp = cpp?replace( "unsigned hyper", "::sal_uInt64" )> + <#local cpp = cpp?replace( "hyper", "::sal_Int64" )> + + <#local cpp = scopedCppName( cpp, shortname )> </#if> + <#elseif unotype["type"] == "interface"> + <#local cpp = "::com::sun::star::uno::Reference< " + scopedCppName( cpp ) + " >"> + </#if> + + <#local levels = (unotype["nested_levels"] - 1)> + <#if (levels > 0)> + <#list 0..levels as i> + <#local cpp = "::com::sun::star::uno::Sequence< " + cpp + " >"> + </#list> + </#if> + + <#if shortname> + <#local name = name?replace( "::com::sun::star", "css" )> </#if> <#return cpp> </#function> -<#function printFieldSignature field setter> +<#function defaultValue unotype> + <#local value = ""> + <#if unotype["type"] == "simple"> + <#local value = "0"> + <#if unotype["name"] == "boolean"> + <#local value = "sal_False"> + <#elseif unotype["name"] == "string"> + <#local value = "::rtl::OUString()"> + <#elseif unotype["name"] == "double" || unotype["name"] == "float"> + <#local value = "0.0"> + <#elseif unotype["name"] == "void"> + <#local value = cppType( unotype )> + <#elseif unotype["name"] == "any" || unotype["name"] == "type"> + <#local value = cppType( unotype ) + "()"> + </#if> + <#elseif unotype["type"] == "interface"> + <#local value = cppType( unotype ) + "()"> + </#if> + <#return value> +</#function> + +<#function printFieldSignature field setter classname = ""> <#if setter> <#local return_type = "void"> <#local name_prefix = "set"> @@ -110,41 +125,111 @@ <#local args = "" > </#if> - <#local result = return_type + " SAL_CALL " + name_prefix + field["name"] + "(" + args + ")" > - <#local result = result + " throw (" + printExceptions( field["get_exceptions"] ) +")" > + <#local result = return_type + " SAL_CALL " + classname + name_prefix + field["name"] + "(" + args + ")" > + <#local result = result + " throw ("> + <#if setter> + <#local result = result + printExceptions( field["set_exceptions"] ) +")" > + <#else> + <#local result = result + printExceptions( field["get_exceptions"] ) +")" > + </#if> <#return result> </#function> -<#macro printField field print_body> - <#if !print_body>virtual </#if>${printFieldSignature( field, false )}<#if !print_body>;<#else> +<#macro printSetPropertyMixinBody field> + <#if field["bound"]>BoundListeners l; + </#if><#if field["set_exceptions"]?seq_contains("com.sun.star.beans.PropertyVetoException")>css::Any v; + <#if field["type"]["name"]?contains("com.sun.star.beans.Optional")>if ( the_value.IsPresent ) { - // TODO Implement the body here - } - </#if> - -<#if !field["readonly"]><#if !print_body>virtual </#if>${printFieldSignature( field, true )}<#if !print_body>;<#else> + v <<= the_value.Value; + }<#else>v <<= the_value.Value;</#if> + prepareSet( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("${field["name"]}")), + css::uno::Any(), v, <#if field["bound"]>&l<#else>NULL</#if>); + <#else> + prepareSet( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("${field["name"]}")), + css::uno::Any(), css::uno::Any(), <#if field["bound"]>&l<#else>NULL</#if>); + </#if> { - // TODO Implement the body here - } -</#if></#if> + osl::MutexGuard g(m_aMutex); + m_${field["name"]} = the_value; + }<#if !field["bound"]><#return></#if> + <#if field["bound"]>l.notify();<#return></#if> </#macro> -<#macro printMethods intf> - // TODO -<#assign generated = generated + ":" + intf["name"] + ":"> -// TODO Continue -<#if all_methods > -<#list intf["super_types"] as super> -<@printMethods super/> -</#list> -<#if intf["fields"]?size > 0 || intf["methods"]?size > 0> - // ${intf["name"]?replace( ".", ":" )}: +<#macro printField field print_body><#local scopedname = ""> +<#if !print_body>virtual <#else><#local scopedname = classname() + "::"></#if>${printFieldSignature( field, false, scopedname )}<#if !print_body>;<#else> +{ + <#if (propertyHelper?length > 0)>osl::MutexGuard g(m_aMutex); + </#if>return m_${field["name"]}; +} </#if> + +<#if !field["readonly"]><#if !print_body>virtual </#if>${printFieldSignature( field, true, scopedname )}<#if !print_body>;<#else> +{ +<#if (propertyHelper?length > 0)><@printSetPropertyMixinBody field /><#else> m_${field["name"]} = the_value;</#if> +} +</#if></#if> +</#macro> + +<#function getRef unotype> + <#local ref = ""> + <#if unotype["name"] == "string" || unotype["name"] == "any" || unotype["name"] == "type" + || (unotype["nested_levels"] > 0) || unotype["type"] == "interface"> + <#local ref = "&"> + </#if> + <#return ref> +</#function> + +<#-- + Returns the arguments list for the given method + * args: the list of parameters to print + --> +<#function printMethodParams args> + <#local result = ""> + <#list args as arg> + <#if !arg["flags"]?contains( "out" )> + <#local result = result + "const "> + </#if> + <#local result = result + cppType( arg["type"] ) + getRef( arg["type"]) + " " + arg["name"]> + <#if arg_has_next><#local result = result + ", "></#if> + </#list> + <#return result> +</#function> + +<#-- + Returns the interface method signature. + * method: the method object for which to print the signature + * classname: is used when printing the implementation signature + --> +<#function printMethodSignature method classname = ""> + <#local sig = cppType(method["return_type"]) + " SAL_CALL " + method["name"] + "(" + printMethodParams(method["parameters"]) + ")"> + <#local sig = sig + " throw (" + printExceptions( method["exceptions"] ) + ")"> + <#return sig> +</#function> + +<#macro printMethod method print_body> +<#if !print_body>virtual </#if>${printMethodSignature(method)}<#if !print_body>;<#else> +{ + <#if method["return_type"] != "void">// TODO: Exchange the default return implementation for "${method["name"]}"!!! + // Exchange the default return implementation. + // NOTE: Default initialized polymorphic structs can cause problems because of + // missing default initialization of primitive types of some C++ compilers or + // different Any initialization in Java and C++ polymorphic structs. + return ${defaultValue( method["return_type"] )};<#else>// TODO: Insert your implementation for "${method["name"]}" here.</#if> +} </#if> +</#macro> +<#macro printMethods intf><#assign generated = generated + ":" + intf["name"] + ":"> +<#if all_methods ><#list intf["super_types"] as super><@printMethods super/></#list> +<#if (intf["fields"]?size > 0) || (intf["methods"]?size > 0)> // ${intf["name"]?replace( ".", ":" )}:</#if></#if> <#list intf["fields"] as field> <@printField(field, false)/> </#list> +<#list intf["methods"] as method> +<@printMethod(method, false)/> +</#list> </#macro> <#macro printMethodsBodies intf> |