LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - cppcompskeleton.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 564 0.0 %
Date: 2014-04-11 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include "codemaker/commoncpp.hxx"
      23             : #include "codemaker/global.hxx"
      24             : 
      25             : #include "skeletoncommon.hxx"
      26             : #include "skeletoncpp.hxx"
      27             : 
      28             : #include <iostream>
      29             : 
      30             : using namespace ::rtl;
      31             : using namespace ::codemaker::cpp;
      32             : 
      33             : namespace skeletonmaker { namespace cpp {
      34             : 
      35           0 : void generateIncludes(std::ostream & o,
      36             :          const std::set< OUString >& interfaces,
      37             :          const OUString & propertyhelper, const bool serviceobject,
      38             :          const bool supportxcomponent)
      39             : {
      40           0 :     o << "#include \"sal/config.h\"\n";
      41           0 :     if (serviceobject) {
      42           0 :         o << "#include \"cppuhelper/factory.hxx\"\n"
      43           0 :           << "#include \"cppuhelper/implementationentry.hxx\"\n";
      44             :     } else {
      45           0 :         o << "#include \"com/sun/star/uno/XComponentContext.hpp\"\n";
      46             :     }
      47           0 :     if (supportxcomponent) {
      48           0 :         o << "#include \"cppuhelper/compbase" << interfaces.size() << ".hxx\"\n";
      49           0 :         o << "#include \"cppuhelper/basemutex.hxx\"\n";
      50             :     } else {
      51           0 :         o << "#include \"cppuhelper/implbase" << interfaces.size() << ".hxx\"\n";
      52             :     }
      53             : 
      54           0 :     if (propertyhelper.getLength() > 1) {
      55           0 :         if (propertyhelper.equals("_"))
      56           0 :             o << "#include \"cppuhelper/rpopshlp.hxx\"\n";
      57             :         else
      58           0 :             o << "#include \"cppuhelper/propertysetmixin.hxx\"\n";
      59             :     }
      60             : 
      61           0 :     std::set< OUString >::const_iterator iter = interfaces.begin();
      62           0 :     while (iter != interfaces.end())
      63             :     {
      64           0 :         o << "#include \""
      65           0 :           << ((*iter).replace('.', '/').getStr())
      66           0 :           << ".hpp\"\n";
      67           0 :         ++iter;
      68             :     }
      69           0 : }
      70             : 
      71           0 : short generateNamespace(std::ostream & o,
      72             :                         const OString & implname,
      73             :                         bool serviceobject,
      74             :                         OString & nm)
      75             : {
      76           0 :     short count=0;
      77           0 :     sal_Int32 index = implname.lastIndexOf('.');
      78           0 :     if (serviceobject) {
      79           0 :         o << "\n\n// component helper namespace\n";
      80             :     } else {
      81           0 :         o << "\n";
      82             :     }
      83           0 :     OStringBuffer buf;
      84           0 :     if (index == -1) {
      85           0 :         if (serviceobject) {
      86           0 :             buf.append("comp_");
      87           0 :             buf.append(implname);
      88           0 :             nm = buf.makeStringAndClear();
      89           0 :             o << "namespace comp_" << implname << " {\n\n";
      90           0 :             count=1;
      91             :         } else {
      92           0 :             nm = OString();
      93             :         }
      94             :     } else {
      95           0 :         sal_Int32 nPos=0;
      96           0 :         do {
      97           0 :             OString token(implname.getToken(0, '.', nPos));
      98           0 :             if (nPos < 0 && serviceobject) {
      99           0 :                 buf.append("::comp_");
     100           0 :                 buf.append(token);
     101           0 :                 o << "namespace comp_" << token << " { ";
     102           0 :                 count++;
     103             :             } else {
     104           0 :                 buf.append("::");
     105           0 :                 buf.append(token);
     106           0 :                 o << "namespace " << token << " { ";
     107           0 :                 count++;
     108           0 :             }
     109           0 :         } while( nPos <= index );
     110           0 :         nm = buf.makeStringAndClear();
     111           0 :         o << "\n\n";
     112             :     }
     113           0 :     return count;
     114             : }
     115             : 
     116           0 : OString generateCompHelperDeclaration(std::ostream & o,
     117             :                                       const OString & implname)
     118             : {
     119           0 :     OString nm;
     120           0 :     short nbrackets = generateNamespace(o, implname, true, nm);
     121             : 
     122           0 :     o << "namespace css = ::com::sun::star;\n\n";
     123             : 
     124             :     // generate component/service helper functions
     125             :     o << "// component and service helper functions:\n"
     126             :         "::rtl::OUString SAL_CALL _getImplementationName();\n"
     127             :         "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
     128             :         "_getSupportedServiceNames();\n"
     129             :         "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
     130             :         " css::uno::Reference< css::uno::XComponentContext > const & "
     131           0 :         "context );\n\n";
     132             : 
     133             :     // close namepsace
     134           0 :     for (short i=0; i < nbrackets; i++)
     135           0 :         o << "} ";
     136           0 :     o << "// closing component helper namespace\n\n";
     137             : 
     138           0 :     return nm;
     139             : }
     140             : 
     141           0 : void generateCompHelperDefinition(std::ostream & o,
     142             :          const OString & implname,
     143             :          const OString & classname,
     144             :          const std::set< OUString >& services)
     145             : {
     146           0 :     OString nm;
     147           0 :     short nbrackets = generateNamespace(o, implname, true, nm);
     148             : 
     149           0 :     o << "::rtl::OUString SAL_CALL _getImplementationName() {\n"
     150           0 :       << "    return ::rtl::OUString(\n"
     151           0 :       << "        \"" << implname << "\");\n}\n\n";
     152             : 
     153             :     o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
     154           0 :         "_getSupportedServiceNames()\n{\n    css::uno::Sequence< "
     155           0 :       << "::rtl::OUString >" << " s(" << services.size() << ");\n";
     156             : 
     157           0 :     std::set< OUString >::const_iterator iter = services.begin();
     158           0 :     short i=0;
     159           0 :     while (iter != services.end())
     160             :     {
     161           0 :         o << "    s[" << i++ << "] = ::rtl::OUString(\""
     162           0 :           << *iter << "\");\n";
     163           0 :         ++iter;
     164             :     }
     165           0 :     o << "    return s;\n}\n\n";
     166             : 
     167           0 :     o << "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
     168           0 :       << "\n    const css::uno::Reference< css::uno::XComponentContext > & "
     169           0 :       << "context)\n        SAL_THROW((css::uno::Exception))\n{\n"
     170           0 :       << "    return static_cast< ::cppu::OWeakObject * >(new "
     171           0 :       << classname <<  "(context));\n}\n\n";
     172             : 
     173             :     // close namepsace
     174           0 :     for (short j=0; j < nbrackets; j++)
     175           0 :         o << "} ";
     176           0 :     o << "// closing component helper namespace\n\n";
     177             : 
     178           0 : }
     179             : 
     180           0 : void generateCompFunctions(std::ostream & o, const OString & nmspace)
     181             : {
     182           0 :     o << "static ::cppu::ImplementationEntry const entries[] = {\n"
     183           0 :       << "    { &" << nmspace << "::_create,\n      &"
     184           0 :       << nmspace << "::_getImplementationName,\n      &"
     185           0 :       << nmspace << "::_getSupportedServiceNames,\n"
     186           0 :       << "      &::cppu::createSingleComponentFactory, 0, 0 },\n"
     187           0 :       << "    { 0, 0, 0, 0, 0, 0 }\n};\n\n";
     188             : 
     189           0 :     o << "extern \"C\" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(\n"
     190           0 :       << "    const char * implName, void * serviceManager, void * registryKey)\n{\n"
     191           0 :       << "    return ::cppu::component_getFactoryHelper(\n"
     192           0 :       << "        implName, serviceManager, registryKey, entries);\n}\n\n";
     193             : 
     194           0 :     o << "extern \"C\" sal_Bool SAL_CALL component_writeInfo(\n"
     195           0 :       << "    void * serviceManager, void * registryKey)\n{\n"
     196           0 :       << "    return ::cppu::component_writeInfoHelper("
     197           0 :       << "serviceManager, registryKey, entries);\n}\n";
     198           0 : }
     199             : 
     200           0 : void generateXPropertySetBodies(std::ostream& o,
     201             :                                 const OString & classname,
     202             :                                 const OString & propertyhelper)
     203             : {
     204           0 :     o << "// com.sun.star.beans.XPropertySet:\n";
     205             : 
     206           0 :     o << "css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL "
     207           0 :       << classname << "getPropertySetInfo() throw ("
     208           0 :         "css::uno::RuntimeException)\n{\n    return ::cppu::PropertySetMixin< "
     209           0 :       << propertyhelper
     210           0 :       << " >::getPropertySetInfo();\n}\n\n";
     211             : 
     212           0 :     o << "void SAL_CALL " << classname << "setPropertyValue(const ::rtl::OUString"
     213             :         " & aPropertyName, const css::uno::Any & aValue) throw ("
     214             :         "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
     215             :         "css::beans::PropertyVetoException, css::lang::IllegalArgumentException, "
     216           0 :         "css::lang::WrappedTargetException)\n{\n    ::cppu::PropertySetMixin< "
     217           0 :       << propertyhelper << " >::setPropertyValue(aPropertyName, aValue);\n}\n\n";
     218             : 
     219             : 
     220           0 :     o << "css::uno::Any SAL_CALL " << classname << "getPropertyValue(const "
     221             :         "::rtl::OUString & aPropertyName) throw (css::uno::RuntimeException, "
     222             :         "css::beans::UnknownPropertyException, css::lang::WrappedTargetException)"
     223           0 :         "\n{\n    return ::cppu::PropertySetMixin< "
     224           0 :       << propertyhelper << " >::getPropertyValue(aPropertyName);\n}\n\n";
     225             : 
     226           0 :     o << "void SAL_CALL " << classname << "addPropertyChangeListener(const "
     227             :         "::rtl::OUString & aPropertyName, const css::uno::Reference< "
     228             :         "css::beans::XPropertyChangeListener > & xListener) throw ("
     229             :         "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
     230           0 :         "css::lang::WrappedTargetException)\n{\n    ::cppu::PropertySetMixin< "
     231           0 :       << propertyhelper
     232           0 :       << " >::addPropertyChangeListener(aPropertyName, xListener);\n}\n\n";
     233             : 
     234           0 :     o << "void SAL_CALL " << classname << "removePropertyChangeListener(const "
     235             :         "::rtl::OUString & aPropertyName, const css::uno::Reference< "
     236             :         "css::beans::XPropertyChangeListener > & xListener) throw ("
     237             :         "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
     238           0 :         "css::lang::WrappedTargetException)\n{\n    ::cppu::PropertySetMixin< "
     239           0 :       << propertyhelper
     240           0 :       << " >::removePropertyChangeListener(aPropertyName, xListener);\n}\n\n";
     241             : 
     242           0 :     o << "void SAL_CALL " << classname << "addVetoableChangeListener(const "
     243             :         "::rtl::OUString & aPropertyName, const css::uno::Reference< "
     244             :         "css::beans::XVetoableChangeListener > & xListener) throw ("
     245             :         "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
     246           0 :         "css::lang::WrappedTargetException)\n{\n    ::cppu::PropertySetMixin< "
     247           0 :       << propertyhelper
     248           0 :       << " >::addVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
     249             : 
     250           0 :     o << "void SAL_CALL " << classname << "removeVetoableChangeListener(const "
     251             :         "::rtl::OUString & aPropertyName, const css::uno::Reference< "
     252             :         "css::beans::XVetoableChangeListener > & xListener) throw ("
     253             :         "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
     254           0 :         "css::lang::WrappedTargetException)\n{\n    ::cppu::PropertySetMixin< "
     255           0 :       << propertyhelper
     256           0 :       << " >::removeVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
     257           0 : }
     258             : 
     259           0 : void generateXFastPropertySetBodies(std::ostream& o,
     260             :                                     const OString & classname,
     261             :                                     const OString & propertyhelper)
     262             : {
     263           0 :     o << "// com.sun.star.beans.XFastPropertySet:\n";
     264             : 
     265           0 :     o << "void SAL_CALL " << classname << "setFastPropertyValue( ::sal_Int32 "
     266             :         "nHandle, const css::uno::Any& aValue ) throw ("
     267             :         "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
     268             :         "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
     269           0 :         "css::uno::RuntimeException)\n{\n    ::cppu::PropertySetMixin< "
     270           0 :       << propertyhelper << " >::setFastPropertyValue(nHandle, aValue);\n}\n\n";
     271             : 
     272             : 
     273           0 :     o << "css::uno::Any SAL_CALL " << classname << "getFastPropertyValue( "
     274             :         "::sal_Int32 nHandle ) throw (css::beans::UnknownPropertyException, "
     275             :         "css::lang::WrappedTargetException, css::uno::RuntimeException)\n{\n"
     276           0 :         "    return ::cppu::PropertySetMixin< "
     277           0 :       << propertyhelper << " >::getFastPropertyValue(nHandle);\n}\n\n";
     278           0 : }
     279             : 
     280           0 : void generateXPropertyAccessBodies(std::ostream& o,
     281             :                                    const OString & classname,
     282             :                                    const OString & propertyhelper)
     283             : {
     284           0 :     o << "    // com.sun.star.beans.XPropertyAccess:\n";
     285             : 
     286           0 :     o << "css::uno::Sequence< css::beans::PropertyValue > SAL_CALL "
     287           0 :       << classname << "getPropertyValues(  ) throw ("
     288             :         "css::uno::RuntimeException)\n{\n"
     289           0 :         "    return ::cppu::PropertySetMixin< "
     290           0 :       << propertyhelper << " >::getPropertyValues();\n}\n\n";
     291             : 
     292           0 :     o << "void SAL_CALL " << classname << "setPropertyValues( const "
     293             :         "css::uno::Sequence< css::beans::PropertyValue >& aProps ) throw ("
     294             :         "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
     295             :         "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
     296             :         "css::uno::RuntimeException)\n{\n"
     297           0 :         "    ::cppu::PropertySetMixin< "
     298           0 :       << propertyhelper << " >::setPropertyValues(aProps);\n}\n\n";
     299           0 : }
     300             : 
     301           0 : void generateXLocalizable(std::ostream& o, const OString & classname)
     302             : {
     303             :     o << "// css::lang::XLocalizable:\n"
     304           0 :         "void SAL_CALL " << classname << "setLocale(const css::lang::"
     305             :         "Locale & eLocale) throw (css::uno::RuntimeException)\n{\n"
     306             :         "     m_locale = eLocale;\n}\n\n"
     307           0 :         "css::lang::Locale SAL_CALL " << classname << "getLocale() "
     308           0 :         "throw (css::uno::RuntimeException)\n{\n    return m_locale;\n}\n\n";
     309           0 : }
     310             : 
     311           0 : void generateXAddInBodies(std::ostream& o, const OString & classname)
     312             : {
     313           0 :     o << "// css::sheet::XAddIn:\n";
     314             : 
     315           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticFuntionName("
     316             :         "const ::rtl::OUString & aDisplayName) throw (css::uno::RuntimeException)"
     317             :         "\n{\n    ::rtl::OUString ret;\n    try {\n        css::uno::Reference< "
     318             :         "css::container::XNameAccess > xNAccess(m_xHAccess, css::uno::UNO_QUERY);\n"
     319             :         "        css::uno::Sequence< ::rtl::OUString > functions = "
     320             :         "xNAccess->getElementNames();\n        sal_Int32 len = functions."
     321             :         "getLength();\n        ::rtl::OUString sDisplayName;\n"
     322             :         "        for (sal_Int32 i=0; i < len; ++i) {\n"
     323             :         "            sDisplayName = getAddinProperty(functions[i], "
     324             :         "::rtl::OUString(),\n                                           "
     325             :         "sDISPLAYNAME);\n            if (sDisplayName.equals(aDisplayName))\n"
     326             :         "                return functions[i];\n        }\n    }\n"
     327             :         "     catch ( const css::uno::RuntimeException & e ) {\n        throw e;\n    }\n"
     328           0 :         "     catch ( css::uno::Exception & ) {\n    }\n    return ret;\n}\n\n";
     329             : 
     330           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getDisplayFunctionName(const "
     331             :         "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
     332             :         "{\n    return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
     333           0 :         "sDISPLAYNAME);\n}\n\n";
     334             : 
     335           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getFunctionDescription(const "
     336             :         "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
     337             :         "{\n    return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
     338           0 :         "sDESCRIPTION);\n}\n\n";
     339             : 
     340           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getDisplayArgumentName(const "
     341             :         "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
     342             :         "(css::uno::RuntimeException)\n{\n    return getAddinProperty("
     343             :         "aProgrammaticFunctionName,\n                            m_functionMap["
     344             :         "aProgrammaticFunctionName][nArgument],\n"
     345           0 :         "                            sDISPLAYNAME);\n}\n\n";
     346             : 
     347           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getArgumentDescription(const "
     348             :         "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
     349             :         "(css::uno::RuntimeException)\n{\n    return getAddinProperty("
     350             :         "aProgrammaticFunctionName,\n                            "
     351             :         "m_functionMap[aProgrammaticFunctionName][nArgument],\n"
     352           0 :         "                            sDESCRIPTION);\n}\n\n";
     353             : 
     354           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticCategoryName("
     355             :         "const ::rtl::OUString & aProgrammaticFunctionName) throw ("
     356             :         "css::uno::RuntimeException)\n{\n    return getAddinProperty("
     357           0 :         "aProgrammaticFunctionName, ::rtl::OUString(), sCATEGORY);\n}\n\n";
     358             : 
     359           0 :     o << "::rtl::OUString SAL_CALL " << classname << "getDisplayCategoryName(const "
     360             :         "::rtl::OUString & aProgrammaticFunctionName) throw ("
     361             :         "css::uno::RuntimeException)\n{\n    return getAddinProperty("
     362             :         "aProgrammaticFunctionName, ::rtl::OUString(), "
     363           0 :         "sCATEGORYDISPLAYNAME);\n}\n\n";
     364           0 : }
     365             : 
     366           0 : void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname)
     367             : {
     368             :     o << "// css::sheet::XCompatibilityNames:\n"
     369           0 :         "css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL " << classname
     370             :       << "getCompatibilityNames(const ::rtl::OUString & aProgrammaticName) throw "
     371             :         "(css::uno::RuntimeException)\n{\n    css::uno::Sequence< "
     372             :         "css::sheet::LocalizedName > seqLocalizedNames;\n    try {\n        "
     373             :         "::rtl::OUStringBuffer buf("
     374             :         "aProgrammaticName);\n        buf.appendAscii(\"/CompatibilityName\");\n"
     375             :         "        ::rtl::OUString hname(buf.makeStringAndClear());\n\n        "
     376             :         "if ( m_xCompAccess->hasByHierarchicalName(hname) ) {\n"
     377             :         "            css::uno::Reference< css::container::XNameAccess > "
     378             :         "xNameAccess(\n"
     379             :         "                m_xCompAccess->getByHierarchicalName(hname), "
     380             :         "css::uno::UNO_QUERY);\n\n            css::uno::Sequence< ::rtl::OUString"
     381             :         " > elems = \n            xNameAccess->getElementNames();"
     382             :         "\n            ::sal_Int32 len = elems.getLength();\n\n            "
     383             :         "seqLocalizedNames.realloc(len);\n\n            ::rtl::OUString "
     384             :         "sCompatibilityName;\n            for (::sal_Int32 i=0; i < len; ++i) {\n"
     385             :         "                ::rtl::OUString sLocale(elems[i]);\n                "
     386             :         "xNameAccess->getByName(sLocale) >>= sCompatibilityName;\n\n"
     387             :         "                css::lang::Locale aLocale;\n                "
     388             :         "::sal_Int32 nIndex = 0, nToken = 0;\n                "
     389             :         /* FIXME-BCP47: this will break. */
     390             :         "do {\n                    ::rtl::OUString aToken = sLocale.getToken(0, '-', "
     391             :         "nIndex);\n                    switch (nToken++) {\n                    "
     392             :         "case 0:\n                        aLocale.Language = aToken;\n"
     393             :         "                        break;\n                    case 1:\n"
     394             :         "                        aLocale.Country = aToken;\n                    "
     395             :         "    break;\n                    default:\n                        "
     396             :         "aLocale.Variant = sLocale.copy(nIndex-aToken.getLength()-1);\n"
     397             :         "                        nIndex = -1;\n                    }\n"
     398             :         "                } while ( nIndex >= 0 );\n\n                "
     399             :         "seqLocalizedNames[i].Locale = aLocale;\n                "
     400             :         "seqLocalizedNames[i].Name = sCompatibilityName;\n            }"
     401             :         "\n        }\n    }\n    catch ( const css::uno::RuntimeException & e ) {\n        "
     402             :         "throw e;\n    }\n    catch ( css::uno::Exception & ) {\n    }\n\n"
     403           0 :         "    return seqLocalizedNames;\n}\n\n";
     404           0 : }
     405             : 
     406           0 : void generateXInitialization(std::ostream& o, const OString & classname)
     407             : {
     408             :     o << "// css::lang::XInitialization:\n"
     409           0 :         "void SAL_CALL " << classname << "initialize( const css::uno::Sequence< "
     410             :         "css::uno::Any >& aArguments ) "
     411             :         "throw (css::uno::Exception, css::uno::RuntimeException)\n{\n"
     412             :         "    css::uno::Reference < css::frame::XFrame > xFrame;\n"
     413             :         "    if ( aArguments.getLength() ) {\n        aArguments[0] >>= xFrame;\n"
     414           0 :         "        m_xFrame = xFrame;\n    }\n}\n\n";
     415           0 : }
     416             : 
     417           0 : void generateXDispatch(std::ostream& o,
     418             :                        const OString & classname,
     419             :                        const ProtocolCmdMap & protocolCmdMap)
     420             : {
     421             :     // com.sun.star.frame.XDispatch
     422             :     // dispatch
     423             :     o << "// css::frame::XDispatch:\n"
     424           0 :         "void SAL_CALL " << classname << "dispatch( const css::util::URL& aURL, const "
     425             :         "css::uno::Sequence< css::beans::PropertyValue >& aArguments ) throw"
     426           0 :         "(css::uno::RuntimeException)\n{\n";
     427             : 
     428           0 :     ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
     429           0 :     while (iter != protocolCmdMap.end()) {
     430           0 :         o << "    if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
     431           0 :           << "\") == 0 )\n    {\n";
     432             : 
     433           0 :         for (std::vector< OString >::const_iterator i = (*iter).second.begin();
     434           0 :              i != (*iter).second.end(); ++i) {
     435           0 :             o << "        if ( aURL.Path.equalsAscii(\"" << (*i) << "\") )\n"
     436             :                 "        {\n                // add your own code here\n"
     437           0 :                 "                return;\n        }\n";
     438             :         }
     439             : 
     440           0 :         o << "    }\n";
     441           0 :         ++iter;
     442             :     }
     443           0 :     o << "}\n\n";
     444             : 
     445             :     // addStatusListener
     446           0 :     o << "void SAL_CALL " << classname << "addStatusListener( const css::uno::Reference< "
     447             :         "css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
     448             :         "throw (css::uno::RuntimeException)\n{\n"
     449           0 :         "    // add your own code here\n}\n\n";
     450             : 
     451             :     // removeStatusListener
     452           0 :     o << "void SAL_CALL " << classname << "removeStatusListener( const css::uno::Reference"
     453             :         "< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
     454             :         "throw (css::uno::RuntimeException)\n{\n"
     455           0 :         "    // add your own code here\n}\n\n";
     456           0 : }
     457             : 
     458           0 : void generateXDispatchProvider(std::ostream& o,
     459             :                                const OString & classname,
     460             :                                const ProtocolCmdMap & protocolCmdMap)
     461             : {
     462             : 
     463             :     // com.sun.star.frame.XDispatchProvider
     464             :     // queryDispatch
     465             :     o << "// css::frame::XDispatchProvider:\n"
     466           0 :         "css::uno::Reference< css::frame::XDispatch > SAL_CALL " << classname
     467             :       << "queryDispatch( const css::util::URL& aURL,"
     468             :         " const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) "
     469             :         "throw(css::uno::RuntimeException)\n{\n    css::uno::Reference< "
     470             :         "css::frame::XDispatch > xRet;\n"
     471           0 :         "    if ( !m_xFrame.is() )\n        return 0;\n\n";
     472             : 
     473           0 :     ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
     474           0 :     while (iter != protocolCmdMap.end()) {
     475           0 :         o << "    if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
     476           0 :           << "\") == 0 )\n    {\n";
     477             : 
     478           0 :         for (std::vector< OString >::const_iterator i = (*iter).second.begin();
     479           0 :              i != (*iter).second.end(); ++i) {
     480           0 :             o << "        if ( aURL.Path.equalsAscii(\"" << (*i) << "\") == 0 )\n"
     481           0 :                 "            xRet = this;\n";
     482             :         }
     483             : 
     484           0 :         o << "    }\n";
     485           0 :         ++iter;
     486             :     }
     487           0 :     o << "    return xRet;\n}\n\n";
     488             : 
     489             :     // queryDispatches
     490           0 :     o << "css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL "
     491           0 :       << classname << "queryDispatches( const css::uno::Sequence< "
     492             :         "css::frame::DispatchDescriptor >& seqDescripts ) throw("
     493             :         "css::uno::RuntimeException)\n{\n"
     494             :         "    sal_Int32 nCount = seqDescripts.getLength();\n"
     495             :         "    css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > "
     496             :         "lDispatcher(nCount);\n\n"
     497             :         "    for( sal_Int32 i=0; i<nCount; ++i ) {\n"
     498             :         "        lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL,\n"
     499             :         "                                        seqDescripts[i].FrameName,\n"
     500             :         "                                        seqDescripts[i].SearchFlags );\n"
     501           0 :         "    }\n\n    return lDispatcher;\n}\n\n";
     502           0 : }
     503             : 
     504           0 : void generateAddinConstructorAndHelper(std::ostream& o,
     505             :          ProgramOptions const & options,
     506             :          rtl::Reference< TypeManager > const & manager, const OString & classname,
     507             :          const std::set< OUString >& interfaces)
     508             : {
     509           0 :     o << classname << "::" << classname
     510           0 :       << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n"
     511           0 :       << "    m_xContext(context),    m_locale()\n{\n";
     512             : 
     513           0 :     if (options.backwardcompatible) {
     514           0 :         o << "     try {\n";
     515             : 
     516           0 :         generateFunctionParameterMap(o, options, manager, interfaces);
     517             : 
     518             :         o << "        css::uno::Reference< css::lang::XMultiServiceFactory > xProvider"
     519             :             "(\n             m_xContext->getServiceManager()->createInstanceWithContext"
     520             :             "(\n                 ::rtl::OUString(\n    "
     521             :             "                 \"com.sun.star.configuration.ConfigurationProvider\"),"
     522           0 :             "\n                 m_xContext ), css::uno::UNO_QUERY );\n\n";
     523             : 
     524             :         o << "        ::rtl::OUString sReadOnlyView(\n"
     525           0 :             "                \"com.sun.star.configuration.ConfigurationAccess\");\n\n";
     526             : 
     527             :         o << "        ::rtl::OUStringBuffer sPath(::rtl::OUString(\n"
     528             :             "             \"/org.openoffice.Office.CalcAddIns/AddInInfo/\"));\n"
     529             :             "        sPath.appendAscii(sADDIN_SERVICENAME);\n"
     530             :             "        sPath.appendAscii(\"/AddInFunctions\");\n\n"
     531             :             "        // create arguments: nodepath\n"
     532             :             "        css::beans::PropertyValue aArgument;\n"
     533             :             "        aArgument.Name = ::rtl::OUString(\"nodepath\");\n"
     534             :             "        aArgument.Value <<= sPath.makeStringAndClear();\n\n"
     535             :             "        css::uno::Sequence< css::uno::Any > aArguments(1);\n"
     536           0 :             "        aArguments[0] <<= aArgument;\n\n";
     537             : 
     538             :         o << "        // create the default view using default UI locale\n"
     539             :             "        css::uno::Reference< css::uno::XInterface > xIface =\n"
     540             :             "            xProvider->createInstanceWithArguments(sReadOnlyView, "
     541             :             "aArguments);\n\n"
     542             :             "         m_xHAccess = css::uno::Reference<\n            "
     543             :             "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);"
     544           0 :             "\n\n";
     545             : 
     546             :         o << "        // extend arguments to create a view for all locales to get "
     547             :             "simple\n        // access to the compatibilityname property\n"
     548             :             "        aArgument.Name = ::rtl::OUString(\"locale\");\n"
     549             :             "        aArgument.Value <<= ::rtl::OUString(\"*\");\n"
     550             :             "        aArguments.realloc(2);\n"
     551             :             "        aArguments[1] <<= aArgument;\n\n"
     552             :             "        // create view for all locales\n"
     553             :             "        xIface = xProvider->createInstanceWithArguments(sReadOnlyView, "
     554             :             "aArguments);\n\n"
     555             :             "        m_xCompAccess = css::uno::Reference<\n            "
     556           0 :             "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);\n";
     557             : 
     558           0 :         o << "    }\n    catch ( css::uno::Exception & ) {\n    }\n}\n\n";
     559             : 
     560             :         o << "// addin configuration property helper function:\n::rtl::OUString "
     561           0 :             "SAL_CALL " << classname << "::getAddinProperty(const ::rtl::OUString &"
     562             :             " funcName, const ::rtl::OUString & paramName, const char * propName) "
     563             :             "throw (css::uno::RuntimeException)\n{\n"
     564             :             "    ::rtl::OUString ret;\n    try {\n        "
     565             :             "::rtl::OUStringBuffer buf(funcName);\n"
     566             :             "        if (!paramName.isEmpty()) {\n"
     567             :             "            buf.appendAscii(\"/Parameters/\");\n"
     568             :             "            buf.append(paramName);\n        }\n\n"
     569             :             "        css::uno::Reference< css::beans::XPropertySet > xPropSet(\n"
     570             :             "            m_xHAccess->getByHierarchicalName(\n"
     571             :             "                buf.makeStringAndClear()), css::uno::UNO_QUERY);\n"
     572             :             "        xPropSet->getPropertyValue(\n            "
     573             :             "::rtl::OUString(propName)) >>= ret;\n    }\n"
     574             :             "     catch ( const css::uno::RuntimeException & e ) {\n        throw e;\n    }\n"
     575           0 :             "     catch ( css::uno::Exception & ) {\n    }\n    return ret;\n";
     576             :     }
     577           0 :     o <<"}\n\n";
     578           0 : }
     579             : 
     580           0 : void generateMemberInitialization(std::ostream& o,
     581             :                                   ProgramOptions const & options,
     582             :                                   rtl::Reference< TypeManager > const & manager,
     583             :                                   AttributeInfo const & members)
     584             : {
     585           0 :     if (!members.empty()) {
     586           0 :         for (AttributeInfo::const_iterator i(members.begin());
     587           0 :              i != members.end(); ++i)
     588             :         {
     589             :             sal_Int32 rank;
     590           0 :             if ((manager->decompose(i->type, true, 0, &rank, 0, 0)
     591           0 :                  <= codemaker::UnoType::SORT_CHAR)
     592           0 :                 && rank == 0)
     593             :             {
     594           0 :                 o << ",\n    m_" << i->name << "(";
     595           0 :                 printType(o, options, manager, i->type, 16, true);
     596           0 :                 o << ")";
     597             :             }
     598             :         }
     599             :     }
     600           0 : }
     601             : 
     602           0 : void generateMemberDeclaration(std::ostream& o,
     603             :                                ProgramOptions const & options,
     604             :                                rtl::Reference< TypeManager > const & manager,
     605             :                                AttributeInfo const & members)
     606             : {
     607           0 :     for (AttributeInfo::const_iterator i(members.begin());
     608           0 :          i != members.end(); ++i)
     609             :     {
     610           0 :         o << "    ";
     611           0 :         printType(o, options, manager, i->type, 1, false);
     612           0 :         o << " m_" << i->name << ";\n";
     613             :     }
     614           0 : }
     615             : 
     616           0 : OString generateClassDefinition(std::ostream& o,
     617             :          ProgramOptions const & options,
     618             :          rtl::Reference< TypeManager > const & manager,
     619             :          OString const & classname,
     620             :          std::set< OUString > const & interfaces,
     621             :          AttributeInfo const & properties,
     622             :          AttributeInfo const & attributes,
     623             :          std::set< OUString > const & propinterfaces,
     624             :          OUString const & propertyhelper, bool supportxcomponent)
     625             : {
     626           0 :     OStringBuffer parentname(64);
     627           0 :     o << "class " << classname << ":\n";
     628             : 
     629           0 :     if (!interfaces.empty()) {
     630           0 :         if (supportxcomponent) {
     631           0 :             parentname.append("::cppu::WeakComponentImplHelper");
     632           0 :             parentname.append(static_cast<sal_Int32>(interfaces.size()));
     633           0 :             o << "    private ::cppu::BaseMutex,\n"
     634           0 :               << "    public ::cppu::WeakComponentImplHelper"
     635           0 :               << interfaces.size() << "<";
     636             :         } else {
     637           0 :             parentname.append("::cppu::WeakImplHelper");
     638           0 :             parentname.append(static_cast<sal_Int32>(interfaces.size()));
     639           0 :             o << "    public ::cppu::WeakImplHelper" << interfaces.size() << "<";
     640             :         }
     641             : 
     642           0 :         std::set< OUString >::const_iterator iter = interfaces.begin();
     643           0 :         while (iter != interfaces.end())
     644             :         {
     645           0 :             o << "\n        " << scopedCppName(u2b(*iter));
     646           0 :             ++iter;
     647           0 :             if (iter != interfaces.end())
     648           0 :                 o << ",";
     649             :             else
     650           0 :                 o << ">";
     651             :         }
     652             :     }
     653             : 
     654           0 :     if (propertyhelper.getLength() > 1) {
     655           0 :         o << ",\n    public ::cppu::PropertySetMixin< "
     656           0 :           << scopedCppName(u2b(propertyhelper)) << " >";
     657             :     }
     658             : 
     659           0 :     o << "\n{\npublic:\n"
     660           0 :       << "    explicit " << classname << "("
     661           0 :       << "css::uno::Reference< css::uno::XComponentContext > const & context);\n\n";
     662             : 
     663             :     // generate component/service helper functions
     664             : //     o << "    // component and service helper functions:\n"
     665             : //       << "    static ::rtl::OUString SAL_CALL _getImplementationName();\n"
     666             : //       << "    static css::uno::Sequence< ::rtl::OUString > SAL_CALL "
     667             : //       << "_getSupportedServiceNames();\n"
     668             : //       << "    static css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
     669             : //       << "\n        css::uno::Reference< css::uno::XComponentContext > const & "
     670             : //       << "context);\n\n";
     671             : 
     672             :     // overload queryInterface
     673           0 :     if (propertyhelper.getLength() > 1) {
     674             :         o << "    // css::uno::XInterface:\n"
     675             :             "    virtual css::uno::Any SAL_CALL queryInterface("
     676             :             "css::uno::Type const & type) throw ("
     677           0 :             "css::uno::RuntimeException);\n";
     678             : 
     679           0 :         OStringBuffer buffer(256);
     680           0 :         buffer.append(parentname.toString());
     681           0 :         buffer.append("< ");
     682           0 :         std::set< OUString >::const_iterator iter = interfaces.begin();
     683           0 :         while (iter != interfaces.end())
     684             :         {
     685           0 :             buffer.append(scopedCppName(u2b(*iter)));
     686           0 :             ++iter;
     687           0 :             if (iter != interfaces.end())
     688           0 :                 buffer.append(", ");
     689             :             else
     690           0 :                 buffer.append(" >");
     691             :         }
     692           0 :         OString parent(buffer.makeStringAndClear());
     693           0 :         o << "    virtual void SAL_CALL acquire() throw ()\n        { "
     694           0 :           << parent << "::acquire(); }\n";
     695           0 :         o << "    virtual void SAL_CALL release() throw ()\n        { "
     696           0 :           << parent << "::release(); }\n\n";
     697             :     }
     698             : 
     699           0 :     std::set< OUString >::const_iterator it = interfaces.begin();
     700           0 :     codemaker::GeneratedTypeSet generated;
     701           0 :     while (it != interfaces.end())
     702             :     {
     703           0 :         printMethods(o, options, manager, *it, generated, "", "", "    ",
     704           0 :                      true, propertyhelper);
     705           0 :         ++it;
     706             :     }
     707             : 
     708           0 :     o << "private:\n    " << classname << "(const " << classname << " &); // not defined\n"
     709           0 :       << "    " << classname << "& operator=(const " << classname << " &); // not defined\n\n"
     710           0 :       << "    // destructor is private and will be called indirectly by the release call"
     711           0 :       << "    virtual ~" << classname << "() {}\n\n";
     712             : 
     713           0 :     if (options.componenttype == 2) {
     714             :         o << "    typedef boost::unordered_map< ::sal_Int32, rtl::OUString, "
     715             :             "boost::hash<::sal_Int32> > ParamMap;\n"
     716             :             "    typedef boost::unordered_map< rtl::OUString, ParamMap, "
     717             :             "rtl::OUStringHash > FunctionMap;\n\n"
     718             :             "    ::rtl::OUString SAL_CALL getAddinProperty(const ::rtl::OUString & "
     719             :             "funcName, const ::rtl::OUString & paramName, const char * propName) "
     720           0 :             "throw (css::uno::RuntimeException);\n\n";
     721             :     }
     722             : 
     723           0 :     if (supportxcomponent) {
     724             :         o << "    // overload WeakComponentImplHelperBase::disposing()\n"
     725             :             "    // This function is called upon disposing the component,\n"
     726             :             "    // if your component needs special work when it becomes\n"
     727             :             "    // disposed, do it here.\n"
     728           0 :             "    virtual void SAL_CALL disposing();\n\n";
     729             :     }
     730             : 
     731             :     // members
     732           0 :     o << "    css::uno::Reference< css::uno::XComponentContext > m_xContext;\n";
     733           0 :     if (!supportxcomponent && !attributes.empty())
     734           0 :         o << "   mutable ::osl::Mutex m_aMutex;\n";
     735             : 
     736             :     // additional member for add-ons
     737           0 :     if (options.componenttype == 3) {
     738           0 :         o << "    css::uno::Reference< css::frame::XFrame > m_xFrame;\n";
     739             :     }
     740             : 
     741           0 :     if (options.componenttype == 2) {
     742           0 :         if (options.backwardcompatible) {
     743             :             o <<"    css::uno::Reference< css::container::XHierarchicalNameAccess > "
     744             :                 "m_xHAccess;\n"
     745             :                 "    css::uno::Reference< css::container::XHierarchicalNameAccess > "
     746             :                 "m_xCompAccess;\n"
     747           0 :                 "    FunctionMap m_functionMap;\n";
     748             :         }
     749           0 :         o << "    css::lang::Locale m_locale;\n";
     750             :     }
     751             : 
     752           0 :     generateMemberDeclaration(o, options, manager, properties);
     753           0 :     generateMemberDeclaration(o, options, manager, attributes);
     754             : 
     755             : //     if (!properties.empty())
     756             : //     {
     757             : //         AttributeInfo::const_iterator iter = properties.begin();
     758             : //         while (iter != properties.end())
     759             : //         {
     760             : //             o << "    ";
     761             : //             printType(o, options, manager, iter->second.first.replace('.','/'),
     762             : //                       1, false);
     763             : //             o << " m_" << iter->first << ";\n";
     764             : //             iter++;
     765             : //         }
     766             : //     }
     767             : //     if (!attributes.empty())
     768             : //     {
     769             : //         AttributeInfo::const_iterator iter = attributes.begin();
     770             : //         while (iter != attributes.end())
     771             : //         {
     772             : //             o << "    ";
     773             : //             printType(o, options, manager, iter->second.first.replace('.','/'),
     774             : //                       1, false);
     775             : //             o << " m_" << iter->first << ";\n";
     776             : //             iter++;
     777             : //         }
     778             : //     }
     779             : 
     780           0 :     o << "};\n\n";
     781             : 
     782             :     // generate constructor
     783           0 :     if (options.componenttype == 2) {
     784             :         generateAddinConstructorAndHelper(o, options, manager,
     785           0 :                                           classname, interfaces);
     786             :     } else {
     787           0 :         o << classname << "::" << classname
     788           0 :           << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n";
     789           0 :         if (supportxcomponent) {
     790           0 :             o << "    ::cppu::WeakComponentImplHelper" << interfaces.size() << "<";
     791           0 :             std::set< OUString >::const_iterator iter = interfaces.begin();
     792           0 :             while (iter != interfaces.end()) {
     793           0 :                 o << "\n        " << scopedCppName(u2b(*iter));
     794           0 :                 ++iter;
     795           0 :                 if (iter != interfaces.end())
     796           0 :                     o << ",";
     797             :                 else
     798           0 :                     o << ">(m_aMutex),\n";
     799             :             }
     800             :         }
     801           0 :         if (propertyhelper.getLength() > 1) {
     802           0 :             o << "    ::cppu::PropertySetMixin< "
     803           0 :               << scopedCppName(u2b(propertyhelper)) << " >(\n"
     804           0 :               << "        context, static_cast< Implements >(\n            ";
     805           0 :             OStringBuffer buffer(128);
     806           0 :             if (propinterfaces.find("com/sun/star/beans/XPropertySet")
     807           0 :                 != propinterfaces.end()) {
     808           0 :                 buffer.append("IMPLEMENTS_PROPERTY_SET");
     809             :             }
     810           0 :             if (propinterfaces.find("com/sun/star/beans/XFastPropertySet")
     811           0 :                 != propinterfaces.end()) {
     812           0 :                 if (!buffer.isEmpty())
     813           0 :                     buffer.append(" | IMPLEMENTS_FAST_PROPERTY_SET");
     814             :                 else
     815           0 :                     buffer.append("IMPLEMENTS_FAST_PROPERTY_SET");
     816             :             }
     817           0 :             if (propinterfaces.find("com/sun/star/beans/XPropertyAccess")
     818           0 :                 != propinterfaces.end()) {
     819           0 :                 if (!buffer.isEmpty())
     820           0 :                     buffer.append(" | IMPLEMENTS_PROPERTY_ACCESS");
     821             :                 else
     822           0 :                     buffer.append("IMPLEMENTS_PROPERTY_ACCESS");
     823             :             }
     824           0 :             o << buffer.makeStringAndClear()
     825           0 :               << "), css::uno::Sequence< ::rtl::OUString >()),\n";
     826             :         }
     827           0 :         o << "    m_xContext(context)";
     828             : 
     829           0 :         generateMemberInitialization(o, options, manager, properties);
     830           0 :         generateMemberInitialization(o, options, manager, attributes);
     831             : 
     832           0 :         o << "\n{}\n\n";
     833             :     }
     834             : 
     835             :     // generate service/component helper function implementations
     836             : //     generateServiceHelper(o, options.implname, classname, services);
     837             : 
     838           0 :     if (supportxcomponent) {
     839             :         o << "// overload WeakComponentImplHelperBase::disposing()\n"
     840             :             "// This function is called upon disposing the component,\n"
     841             :             "// if your component needs special work when it becomes\n"
     842             :             "// disposed, do it here.\n"
     843           0 :             "void SAL_CALL " << classname << "::disposing()\n{\n\n}\n\n";
     844             :     }
     845             : 
     846           0 :     return parentname.makeStringAndClear();
     847             : }
     848             : 
     849           0 : void generateXServiceInfoBodies(std::ostream& o,
     850             :                                 OString const & classname,
     851             :                                 OString const & comphelpernamespace)
     852             : {
     853           0 :     o << "// com.sun.star.uno.XServiceInfo:\n"
     854           0 :       << "::rtl::OUString SAL_CALL " << classname << "getImplementationName() "
     855           0 :       << "throw (css::uno::RuntimeException)\n{\n    "
     856           0 :       << "return " << comphelpernamespace << "::_getImplementationName();\n}\n\n";
     857             : 
     858           0 :     o << "sal_Bool SAL_CALL " << classname
     859           0 :       << "supportsService(::rtl::OUString const & "
     860           0 :       << "serviceName) throw (css::uno::RuntimeException)\n{\n    "
     861           0 :       << "css::uno::Sequence< ::rtl::OUString > serviceNames = "
     862           0 :       << comphelpernamespace << "::_getSupportedServiceNames();\n    "
     863           0 :       << "for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {\n    "
     864           0 :       << "    if (serviceNames[i] == serviceName)\n            return sal_True;\n"
     865           0 :       << "    }\n    return sal_False;\n}\n\n";
     866             : 
     867           0 :     o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL " << classname
     868           0 :       << "getSupportedServiceNames() throw (css::uno::RuntimeException)\n{\n    "
     869           0 :       << "return " << comphelpernamespace
     870           0 :       << "::_getSupportedServiceNames();\n}\n\n";
     871           0 : }
     872             : 
     873             : 
     874           0 : void generateMethodBodies(std::ostream& o,
     875             :         ProgramOptions const & options,
     876             :         rtl::Reference< TypeManager > const & manager,
     877             :         std::set< OUString > const & interfaces,
     878             :         OString const & classname,
     879             :         OString const & comphelpernamespace,
     880             :         OUString const & propertyhelper)
     881             : {
     882           0 :     OString name(classname.concat("::"));
     883           0 :     std::set< OUString >::const_iterator iter = interfaces.begin();
     884           0 :     codemaker::GeneratedTypeSet generated;
     885           0 :     while (iter != interfaces.end()) {
     886           0 :         if ( (*iter).equals("com.sun.star.lang.XServiceInfo") ) {
     887           0 :             generateXServiceInfoBodies(o, name, comphelpernamespace);
     888           0 :             generated.add(u2b(*iter));
     889             :         } else {
     890           0 :             printMethods(o, options, manager, *iter, generated, "_",
     891           0 :                          name, "", true, propertyhelper);
     892             :         }
     893           0 :         ++iter;
     894           0 :     }
     895           0 : }
     896             : 
     897           0 : void generateQueryInterface(std::ostream& o,
     898             :                             ProgramOptions const & options,
     899             :                             rtl::Reference< TypeManager > const & manager,
     900             :                             const std::set< OUString >& interfaces,
     901             :                             OString const & parentname,
     902             :                             OString const & classname,
     903             :                             OUString const & propertyhelper)
     904             : {
     905           0 :     if (propertyhelper.isEmpty())
     906           0 :         return;
     907             : 
     908           0 :     o << "css::uno::Any " << classname
     909             :       << "::queryInterface(css::uno::Type const & type) throw ("
     910           0 :         "css::uno::RuntimeException)\n{\n    ";
     911             : 
     912           0 :     if (!propertyhelper.isEmpty())
     913           0 :         o << "return ";
     914             :     else
     915           0 :         o << "css::uno::Any a(";
     916             : 
     917           0 :     o   << parentname << "<";
     918           0 :     std::set< OUString >::const_iterator iter = interfaces.begin();
     919           0 :     while (iter != interfaces.end())
     920             :     {
     921           0 :         o << "\n        " << scopedCppName(u2b(*iter));
     922           0 :         ++iter;
     923           0 :         if (iter != interfaces.end())
     924           0 :             o << ",";
     925             :         else
     926           0 :             o << ">";
     927             :     }
     928             : 
     929           0 :     if (!propertyhelper.isEmpty()) {
     930           0 :         o << "::queryInterface(type);\n";
     931             :     } else {
     932           0 :         o << "::queryInterface(type));\n";
     933           0 :         o << "    return a.hasValue() ? a\n        : (";
     934           0 :         if (propertyhelper.equals("_")) {
     935           0 :             o << "::cppu::OPropertySetHelper::queryInterface(type));\n";
     936             :         } else {
     937           0 :             o << "::cppu::PropertySetMixin<\n            ";
     938           0 :             printType(o, options, manager, propertyhelper, 0, false);
     939           0 :             o << " >::queryInterface(\n               type));\n";
     940             :         }
     941             :     }
     942           0 :     o << "}\n\n";
     943             : }
     944             : 
     945           0 : void generateSkeleton(ProgramOptions const & options,
     946             :                       rtl::Reference< TypeManager > const & manager,
     947             :                       std::vector< OString > const & types)
     948             : {
     949             :     // special handling of calc add-ins
     950           0 :     if (options.componenttype == 2) {
     951           0 :         generateCalcAddin(options, manager, types);
     952           0 :         return;
     953             :     }
     954             : 
     955           0 :     std::set< OUString > interfaces;
     956           0 :     std::set< OUString > services;
     957           0 :     AttributeInfo properties;
     958           0 :     AttributeInfo attributes;
     959           0 :     std::set< OUString > propinterfaces;
     960           0 :     bool serviceobject = false;
     961           0 :     bool supportxcomponent = false;
     962             : 
     963           0 :     std::vector< OString >::const_iterator iter = types.begin();
     964           0 :     while (iter != types.end()) {
     965           0 :         checkType(manager, b2u(*iter), interfaces, services, properties);
     966           0 :         ++iter;
     967             :     }
     968             : 
     969           0 :     if (options.componenttype == 3) {
     970             :         // the Protocolhandler service is mandatory for an protocol handler add-on,
     971             :         // so it is defaulted. The XDispatchProvider provides Dispatch objects for
     972             :         // certain functions and the generated impl object implements XDispatch
     973             :         // directly for simplicity reasons.
     974             :         checkType(manager, "com.sun.star.frame.ProtocolHandler",
     975           0 :                   interfaces, services, properties);
     976             :         checkType(manager, "com.sun.star.frame.XDispatch",
     977           0 :                   interfaces, services, properties);
     978             :     }
     979             : 
     980             :     // check if service object or simple UNO object
     981           0 :     if (!services.empty())
     982           0 :         serviceobject = true;
     983             : 
     984             :     OUString propertyhelper = checkPropertyHelper(
     985           0 :         options, manager, services, interfaces, attributes, propinterfaces);
     986             : 
     987           0 :     checkDefaultInterfaces(interfaces, services, propertyhelper);
     988             : 
     989           0 :     if (interfaces.size() > 12)
     990             :         throw CannotDumpException(
     991             :             "the skeletonmaker supports components with 12 interfaces "
     992           0 :             "only (limitation of the UNO implementation helpers)!");
     993             : 
     994             : 
     995           0 :     supportxcomponent = checkXComponentSupport(manager, interfaces);
     996             : 
     997           0 :     OString compFileName;
     998           0 :     OString tmpFileName;
     999           0 :     std::ostream* pofs = NULL;
    1000             :     bool standardout = getOutputStream(options, ".cxx",
    1001           0 :                                        &pofs, compFileName, tmpFileName);
    1002             : 
    1003             :     try {
    1004           0 :         if (!standardout && options.license) {
    1005           0 :             printLicenseHeader(*pofs, compFileName);
    1006             :         }
    1007             : 
    1008             :         generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
    1009           0 :                          supportxcomponent);
    1010             : 
    1011           0 :         if (options.componenttype == 3) {
    1012           0 :             *pofs << "#include \"com/sun/star/frame/XFrame.hpp\"\n";
    1013             :         }
    1014             : 
    1015             :         // namespace
    1016           0 :         OString nmspace;
    1017           0 :         short nm = 0;
    1018             : 
    1019           0 :         if (serviceobject) {
    1020           0 :             nmspace = generateCompHelperDeclaration(*pofs, options.implname);
    1021             : 
    1022             :             *pofs <<
    1023             :                 "\n\n/// anonymous implementation namespace\nnamespace {\n\n"
    1024           0 :                 "namespace css = ::com::sun::star;\n\n";
    1025             :         } else {
    1026           0 :             nm = generateNamespace(*pofs, options.implname, false, nmspace);
    1027           0 :             *pofs << "namespace css = ::com::sun::star;\n\n";
    1028             :         }
    1029             : 
    1030           0 :         sal_Int32 index = 0;
    1031           0 :         OString classname(options.implname);
    1032           0 :         if ((index = classname.lastIndexOf('.')) > 0)
    1033           0 :             classname = classname.copy(index+1);
    1034             : 
    1035             :         OString parentname(
    1036             :             generateClassDefinition(*pofs,
    1037             :                 options, manager, classname, interfaces, properties,
    1038           0 :                 attributes, propinterfaces, propertyhelper, supportxcomponent));
    1039             : 
    1040             :         generateQueryInterface(*pofs, options, manager, interfaces, parentname,
    1041           0 :                                classname, propertyhelper);
    1042             : 
    1043             :         generateMethodBodies(*pofs, options, manager, interfaces, classname,
    1044           0 :                              nmspace, propertyhelper);
    1045             : 
    1046           0 :         if (serviceobject) {
    1047             :             // close namepsace
    1048           0 :             *pofs << "} // closing anonymous implementation namespace\n\n";
    1049             : 
    1050             :             generateCompHelperDefinition(*pofs, options.implname,
    1051           0 :                                          classname, services);
    1052           0 :             generateCompFunctions(*pofs, nmspace);
    1053             :         } else {
    1054             :             // close namepsace
    1055           0 :             for (short i=0; i < nm; i++)
    1056           0 :                 *pofs << "} ";
    1057           0 :             *pofs << (nm > 0 ? "// closing namespace\n\n" : "\n");
    1058             :         }
    1059             : 
    1060           0 :         if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
    1061           0 :             ((std::ofstream*)pofs)->close();
    1062           0 :             delete pofs;
    1063           0 :             OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, false));
    1064           0 :         }
    1065           0 :     } catch (CannotDumpException & e) {
    1066           0 :         std::cerr << "ERROR: " << e.getMessage() << "\n";
    1067           0 :         if ( !standardout ) {
    1068           0 :             if (pofs && ((std::ofstream*)pofs)->is_open()) {
    1069           0 :                 ((std::ofstream*)pofs)->close();
    1070           0 :                 delete pofs;
    1071             :             }
    1072             :             // remove existing type file if something goes wrong to ensure
    1073             :             // consistency
    1074           0 :             if (fileExists(compFileName))
    1075           0 :                 removeTypeFile(compFileName);
    1076             : 
    1077             :             // remove tmp file if something goes wrong
    1078           0 :             removeTypeFile(tmpFileName);
    1079             :         }
    1080           0 :     }
    1081             : }
    1082             : 
    1083           0 : void generateCalcAddin(ProgramOptions const & options,
    1084             :                        rtl::Reference< TypeManager > const & manager,
    1085             :                        std::vector< OString > const & types)
    1086             : {
    1087           0 :     std::set< OUString > interfaces;
    1088           0 :     std::set< OUString > services;
    1089           0 :     AttributeInfo properties;
    1090           0 :     AttributeInfo attributes;
    1091           0 :     std::set< OUString > propinterfaces;
    1092           0 :     bool serviceobject = false;
    1093           0 :     bool supportxcomponent = false;
    1094             : 
    1095             : 
    1096           0 :     std::vector< OString >::const_iterator iter = types.begin();
    1097           0 :     while (iter != types.end()) {
    1098           0 :         checkType(manager, b2u(*iter), interfaces, services, properties);
    1099           0 :         ++iter;
    1100             :     }
    1101             : 
    1102           0 :     OUString sAddinService;
    1103           0 :     if (services.size() != 1) {
    1104             :         throw CannotDumpException(
    1105             :             "for calc add-in components one and only one service type is necessary!"
    1106           0 :             " Please reference a valid type with the '-t' option.");
    1107             :     }
    1108             : 
    1109             : 
    1110             :     // get the one and only add-in service for later use
    1111           0 :     std::set< OUString >::const_iterator iter2 = services.begin();
    1112           0 :     sAddinService = *iter2;
    1113           0 :     if (sAddinService.equals("com.sun.star.sheet.AddIn")) {
    1114           0 :         sAddinService = *(++iter2);
    1115             :     }
    1116             : 
    1117             :     // if backwardcompatible==true the AddIn service needs to be added to the
    1118             :     // supported service list, the necessary intefaces are mapped to the add-in
    1119             :     // configuration. Since OO.org 2.0.4 this is obsolete and the add-in is
    1120             :     // take form the configuration from Calc directly, this simplifies the
    1121             :     // add-in code
    1122           0 :     if (options.backwardcompatible) {
    1123             :         checkType(manager, "com.sun.star.sheet.AddIn",
    1124           0 :                   interfaces, services, properties);
    1125             :     } else {
    1126             :         // special case for the optional XLocalization interface. It should be
    1127             :         // implemented always. But it is parent of the XAddIn and we need it only
    1128             :         // if backwardcompatible is false.
    1129           0 :         if (interfaces.find("com.sun.star.lang.XLocalizable") == interfaces.end()) {
    1130           0 :             interfaces.insert("com.sun.star.lang.XLocalizable");
    1131             :         }
    1132             :     }
    1133             : 
    1134             :     OUString propertyhelper = checkPropertyHelper(
    1135           0 :         options, manager, services, interfaces, attributes, propinterfaces);
    1136             : 
    1137           0 :     if (!propertyhelper.isEmpty())
    1138             :         std::cerr << "WARNING: interfaces specifying calc add-in functions "
    1139           0 :             "shouldn't support attributes!\n";
    1140             : 
    1141           0 :     checkDefaultInterfaces(interfaces, services, propertyhelper);
    1142             : 
    1143           0 :     if (interfaces.size() > 12) {
    1144             :         throw CannotDumpException(
    1145             :             "the skeletonmaker supports components with 12 interfaces "
    1146           0 :             "only (limitation of the UNO implementation helpers)!");
    1147             :     }
    1148             : 
    1149             :     // check if service object or simple UNO object
    1150           0 :     if (!services.empty())
    1151           0 :         serviceobject = true;
    1152             : 
    1153           0 :     supportxcomponent = checkXComponentSupport(manager, interfaces);
    1154           0 :     if (supportxcomponent)
    1155             :         std::cerr << "WARNING: add-ins shouldn't support "
    1156           0 :             "com.sun.star.uno.XComponent!\n";
    1157             : 
    1158           0 :     OString compFileName;
    1159           0 :     OString tmpFileName;
    1160           0 :     std::ostream* pofs = NULL;
    1161             :     bool standardout = getOutputStream(options, ".cxx",
    1162           0 :                                        &pofs, compFileName, tmpFileName);
    1163             : 
    1164             :     try {
    1165           0 :         if (!standardout && options.license) {
    1166           0 :             printLicenseHeader(*pofs, compFileName);
    1167             :         }
    1168             : 
    1169             :         generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
    1170           0 :                          supportxcomponent);
    1171             : 
    1172             :         *pofs <<
    1173             :             "#include \"com/sun/star/beans/PropertyValue.hpp\"\n"
    1174             :             "#include \"com/sun/star/beans/XPropertySet.hpp\"\n"
    1175             :             "#include \"com/sun/star/container/XNameAccess.hpp\"\n"
    1176             :             "#include \"com/sun/star/container/XHierarchicalNameAccess.hpp\"\n\n"
    1177             :             "#include \"rtl/ustrbuf.hxx\"\n\n"
    1178             :             "#include <boost/unordered_map.hpp>\n"
    1179           0 :             "#include <set>\n";
    1180             : 
    1181             :         // namespace
    1182           0 :         OString nmspace(generateCompHelperDeclaration(*pofs, options.implname));
    1183             : 
    1184             :         *pofs <<
    1185             :             "\n\n// anonymous implementation namespace\nnamespace {\n\n"
    1186           0 :             "namespace css = ::com::sun::star;\n\n";
    1187             : 
    1188           0 :         sal_Int32 index = 0;
    1189           0 :         OString classname(options.implname);
    1190           0 :         if ((index = classname.lastIndexOf('.')) > 0) {
    1191           0 :             classname = classname.copy(index+1);
    1192             :         }
    1193             : 
    1194           0 :         if (options.backwardcompatible) {
    1195           0 :             *pofs << "static const char * sADDIN_SERVICENAME = \""
    1196           0 :                   << sAddinService << "\";\n\n";
    1197             :             *pofs << "static const char * sDISPLAYNAME = \"DisplayName\";\n"
    1198             :                 "static const char * sDESCRIPTION = \"Description\";\n"
    1199             :                 "static const char * sCATEGORY = \"Category\";\n"
    1200             :                 "static const char * sCATEGORYDISPLAYNAME = \"CategoryDisplayName\";"
    1201           0 :                 "\n\n";
    1202             :         }
    1203             : 
    1204             :         OString parentname(
    1205             :             generateClassDefinition(*pofs,
    1206             :                 options, manager, classname, interfaces, properties,
    1207           0 :                 attributes, propinterfaces, propertyhelper, supportxcomponent));
    1208             : 
    1209             :         generateQueryInterface(*pofs, options, manager, interfaces, parentname,
    1210           0 :                                classname, propertyhelper);
    1211             : 
    1212             :         generateMethodBodies(*pofs, options, manager, interfaces, classname,
    1213           0 :                              nmspace, propertyhelper);
    1214             : 
    1215             :         // close namepsace
    1216           0 :         *pofs << "} // closing anonymous implementation namespace\n\n";
    1217             : 
    1218             :         generateCompHelperDefinition(*pofs, options.implname, classname,
    1219           0 :                                      services);
    1220             : 
    1221           0 :         generateCompFunctions(*pofs, nmspace);
    1222             : 
    1223           0 :         if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
    1224           0 :             ((std::ofstream*)pofs)->close();
    1225           0 :             delete pofs;
    1226           0 :             OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, false));
    1227           0 :         }
    1228           0 :     } catch (CannotDumpException & e) {
    1229           0 :         std::cerr << "ERROR: " << e.getMessage() << "\n";
    1230           0 :         if ( !standardout ) {
    1231           0 :             if (pofs && ((std::ofstream*)pofs)->is_open()) {
    1232           0 :                 ((std::ofstream*)pofs)->close();
    1233           0 :                 delete pofs;
    1234             :             }
    1235             :             // remove existing type file if something goes wrong to ensure
    1236             :             // consistency
    1237           0 :             if (fileExists(compFileName))
    1238           0 :                 removeTypeFile(compFileName);
    1239             : 
    1240             :             // remove tmp file if something goes wrong
    1241           0 :             removeTypeFile(tmpFileName);
    1242             :         }
    1243           0 :     }
    1244           0 : }
    1245             : 
    1246           0 : } }
    1247             : 
    1248             : 
    1249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10