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