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

Generated by: LCOV version 1.10