Bump for 3.6-28
[LibreOffice.git] / unodevtools / source / skeletonmaker / cppcompskeleton.cxx
blob825e535ec7f4087cebd72196e432b38a72dfeecc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "codemaker/commoncpp.hxx"
31 #include "ostringostreaminserter.hxx"
32 #include "skeletoncommon.hxx"
33 #include "skeletoncpp.hxx"
35 #include <iostream>
37 using namespace ::rtl;
38 using namespace ::codemaker::cpp;
40 namespace skeletonmaker { namespace cpp {
42 void generateIncludes(std::ostream & o,
43 const boost::unordered_set< OString, OStringHash >& interfaces,
44 OString propertyhelper, bool serviceobject,
45 bool supportxcomponent)
47 o << "#include \"sal/config.h\"\n";
48 if (serviceobject) {
49 o << "#include \"cppuhelper/factory.hxx\"\n"
50 << "#include \"cppuhelper/implementationentry.hxx\"\n";
51 } else {
52 o << "#include \"com/sun/star/uno/XComponentContext.hpp\"\n";
54 if (supportxcomponent) {
55 o << "#include \"cppuhelper/compbase" << interfaces.size() << ".hxx\"\n";
56 o << "#include \"cppuhelper/basemutex.hxx\"\n";
57 } else {
58 o << "#include \"cppuhelper/implbase" << interfaces.size() << ".hxx\"\n";
61 if (propertyhelper.getLength() > 1) {
62 if (propertyhelper.equals("_"))
63 o << "#include \"cppuhelper/rpopshlp.hxx\"\n";
64 else
65 o << "#include \"cppuhelper/propertysetmixin.hxx\"\n";
68 boost::unordered_set< OString, OStringHash >::const_iterator iter = interfaces.begin();
69 while (iter != interfaces.end())
71 o << "#include \""
72 << ((*iter).replace('.', '/').getStr())
73 << ".hpp\"\n";
74 ++iter;
78 short generateNamespace(std::ostream & o,
79 const OString & implname,
80 bool serviceobject,
81 OString & nm)
83 short count=0;
84 sal_Int32 index = implname.lastIndexOf('.');
85 if (serviceobject) {
86 o << "\n\n// component helper namespace\n";
87 } else {
88 o << "\n";
90 OStringBuffer buf;
91 if (index == -1) {
92 if (serviceobject) {
93 buf.append("comp_");
94 buf.append(implname);
95 nm = buf.makeStringAndClear();
96 o << "namespace comp_" << implname << " {\n\n";
97 count=1;
98 } else {
99 nm = OString();
101 } else {
102 sal_Int32 nPos=0;
103 do {
104 OString token(implname.getToken(0, '.', nPos));
105 if (nPos < 0 && serviceobject) {
106 buf.append("::comp_");
107 buf.append(token);
108 o << "namespace comp_" << token << " { ";
109 count++;
110 } else {
111 buf.append("::");
112 buf.append(token);
113 o << "namespace " << token << " { ";
114 count++;
116 } while( nPos <= index );
117 nm = buf.makeStringAndClear();
118 o << "\n\n";
120 return count;
123 OString generateCompHelperDeclaration(std::ostream & o,
124 const OString & implname)
126 OString nm;
127 short nbrackets = generateNamespace(o, implname, true, nm);
129 o << "namespace css = ::com::sun::star;\n\n";
131 // generate component/service helper functions
132 o << "// component and service helper functions:\n"
133 "::rtl::OUString SAL_CALL _getImplementationName();\n"
134 "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
135 "_getSupportedServiceNames();\n"
136 "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
137 " css::uno::Reference< css::uno::XComponentContext > const & "
138 "context );\n\n";
140 // close namepsace
141 for (short i=0; i < nbrackets; i++)
142 o << "} ";
143 o << "// closing component helper namespace\n\n";
145 return nm;
148 void generateCompHelperDefinition(std::ostream & o,
149 const OString & implname,
150 const OString & classname,
151 const boost::unordered_set< OString, OStringHash >& services)
153 OString nm;
154 short nbrackets = generateNamespace(o, implname, true, nm);
156 o << "::rtl::OUString SAL_CALL _getImplementationName() {\n"
157 << " return ::rtl::OUString(\n"
158 << " \"" << implname << "\");\n}\n\n";
160 o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL "
161 "_getSupportedServiceNames()\n{\n css::uno::Sequence< "
162 << "::rtl::OUString >" << " s(" << services.size() << ");\n";
164 boost::unordered_set< OString, OStringHash >::const_iterator iter = services.begin();
165 short i=0;
166 while (iter != services.end())
168 o << " s[" << i++ << "] = ::rtl::OUString(\""
169 << (*iter).replace('/','.') << "\");\n";
170 ++iter;
172 o << " return s;\n}\n\n";
174 o << "css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
175 << "\n const css::uno::Reference< css::uno::XComponentContext > & "
176 << "context)\n SAL_THROW((css::uno::Exception))\n{\n"
177 << " return static_cast< ::cppu::OWeakObject * >(new "
178 << classname << "(context));\n}\n\n";
180 // close namepsace
181 for (short j=0; j < nbrackets; j++)
182 o << "} ";
183 o << "// closing component helper namespace\n\n";
187 void generateCompFunctions(std::ostream & o, const OString & nmspace)
189 o << "static ::cppu::ImplementationEntry const entries[] = {\n"
190 << " { &" << nmspace << "::_create,\n &"
191 << nmspace << "::_getImplementationName,\n &"
192 << nmspace << "::_getSupportedServiceNames,\n"
193 << " &::cppu::createSingleComponentFactory, 0, 0 },\n"
194 << " { 0, 0, 0, 0, 0, 0 }\n};\n\n";
196 o << "extern \"C\" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(\n"
197 << " const char * implName, void * serviceManager, void * registryKey)\n{\n"
198 << " return ::cppu::component_getFactoryHelper(\n"
199 << " implName, serviceManager, registryKey, entries);\n}\n\n";
201 o << "extern \"C\" sal_Bool SAL_CALL component_writeInfo(\n"
202 << " void * serviceManager, void * registryKey)\n{\n"
203 << " return ::cppu::component_writeInfoHelper("
204 << "serviceManager, registryKey, entries);\n}\n";
207 void generateXPropertySetBodies(std::ostream& o,
208 const OString & classname,
209 const OString & propertyhelper)
211 o << "// com.sun.star.beans.XPropertySet:\n";
213 o << "css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL "
214 << classname << "getPropertySetInfo() throw ("
215 "css::uno::RuntimeException)\n{\n return ::cppu::PropertySetMixin< "
216 << propertyhelper
217 << " >::getPropertySetInfo();\n}\n\n";
219 o << "void SAL_CALL " << classname << "setPropertyValue(const ::rtl::OUString"
220 " & aPropertyName, const css::uno::Any & aValue) throw ("
221 "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
222 "css::beans::PropertyVetoException, css::lang::IllegalArgumentException, "
223 "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
224 << propertyhelper << " >::setPropertyValue(aPropertyName, aValue);\n}\n\n";
227 o << "css::uno::Any SAL_CALL " << classname << "getPropertyValue(const "
228 "::rtl::OUString & aPropertyName) throw (css::uno::RuntimeException, "
229 "css::beans::UnknownPropertyException, css::lang::WrappedTargetException)"
230 "\n{\n return ::cppu::PropertySetMixin< "
231 << propertyhelper << " >::getPropertyValue(aPropertyName);\n}\n\n";
233 o << "void SAL_CALL " << classname << "addPropertyChangeListener(const "
234 "::rtl::OUString & aPropertyName, const css::uno::Reference< "
235 "css::beans::XPropertyChangeListener > & xListener) throw ("
236 "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
237 "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
238 << propertyhelper
239 << " >::addPropertyChangeListener(aPropertyName, xListener);\n}\n\n";
241 o << "void SAL_CALL " << classname << "removePropertyChangeListener(const "
242 "::rtl::OUString & aPropertyName, const css::uno::Reference< "
243 "css::beans::XPropertyChangeListener > & xListener) throw ("
244 "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
245 "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
246 << propertyhelper
247 << " >::removePropertyChangeListener(aPropertyName, xListener);\n}\n\n";
249 o << "void SAL_CALL " << classname << "addVetoableChangeListener(const "
250 "::rtl::OUString & aPropertyName, const css::uno::Reference< "
251 "css::beans::XVetoableChangeListener > & xListener) throw ("
252 "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
253 "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
254 << propertyhelper
255 << " >::addVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
257 o << "void SAL_CALL " << classname << "removeVetoableChangeListener(const "
258 "::rtl::OUString & aPropertyName, const css::uno::Reference< "
259 "css::beans::XVetoableChangeListener > & xListener) throw ("
260 "css::uno::RuntimeException, css::beans::UnknownPropertyException, "
261 "css::lang::WrappedTargetException)\n{\n ::cppu::PropertySetMixin< "
262 << propertyhelper
263 << " >::removeVetoableChangeListener(aPropertyName, xListener);\n}\n\n";
266 void generateXFastPropertySetBodies(std::ostream& o,
267 const OString & classname,
268 const OString & propertyhelper)
270 o << "// com.sun.star.beans.XFastPropertySet:\n";
272 o << "void SAL_CALL " << classname << "setFastPropertyValue( ::sal_Int32 "
273 "nHandle, const css::uno::Any& aValue ) throw ("
274 "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
275 "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
276 "css::uno::RuntimeException)\n{\n ::cppu::PropertySetMixin< "
277 << propertyhelper << " >::setFastPropertyValue(nHandle, aValue);\n}\n\n";
280 o << "css::uno::Any SAL_CALL " << classname << "getFastPropertyValue( "
281 "::sal_Int32 nHandle ) throw (css::beans::UnknownPropertyException, "
282 "css::lang::WrappedTargetException, css::uno::RuntimeException)\n{\n"
283 " return ::cppu::PropertySetMixin< "
284 << propertyhelper << " >::getFastPropertyValue(nHandle);\n}\n\n";
287 void generateXPropertyAccessBodies(std::ostream& o,
288 const OString & classname,
289 const OString & propertyhelper)
291 o << " // com.sun.star.beans.XPropertyAccess:\n";
293 o << "css::uno::Sequence< css::beans::PropertyValue > SAL_CALL "
294 << classname << "getPropertyValues( ) throw ("
295 "::com::sun::star::uno::RuntimeException)\n{\n"
296 " return ::cppu::PropertySetMixin< "
297 << propertyhelper << " >::getPropertyValues();\n}\n\n";
299 o << "void SAL_CALL " << classname << "setPropertyValues( const "
300 "css::uno::Sequence< css::beans::PropertyValue >& aProps ) throw ("
301 "css::beans::UnknownPropertyException, css::beans::PropertyVetoException, "
302 "css::lang::IllegalArgumentException, css::lang::WrappedTargetException, "
303 "css::uno::RuntimeException)\n{\n"
304 " ::cppu::PropertySetMixin< "
305 << propertyhelper << " >::setPropertyValues(aProps);\n}\n\n";
308 void generateXLocalizable(std::ostream& o, const OString & classname)
310 o << "// ::com::sun::star::lang::XLocalizable:\n"
311 "void SAL_CALL " << classname << "setLocale(const css::lang::"
312 "Locale & eLocale) throw (css::uno::RuntimeException)\n{\n"
313 " m_locale = eLocale;\n}\n\n"
314 "css::lang::Locale SAL_CALL " << classname << "getLocale() "
315 "throw (css::uno::RuntimeException)\n{\n return m_locale;\n}\n\n";
318 void generateXAddInBodies(std::ostream& o, const OString & classname)
320 o << "// ::com::sun::star::sheet::XAddIn:\n";
322 o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticFuntionName("
323 "const ::rtl::OUString & aDisplayName) throw (css::uno::RuntimeException)"
324 "\n{\n ::rtl::OUString ret;\n try {\n css::uno::Reference< "
325 "css::container::XNameAccess > xNAccess(m_xHAccess, css::uno::UNO_QUERY);\n"
326 " css::uno::Sequence< ::rtl::OUString > functions = "
327 "xNAccess->getElementNames();\n sal_Int32 len = functions."
328 "getLength();\n ::rtl::OUString sDisplayName;\n"
329 " for (sal_Int32 i=0; i < len; ++i) {\n"
330 " sDisplayName = getAddinProperty(functions[i], "
331 "::rtl::OUString(),\n "
332 "sDISPLAYNAME);\n if (sDisplayName.equals(aDisplayName))\n"
333 " return functions[i];\n }\n }\n"
334 " catch ( const css::uno::RuntimeException & e ) {\n throw e;\n }\n"
335 " catch ( css::uno::Exception & ) {\n }\n return ret;\n}\n\n";
337 o << "::rtl::OUString SAL_CALL " << classname << "getDisplayFunctionName(const "
338 "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
339 "{\n return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
340 "sDISPLAYNAME);\n}\n\n";
342 o << "::rtl::OUString SAL_CALL " << classname << "getFunctionDescription(const "
343 "::rtl::OUString & aProgrammaticName) throw (css::uno::RuntimeException)\n"
344 "{\n return getAddinProperty(aProgrammaticName, ::rtl::OUString(), "
345 "sDESCRIPTION);\n}\n\n";
347 o << "::rtl::OUString SAL_CALL " << classname << "getDisplayArgumentName(const "
348 "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
349 "(css::uno::RuntimeException)\n{\n return getAddinProperty("
350 "aProgrammaticFunctionName,\n m_functionMap["
351 "aProgrammaticFunctionName][nArgument],\n"
352 " sDISPLAYNAME);\n}\n\n";
354 o << "::rtl::OUString SAL_CALL " << classname << "getArgumentDescription(const "
355 "::rtl::OUString & aProgrammaticFunctionName, ::sal_Int32 nArgument) throw "
356 "(css::uno::RuntimeException)\n{\n return getAddinProperty("
357 "aProgrammaticFunctionName,\n "
358 "m_functionMap[aProgrammaticFunctionName][nArgument],\n"
359 " sDESCRIPTION);\n}\n\n";
361 o << "::rtl::OUString SAL_CALL " << classname << "getProgrammaticCategoryName("
362 "const ::rtl::OUString & aProgrammaticFunctionName) throw ("
363 "css::uno::RuntimeException)\n{\n return getAddinProperty("
364 "aProgrammaticFunctionName, ::rtl::OUString(), sCATEGORY);\n}\n\n";
366 o << "::rtl::OUString SAL_CALL " << classname << "getDisplayCategoryName(const "
367 "::rtl::OUString & aProgrammaticFunctionName) throw ("
368 "css::uno::RuntimeException)\n{\n return getAddinProperty("
369 "aProgrammaticFunctionName, ::rtl::OUString(), "
370 "sCATEGORYDISPLAYNAME);\n}\n\n";
373 void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname)
375 o << "// ::com::sun::star::sheet::XCompatibilityNames:\n"
376 "css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL " << classname
377 << "getCompatibilityNames(const ::rtl::OUString & aProgrammaticName) throw "
378 "(css::uno::RuntimeException)\n{\n css::uno::Sequence< "
379 "css::sheet::LocalizedName > seqLocalizedNames;\n try {\n "
380 "::rtl::OUStringBuffer buf("
381 "aProgrammaticName);\n buf.appendAscii(\"/CompatibilityName\");\n"
382 " ::rtl::OUString hname(buf.makeStringAndClear());\n\n "
383 "if ( m_xCompAccess->hasByHierarchicalName(hname) ) {\n"
384 " css::uno::Reference< css::container::XNameAccess > "
385 "xNameAccess(\n"
386 " m_xCompAccess->getByHierarchicalName(hname), "
387 "css::uno::UNO_QUERY);\n\n css::uno::Sequence< ::rtl::OUString"
388 " > elems = \n xNameAccess->getElementNames();"
389 "\n ::sal_Int32 len = elems.getLength();\n\n "
390 "seqLocalizedNames.realloc(len);\n\n ::rtl::OUString "
391 "sCompatibilityName;\n for (::sal_Int32 i=0; i < len; ++i) {\n"
392 " ::rtl::OUString sLocale(elems[i]);\n "
393 "xNameAccess->getByName(sLocale) >>= sCompatibilityName;\n\n"
394 " css::lang::Locale aLocale;\n "
395 "::sal_Int32 nIndex = 0, nToken = 0;\n "
396 "do {\n ::rtl::OUString aToken = sLocale.getToken(0, '-', "
397 "nIndex);\n switch (nToken++) {\n "
398 "case 0:\n aLocale.Language = aToken;\n"
399 " break;\n case 1:\n"
400 " aLocale.Country = aToken;\n "
401 " break;\n default:\n "
402 "aLocale.Variant = sLocale.copy(nIndex-aToken.getLength()-1);\n"
403 " nIndex = -1;\n }\n"
404 " } while ( nIndex >= 0 );\n\n "
405 "seqLocalizedNames[i].Locale = aLocale;\n "
406 "seqLocalizedNames[i].Name = sCompatibilityName;\n }"
407 "\n }\n }\n catch ( const css::uno::RuntimeException & e ) {\n "
408 "throw e;\n }\n catch ( css::uno::Exception & ) {\n }\n\n"
409 " return seqLocalizedNames;\n}\n\n";
412 void generateXInitialization(std::ostream& o, const OString & classname)
414 o << "// ::com::sun::star::lang::XInitialization:\n"
415 "void SAL_CALL " << classname << "initialize( const css::uno::Sequence< "
416 "css::uno::Any >& aArguments ) "
417 "throw (css::uno::Exception, css::uno::RuntimeException)\n{\n"
418 " css::uno::Reference < css::frame::XFrame > xFrame;\n"
419 " if ( aArguments.getLength() ) {\n aArguments[0] >>= xFrame;\n"
420 " m_xFrame = xFrame;\n }\n}\n\n";
423 void generateXDispatch(std::ostream& o,
424 const OString & classname,
425 const ProtocolCmdMap & protocolCmdMap)
427 // com.sun.star.frame.XDispatch
428 // dispatch
429 o << "// ::com::sun::star::frame::XDispatch:\n"
430 "void SAL_CALL " << classname << "dispatch( const css::util::URL& aURL, const "
431 "css::uno::Sequence< css::beans::PropertyValue >& aArguments ) throw"
432 "(css::uno::RuntimeException)\n{\n";
434 ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
435 while (iter != protocolCmdMap.end()) {
436 o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
437 << "\") == 0 )\n {\n";
439 for (std::vector< OString >::const_iterator i = (*iter).second.begin();
440 i != (*iter).second.end(); ++i) {
441 o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") )\n"
442 " {\n // add your own code here\n"
443 " return;\n }\n";
446 o << " }\n";
447 ++iter;
449 o << "}\n\n";
451 // addStatusListener
452 o << "void SAL_CALL " << classname << "addStatusListener( const css::uno::Reference< "
453 "css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
454 "throw (css::uno::RuntimeException)\n{\n"
455 " // add your own code here\n}\n\n";
457 // removeStatusListener
458 o << "void SAL_CALL " << classname << "removeStatusListener( const css::uno::Reference"
459 "< css::frame::XStatusListener >& xControl, const css::util::URL& aURL ) "
460 "throw (css::uno::RuntimeException)\n{\n"
461 " // add your own code here\n}\n\n";
464 void generateXDispatchProvider(std::ostream& o,
465 const OString & classname,
466 const ProtocolCmdMap & protocolCmdMap)
469 // com.sun.star.frame.XDispatchProvider
470 // queryDispatch
471 o << "// ::com::sun::star::frame::XDispatchProvider:\n"
472 "css::uno::Reference< css::frame::XDispatch > SAL_CALL " << classname
473 << "queryDispatch( const css::util::URL& aURL,"
474 " const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) "
475 "throw(css::uno::RuntimeException)\n{\n css::uno::Reference< "
476 "css::frame::XDispatch > xRet;\n"
477 " if ( !m_xFrame.is() )\n return 0;\n\n";
479 ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
480 while (iter != protocolCmdMap.end()) {
481 o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
482 << "\") == 0 )\n {\n";
484 for (std::vector< OString >::const_iterator i = (*iter).second.begin();
485 i != (*iter).second.end(); ++i) {
486 o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") == 0 )\n"
487 " xRet = this;\n";
490 o << " }\n";
491 ++iter;
493 o << " return xRet;\n}\n\n";
495 // queryDispatches
496 o << "css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL "
497 << classname << "queryDispatches( const css::uno::Sequence< "
498 "css::frame::DispatchDescriptor >& seqDescripts ) throw("
499 "css::uno::RuntimeException)\n{\n"
500 " sal_Int32 nCount = seqDescripts.getLength();\n"
501 " css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > "
502 "lDispatcher(nCount);\n\n"
503 " for( sal_Int32 i=0; i<nCount; ++i ) {\n"
504 " lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL,\n"
505 " seqDescripts[i].FrameName,\n"
506 " seqDescripts[i].SearchFlags );\n"
507 " }\n\n return lDispatcher;\n}\n\n";
510 void generateAddinConstructorAndHelper(std::ostream& o,
511 ProgramOptions const & options,
512 TypeManager const & manager, const OString & classname,
513 const boost::unordered_set< OString, OStringHash >& interfaces)
515 o << classname << "::" << classname
516 << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n"
517 << " m_xContext(context), m_locale()\n{\n";
519 if (options.backwardcompatible) {
520 o << " try {\n";
522 generateFunctionParameterMap(o, options, manager, interfaces);
524 o << " css::uno::Reference< css::lang::XMultiServiceFactory > xProvider"
525 "(\n m_xContext->getServiceManager()->createInstanceWithContext"
526 "(\n ::rtl::OUString(\n "
527 " \"com.sun.star.configuration.ConfigurationProvider\"),"
528 "\n m_xContext ), css::uno::UNO_QUERY );\n\n";
530 o << " ::rtl::OUString sReadOnlyView(\n"
531 " \"com.sun.star.configuration.ConfigurationAccess\");\n\n";
533 o << " ::rtl::OUStringBuffer sPath(::rtl::OUString(\n"
534 " \"/org.openoffice.Office.CalcAddIns/AddInInfo/\"));\n"
535 " sPath.appendAscii(sADDIN_SERVICENAME);\n"
536 " sPath.appendAscii(\"/AddInFunctions\");\n\n"
537 " // create arguments: nodepath\n"
538 " css::beans::PropertyValue aArgument;\n"
539 " aArgument.Name = ::rtl::OUString(\"nodepath\");\n"
540 " aArgument.Value <<= sPath.makeStringAndClear();\n\n"
541 " css::uno::Sequence< css::uno::Any > aArguments(1);\n"
542 " aArguments[0] <<= aArgument;\n\n";
544 o << " // create the default view using default UI locale\n"
545 " css::uno::Reference< css::uno::XInterface > xIface =\n"
546 " xProvider->createInstanceWithArguments(sReadOnlyView, "
547 "aArguments);\n\n"
548 " m_xHAccess = css::uno::Reference<\n "
549 "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);"
550 "\n\n";
552 o << " // extend arguments to create a view for all locales to get "
553 "simple\n // access to the compatibilityname property\n"
554 " aArgument.Name = ::rtl::OUString(\"locale\");\n"
555 " aArgument.Value <<= ::rtl::OUString(\"*\");\n"
556 " aArguments.realloc(2);\n"
557 " aArguments[1] <<= aArgument;\n\n"
558 " // create view for all locales\n"
559 " xIface = xProvider->createInstanceWithArguments(sReadOnlyView, "
560 "aArguments);\n\n"
561 " m_xCompAccess = css::uno::Reference<\n "
562 "css::container::XHierarchicalNameAccess >(xIface, css::uno::UNO_QUERY);\n";
564 o << " }\n catch ( css::uno::Exception & ) {\n }\n}\n\n";
566 o << "// addin configuration property helper function:\n::rtl::OUString "
567 "SAL_CALL " << classname << "::getAddinProperty(const ::rtl::OUString &"
568 " funcName, const ::rtl::OUString & paramName, const char * propName) "
569 "throw (css::uno::RuntimeException)\n{\n"
570 " ::rtl::OUString ret;\n try {\n "
571 "::rtl::OUStringBuffer buf(funcName);\n"
572 " if (!paramName.isEmpty()) {\n"
573 " buf.appendAscii(\"/Parameters/\");\n"
574 " buf.append(paramName);\n }\n\n"
575 " css::uno::Reference< css::beans::XPropertySet > xPropSet(\n"
576 " m_xHAccess->getByHierarchicalName(\n"
577 " buf.makeStringAndClear()), css::uno::UNO_QUERY);\n"
578 " xPropSet->getPropertyValue(\n "
579 "::rtl::OUString(propName)) >>= ret;\n }\n"
580 " catch ( const css::uno::RuntimeException & e ) {\n throw e;\n }\n"
581 " catch ( css::uno::Exception & ) {\n }\n return ret;\n";
583 o <<"}\n\n";
586 void generateMemberInitialization(std::ostream& o,
587 ProgramOptions const & options,
588 TypeManager const & manager,
589 AttributeInfo const & members)
591 if (!members.empty()) {
592 for (AttributeInfo::const_iterator i(members.begin());
593 i != members.end(); ++i)
595 RTTypeClass typeClass;
596 OString type(i->second.first.replace('.','/'));
597 OString name;
598 sal_Int32 rank;
599 std::vector< OString > arguments;
600 codemaker::UnoType::Sort sort = codemaker::decomposeAndResolve(
601 manager, type, true, true, true, &typeClass, &name, &rank,
602 &arguments);
604 if (sort <= codemaker::UnoType::SORT_CHAR && rank == 0) {
605 o << ",\n m_" << i->first << "(";
606 printType(o, options, manager, type, 16, true);
607 o << ")";
613 void generateMemberDeclaration(std::ostream& o,
614 ProgramOptions const & options,
615 TypeManager const & manager,
616 AttributeInfo const & members)
618 for (AttributeInfo::const_iterator i(members.begin());
619 i != members.end(); ++i)
621 o << " ";
622 printType(o, options, manager, i->second.first.replace('.','/'),
623 1, false);
624 o << " m_" << i->first << ";\n";
628 OString generateClassDefinition(std::ostream& o,
629 ProgramOptions const & options,
630 TypeManager const & manager,
631 OString const & classname,
632 boost::unordered_set< OString, OStringHash > const & interfaces,
633 AttributeInfo const & properties,
634 AttributeInfo const & attributes,
635 boost::unordered_set< OString, OStringHash > const & propinterfaces,
636 OString const & propertyhelper, bool supportxcomponent)
638 OStringBuffer parentname(64);
639 o << "class " << classname << ":\n";
641 if (!interfaces.empty()) {
642 if (supportxcomponent) {
643 parentname.append("::cppu::WeakComponentImplHelper");
644 parentname.append(static_cast<sal_Int32>(interfaces.size()));
645 o << " private ::cppu::BaseMutex,\n"
646 << " public ::cppu::WeakComponentImplHelper"
647 << interfaces.size() << "<";
648 } else {
649 parentname.append("::cppu::WeakImplHelper");
650 parentname.append(static_cast<sal_Int32>(interfaces.size()));
651 o << " public ::cppu::WeakImplHelper" << interfaces.size() << "<";
654 boost::unordered_set< OString, OStringHash >::const_iterator iter =
655 interfaces.begin();
656 while (iter != interfaces.end())
658 o << "\n " << scopedCppName(*iter, false, true);
659 ++iter;
660 if (iter != interfaces.end())
661 o << ",";
662 else
663 o << ">";
667 if (propertyhelper.getLength() > 1) {
668 o << ",\n public ::cppu::PropertySetMixin< "
669 << scopedCppName(propertyhelper, false, true) << " >";
672 o << "\n{\npublic:\n"
673 << " explicit " << classname << "("
674 << "css::uno::Reference< css::uno::XComponentContext > const & context);\n\n";
676 // generate component/service helper functions
677 // o << " // component and service helper functions:\n"
678 // << " static ::rtl::OUString SAL_CALL _getImplementationName();\n"
679 // << " static css::uno::Sequence< ::rtl::OUString > SAL_CALL "
680 // << "_getSupportedServiceNames();\n"
681 // << " static css::uno::Reference< css::uno::XInterface > SAL_CALL _create("
682 // << "\n css::uno::Reference< css::uno::XComponentContext > const & "
683 // << "context);\n\n";
685 // overload queryInterface
686 if (propertyhelper.getLength() > 1) {
687 o << " // ::com::sun::star::uno::XInterface:\n"
688 " virtual css::uno::Any SAL_CALL queryInterface("
689 "css::uno::Type const & type) throw ("
690 "css::uno::RuntimeException);\n";
692 OStringBuffer buffer(256);
693 buffer.append(parentname.toString());
694 buffer.append("< ");
695 boost::unordered_set< OString, OStringHash >::const_iterator iter =
696 interfaces.begin();
697 while (iter != interfaces.end())
699 buffer.append(scopedCppName(*iter, false, true));
700 ++iter;
701 if (iter != interfaces.end())
702 buffer.append(", ");
703 else
704 buffer.append(" >");
706 OString parent(buffer.makeStringAndClear());
707 o << " virtual void SAL_CALL acquire() throw ()\n { "
708 << parent << "::acquire(); }\n";
709 o << " virtual void SAL_CALL release() throw ()\n { "
710 << parent << "::release(); }\n\n";
713 boost::unordered_set< OString, OStringHash >::const_iterator it =
714 interfaces.begin();
715 codemaker::GeneratedTypeSet generated;
716 while (it != interfaces.end())
718 typereg::Reader reader(manager.getTypeReader((*it).replace('.','/')));
719 printMethods(o, options, manager, reader, generated, "", "", " ",
720 true, propertyhelper);
721 ++it;
724 o << "private:\n " << classname << "(const " << classname << " &); // not defined\n"
725 << " " << classname << "& operator=(const " << classname << " &); // not defined\n\n"
726 << " // destructor is private and will be called indirectly by the release call"
727 << " virtual ~" << classname << "() {}\n\n";
729 if (options.componenttype == 2) {
730 o << " typedef boost::unordered_map< ::sal_Int32, rtl::OUString, "
731 "boost::hash<::sal_Int32> > ParamMap;\n"
732 " typedef boost::unordered_map< rtl::OUString, ParamMap, "
733 "rtl::OUStringHash > FunctionMap;\n\n"
734 " ::rtl::OUString SAL_CALL getAddinProperty(const ::rtl::OUString & "
735 "funcName, const ::rtl::OUString & paramName, const char * propName) "
736 "throw (css::uno::RuntimeException);\n\n";
739 if (supportxcomponent) {
740 o << " // overload WeakComponentImplHelperBase::disposing()\n"
741 " // This function is called upon disposing the component,\n"
742 " // if your component needs special work when it becomes\n"
743 " // disposed, do it here.\n"
744 " virtual void SAL_CALL disposing();\n\n";
747 // members
748 o << " css::uno::Reference< css::uno::XComponentContext > m_xContext;\n";
749 if (!supportxcomponent && !attributes.empty())
750 o << " mutable ::osl::Mutex m_aMutex;\n";
752 // additional member for add-ons
753 if (options.componenttype == 3) {
754 o << " css::uno::Reference< css::frame::XFrame > m_xFrame;\n";
757 if (options.componenttype == 2) {
758 if (options.backwardcompatible) {
759 o <<" css::uno::Reference< css::container::XHierarchicalNameAccess > "
760 "m_xHAccess;\n"
761 " css::uno::Reference< css::container::XHierarchicalNameAccess > "
762 "m_xCompAccess;\n"
763 " FunctionMap m_functionMap;\n";
765 o << " css::lang::Locale m_locale;\n";
768 generateMemberDeclaration(o, options, manager, properties);
769 generateMemberDeclaration(o, options, manager, attributes);
771 // if (!properties.empty())
772 // {
773 // AttributeInfo::const_iterator iter = properties.begin();
774 // while (iter != properties.end())
775 // {
776 // o << " ";
777 // printType(o, options, manager, iter->second.first.replace('.','/'),
778 // 1, false);
779 // o << " m_" << iter->first << ";\n";
780 // iter++;
781 // }
782 // }
783 // if (!attributes.empty())
784 // {
785 // AttributeInfo::const_iterator iter = attributes.begin();
786 // while (iter != attributes.end())
787 // {
788 // o << " ";
789 // printType(o, options, manager, iter->second.first.replace('.','/'),
790 // 1, false);
791 // o << " m_" << iter->first << ";\n";
792 // iter++;
793 // }
794 // }
796 o << "};\n\n";
798 // generate constructor
799 if (options.componenttype == 2) {
800 generateAddinConstructorAndHelper(o, options, manager,
801 classname, interfaces);
802 } else {
803 o << classname << "::" << classname
804 << "(css::uno::Reference< css::uno::XComponentContext > const & context) :\n";
805 if (supportxcomponent) {
806 o << " ::cppu::WeakComponentImplHelper" << interfaces.size() << "<";
807 boost::unordered_set< OString, OStringHash >::const_iterator iter =
808 interfaces.begin();
809 while (iter != interfaces.end()) {
810 o << "\n " << scopedCppName(*iter, false, true);
811 ++iter;
812 if (iter != interfaces.end())
813 o << ",";
814 else
815 o << ">(m_aMutex),\n";
818 if (propertyhelper.getLength() > 1) {
819 o << " ::cppu::PropertySetMixin< "
820 << scopedCppName(propertyhelper, false, true) << " >(\n"
821 << " context, static_cast< Implements >(\n ";
822 OStringBuffer buffer(128);
823 if (propinterfaces.find("com/sun/star/beans/XPropertySet")
824 != propinterfaces.end()) {
825 buffer.append("IMPLEMENTS_PROPERTY_SET");
827 if (propinterfaces.find("com/sun/star/beans/XFastPropertySet")
828 != propinterfaces.end()) {
829 if (buffer.getLength() > 0)
830 buffer.append(" | IMPLEMENTS_FAST_PROPERTY_SET");
831 else
832 buffer.append("IMPLEMENTS_FAST_PROPERTY_SET");
834 if (propinterfaces.find("com/sun/star/beans/XPropertyAccess")
835 != propinterfaces.end()) {
836 if (buffer.getLength() > 0)
837 buffer.append(" | IMPLEMENTS_PROPERTY_ACCESS");
838 else
839 buffer.append("IMPLEMENTS_PROPERTY_ACCESS");
841 o << buffer.makeStringAndClear()
842 << "), css::uno::Sequence< ::rtl::OUString >()),\n";
844 o << " m_xContext(context)";
846 generateMemberInitialization(o, options, manager, properties);
847 generateMemberInitialization(o, options, manager, attributes);
849 o << "\n{}\n\n";
852 // generate service/component helper function implementations
853 // generateServiceHelper(o, options.implname, classname, services);
855 if (supportxcomponent) {
856 o << "// overload WeakComponentImplHelperBase::disposing()\n"
857 "// This function is called upon disposing the component,\n"
858 "// if your component needs special work when it becomes\n"
859 "// disposed, do it here.\n"
860 "void SAL_CALL " << classname << "::disposing()\n{\n\n}\n\n";
863 return parentname.makeStringAndClear();
866 void generateXServiceInfoBodies(std::ostream& o,
867 OString const & classname,
868 OString const & comphelpernamespace)
870 o << "// com.sun.star.uno.XServiceInfo:\n"
871 << "::rtl::OUString SAL_CALL " << classname << "getImplementationName() "
872 << "throw (css::uno::RuntimeException)\n{\n "
873 << "return " << comphelpernamespace << "::_getImplementationName();\n}\n\n";
875 o << "::sal_Bool SAL_CALL " << classname
876 << "supportsService(::rtl::OUString const & "
877 << "serviceName) throw (css::uno::RuntimeException)\n{\n "
878 << "css::uno::Sequence< ::rtl::OUString > serviceNames = "
879 << comphelpernamespace << "::_getSupportedServiceNames();\n "
880 << "for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {\n "
881 << " if (serviceNames[i] == serviceName)\n return sal_True;\n"
882 << " }\n return sal_False;\n}\n\n";
884 o << "css::uno::Sequence< ::rtl::OUString > SAL_CALL " << classname
885 << "getSupportedServiceNames() throw (css::uno::RuntimeException)\n{\n "
886 << "return " << comphelpernamespace
887 << "::_getSupportedServiceNames();\n}\n\n";
891 void generateMethodBodies(std::ostream& o,
892 ProgramOptions const & options,
893 TypeManager const & manager,
894 boost::unordered_set< OString, OStringHash > const & interfaces,
895 OString const & classname,
896 OString const & comphelpernamespace,
897 OString const & propertyhelper)
899 OString name(classname.concat("::"));
900 boost::unordered_set< OString, OStringHash >::const_iterator iter =
901 interfaces.begin();
902 codemaker::GeneratedTypeSet generated;
903 while (iter != interfaces.end()) {
904 if ( (*iter).equals("com.sun.star.lang.XServiceInfo") ) {
905 generateXServiceInfoBodies(o, name, comphelpernamespace);
906 generated.add(*iter);
907 } else {
908 typereg::Reader reader(manager.getTypeReader((*iter).replace('.','/')));
909 printMethods(o, options, manager, reader, generated, "_",
910 name, "", true, propertyhelper);
912 ++iter;
916 void generateQueryInterface(std::ostream& o,
917 ProgramOptions const & options,
918 TypeManager const & manager,
919 const boost::unordered_set< OString, OStringHash >& interfaces,
920 OString const & parentname,
921 OString const & classname,
922 OString const & propertyhelper)
924 if (propertyhelper.isEmpty())
925 return;
927 o << "css::uno::Any " << classname
928 << "::queryInterface(css::uno::Type const & type) throw ("
929 "css::uno::RuntimeException)\n{\n ";
931 if (!propertyhelper.isEmpty())
932 o << "return ";
933 else
934 o << "css::uno::Any a(";
936 o << parentname << "<";
937 boost::unordered_set< OString, OStringHash >::const_iterator iter =
938 interfaces.begin();
939 while (iter != interfaces.end())
941 o << "\n " << scopedCppName(*iter, false, true);
942 ++iter;
943 if (iter != interfaces.end())
944 o << ",";
945 else
946 o << ">";
949 if (!propertyhelper.isEmpty()) {
950 o << "::queryInterface(type);\n";
951 } else {
952 o << "::queryInterface(type));\n";
953 o << " return a.hasValue() ? a\n : (";
954 if (propertyhelper.equals("_")) {
955 o << "::cppu::OPropertySetHelper::queryInterface(type));\n";
956 } else {
957 o << "::cppu::PropertySetMixin<\n ";
958 printType(o, options, manager, propertyhelper.replace('.', '/'),
959 0, false);
960 o << " >::queryInterface(\n type));\n";
963 o << "}\n\n";
966 void generateSkeleton(ProgramOptions const & options,
967 TypeManager const & manager,
968 std::vector< OString > const & types)
970 // special handling of calc add-ins
971 if (options.componenttype == 2) {
972 generateCalcAddin(options, manager, types);
973 return;
976 boost::unordered_set< OString, OStringHash > interfaces;
977 boost::unordered_set< OString, OStringHash > services;
978 AttributeInfo properties;
979 AttributeInfo attributes;
980 boost::unordered_set< OString, OStringHash > propinterfaces;
981 bool serviceobject = false;
982 bool supportxcomponent = false;
984 std::vector< OString >::const_iterator iter = types.begin();
985 while (iter != types.end()) {
986 checkType(manager, *iter, interfaces, services, properties);
987 ++iter;
990 if (options.componenttype == 3) {
991 // the Protocolhandler service is mandatory for an protocol handler add-on,
992 // so it is defaulted. The XDispatchProvider provides Dispatch objects for
993 // certain functions and the generated impl object implements XDispatch
994 // directly for simplicity reasons.
995 checkType(manager, "com.sun.star.frame.ProtocolHandler",
996 interfaces, services, properties);
997 checkType(manager, "com.sun.star.frame.XDispatch",
998 interfaces, services, properties);
1001 // check if service object or simple UNO object
1002 if (!services.empty())
1003 serviceobject = true;
1005 OString propertyhelper = checkPropertyHelper(
1006 options, manager, services, interfaces, attributes, propinterfaces);
1008 checkDefaultInterfaces(interfaces, services, propertyhelper);
1010 if (interfaces.size() > 12)
1011 throw CannotDumpException(
1012 "the skeletonmaker supports components with 12 interfaces "
1013 "only (limitation of the UNO implementation helpers)!");
1016 supportxcomponent = checkXComponentSupport(manager, interfaces);
1018 OString compFileName;
1019 OString tmpFileName;
1020 std::ostream* pofs = NULL;
1021 bool standardout = getOutputStream(options, ".cxx",
1022 &pofs, compFileName, tmpFileName);
1024 try {
1025 if (!standardout && options.license) {
1026 printLicenseHeader(*pofs, compFileName);
1029 generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
1030 supportxcomponent);
1032 if (options.componenttype == 3) {
1033 *pofs << "#include \"com/sun/star/frame/XFrame.hpp\"\n";
1036 // namespace
1037 OString nmspace;
1038 short nm = 0;
1040 if (serviceobject) {
1041 nmspace = generateCompHelperDeclaration(*pofs, options.implname);
1043 *pofs <<
1044 "\n\n/// anonymous implementation namespace\nnamespace {\n\n"
1045 "namespace css = ::com::sun::star;\n\n";
1046 } else {
1047 nm = generateNamespace(*pofs, options.implname, false, nmspace);
1048 *pofs << "namespace css = ::com::sun::star;\n\n";
1051 sal_Int32 index = 0;
1052 OString classname(options.implname);
1053 if ((index = classname.lastIndexOf('.')) > 0)
1054 classname = classname.copy(index+1);
1056 OString parentname(
1057 generateClassDefinition(*pofs,
1058 options, manager, classname, interfaces, properties,
1059 attributes, propinterfaces, propertyhelper, supportxcomponent));
1061 generateQueryInterface(*pofs, options, manager, interfaces, parentname,
1062 classname, propertyhelper);
1064 generateMethodBodies(*pofs, options, manager, interfaces, classname,
1065 nmspace, propertyhelper);
1067 if (serviceobject) {
1068 // close namepsace
1069 *pofs << "} // closing anonymous implementation namespace\n\n";
1071 generateCompHelperDefinition(*pofs, options.implname,
1072 classname, services);
1073 generateCompFunctions(*pofs, nmspace);
1074 } else {
1075 // close namepsace
1076 for (short i=0; i < nm; i++)
1077 *pofs << "} ";
1078 *pofs << (nm > 0 ? "// closing namespace\n\n" : "\n");
1081 if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
1082 ((std::ofstream*)pofs)->close();
1083 delete pofs;
1084 OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
1086 } catch(const CannotDumpException& e) {
1088 std::cerr << "ERROR: " << e.m_message.getStr() << "\n";
1089 if ( !standardout ) {
1090 if (pofs && ((std::ofstream*)pofs)->is_open()) {
1091 ((std::ofstream*)pofs)->close();
1092 delete pofs;
1094 // remove existing type file if something goes wrong to ensure
1095 // consistency
1096 if (fileExists(compFileName))
1097 removeTypeFile(compFileName);
1099 // remove tmp file if something goes wrong
1100 removeTypeFile(tmpFileName);
1105 void generateCalcAddin(ProgramOptions const & options,
1106 TypeManager const & manager,
1107 std::vector< OString > const & types)
1109 boost::unordered_set< OString, OStringHash > interfaces;
1110 boost::unordered_set< OString, OStringHash > services;
1111 AttributeInfo properties;
1112 AttributeInfo attributes;
1113 boost::unordered_set< OString, OStringHash > propinterfaces;
1114 bool serviceobject = false;
1115 bool supportxcomponent = false;
1118 std::vector< OString >::const_iterator iter = types.begin();
1119 while (iter != types.end()) {
1120 checkType(manager, *iter, interfaces, services, properties);
1121 ++iter;
1124 OString sAddinService;
1125 if (services.size() != 1) {
1126 throw CannotDumpException(
1127 "for calc add-in components one and only one service type is necessary!"
1128 " Please reference a valid type with the '-t' option.");
1132 // get the one and only add-in service for later use
1133 boost::unordered_set< OString, OStringHash >::const_iterator iter2 = services.begin();
1134 sAddinService = (*iter2).replace('/', '.');
1135 if (sAddinService.equals("com.sun.star.sheet.AddIn")) {
1136 sAddinService = (*(++iter2)).replace('/', '.');
1139 // if backwardcompatible==true the AddIn service needs to be added to the
1140 // suported service list, the necessary intefaces are mapped to the add-in
1141 // configuration. Since OO.org 2.0.4 this is obsolete and the add-in is
1142 // take form the configuration from Calc directly, this simplifies the
1143 // add-in code
1144 if (options.backwardcompatible) {
1145 checkType(manager, "com.sun.star.sheet.AddIn",
1146 interfaces, services, properties);
1147 } else {
1148 // special case for the optional XLocalization interface. It should be
1149 // implemented always. But it is parent of the XAddIn and we need it only
1150 // if backwardcompatible is false.
1151 if (interfaces.find("com.sun.star.lang.XLocalizable") == interfaces.end()) {
1152 interfaces.insert("com.sun.star.lang.XLocalizable");
1156 OString propertyhelper = checkPropertyHelper(
1157 options, manager, services, interfaces, attributes, propinterfaces);
1159 if (!propertyhelper.isEmpty())
1160 std::cerr << "WARNING: interfaces specifying calc add-in functions "
1161 "shouldn't support attributes!\n";
1163 checkDefaultInterfaces(interfaces, services, propertyhelper);
1165 if (interfaces.size() > 12) {
1166 throw CannotDumpException(
1167 "the skeletonmaker supports components with 12 interfaces "
1168 "only (limitation of the UNO implementation helpers)!");
1171 // check if service object or simple UNO object
1172 if (!services.empty())
1173 serviceobject = true;
1175 supportxcomponent = checkXComponentSupport(manager, interfaces);
1176 if (supportxcomponent)
1177 std::cerr << "WARNING: add-ins shouldn't support "
1178 "com.sun.star.uno.XComponent!\n";
1180 OString compFileName;
1181 OString tmpFileName;
1182 std::ostream* pofs = NULL;
1183 bool standardout = getOutputStream(options, ".cxx",
1184 &pofs, compFileName, tmpFileName);
1186 try {
1187 if (!standardout && options.license) {
1188 printLicenseHeader(*pofs, compFileName);
1191 generateIncludes(*pofs, interfaces, propertyhelper, serviceobject,
1192 supportxcomponent);
1194 *pofs <<
1195 "#include \"com/sun/star/beans/PropertyValue.hpp\"\n"
1196 "#include \"com/sun/star/beans/XPropertySet.hpp\"\n"
1197 "#include \"com/sun/star/container/XNameAccess.hpp\"\n"
1198 "#include \"com/sun/star/container/XHierarchicalNameAccess.hpp\"\n\n"
1199 "#include \"rtl/ustrbuf.hxx\"\n\n"
1200 "#include <boost/unordered_map.hpp>\n"
1201 "#include <set>\n";
1203 // namespace
1204 OString nmspace(generateCompHelperDeclaration(*pofs, options.implname));
1206 *pofs <<
1207 "\n\n// anonymous implementation namespace\nnamespace {\n\n"
1208 "namespace css = ::com::sun::star;\n\n";
1210 sal_Int32 index = 0;
1211 OString classname(options.implname);
1212 if ((index = classname.lastIndexOf('.')) > 0) {
1213 classname = classname.copy(index+1);
1216 if (options.backwardcompatible) {
1217 *pofs << "static const char * sADDIN_SERVICENAME = \""
1218 << sAddinService << "\";\n\n";
1219 *pofs << "static const char * sDISPLAYNAME = \"DisplayName\";\n"
1220 "static const char * sDESCRIPTION = \"Description\";\n"
1221 "static const char * sCATEGORY = \"Category\";\n"
1222 "static const char * sCATEGORYDISPLAYNAME = \"CategoryDisplayName\";"
1223 "\n\n";
1226 OString parentname(
1227 generateClassDefinition(*pofs,
1228 options, manager, classname, interfaces, properties,
1229 attributes, propinterfaces, propertyhelper, supportxcomponent));
1231 generateQueryInterface(*pofs, options, manager, interfaces, parentname,
1232 classname, propertyhelper);
1234 generateMethodBodies(*pofs, options, manager, interfaces, classname,
1235 nmspace, propertyhelper);
1237 // close namepsace
1238 *pofs << "} // closing anonymous implementation namespace\n\n";
1240 generateCompHelperDefinition(*pofs, options.implname, classname,
1241 services);
1243 generateCompFunctions(*pofs, nmspace);
1245 if ( !standardout && pofs && ((std::ofstream*)pofs)->is_open()) {
1246 ((std::ofstream*)pofs)->close();
1247 delete pofs;
1248 OSL_VERIFY(makeValidTypeFile(compFileName, tmpFileName, sal_False));
1250 } catch(const CannotDumpException& e) {
1252 std::cerr << "ERROR: " << e.m_message.getStr() << "\n";
1253 if ( !standardout ) {
1254 if (pofs && ((std::ofstream*)pofs)->is_open()) {
1255 ((std::ofstream*)pofs)->close();
1256 delete pofs;
1258 // remove existing type file if something goes wrong to ensure
1259 // consistency
1260 if (fileExists(compFileName))
1261 removeTypeFile(compFileName);
1263 // remove tmp file if something goes wrong
1264 removeTypeFile(tmpFileName);
1272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */