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

Generated by: LCOV version 1.10