diff options
author | Cédric Bosdonnat <cedricbosdo@openoffice.org> | 2011-01-27 15:12:24 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedricbosdo@openoffice.org> | 2011-01-27 15:12:24 +0100 |
commit | 11431cec416a133cdb9dfbbb6d8d69553702d8fd (patch) | |
tree | bdd9856933bece6e08aed9d6ceda84f8a25240ac | |
parent | 8c30dc0e04949ed85887df71c19b0cd2df8edd96 (diff) |
Progresses on cpp templates
-rw-r--r-- | langs/cpp/classDef.tpl | 53 | ||||
-rw-r--r-- | langs/cpp/component.tpl | 31 | ||||
-rw-r--r-- | langs/cpp/includes.tpl | 2 | ||||
-rw-r--r-- | langs/cpp/tools.tpl | 184 |
4 files changed, 251 insertions, 19 deletions
diff --git a/langs/cpp/classDef.tpl b/langs/cpp/classDef.tpl index fbd3d1b..203957d 100644 --- a/langs/cpp/classDef.tpl +++ b/langs/cpp/classDef.tpl @@ -1,14 +1,15 @@ -class ${classname} : +class ${classname()} : <#if interfaces?size > 0> <#if supportsXComponent> private ::cppu::BaseMutex, - public ::cppu::WeakComponentImplHelper${interfaces?size}< +<#assign parentname = "::cppu::WeakComponentImplHelper${interfaces?size}"/> <#else> - public ::cppu::WeakComponentImplHelper${interfaces?size}< +<#assign parentname = "::cppu::WeakImplHelper${interfaces?size}"/> </#if> + public ${parentname}< <#list interfaces as intf> -<assign propHelperNext = !intf_has_next && propertyHelper?length > 0> - ${scopedCppName intf.name true}${intf_has_next?string( ",", ">" )}${propHelperNext?string( ",", "" )} +<#assign propHelperNext = !intf_has_next && propertyHelper?length > 0> + ${scopedCppName intf["name"] true}${intf_has_next?string( ",", ">" )}${propHelperNext?string( ",", "" )} </#list> <#/if> <#if propertyHelper?length > 0> @@ -16,20 +17,34 @@ class ${classname} : </#if> { public: - explicit ${classname} (css::uno::Reference< css::uno::XComponentContext > const & context); + explicit ${classname()} (css::uno::Reference< css::uno::XComponentContext > const & context); +<#if propertyHelper?length > 0> +<#assign parentname>${parentname}<<#list interfaces as intf>${scopedCppName intf["name"] true}${intf_has_next?string( ",", ">" )}</#list>></#assign> + // ::com::sun::star::uno::XInterface + virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const & type) throw (css::uno::RuntimeException); + virtual void SAL_CALL acquire() throw () + { ${parentname}::acquire(); } + virtual void SAL_CALL release() throw () + { ${parentname}::release(); } +</#if> + +<#assign generated = ":com.sun.star.uno.XInterface::com.sun.star.lang.XComponent::com.sun.star.lang.XTypeProvider::com.sun.star.uno.XWeak:"> <#list interfaces as intf> - <@printMethods intf/> +<#if !generated?contains( ":" + intf["name"] + ":" )> +<@printMethods intf> +</#if> +<#assign generated = generated + ":" + intf["name"] + ":"> </#list> private: - ${classname}(const ${classname} &); // not defined - ${classname}& operator=(const ${classname} &); // not defined + ${classname()}(const ${classname()} &); // not defined + ${classname()}& operator=(const ${classname()} &); // not defined // destructor is private and will be called indirectly by the release call - virtual ~${classname}(){} + virtual ~${classname()}(){} -<#if componentType == "calc-addin"> +<#if component_type == "calc-add-in"> // TODO </#if> @@ -39,8 +54,18 @@ private: // if your component needs special work when it becomes // disposed, do it here. virtual void SAL_CALL disposing(); - - </#if> css::uno::Reference< css::uno::XComponentContext > m_xContext; -}
\ No newline at end of file +<#if component_type == "add-on"> + css::uno::Reference< css::frame::XFrame > m_xFrame; +</#if> +<#if component_type == "calc-add-in" && backward_compatible> + css::uno::Reference< css::container::XHierarchicalNameAccess > m_xHAccess; + css::uno::Reference< css::container::XHierarchicalNameAccess > m_xCompAccess; + FunctionMap m_functionMap; + css::lang::Locale m_locale; +</#if> + + // TODO Members declaration goes here: properties + // TODO Members declaration goes here: attributes +};
\ No newline at end of file diff --git a/langs/cpp/component.tpl b/langs/cpp/component.tpl index 3f24a40..149059e 100644 --- a/langs/cpp/component.tpl +++ b/langs/cpp/component.tpl @@ -1,10 +1,35 @@ <#include "tools.tpl"> -<#if hasLicense><#include "license.tpl"/></#if> - <#include "includes.tpl"/> +<#if services?size > 0> +/// anonymous implementation namespace +namespace { + +//Component helper namespace +${generateNamespace( "comp_" )} + +namespace css = ::com::sun::star; + +// component and service helper functions: +::rtl::OUString SAL_CALL _getImplementationName(); +css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames(); +css::uno::Reference< css::uno::XInterface > SAL_CALL _create( css::uno::Reference< css::uno::XComponentContext > const & context ); + +<#list generateNamespace( "comp_" )?split( "::" ) as segment>} <#/list>// closing component helper namespace +<#else> +${generateNamespace( )} + +namespace css = ::com::sun::star; +</#if> + <#include "classDef.tpl"/> <#include "classImpl.tpl"/> -<#include "registrationHelper.tpl"/>
\ No newline at end of file +<#if services?size > 0> +} // closing anonymous implementation namespace + +<#include "registrationHelper.tpl"/> +<#else> +<#list generateNamespace( )?split( "::" ) as segment>} <#/list>// closing namespace +</#if>
\ No newline at end of file diff --git a/langs/cpp/includes.tpl b/langs/cpp/includes.tpl index 33ee1e1..55538e4 100644 --- a/langs/cpp/includes.tpl +++ b/langs/cpp/includes.tpl @@ -1,5 +1,5 @@ #include "sal/config.h" -<#if serviceObject> +<#if services?size > 0> #include "cppuhelper/factory.hxx" #include "cppuhelper/implementationentry.hxx" <#else> diff --git a/langs/cpp/tools.tpl b/langs/cpp/tools.tpl index bb7a0cd..a0df9f9 100644 --- a/langs/cpp/tools.tpl +++ b/langs/cpp/tools.tpl @@ -1,11 +1,193 @@ <#function scopedCppName type shortname=false> <#local name = "::" + type?replace( ".", "::" )> <#if shortname> - <local name = name?replace( "::com::sun::star", "css" ) + <#local name = name?replace( "::com::sun::star", "css" )> </#if> <#return name> </#function> +<#function classname> + <#local pos = implname?last_index_of( "." )> + <#local name = implname> + <#if (pos > -1) > + <#local name = implname?substring( pos + 1 )> + </#if> + <#return name> +</#function> + +<#function generateNamespace prefix="" > + <#local pos = implname?last_index_of( "." ) > + <#local namespace = ""> + <#if (pos > -1 )> + <#local namespace = scopedCppName( implname?substring( 0, pos ) ) > + </#if> + <#local namespace = namespace + "::" + prefix + classname( ) > + <#return namespace> +</#function> + +<#function printExceptions exceptions> + <#local result = scopedCppName( "com.sun.star.uno.RuntimeException" )> + <#list exceptions as except> + <#local result = result + ", " + scopedCppName( except )> + </#list> + <#return result> +</#function> + +<#function propertySetMixinFlags> + <#local flags = ""> + <#if prop_interfaces?seq_contains( "com.sun.star.beans.XPropertySet" )> + <#local flags = flags + "IMPLEMENTS_PROPERTY_SET"> + </#if> + <#if prop_interfaces?seq_contains( "com.sun.star.beans.XFastPropertySet" )> + <#local noflags = (flags?length == 0)> + <#local flags = flags + noflags?string( "", " | " ) + "IMPLEMENTS_FAST_PROPERTY_SET"> + </#if> + <#if prop_interfaces?seq_contains( "com.sun.star.beans.XPropertyAccess" )> + <#local noflags = (flags?length == 0)> + <#local flags = flags + noflags?string( "", " | " ) + "IMPLEMENTS_PROPERTY_ACCESS"> + </#if> + <#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> + </#if> + </#if> + <#return cpp> +</#function> + +<#function printFieldSignature field setter> + <#if setter> + <#local return_type = "void"> + <#local name_prefix = "set"> + <#local args = cppType( field["type"] ) + " the_value"> + <#else> + <#local return_type = cppType( field["type"] )> + <#local name_prefix = "get"> + <#local args = "" > + </#if> + + <#local result = return_type + " SAL_CALL " + name_prefix + field["name"] + "(" + args + ")" > + <#local result = result + " throw (" + printExceptions( field["get_exceptions"] ) +")" > + <#return result> +</#function> + +<#macro printField field print_body> + <#if !print_body>virtual </#if>${printFieldSignature( field, false )}<#if !print_body>;<#else> + { + // TODO Implement the body here + } + </#if> + +<#if !field["readonly"]><#if !print_body>virtual </#if>${printFieldSignature( field, true )}<#if !print_body>;<#else> + { + // TODO Implement the body here + } +</#if></#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( ".", ":" )}: +</#if> +</#if> + +<#list intf["fields"] as field> +<@printField(field, false)/> +</#list> +</#macro> + +<#macro printMethodsBodies intf> +<#if propertyHelper?length > 0> +<#if intf["name"] == "com.sun.star.beans.XPropertySet"> + // TODO generateXPropertySetBodies +<#elseif intf["name"] == "com.sun.star.beans.XFastPropertySet"> + // TODO generateXFastPropertySetBodies +<#elseif intf["name"] == "com.sun.star.beans.XPropertyAccess"> + // TODO generateXPropertyAccessBodies +</#if> +</#if> + +<#if component_type == "calc-add-in"> +<#if intf["name"] == "com.sun.star.lang.XServiceName"> +// ::com::sun::star::lang::XServiceName: +::rtl::OUString SAL_CALL ${classname()} getServiceName() throw (css::uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(sADDIN_SERVICENAME)); +} +<#elseif intf["name"] == "com.sun.star.sheet.XAddIn"> + // TODO generateXAddInBodies +<#if !generated?contains( ":com.sun.star.lang.XLocalizable:" )> + // TODO generateXLocalizable +<#assign generated = generated + ":com.sun.star.lang.XLocalizable:"> +</#if> +<#elseif intf["name"] == "com.sun.star.lang.XLocalizable"> + // TODO generateXLocalizable +<#elseif intf["name"] == "com.sun.star.sheet.XCompatibilityNames"> + // TODO generateXCompatibilityNamesBodies +</#if> +</#if> + +<#if component_type == "add-on"> +<#if intf["name"] == "com.sun.star.lang.XInitialization"> + // TODO generateXInitialization +<#elseif intf["name"] == "com.sun.star.frame.XDispatch"> + // TODO generateXDispatch +<#elseif intf["name"] == "com.sun.star.frame.XDispatchProvider"> + // TODO generateXDispatch +</#if> +</#if> + +<#assign generated = generated + ":" + intf["name"] + ":"> +// TODO Continue </#macro>
\ No newline at end of file |