update credits
[LibreOffice.git] / codemaker / source / cppumaker / cpputype.cxx
bloba1e17d6777cbee7216072e8b765e446cd13bd7c8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
22 #include <algorithm>
23 #include <cassert>
24 #include <map>
25 #include <set>
26 #include <vector>
28 #include "boost/noncopyable.hpp"
29 #include "rtl/alloc.h"
30 #include "rtl/ref.hxx"
31 #include "rtl/ustrbuf.hxx"
32 #include "rtl/ustring.hxx"
33 #include "rtl/strbuf.hxx"
34 #include "unoidl/unoidl.hxx"
36 #include "codemaker/commoncpp.hxx"
37 #include "codemaker/exceptiontree.hxx"
38 #include "codemaker/generatedtypeset.hxx"
39 #include "codemaker/typemanager.hxx"
40 #include "codemaker/unotype.hxx"
42 #include "cpputype.hxx"
43 #include "cppuoptions.hxx"
44 #include "dependencies.hxx"
45 #include "dumputils.hxx"
46 #include "includes.hxx"
48 namespace {
50 bool isBootstrapType(OUString const & name) {
51 static char const * const names[] = {
52 "com.sun.star.beans.Property",
53 "com.sun.star.beans.PropertyAttribute",
54 "com.sun.star.beans.PropertyChangeEvent",
55 "com.sun.star.beans.PropertyState",
56 "com.sun.star.beans.PropertyValue",
57 "com.sun.star.beans.XFastPropertySet",
58 "com.sun.star.beans.XMultiPropertySet",
59 "com.sun.star.beans.XPropertiesChangeListener",
60 "com.sun.star.beans.XPropertyAccess",
61 "com.sun.star.beans.XPropertyChangeListener",
62 "com.sun.star.beans.XPropertySet",
63 "com.sun.star.beans.XPropertySetInfo",
64 "com.sun.star.beans.XPropertySetOption",
65 "com.sun.star.beans.XVetoableChangeListener",
66 "com.sun.star.bridge.UnoUrlResolver",
67 "com.sun.star.bridge.XUnoUrlResolver",
68 "com.sun.star.connection.SocketPermission",
69 "com.sun.star.container.XElementAccess",
70 "com.sun.star.container.XEnumeration",
71 "com.sun.star.container.XEnumerationAccess",
72 "com.sun.star.container.XHierarchicalNameAccess",
73 "com.sun.star.container.XNameAccess",
74 "com.sun.star.container.XNameContainer",
75 "com.sun.star.container.XNameReplace",
76 "com.sun.star.container.XSet",
77 "com.sun.star.io.FilePermission",
78 "com.sun.star.io.IOException",
79 "com.sun.star.lang.DisposedException",
80 "com.sun.star.lang.EventObject",
81 "com.sun.star.lang.WrappedTargetRuntimeException",
82 "com.sun.star.lang.XComponent",
83 "com.sun.star.lang.XEventListener",
84 "com.sun.star.lang.XInitialization",
85 "com.sun.star.lang.XMultiComponentFactory",
86 "com.sun.star.lang.XMultiServiceFactory",
87 "com.sun.star.lang.XServiceInfo",
88 "com.sun.star.lang.XSingleComponentFactory",
89 "com.sun.star.lang.XSingleServiceFactory",
90 "com.sun.star.lang.XTypeProvider",
91 "com.sun.star.loader.XImplementationLoader",
92 "com.sun.star.reflection.FieldAccessMode",
93 "com.sun.star.reflection.MethodMode",
94 "com.sun.star.reflection.ParamInfo",
95 "com.sun.star.reflection.ParamMode",
96 "com.sun.star.reflection.TypeDescriptionSearchDepth",
97 "com.sun.star.reflection.XArrayTypeDescription",
98 "com.sun.star.reflection.XCompoundTypeDescription",
99 "com.sun.star.reflection.XEnumTypeDescription",
100 "com.sun.star.reflection.XIdlArray",
101 "com.sun.star.reflection.XIdlClass",
102 "com.sun.star.reflection.XIdlField",
103 "com.sun.star.reflection.XIdlField2",
104 "com.sun.star.reflection.XIdlMethod",
105 "com.sun.star.reflection.XIdlReflection",
106 "com.sun.star.reflection.XIndirectTypeDescription",
107 "com.sun.star.reflection.XInterfaceAttributeTypeDescription",
108 "com.sun.star.reflection.XInterfaceAttributeTypeDescription2",
109 "com.sun.star.reflection.XInterfaceMemberTypeDescription",
110 "com.sun.star.reflection.XInterfaceMethodTypeDescription",
111 "com.sun.star.reflection.XInterfaceTypeDescription",
112 "com.sun.star.reflection.XInterfaceTypeDescription2",
113 "com.sun.star.reflection.XMethodParameter",
114 "com.sun.star.reflection.XStructTypeDescription",
115 "com.sun.star.reflection.XTypeDescription",
116 "com.sun.star.reflection.XTypeDescriptionEnumeration",
117 "com.sun.star.reflection.XTypeDescriptionEnumerationAccess",
118 "com.sun.star.reflection.XUnionTypeDescription",
119 "com.sun.star.registry.RegistryKeyType",
120 "com.sun.star.registry.RegistryValueType",
121 "com.sun.star.registry.XImplementationRegistration",
122 "com.sun.star.registry.XRegistryKey",
123 "com.sun.star.registry.XSimpleRegistry",
124 "com.sun.star.security.RuntimePermission",
125 "com.sun.star.security.XAccessControlContext",
126 "com.sun.star.security.XAccessController",
127 "com.sun.star.security.XAction",
128 "com.sun.star.uno.DeploymentException",
129 "com.sun.star.uno.RuntimeException",
130 "com.sun.star.uno.TypeClass",
131 "com.sun.star.uno.Uik",
132 "com.sun.star.uno.XAdapter",
133 "com.sun.star.uno.XAggregation",
134 "com.sun.star.uno.XComponentContext",
135 "com.sun.star.uno.XCurrentContext",
136 "com.sun.star.uno.XInterface",
137 "com.sun.star.uno.XReference",
138 "com.sun.star.uno.XUnloadingPreference",
139 "com.sun.star.uno.XWeak",
140 "com.sun.star.util.XMacroExpander" };
141 // cf. cppuhelper/unotypes/Makefile UNOTYPES (plus missing dependencies)
142 for (std::size_t i = 0; i < SAL_N_ELEMENTS(names); ++i) {
143 if (name.equalsAscii(names[i])) {
144 return true;
147 return false;
150 class CppuType: private boost::noncopyable {
151 public:
152 CppuType(
153 OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
155 virtual ~CppuType() {}
157 void dump(CppuOptions const & options);
159 void dumpFile(
160 OUString const & uri, OUString const & name, bool hpp,
161 CppuOptions const & options);
163 void dumpDependedTypes(
164 codemaker::GeneratedTypeSet & generated, CppuOptions const & options);
166 virtual void dumpHFile(
167 FileStream & out, codemaker::cppumaker::Includes & includes)
168 { dumpHFileContent(out, includes); }
170 virtual void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes) = 0;
172 OUString dumpHeaderDefine(FileStream& o, OUString const & extension);
174 void dumpGetCppuType(FileStream & out);
176 virtual void dumpLightGetCppuType(FileStream & out);
178 virtual void dumpNormalGetCppuType(FileStream &)
179 { assert(false); } // this cannot happen
181 virtual void dumpComprehensiveGetCppuType(FileStream &)
182 { assert(false); } // this cannot happen
184 void dumpType(
185 FileStream & out, OUString const & name, bool isConst = false,
186 bool isRef = false, bool native = false, bool cppuUnoType = false)
187 const;
189 OUString getTypeClass(OUString const & name, bool cStyle = false);
191 void dumpCppuGetType(
192 FileStream & out, OUString const & name, OUString const * ownName = 0);
194 sal_uInt32 getInheritedMemberCount();
196 void inc(sal_Int32 num=4);
197 void dec(sal_Int32 num=4);
198 OUString indent() const;
199 protected:
200 virtual sal_uInt32 checkInheritedMemberCount() const
201 { assert(false); return 0; } // this cannot happen
203 bool passByReference(OUString const & name) const;
205 OUString resolveOuterTypedefs(OUString const & name) const;
207 OUString resolveAllTypedefs(OUString const & name) const;
209 codemaker::cpp::IdentifierTranslationMode isGlobal() const;
211 virtual void dumpDeclaration(FileStream &)
212 { assert(false); } // this cannot happen
214 virtual void dumpFiles(OUString const & uri, CppuOptions const & options);
216 virtual void addLightGetCppuTypeIncludes(
217 codemaker::cppumaker::Includes & includes) const;
219 virtual void addNormalGetCppuTypeIncludes(
220 codemaker::cppumaker::Includes & includes) const;
222 virtual void addComprehensiveGetCppuTypeIncludes(
223 codemaker::cppumaker::Includes & includes) const;
225 virtual bool isPolymorphic() const;
227 virtual void dumpTemplateHead(FileStream &) const {}
229 virtual void dumpTemplateParameters(FileStream &) const {}
231 void dumpGetCppuTypePreamble(FileStream & out);
233 void dumpGetCppuTypePostamble(FileStream & out);
235 void addDefaultHIncludes(codemaker::cppumaker::Includes & includes) const;
236 void addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes) const;
238 void dumpInitializer(
239 FileStream & out, bool parameterized, OUString const & name) const;
241 void dumpHFileContent(
242 FileStream & out, codemaker::cppumaker::Includes & includes);
244 protected:
245 sal_uInt32 m_inheritedMemberCount;
247 bool m_cppuTypeLeak;
248 bool m_cppuTypeDynamic;
249 sal_Int32 m_indentLength;
250 OUString name_;
251 OUString id_;
252 rtl::Reference< TypeManager > m_typeMgr;
253 codemaker::cppumaker::Dependencies m_dependencies;
255 private:
256 void addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
257 const;
260 CppuType::CppuType(
261 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
262 m_inheritedMemberCount(0)
263 , m_cppuTypeLeak(false)
264 , m_cppuTypeDynamic(true)
265 , m_indentLength(0)
266 , name_(name)
267 , id_(name_.copy(name_.lastIndexOf('.') + 1))
268 , m_typeMgr(typeMgr)
269 , m_dependencies(typeMgr, name_)
272 void CppuType::addGetCppuTypeIncludes(codemaker::cppumaker::Includes & includes)
273 const
275 if (name_ == "com.sun.star.uno.XInterface"
276 || name_ == "com.sun.star.uno.Exception")
278 includes.addType();
279 includes.addCppuUnotypeHxx();
280 includes.addSalTypesH();
281 includes.addTypelibTypeclassH();
282 includes.addTypelibTypedescriptionH();
283 } else if (m_cppuTypeLeak) {
284 addLightGetCppuTypeIncludes(includes);
285 } else if (m_cppuTypeDynamic) {
286 addNormalGetCppuTypeIncludes(includes);
287 } else {
288 addComprehensiveGetCppuTypeIncludes(includes);
292 void CppuType::dumpFiles(OUString const & uri, CppuOptions const & options) {
293 dumpFile(uri, name_, false, options);
294 dumpFile(uri, name_, true, options);
297 void CppuType::addLightGetCppuTypeIncludes(
298 codemaker::cppumaker::Includes & includes) const
300 //TODO: Determine what is really needed, instead of relying on
301 // addDefaultHxxIncludes
302 includes.addCppuUnotypeHxx();
305 void CppuType::addNormalGetCppuTypeIncludes(
306 codemaker::cppumaker::Includes & includes) const
308 //TODO: Determine what is really needed, instead of relying on
309 // addDefaultHxxIncludes
310 includes.addCppuUnotypeHxx();
313 void CppuType::addComprehensiveGetCppuTypeIncludes(
314 codemaker::cppumaker::Includes & includes) const
316 //TODO: Determine what is really needed, instead of relying on
317 // addDefaultHxxIncludes
318 includes.addCppuUnotypeHxx();
321 bool CppuType::isPolymorphic() const { return false; }
323 void CppuType::dumpGetCppuTypePreamble(FileStream & out) {
324 if (isPolymorphic()) {
325 out << "namespace cppu {\n\n";
326 dumpTemplateHead(out);
327 out << "class UnoType< ";
328 dumpType(out, name_);
329 dumpTemplateParameters(out);
330 out << " > {\npublic:\n";
331 inc();
332 out << indent()
333 << "static inline ::com::sun::star::uno::Type const & get() {\n";
334 } else {
335 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
336 out << "\n\n";
338 out << ("inline ::com::sun::star::uno::Type const &"
339 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
340 dumpType(out, name_, false, false, true);
341 out << " const *) {\n";
343 inc();
346 void CppuType::dumpGetCppuTypePostamble(FileStream & out) {
347 dec();
348 if (isPolymorphic()) {
349 out << indent() << "}\n\nprivate:\n"
350 << indent() << "UnoType(UnoType &); // not defined\n"
351 << indent() << "~UnoType(); // not defined\n"
352 << indent()
353 << "void operator =(UnoType); // not defined\n};\n\n}\n\n";
354 } else {
355 out << "}\n\n";
356 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
357 out << "\n\n";
360 dumpTemplateHead(out);
361 out << ("inline ::com::sun::star::uno::Type const & SAL_CALL"
362 " getCppuType(SAL_UNUSED_PARAMETER ");
363 dumpType(out, name_);
364 dumpTemplateParameters(out);
365 out << " const *) SAL_THROW(()) {\n";
366 inc();
367 out << indent() << "return ::cppu::UnoType< ";
368 dumpType(out, name_);
369 dumpTemplateParameters(out);
370 out << " >::get();\n";
371 dec();
372 out << indent() << "}\n";
375 void CppuType::dump(CppuOptions const & options) {
376 if (isBootstrapType(name_)) {
377 m_cppuTypeDynamic = false;
378 } else {
379 // -CS was used as an undocumented option to generate static getCppuType
380 // functions; since the introduction of cppu::UnoType this no longer is
381 // meaningful (getCppuType is just a forward to cppu::UnoType::get now),
382 // and -CS is handled the same way as -C now:
383 if (options.isValid("-L"))
384 m_cppuTypeLeak = true;
385 if (options.isValid("-C") || options.isValid("-CS"))
386 m_cppuTypeDynamic = false;
388 dumpFiles(
389 options.isValid("-O") ? b2u(options.getOption("-O")) : "", options);
392 void CppuType::dumpFile(
393 OUString const & uri, OUString const & name, bool hpp,
394 CppuOptions const & options)
396 OUString fileUri(
397 b2u(createFileNameFromType(
398 u2b(uri), u2b(name), hpp ? ".hpp" : ".hdl")));
399 if (fileUri.isEmpty()) {
400 throw CannotDumpException("empty target URI for entity " + name);
402 bool exists = fileExists(u2b(fileUri));
403 if (exists && options.isValid("-G")) {
404 return;
406 FileStream out;
407 out.createTempFile(getTempDir(u2b(fileUri)));
408 OUString tmpUri(b2u(out.getName()));
409 if(!out.isValid()) {
410 throw CannotDumpException("cannot open " + tmpUri + " for writing");
412 codemaker::cppumaker::Includes includes(m_typeMgr, m_dependencies, hpp);
413 try {
414 if (hpp) {
415 addGetCppuTypeIncludes(includes);
416 dumpHxxFile(out, includes);
417 } else {
418 dumpHFile(out, includes);
420 } catch (...) {
421 out.close();
422 // Remove existing type file if something goes wrong to ensure
423 // consistency:
424 if (fileExists(u2b(fileUri))) {
425 removeTypeFile(u2b(fileUri));
427 removeTypeFile(u2b(tmpUri));
428 throw;
430 out.close();
431 makeValidTypeFile(
432 u2b(fileUri), u2b(tmpUri), exists && options.isValid("-Gc"));
435 void CppuType::dumpDependedTypes(
436 codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
438 codemaker::cppumaker::Dependencies::Map const & map
439 = m_dependencies.getMap();
440 for (codemaker::cppumaker::Dependencies::Map::const_iterator i(map.begin());
441 i != map.end(); ++i)
443 produce(i->first, m_typeMgr, generated, options);
447 OUString CppuType::dumpHeaderDefine(
448 FileStream & out, OUString const & extension)
450 OUString def(
451 "INCLUDED_" + name_.replace('.', '_').toAsciiUpperCase() + "_"
452 + extension);
453 out << "#ifndef " << def << "\n#define " << def << "\n";
454 return def;
457 void CppuType::addDefaultHIncludes(codemaker::cppumaker::Includes & includes)
458 const
460 //TODO: Only include what is really needed
461 includes.addCppuMacrosHxx();
462 if (m_typeMgr->getSort(name_)
463 == codemaker::UnoType::SORT_INTERFACE_TYPE)
465 includes.addReference();
469 void CppuType::addDefaultHxxIncludes(codemaker::cppumaker::Includes & includes)
470 const
472 //TODO: Only include what is really needed
473 includes.addRtlInstanceHxx();
474 includes.addOslMutexHxx();
475 includes.addType();
476 if (m_typeMgr->getSort(name_)
477 == codemaker::UnoType::SORT_INTERFACE_TYPE)
479 includes.addReference();
483 void CppuType::dumpInitializer(
484 FileStream & out, bool parameterized, OUString const & name) const
486 out << "(";
487 if (!parameterized) {
488 sal_Int32 k;
489 std::vector< OString > args;
490 OUString n(
491 b2u(codemaker::UnoType::decompose(
492 u2b(resolveAllTypedefs(name)), &k, &args)));
493 if (k == 0) {
494 rtl::Reference< unoidl::Entity > ent;
495 switch (m_typeMgr->getSort(n, &ent)) {
496 case codemaker::UnoType::SORT_BOOLEAN:
497 out << "false";
498 break;
499 case codemaker::UnoType::SORT_BYTE:
500 case codemaker::UnoType::SORT_SHORT:
501 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
502 case codemaker::UnoType::SORT_LONG:
503 case codemaker::UnoType::SORT_UNSIGNED_LONG:
504 case codemaker::UnoType::SORT_HYPER:
505 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
506 case codemaker::UnoType::SORT_FLOAT:
507 case codemaker::UnoType::SORT_DOUBLE:
508 case codemaker::UnoType::SORT_CHAR:
509 out << "0";
510 break;
511 case codemaker::UnoType::SORT_ENUM_TYPE:
512 out << codemaker::cpp::scopedCppName(u2b(n)) << "_"
513 << (dynamic_cast< unoidl::EnumTypeEntity * >(ent.get())->
514 getMembers()[0].name);
515 break;
516 case codemaker::UnoType::SORT_STRING:
517 case codemaker::UnoType::SORT_TYPE:
518 case codemaker::UnoType::SORT_ANY:
519 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
520 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
521 case codemaker::UnoType::SORT_INTERFACE_TYPE:
522 break;
523 default:
524 throw CannotDumpException(
525 "unexpected entity \"" + name
526 + "\" in call to CppuType::dumpInitializer");
530 out << ")";
533 void CppuType::dumpHFileContent(
534 FileStream & out, codemaker::cppumaker::Includes & includes)
536 addDefaultHIncludes(includes);
537 dumpHeaderDefine(out, "HDL");
538 out << "\n";
539 includes.dump(out, 0);
540 out << ("\nnamespace com { namespace sun { namespace star { namespace uno"
541 " { class Type; } } } }\n\n");
542 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
543 out << "\n";
545 dumpDeclaration(out);
546 if (!(name_ == "com.sun.star.uno.XInterface"
547 || name_ == "com.sun.star.uno.Exception"
548 || isPolymorphic()))
550 out << "\n" << indent()
551 << ("inline ::com::sun::star::uno::Type const &"
552 " cppu_detail_getUnoType(SAL_UNUSED_PARAMETER ");
553 dumpType(out, name_, false, false, true);
554 out << " const *);\n";
556 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
557 out << "\n";
559 out << "\n";
560 dumpTemplateHead(out);
561 out << "inline ::com::sun::star::uno::Type const & SAL_CALL getCppuType(";
562 dumpType(out, name_, true);
563 dumpTemplateParameters(out);
564 out << " *) SAL_THROW(());\n\n#endif\n";
567 void CppuType::dumpGetCppuType(FileStream & out) {
568 if (name_ == "com.sun.star.uno.XInterface") {
569 out << indent()
570 << ("inline ::com::sun::star::uno::Type const & SAL_CALL"
571 " getCppuType(SAL_UNUSED_PARAMETER ");
572 dumpType(out, name_, true);
573 out << " *) SAL_THROW(()) {\n";
574 inc();
575 out << indent()
576 << ("return ::cppu::UnoType< ::com::sun::star::uno::XInterface"
577 " >::get();\n");
578 dec();
579 out << indent() << "}\n";
580 } else if (name_ == "com.sun.star.uno.Exception") {
581 out << indent()
582 << ("inline ::com::sun::star::uno::Type const & SAL_CALL"
583 " getCppuType(SAL_UNUSED_PARAMETER ");
584 dumpType(out, name_, true);
585 out << " *) SAL_THROW(()) {\n";
586 inc();
587 out << indent()
588 << ("return ::cppu::UnoType< ::com::sun::star::uno::Exception"
589 " >::get();\n");
590 dec();
591 out << indent() << "}\n";
592 } else if (m_cppuTypeLeak) {
593 dumpLightGetCppuType(out);
594 } else if (m_cppuTypeDynamic) {
595 dumpNormalGetCppuType(out);
596 } else {
597 dumpComprehensiveGetCppuType(out);
601 void CppuType::dumpLightGetCppuType(FileStream & out) {
602 dumpGetCppuTypePreamble(out);
603 out << indent()
604 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
605 << indent() << "if ( !the_type )\n" << indent() << "{\n";
606 inc();
607 out << indent() << "typelib_static_type_init( &the_type, "
608 << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
609 dec();
610 out << indent() << "}\n" << indent()
611 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
612 " &the_type );\n");
613 dumpGetCppuTypePostamble(out);
616 codemaker::cpp::IdentifierTranslationMode CppuType::isGlobal() const {
617 return name_.indexOf('.') == -1
618 ? codemaker::cpp::ITM_GLOBAL : codemaker::cpp::ITM_NONGLOBAL;
621 sal_uInt32 CppuType::getInheritedMemberCount()
623 if (m_inheritedMemberCount == 0)
625 m_inheritedMemberCount = checkInheritedMemberCount();
628 return m_inheritedMemberCount;
631 OUString CppuType::getTypeClass(OUString const & name, bool cStyle) {
632 rtl::Reference< unoidl::Entity > ent;
633 switch (m_typeMgr->getSort(name, &ent)) {
634 case codemaker::UnoType::SORT_VOID:
635 return cStyle
636 ? OUString("typelib_TypeClass_VOID")
637 : OUString("::com::sun::star::uno::TypeClass_VOID");
638 case codemaker::UnoType::SORT_BOOLEAN:
639 return cStyle
640 ? OUString("typelib_TypeClass_BOOLEAN")
641 : OUString("::com::sun::star::uno::TypeClass_BOOLEAN");
642 case codemaker::UnoType::SORT_BYTE:
643 return cStyle
644 ? OUString("typelib_TypeClass_BYTE")
645 : OUString("::com::sun::star::uno::TypeClass_BYTE");
646 case codemaker::UnoType::SORT_SHORT:
647 return cStyle
648 ? OUString("typelib_TypeClass_SHORT")
649 : OUString("::com::sun::star::uno::TypeClass_SHORT");
650 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
651 return cStyle
652 ? OUString("typelib_TypeClass_UNSIGNED_SHORT")
653 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_SHORT");
654 case codemaker::UnoType::SORT_LONG:
655 return cStyle
656 ? OUString("typelib_TypeClass_LONG")
657 : OUString("::com::sun::star::uno::TypeClass_LONG");
658 case codemaker::UnoType::SORT_UNSIGNED_LONG:
659 return cStyle
660 ? OUString("typelib_TypeClass_UNSIGNED_LONG")
661 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_LONG");
662 case codemaker::UnoType::SORT_HYPER:
663 return cStyle
664 ? OUString("typelib_TypeClass_HYPER")
665 : OUString("::com::sun::star::uno::TypeClass_HYPER");
666 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
667 return cStyle
668 ? OUString("typelib_TypeClass_UNSIGNED_HYPER")
669 : OUString("::com::sun::star::uno::TypeClass_UNSIGNED_HYPER");
670 case codemaker::UnoType::SORT_FLOAT:
671 return cStyle
672 ? OUString("typelib_TypeClass_FLOAT")
673 : OUString("::com::sun::star::uno::TypeClass_FLOAT");
674 case codemaker::UnoType::SORT_DOUBLE:
675 return cStyle
676 ? OUString("typelib_TypeClass_DOUBLE")
677 : OUString("::com::sun::star::uno::TypeClass_DOUBLE");
678 case codemaker::UnoType::SORT_CHAR:
679 return cStyle
680 ? OUString("typelib_TypeClass_CHAR")
681 : OUString("::com::sun::star::uno::TypeClass_CHAR");
682 case codemaker::UnoType::SORT_STRING:
683 return cStyle
684 ? OUString("typelib_TypeClass_STRING")
685 : OUString("::com::sun::star::uno::TypeClass_STRING");
686 case codemaker::UnoType::SORT_TYPE:
687 return cStyle
688 ? OUString("typelib_TypeClass_TYPE")
689 : OUString("::com::sun::star::uno::TypeClass_TYPE");
690 case codemaker::UnoType::SORT_ANY:
691 return cStyle
692 ? OUString("typelib_TypeClass_ANY")
693 : OUString("::com::sun::star::uno::TypeClass_ANY");
694 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
695 return cStyle
696 ? OUString("typelib_TypeClass_SEQUENCE")
697 : OUString("::com::sun::star::uno::TypeClass_SEQUENCE");
698 case codemaker::UnoType::SORT_ENUM_TYPE:
699 return cStyle
700 ? OUString("typelib_TypeClass_ENUM")
701 : OUString("::com::sun::star::uno::TypeClass_ENUM");
702 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
703 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
704 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
705 return cStyle
706 ? OUString("typelib_TypeClass_STRUCT")
707 : OUString("::com::sun::star::uno::TypeClass_STRUCT");
708 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
709 return cStyle
710 ? OUString("typelib_TypeClass_EXCEPTION")
711 : OUString("::com::sun::star::uno::TypeClass_EXCEPTION");
712 case codemaker::UnoType::SORT_INTERFACE_TYPE:
713 return cStyle
714 ? OUString("typelib_TypeClass_INTERFACE")
715 : OUString("::com::sun::star::uno::TypeClass_INTERFACE");
716 case codemaker::UnoType::SORT_TYPEDEF:
717 return getTypeClass(
718 dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType(),
719 cStyle);
720 default:
721 for (;;) { std::abort(); }
725 void CppuType::dumpType(
726 FileStream & out, OUString const & name, bool isConst, bool isRef,
727 bool native, bool cppuUnoType) const
729 sal_Int32 k;
730 std::vector< OString > args;
731 OUString n(
732 b2u(codemaker::UnoType::decompose(
733 u2b(resolveAllTypedefs(name)), &k, &args)));
734 if (isConst) {
735 out << "const ";
737 for (sal_Int32 i = 0; i != k; ++i) {
738 out << (cppuUnoType
739 ? "::cppu::UnoSequenceType" : "::com::sun::star::uno::Sequence")
740 << "< ";
742 switch (m_typeMgr->getSort(n)) {
743 case codemaker::UnoType::SORT_VOID:
744 out << "void";
745 break;
746 case codemaker::UnoType::SORT_BOOLEAN:
747 out << "::sal_Bool";
748 break;
749 case codemaker::UnoType::SORT_BYTE:
750 out << "::sal_Int8";
751 break;
752 case codemaker::UnoType::SORT_SHORT:
753 out << "::sal_Int16";
754 break;
755 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
756 out << (cppuUnoType ? "::cppu::UnoUnsignedShortType" : "::sal_uInt16");
757 break;
758 case codemaker::UnoType::SORT_LONG:
759 out << "::sal_Int32";
760 break;
761 case codemaker::UnoType::SORT_UNSIGNED_LONG:
762 out << "::sal_uInt32";
763 break;
764 case codemaker::UnoType::SORT_HYPER:
765 out << "::sal_Int64";
766 break;
767 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
768 out << "::sal_uInt64";
769 break;
770 case codemaker::UnoType::SORT_FLOAT:
771 out << "float";
772 break;
773 case codemaker::UnoType::SORT_DOUBLE:
774 out << "double";
775 break;
776 case codemaker::UnoType::SORT_CHAR:
777 out << (cppuUnoType ? "::cppu::UnoCharType" : "::sal_Unicode");
778 break;
779 case codemaker::UnoType::SORT_STRING:
780 out << "::rtl::OUString";
781 break;
782 case codemaker::UnoType::SORT_TYPE:
783 out << "::com::sun::star::uno::Type";
784 break;
785 case codemaker::UnoType::SORT_ANY:
786 out << "::com::sun::star::uno::Any";
787 break;
788 case codemaker::UnoType::SORT_ENUM_TYPE:
789 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
790 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
791 out << codemaker::cpp::scopedCppName(u2b(n));
792 break;
793 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
794 out << codemaker::cpp::scopedCppName(u2b(n));
795 if (!args.empty()) {
796 out << "< ";
797 for (std::vector< OString >::iterator i(args.begin());
798 i != args.end(); ++i)
800 if (i != args.begin()) {
801 out << ", ";
803 dumpType(out, b2u(*i));
805 out << " >";
807 break;
808 case codemaker::UnoType::SORT_INTERFACE_TYPE:
809 if (!native) {
810 out << "::com::sun::star::uno::Reference< ";
812 out << codemaker::cpp::scopedCppName(u2b(n));
813 if (!native) {
814 out << " >";
816 break;
817 default:
818 throw CannotDumpException(
819 "unexpected entity \"" + name + "\" in call to CppuType::dumpType");
821 for (sal_Int32 i = 0; i != k; ++i) {
822 out << " >";
824 if (isRef) {
825 out << "&";
829 void CppuType::dumpCppuGetType(
830 FileStream & out, OUString const & name, OUString const * ownName)
832 //TODO: What are these calls good for?
833 OUString nucleus;
834 sal_Int32 rank;
835 codemaker::UnoType::Sort sort = m_typeMgr->decompose(
836 name, true, &nucleus, &rank, 0, 0);
837 switch (rank == 0 ? sort : codemaker::UnoType::SORT_SEQUENCE_TYPE) {
838 case codemaker::UnoType::SORT_VOID:
839 case codemaker::UnoType::SORT_BOOLEAN:
840 case codemaker::UnoType::SORT_BYTE:
841 case codemaker::UnoType::SORT_SHORT:
842 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
843 case codemaker::UnoType::SORT_LONG:
844 case codemaker::UnoType::SORT_UNSIGNED_LONG:
845 case codemaker::UnoType::SORT_HYPER:
846 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
847 case codemaker::UnoType::SORT_FLOAT:
848 case codemaker::UnoType::SORT_DOUBLE:
849 case codemaker::UnoType::SORT_CHAR:
850 case codemaker::UnoType::SORT_STRING:
851 case codemaker::UnoType::SORT_TYPE:
852 case codemaker::UnoType::SORT_ANY:
853 break;
854 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
855 case codemaker::UnoType::SORT_ENUM_TYPE:
856 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
857 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
858 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
859 case codemaker::UnoType::SORT_INTERFACE_TYPE:
860 // Take care of recursion like struct S { sequence<S> x; }:
861 if (ownName == 0 || nucleus != *ownName) {
862 out << indent() << "::cppu::UnoType< ";
863 dumpType(out, name, false, false, false, true);
864 out << " >::get();\n";
866 break;
867 case codemaker::UnoType::SORT_TYPEDEF:
868 assert(false); // this cannot happen
869 // fall through
870 default:
871 throw CannotDumpException(
872 "unexpected entity \"" + name
873 + "\" in call to CppuType::dumpCppuGetType");
877 bool CppuType::passByReference(OUString const & name) const {
878 switch (m_typeMgr->getSort(resolveOuterTypedefs(name))) {
879 case codemaker::UnoType::SORT_BOOLEAN:
880 case codemaker::UnoType::SORT_BYTE:
881 case codemaker::UnoType::SORT_SHORT:
882 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
883 case codemaker::UnoType::SORT_LONG:
884 case codemaker::UnoType::SORT_UNSIGNED_LONG:
885 case codemaker::UnoType::SORT_HYPER:
886 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
887 case codemaker::UnoType::SORT_FLOAT:
888 case codemaker::UnoType::SORT_DOUBLE:
889 case codemaker::UnoType::SORT_CHAR:
890 case codemaker::UnoType::SORT_ENUM_TYPE:
891 return false;
892 case codemaker::UnoType::SORT_STRING:
893 case codemaker::UnoType::SORT_TYPE:
894 case codemaker::UnoType::SORT_ANY:
895 case codemaker::UnoType::SORT_SEQUENCE_TYPE:
896 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
897 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
898 case codemaker::UnoType::SORT_INTERFACE_TYPE:
899 return true;
900 default:
901 throw CannotDumpException(
902 "unexpected entity \"" + name
903 + "\" in call to CppuType::passByReference");
907 OUString CppuType::resolveOuterTypedefs(OUString const & name) const {
908 for (OUString n(name);;) {
909 rtl::Reference< unoidl::Entity > ent;
910 if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
911 return n;
913 n = dynamic_cast< unoidl::TypedefEntity * >(ent.get())->getType();
917 OUString CppuType::resolveAllTypedefs(OUString const & name) const {
918 sal_Int32 k1;
919 OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k1)));
920 for (;;) {
921 rtl::Reference< unoidl::Entity > ent;
922 if (m_typeMgr->getSort(n, &ent) != codemaker::UnoType::SORT_TYPEDEF) {
923 break;
925 sal_Int32 k2;
926 n = b2u(
927 codemaker::UnoType::decompose(
928 u2b(dynamic_cast< unoidl::TypedefEntity * >(ent.get())->
929 getType()),
930 &k2));
931 k1 += k2; //TODO: overflow
933 OUStringBuffer b;
934 for (sal_Int32 i = 0; i != k1; ++i) {
935 b.append("[]");
937 b.append(n);
938 return b.makeStringAndClear();
941 void CppuType::inc(sal_Int32 num)
943 m_indentLength += num;
946 void CppuType::dec(sal_Int32 num)
948 m_indentLength = std::max< sal_Int32 >(m_indentLength - num, 0);
951 OUString CppuType::indent() const {
952 OUStringBuffer buf(m_indentLength);
953 for (sal_Int32 i = 0; i != m_indentLength; ++i) {
954 buf.append(' ');
956 return buf.makeStringAndClear();
959 bool isDeprecated(std::vector< OUString > const & annotations) {
960 for (std::vector< OUString >::const_iterator i(annotations.begin());
961 i != annotations.end(); ++i)
963 if (*i == "deprecated") {
964 return true;
967 return false;
970 void dumpDeprecation(FileStream & out, bool deprecated) {
971 if (deprecated) {
972 out << "SAL_DEPRECATED_INTERNAL(\"marked @deprecated in UNOIDL\") ";
976 class BaseOffset: private boost::noncopyable {
977 public:
978 BaseOffset(
979 rtl::Reference< TypeManager > const & manager,
980 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
981 manager_(manager), offset_(0) { calculateBases(entity); }
983 sal_Int32 get() const { return offset_; }
985 private:
986 void calculateBases(
987 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity);
989 rtl::Reference< TypeManager > manager_;
990 std::set< OUString > set_;
991 sal_Int32 offset_;
994 void BaseOffset::calculateBases(
995 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity)
997 assert(entity.is());
998 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
999 entity->getDirectMandatoryBases().begin());
1000 i != entity->getDirectMandatoryBases().end(); ++i)
1002 if (set_.insert(i->name).second) {
1003 rtl::Reference< unoidl::Entity > ent;
1004 codemaker::UnoType::Sort sort = manager_->getSort(i->name, &ent);
1005 if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE) {
1006 throw CannotDumpException(
1007 "interface type base " + i->name
1008 + " is not an interface type");
1010 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
1011 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
1012 assert(ent2.is());
1013 calculateBases(ent2);
1014 offset_ += ent2->getDirectAttributes().size()
1015 + ent2->getDirectMethods().size(); //TODO: overflow
1020 class InterfaceType: public CppuType {
1021 public:
1022 InterfaceType(
1023 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
1024 OUString const & name, rtl::Reference< TypeManager > const & typeMgr);
1026 virtual void dumpDeclaration(FileStream& o);
1027 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes);
1029 void dumpAttributes(FileStream& o);
1030 void dumpMethods(FileStream& o);
1031 void dumpNormalGetCppuType(FileStream& o);
1032 void dumpComprehensiveGetCppuType(FileStream& o);
1033 void dumpCppuAttributeRefs(FileStream& o, sal_uInt32& index);
1034 void dumpCppuMethodRefs(FileStream& o, sal_uInt32& index);
1035 void dumpCppuAttributes(FileStream& o, sal_uInt32& index);
1036 void dumpCppuMethods(FileStream& o, sal_uInt32& index);
1037 void dumpAttributesCppuDecl(FileStream & out, std::set< OUString > * seen);
1038 void dumpMethodsCppuDecl(FileStream & out, std::set< OUString > * seen);
1040 protected:
1041 virtual void addComprehensiveGetCppuTypeIncludes(
1042 codemaker::cppumaker::Includes & includes) const;
1044 virtual sal_uInt32 checkInheritedMemberCount() const
1045 { return BaseOffset(m_typeMgr, entity_).get(); }
1047 sal_uInt32 m_inheritedMemberCount;
1048 bool m_isDeprecated;
1050 private:
1051 void dumpExceptionSpecification(
1052 FileStream & out, std::vector< OUString > const & exceptions,
1053 bool runtimeException);
1055 void dumpExceptionTypeName(
1056 FileStream & out, OUString const & prefix, sal_uInt32 index,
1057 OUString const & name);
1059 sal_Int32 dumpExceptionTypeNames(
1060 FileStream & out, OUString const & prefix,
1061 std::vector< OUString > const & exceptions, bool runtimeException);
1063 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
1066 InterfaceType::InterfaceType(
1067 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity,
1068 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1069 CppuType(name, typeMgr), entity_(entity)
1071 assert(entity.is());
1072 m_inheritedMemberCount = 0;
1073 m_isDeprecated = isDeprecated(entity->getAnnotations());
1076 void InterfaceType::dumpDeclaration(FileStream & out) {
1077 out << "\nclass SAL_NO_VTABLE " << id_;
1078 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1079 entity_->getDirectMandatoryBases().begin());
1080 i != entity_->getDirectMandatoryBases().end(); ++i)
1082 out << (i == entity_->getDirectMandatoryBases().begin() ? " :" : ",")
1083 << " public " << codemaker::cpp::scopedCppName(u2b(i->name));
1085 out << "\n{\npublic:\n";
1086 inc();
1087 dumpAttributes(out);
1088 dumpMethods(out);
1089 out << "\n" << indent()
1090 << ("static inline ::com::sun::star::uno::Type const & SAL_CALL"
1091 " static_type(void * = 0);\n\n");
1092 dec();
1093 out << "protected:\n";
1094 inc();
1095 out << indent() << "~" << id_
1096 << ("() throw () {} // avoid warnings about virtual members and"
1097 " non-virtual dtor\n");
1098 dec();
1099 out << "};\n\n";
1102 void InterfaceType::dumpHxxFile(
1103 FileStream & out, codemaker::cppumaker::Includes & includes)
1105 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1106 out << "\n";
1107 addDefaultHxxIncludes(includes);
1108 includes.dump(out, &name_);
1109 out << "\n";
1110 dumpGetCppuType(out);
1111 out << "\n::com::sun::star::uno::Type const & "
1112 << codemaker::cpp::scopedCppName(u2b(name_))
1113 << "::static_type(SAL_UNUSED_PARAMETER void *) {\n";
1114 inc();
1115 out << indent() << "return ::getCppuType(static_cast< ";
1116 dumpType(out, name_);
1117 out << " * >(0));\n";
1118 dec();
1119 out << "}\n\n#endif // "<< headerDefine << "\n";
1122 void InterfaceType::dumpAttributes(FileStream & out) {
1123 if (!entity_->getDirectAttributes().empty()) {
1124 out << "\n" << indent() << "// Attributes\n";
1126 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1127 i(entity_->getDirectAttributes().begin());
1128 i != entity_->getDirectAttributes().end(); ++i)
1130 bool depr = m_isDeprecated || isDeprecated(i->annotations);
1131 out << indent();
1132 dumpDeprecation(out, depr);
1133 out << "virtual ";
1134 dumpType(out, i->type);
1135 out << " SAL_CALL get" << i->name << "()";
1136 dumpExceptionSpecification(out, i->getExceptions, true);
1137 out << " = 0;\n";
1138 if (!i->readOnly) {
1139 bool byRef = passByReference(i->type);
1140 out << indent();
1141 dumpDeprecation(out, depr);
1142 out << "virtual void SAL_CALL set" << i->name << "( ";
1143 dumpType(out, i->type, byRef, byRef);
1144 out << " _" << i->name.toAsciiLowerCase() << " )";
1145 dumpExceptionSpecification(out, i->setExceptions, true);
1146 out << " = 0;\n";
1151 void InterfaceType::dumpMethods(FileStream & out) {
1152 if (!entity_->getDirectMethods().empty()) {
1153 out << "\n" << indent() << "// Methods\n";
1155 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1156 entity_->getDirectMethods().begin());
1157 i != entity_->getDirectMethods().end(); ++i)
1159 out << indent();
1160 dumpDeprecation(out, m_isDeprecated || isDeprecated(i->annotations));
1161 out << "virtual ";
1162 dumpType(out, i->returnType);
1163 out << " SAL_CALL " << i->name << "(";
1164 if (i->parameters.empty()) {
1165 out << ")";
1166 } else {
1167 out << " ";
1168 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1169 const_iterator j(i->parameters.begin());
1170 j != i->parameters.end();)
1172 bool isConst;
1173 bool isRef;
1174 if (j->direction
1175 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1176 DIRECTION_IN))
1178 isConst = passByReference(j->type);
1179 isRef = isConst;
1180 } else {
1181 isConst = false;
1182 isRef = true;
1184 dumpType(out, j->type, isConst, isRef);
1185 out << " " << j->name;
1186 ++j;
1187 if (j != i->parameters.end()) {
1188 out << ", ";
1191 out << " )";
1193 dumpExceptionSpecification(
1194 out, i->exceptions, i->name != "acquire" && i->name != "release");
1195 out << " = 0;\n";
1199 void InterfaceType::dumpNormalGetCppuType(FileStream & out) {
1200 dumpGetCppuTypePreamble(out);
1201 out << indent()
1202 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
1203 << indent() << "if ( !the_type )\n" << indent() << "{\n";
1204 inc();
1205 std::vector< unoidl::AnnotatedReference >::size_type bases(
1206 entity_->getDirectMandatoryBases().size());
1207 if (bases == 1
1208 && (entity_->getDirectMandatoryBases()[0].name
1209 == "com.sun.star.uno.XInterface"))
1211 bases = 0;
1213 if (bases != 0) {
1214 out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1215 << entity_->getDirectMandatoryBases().size() << "];\n";
1216 std::vector< unoidl::AnnotatedReference >::size_type n = 0;
1217 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1218 entity_->getDirectMandatoryBases().begin());
1219 i != entity_->getDirectMandatoryBases().end(); ++i)
1221 out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
1222 dumpType(out, i->name, true, false, false, true);
1223 out << " >::get().getTypeLibType();\n";
1226 out << indent() << "typelib_static_mi_interface_type_init( &the_type, \""
1227 << name_ << "\", " << bases << ", "
1228 << (bases == 0 ? "0" : "aSuperTypes") << " );\n";
1229 dec();
1230 out << indent() << "}\n" << indent()
1231 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
1232 " &the_type );\n");
1233 dumpGetCppuTypePostamble(out);
1236 void InterfaceType::dumpComprehensiveGetCppuType(FileStream & out) {
1237 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
1238 OUString staticTypeClass("the" + id_ + "Type");
1239 out << " namespace detail {\n\n" << indent() << "struct " << staticTypeClass
1240 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
1241 << staticTypeClass << " >\n" << indent() << "{\n";
1242 inc();
1243 out << indent() << "::com::sun::star::uno::Type * operator()() const\n"
1244 << indent() << "{\n";
1245 inc();
1246 out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
1247 << indent() << "// Start inline typedescription generation\n"
1248 << indent() << "typelib_InterfaceTypeDescription * pTD = 0;\n\n";
1249 out << indent() << "typelib_TypeDescriptionReference * aSuperTypes["
1250 << entity_->getDirectMandatoryBases().size() << "];\n";
1251 std::vector< unoidl::AnnotatedReference >::size_type n = 0;
1252 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
1253 entity_->getDirectMandatoryBases().begin());
1254 i != entity_->getDirectMandatoryBases().end(); ++i)
1256 out << indent() << "aSuperTypes[" << n++ << "] = ::cppu::UnoType< ";
1257 dumpType(out, i->name, false, false, false, true);
1258 out << " >::get().getTypeLibType();\n";
1260 std::size_t count = entity_->getDirectAttributes().size()
1261 + entity_->getDirectMethods().size(); //TODO: overflow
1262 if (count != 0) {
1263 out << indent() << "typelib_TypeDescriptionReference * pMembers["
1264 << count << "] = { ";
1265 for (std::size_t i = 0; i != count; ++i) {
1266 out << "0";
1267 if (i + 1 != count) {
1268 out << ",";
1271 out << " };\n";
1272 sal_uInt32 index = 0;
1273 dumpCppuAttributeRefs(out, index);
1274 dumpCppuMethodRefs(out, index);
1276 out << "\n" << indent() << "typelib_typedescription_newMIInterface(\n";
1277 inc();
1278 out << indent() << "&pTD,\n" << indent()
1279 << ("sTypeName.pData, 0x00000000, 0x0000, 0x0000, 0x00000000,"
1280 " 0x00000000,\n") // UIK
1281 << indent() << entity_->getDirectMandatoryBases().size()
1282 << ", aSuperTypes,\n" << indent() << count << ",\n" << indent()
1283 << (count == 0 ? "0" : "pMembers") << " );\n\n";
1284 dec();
1285 out << indent()
1286 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
1287 " );\n");
1288 for (std::size_t i = 0; i != count; ++i) {
1289 out << indent() << "typelib_typedescriptionreference_release( pMembers["
1290 << i << "] );\n";
1292 out << indent()
1293 << ("typelib_typedescription_release( (typelib_TypeDescription*)pTD"
1294 " );\n\n")
1295 << indent() << "return new ::com::sun::star::uno::Type( "
1296 << getTypeClass(name_) << ", sTypeName ); // leaked\n";
1297 dec();
1298 out << indent() << "}\n";
1299 dec();
1300 out << indent() << "};\n\n";
1301 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
1302 out << " }\n\n";
1303 dumpGetCppuTypePreamble(out);
1304 out << indent() << "const ::com::sun::star::uno::Type &rRet = *detail::"
1305 << staticTypeClass << "::get();\n" << indent()
1306 << "// End inline typedescription generation\n" << indent()
1307 << "static bool bInitStarted = false;\n" << indent()
1308 << "if (!bInitStarted)\n" << indent() << "{\n";
1309 inc();
1310 out << indent()
1311 << "::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );\n"
1312 << indent() << "if (!bInitStarted)\n" << indent() << "{\n";
1313 inc();
1314 out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n"
1315 << indent() << "bInitStarted = true;\n";
1316 std::set< OUString > seen;
1317 // Type for RuntimeException is always needed:
1318 seen.insert("com.sun.star.uno.RuntimeException");
1319 dumpCppuGetType(out, "com.sun.star.uno.RuntimeException");
1320 dumpAttributesCppuDecl(out, &seen);
1321 dumpMethodsCppuDecl(out, &seen);
1322 if (count != 0) {
1323 sal_uInt32 index = getInheritedMemberCount();
1324 dumpCppuAttributes(out, index);
1325 dumpCppuMethods(out, index);
1327 dec();
1328 out << indent() << "}\n";
1329 dec();
1330 out << indent() << "}\n" << indent() << "else\n" << indent() << "{\n";
1331 inc();
1332 out << indent() << "OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();\n";
1333 dec();
1334 out << indent() << "}\n" << indent() << "return rRet;\n";
1335 dumpGetCppuTypePostamble(out);
1338 void InterfaceType::dumpCppuAttributeRefs(FileStream & out, sal_uInt32 & index)
1340 std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
1341 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1342 i(entity_->getDirectAttributes().begin());
1343 i != entity_->getDirectAttributes().end(); ++i)
1345 out << indent() << "::rtl::OUString sAttributeName" << n << "( \""
1346 << name_ << "::" << i->name << "\" );\n" << indent()
1347 << "typelib_typedescriptionreference_new( &pMembers[" << index++
1348 << "],\n";
1349 inc(38);
1350 out << indent()
1351 << ("(typelib_TypeClass)"
1352 "::com::sun::star::uno::TypeClass_INTERFACE_ATTRIBUTE,\n")
1353 << indent() << "sAttributeName" << n << ".pData );\n";
1354 dec(38);
1355 ++n;
1359 void InterfaceType::dumpCppuMethodRefs(FileStream & out, sal_uInt32 & index) {
1360 std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
1361 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1362 entity_->getDirectMethods().begin());
1363 i != entity_->getDirectMethods().end(); ++i)
1365 out << indent() << "::rtl::OUString sMethodName" << n << "( \"" << name_
1366 << "::" << i->name << "\" );\n" << indent()
1367 << "typelib_typedescriptionreference_new( &pMembers[" << index++
1368 << "],\n";
1369 inc(38);
1370 out << indent()
1371 << ("(typelib_TypeClass)"
1372 "::com::sun::star::uno::TypeClass_INTERFACE_METHOD,\n")
1373 << indent() << "sMethodName" << n << ".pData );\n";
1374 dec(38);
1375 ++n;
1379 void InterfaceType::addComprehensiveGetCppuTypeIncludes(
1380 codemaker::cppumaker::Includes & includes) const
1382 // The comprehensive getCppuType method always includes a line
1383 // "getCppuType( (const ::com::sun::star::uno::RuntimeException*)0 );":
1384 includes.addCppuUnotypeHxx();
1385 includes.add("com.sun.star.uno.RuntimeException");
1388 void InterfaceType::dumpCppuAttributes(FileStream & out, sal_uInt32 & index) {
1389 if (!entity_->getDirectAttributes().empty()) {
1390 out << "\n" << indent()
1391 << "typelib_InterfaceAttributeTypeDescription * pAttribute = 0;\n";
1392 std::vector< unoidl::InterfaceTypeEntity::Attribute >::size_type n = 0;
1393 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::
1394 const_iterator i(entity_->getDirectAttributes().begin());
1395 i != entity_->getDirectAttributes().end(); ++i)
1397 OUString type(resolveAllTypedefs(i->type));
1398 out << indent() << "{\n";
1399 inc();
1400 out << indent() << "::rtl::OUString sAttributeType" << n << "( \""
1401 << type << "\" );\n" << indent()
1402 << "::rtl::OUString sAttributeName" << n << "( \"" << name_
1403 << "::" << i->name << "\" );\n";
1404 sal_Int32 getExcn = dumpExceptionTypeNames(
1405 out, "get", i->getExceptions, false);
1406 sal_Int32 setExcn = dumpExceptionTypeNames(
1407 out, "set", i->setExceptions, false);
1408 out << indent()
1409 << ("typelib_typedescription_newExtendedInterfaceAttribute("
1410 " &pAttribute,\n");
1411 inc();
1412 out << indent() << index++ << ", sAttributeName" << n
1413 << ".pData,\n" << indent() << "(typelib_TypeClass)"
1414 << getTypeClass(type) << ", sAttributeType" << n << ".pData,\n"
1415 << indent() << "sal_" << (i->readOnly ? "True" : "False")
1416 << ", " << getExcn << ", "
1417 << (getExcn == 0 ? "0" : "the_getExceptions") << ", " << setExcn
1418 << ", " << (setExcn == 0 ? "0" : "the_setExceptions")
1419 << " );\n";
1420 dec();
1421 out << indent()
1422 << ("typelib_typedescription_register("
1423 " (typelib_TypeDescription**)&pAttribute );\n");
1424 dec();
1425 out << indent() << "}\n";
1426 ++n;
1428 out << indent()
1429 << ("typelib_typedescription_release("
1430 " (typelib_TypeDescription*)pAttribute );\n");
1434 void InterfaceType::dumpCppuMethods(FileStream & out, sal_uInt32 & index) {
1435 if (!entity_->getDirectMethods().empty()) {
1436 out << "\n" << indent()
1437 << "typelib_InterfaceMethodTypeDescription * pMethod = 0;\n";
1438 std::vector< unoidl::InterfaceTypeEntity::Method >::size_type n = 0;
1439 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator
1440 i(entity_->getDirectMethods().begin());
1441 i != entity_->getDirectMethods().end(); ++i)
1443 OUString returnType(resolveAllTypedefs(i->returnType));
1444 out << indent() << "{\n";
1445 inc();
1446 if (!i->parameters.empty()) {
1447 out << indent() << "typelib_Parameter_Init aParameters["
1448 << i->parameters.size() << "];\n";
1450 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1451 size_type m = 0;
1452 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
1453 const_iterator j(i->parameters.begin());
1454 j != i->parameters.end(); ++j)
1456 OUString type(resolveAllTypedefs(j->type));
1457 out << indent() << "::rtl::OUString sParamName" << m << "( \""
1458 << j->name << "\" );\n" << indent()
1459 << "::rtl::OUString sParamType" << m << "( \"" << type
1460 << "\" );\n" << indent() << "aParameters[" << m
1461 << "].pParamName = sParamName" << m << ".pData;\n"
1462 << indent() << "aParameters[" << m
1463 << "].eTypeClass = (typelib_TypeClass)"
1464 << getTypeClass(type) << ";\n" << indent() << "aParameters["
1465 << m << "].pTypeName = sParamType" << m << ".pData;\n"
1466 << indent() << "aParameters[" << m << "].bIn = "
1467 << ((j->direction
1468 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1469 DIRECTION_OUT))
1470 ? "sal_False" : "sal_True")
1471 << ";\n" << indent() << "aParameters[" << m << "].bOut = "
1472 << ((j->direction
1473 == (unoidl::InterfaceTypeEntity::Method::Parameter::
1474 DIRECTION_IN))
1475 ? "sal_False" : "sal_True")
1476 << ";\n";
1477 ++m;
1479 sal_Int32 excn = dumpExceptionTypeNames(
1480 out, "", i->exceptions,
1481 i->name != "acquire" && i->name != "release");
1482 out << indent() << "::rtl::OUString sReturnType" << n << "( \""
1483 << returnType << "\" );\n" << indent()
1484 << "::rtl::OUString sMethodName" << n << "( \"" << name_ << "::"
1485 << i->name << "\" );\n" << indent()
1486 << "typelib_typedescription_newInterfaceMethod( &pMethod,\n";
1487 inc();
1488 out << indent() << index++ << ", sal_False,\n" << indent()
1489 << "sMethodName" << n << ".pData,\n" << indent()
1490 << "(typelib_TypeClass)" << getTypeClass(returnType)
1491 << ", sReturnType" << n << ".pData,\n" << indent()
1492 << i->parameters.size() << ", "
1493 << (i->parameters.empty() ? "0" : "aParameters") << ",\n"
1494 << indent() << excn << ", "
1495 << (excn == 0 ? "0" : "the_Exceptions") << " );\n";
1496 dec();
1497 out << indent()
1498 << ("typelib_typedescription_register("
1499 " (typelib_TypeDescription**)&pMethod );\n");
1500 dec();
1501 out << indent() << "}\n";
1502 ++n;
1504 out << indent()
1505 << ("typelib_typedescription_release("
1506 " (typelib_TypeDescription*)pMethod );\n");
1510 void InterfaceType::dumpAttributesCppuDecl(
1511 FileStream & out, std::set< OUString > * seen)
1513 assert(seen != 0);
1514 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
1515 i(entity_->getDirectAttributes().begin());
1516 i != entity_->getDirectAttributes().end(); ++i)
1518 if (seen->insert(i->type).second) {
1519 dumpCppuGetType(out, i->type);
1521 for (std::vector< OUString >::const_iterator j(
1522 i->getExceptions.begin());
1523 j != i->getExceptions.end(); ++j)
1525 if (seen->insert(*j).second) {
1526 dumpCppuGetType(out, *j);
1529 for (std::vector< OUString >::const_iterator j(
1530 i->setExceptions.begin());
1531 j != i->setExceptions.end(); ++j)
1533 if (seen->insert(*j).second) {
1534 dumpCppuGetType(out, *j);
1540 void InterfaceType::dumpMethodsCppuDecl(
1541 FileStream & out, std::set< OUString > * seen)
1543 assert(seen != 0);
1544 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
1545 entity_->getDirectMethods().begin());
1546 i != entity_->getDirectMethods().end(); ++i)
1548 for (std::vector< OUString >::const_iterator j(i->exceptions.begin());
1549 j != i->exceptions.end(); ++j)
1551 if (seen->insert(*j).second) {
1552 dumpCppuGetType(out, *j);
1558 void InterfaceType::dumpExceptionSpecification(
1559 FileStream & out, std::vector< OUString > const & exceptions,
1560 bool runtimeException)
1562 // Exception specifications are undesirable in production code, but make
1563 // for useful assertions in debug builds (on platforms where they are
1564 // enforced at runtime):
1565 #if !defined DBG_UTIL
1566 out << " /*";
1567 #endif
1568 out << " throw (";
1569 bool first = true;
1570 for (std::vector< OUString >::const_iterator i(exceptions.begin());
1571 i != exceptions.end(); ++i)
1573 if (*i != "com.sun.star.uno.RuntimeException") {
1574 if (!first) {
1575 out << ", ";
1577 out << codemaker::cpp::scopedCppName(u2b(*i));
1578 first = false;
1581 if (runtimeException) {
1582 if (!first) {
1583 out << ", ";
1585 out << "::com::sun::star::uno::RuntimeException";
1587 out << ")";
1588 #if !defined DBG_UTIL
1589 out << " */";
1590 #endif
1593 void InterfaceType::dumpExceptionTypeName(
1594 FileStream & out, OUString const & prefix, sal_uInt32 index,
1595 OUString const & name)
1597 out << indent() << "::rtl::OUString the_" << prefix << "ExceptionName"
1598 << index << "( \"" << name << "\" );\n";
1601 sal_Int32 InterfaceType::dumpExceptionTypeNames(
1602 FileStream & out, OUString const & prefix,
1603 std::vector< OUString > const & exceptions, bool runtimeException)
1605 sal_Int32 count = 0;
1606 for (std::vector< OUString >::const_iterator i(exceptions.begin());
1607 i != exceptions.end(); ++i)
1609 if (*i != "com.sun.star.uno.RuntimeException") {
1610 dumpExceptionTypeName(out, prefix, count++, *i);
1613 if (runtimeException) {
1614 dumpExceptionTypeName(
1615 out, prefix, count++, "com.sun.star.uno.RuntimeException");
1617 if (count != 0) {
1618 out << indent() << "rtl_uString * the_" << prefix << "Exceptions[] = {";
1619 for (sal_Int32 i = 0; i != count; ++i) {
1620 out << (i == 0 ? " " : ", ") << "the_" << prefix << "ExceptionName"
1621 << i << ".pData";
1623 out << " };\n";
1625 return count;
1628 class ConstantGroup: public CppuType {
1629 public:
1630 ConstantGroup(
1631 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
1632 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1633 CppuType(name, typeMgr), entity_(entity)
1634 { assert(entity.is()); }
1636 bool hasConstants() const { return !entity_->getMembers().empty(); }
1638 private:
1639 virtual void dumpHFile(
1640 FileStream & out, codemaker::cppumaker::Includes & includes);
1642 virtual void dumpHxxFile(
1643 FileStream & out, codemaker::cppumaker::Includes & includes);
1645 virtual void dumpDeclaration(FileStream & out);
1647 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1650 void ConstantGroup::dumpHFile(
1651 FileStream & out, codemaker::cppumaker::Includes & includes)
1653 OUString headerDefine(dumpHeaderDefine(out, "HDL"));
1654 out << "\n";
1655 addDefaultHIncludes(includes);
1656 includes.dump(out, 0);
1657 out << "\n";
1658 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, true)) {
1659 out << "\n";
1661 out << "\n";
1662 dumpDeclaration(out);
1663 out << "\n";
1664 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, true)) {
1665 out << "\n";
1667 out << "\n#endif // "<< headerDefine << "\n";
1670 void ConstantGroup::dumpHxxFile(
1671 FileStream & out, codemaker::cppumaker::Includes &)
1673 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1674 out << "\n";
1675 codemaker::cppumaker::Includes::dumpInclude(out, u2b(name_), false);
1676 out << "\n#endif // "<< headerDefine << "\n";
1679 void ConstantGroup::dumpDeclaration(FileStream & out) {
1680 for (std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator i(
1681 entity_->getMembers().begin());
1682 i != entity_->getMembers().end(); ++i)
1684 out << "static const ";
1685 switch (i->value.type) {
1686 case unoidl::ConstantValue::TYPE_BOOLEAN:
1687 out << "::sal_Bool";
1688 break;
1689 case unoidl::ConstantValue::TYPE_BYTE:
1690 out << "::sal_Int8";
1691 break;
1692 case unoidl::ConstantValue::TYPE_SHORT:
1693 out << "::sal_Int16";
1694 break;
1695 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1696 out << "::sal_uInt16";
1697 break;
1698 case unoidl::ConstantValue::TYPE_LONG:
1699 out << "::sal_Int32";
1700 break;
1701 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1702 out << "::sal_uInt32";
1703 break;
1704 case unoidl::ConstantValue::TYPE_HYPER:
1705 out << "::sal_Int64";
1706 break;
1707 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1708 out << "::sal_uInt64";
1709 break;
1710 case unoidl::ConstantValue::TYPE_FLOAT:
1711 out << "float";
1712 break;
1713 case unoidl::ConstantValue::TYPE_DOUBLE:
1714 out << "double";
1715 break;
1717 out << " " << i->name << " = ";
1718 switch (i->value.type) {
1719 case unoidl::ConstantValue::TYPE_BOOLEAN:
1720 out << (i->value.booleanValue ? "sal_True" : "sal_False");
1721 break;
1722 case unoidl::ConstantValue::TYPE_BYTE:
1723 out << "(sal_Int8)" << OUString::number(i->value.byteValue);
1724 break;
1725 case unoidl::ConstantValue::TYPE_SHORT:
1726 out << "(sal_Int16)" << OUString::number(i->value.shortValue);
1727 break;
1728 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1729 out << "(sal_uInt16)"
1730 << OUString::number(i->value.unsignedShortValue);
1731 break;
1732 case unoidl::ConstantValue::TYPE_LONG:
1733 // Avoid C++ compiler warnings about (un)signedness of literal
1734 // -2^31:
1735 if (i->value.longValue == SAL_MIN_INT32) {
1736 out << "SAL_MIN_INT32";
1737 } else {
1738 out << "(sal_Int32)" << OUString::number(i->value.longValue);
1740 break;
1741 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1742 out << "(sal_uInt32)"
1743 << OUString::number(i->value.unsignedLongValue) << "U";
1744 break;
1745 case unoidl::ConstantValue::TYPE_HYPER:
1746 // Avoid C++ compiler warnings about (un)signedness of literal
1747 // -2^63:
1748 if (i->value.hyperValue == SAL_MIN_INT64) {
1749 out << "SAL_MIN_INT64";
1750 } else {
1751 out << "(sal_Int64) SAL_CONST_INT64("
1752 << OUString::number(i->value.hyperValue) << ")";
1754 break;
1755 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1756 out << "SAL_CONST_UINT64("
1757 << OUString::number(i->value.unsignedHyperValue) << ")";
1758 break;
1759 case unoidl::ConstantValue::TYPE_FLOAT:
1760 out << "(float)" << OUString::number(i->value.floatValue);
1761 break;
1762 case unoidl::ConstantValue::TYPE_DOUBLE:
1763 out << "(double)" << OUString::number(i->value.doubleValue);
1764 break;
1766 out << ";\n";
1770 void dumpTypeParameterName(FileStream & out, OUString const & name) {
1771 // Prefix all type parameters with "typeparam_" to avoid problems when a
1772 // struct member has the same name as a type parameter, as in
1773 // struct<T> { T T; };
1774 out << "typeparam_" << name;
1777 class PlainStructType: public CppuType {
1778 public:
1779 PlainStructType(
1780 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity,
1781 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
1782 CppuType(name, typeMgr), entity_(entity)
1783 { assert(entity.is()); }
1785 private:
1786 virtual sal_uInt32 checkInheritedMemberCount() const
1787 { return getTotalMemberCount(entity_->getDirectBase()); }
1789 virtual void dumpDeclaration(FileStream& o);
1791 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes);
1793 virtual void dumpLightGetCppuType(FileStream & out);
1795 virtual void dumpNormalGetCppuType(FileStream & out);
1797 virtual void dumpComprehensiveGetCppuType(FileStream & out);
1799 virtual void addLightGetCppuTypeIncludes(
1800 codemaker::cppumaker::Includes & includes) const;
1802 virtual void addNormalGetCppuTypeIncludes(
1803 codemaker::cppumaker::Includes & includes) const;
1805 virtual void addComprehensiveGetCppuTypeIncludes(
1806 codemaker::cppumaker::Includes & includes) const;
1808 bool dumpBaseMembers(
1809 FileStream & out, OUString const & base, bool withType);
1811 sal_uInt32 getTotalMemberCount(OUString const & base) const;
1813 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
1816 void PlainStructType::dumpDeclaration(FileStream & out) {
1817 out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent()
1818 << "struct " << id_;
1819 OUString base(entity_->getDirectBase());
1820 if (!base.isEmpty()) {
1821 out << ": public " << codemaker::cpp::scopedCppName(u2b(base));
1823 out << " {\n";
1824 inc();
1825 out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
1826 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1827 out << "\n" << indent() << "inline " << id_ << "(";
1828 bool first = !dumpBaseMembers(out, base, true);
1829 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1830 const_iterator i(entity_->getDirectMembers().begin());
1831 i != entity_->getDirectMembers().end(); ++i)
1833 if (!first) {
1834 out << ", ";
1836 dumpType(out, i->type, true, true);
1837 out << " " << i->name << "_";
1838 first = false;
1840 out << ") SAL_THROW(());\n";
1842 if (!entity_->getDirectMembers().empty()) {
1843 out << "\n";
1844 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1845 const_iterator i(entity_->getDirectMembers().begin());
1846 i != entity_->getDirectMembers().end(); ++i)
1848 out << indent();
1849 dumpType(out, i->type);
1850 out << " " << i->name;
1851 if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
1852 && i->type != "hyper" && i->type != "unsigned hyper"
1853 && i->type != "double")
1855 out << " CPPU_GCC3_ALIGN("
1856 << codemaker::cpp::scopedCppName(u2b(base)) << ")";
1858 out << ";\n";
1861 dec();
1862 out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n";
1865 void PlainStructType::dumpHxxFile(
1866 FileStream & out, codemaker::cppumaker::Includes & includes)
1868 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
1869 out << "\n";
1870 includes.dump(out, &name_);
1871 out << "\n";
1872 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
1873 out << "\n";
1875 out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
1876 inc();
1877 OUString base(entity_->getDirectBase());
1878 bool first = true;
1879 if (!base.isEmpty()) {
1880 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
1881 << "()\n";
1882 first = false;
1884 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
1885 entity_->getDirectMembers().begin());
1886 i != entity_->getDirectMembers().end(); ++i)
1888 out << indent() << (first ? ":" : ",") << " " << i->name;
1889 dumpInitializer(out, false, i->type);
1890 out << "\n";
1891 first = false;
1893 dec();
1894 out << "{\n}\n\n";
1895 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
1896 out << "inline " << id_;
1897 out << "::" << id_ << "(";
1898 first = !dumpBaseMembers(out, base, true);
1899 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1900 const_iterator i(entity_->getDirectMembers().begin());
1901 i != entity_->getDirectMembers().end(); ++i)
1903 if (!first) {
1904 out << ", ";
1906 dumpType(out, i->type, true, true);
1907 out << " " << i->name << "_";
1908 first = false;
1910 out << ") SAL_THROW(())\n";
1911 inc();
1912 first = true;
1913 if (!base.isEmpty()) {
1914 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
1915 << "(";
1916 dumpBaseMembers(out, base, false);
1917 out << ")\n";
1918 first = false;
1920 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
1921 const_iterator i(entity_->getDirectMembers().begin());
1922 i != entity_->getDirectMembers().end(); ++i)
1924 out << indent() << (first ? ":" : ",") << " " << i->name << "("
1925 << i->name << "_)\n";
1926 first = false;
1928 dec();
1929 out << "{\n}\n\n";
1931 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
1932 out << "\n";
1934 out << "\n";
1935 dumpGetCppuType(out);
1936 out << "\n#endif // "<< headerDefine << "\n";
1939 void PlainStructType::dumpLightGetCppuType(FileStream & out) {
1940 dumpGetCppuTypePreamble(out);
1941 out << indent()
1942 << ("//TODO: On certain platforms with weak memory models, the"
1943 " following code can result in some threads observing that the_type"
1944 " points to garbage\n")
1945 << indent()
1946 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1947 << indent() << "if (the_type == 0) {\n";
1948 inc();
1949 out << indent() << "::typelib_static_type_init(&the_type, "
1950 << getTypeClass(name_, true) << ", \"" << name_ << "\");\n";
1951 dec();
1952 out << indent() << "}\n" << indent()
1953 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
1954 "&the_type);\n");
1955 dumpGetCppuTypePostamble(out);
1958 void PlainStructType::dumpNormalGetCppuType(FileStream & out) {
1959 dumpGetCppuTypePreamble(out);
1960 out << indent()
1961 << ("//TODO: On certain platforms with weak memory models, the"
1962 " following code can result in some threads observing that the_type"
1963 " points to garbage\n")
1964 << indent()
1965 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
1966 << indent() << "if (the_type == 0) {\n";
1967 inc();
1968 out << indent()
1969 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
1970 inc();
1971 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
1972 entity_->getDirectMembers().begin());
1973 i != entity_->getDirectMembers().end();)
1975 out << indent() << "::cppu::UnoType< ";
1976 dumpType(out, i->type, false, false, false, true);
1977 ++i;
1978 out << " >::get().getTypeLibType()"
1979 << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
1981 dec();
1982 out << indent() << "::typelib_static_struct_type_init(&the_type, \""
1983 << name_ << "\", ";
1984 if (entity_->getDirectBase().isEmpty()) {
1985 out << "0";
1986 } else {
1987 out << "::cppu::UnoType< ";
1988 dumpType(out, entity_->getDirectBase(), false, false, false, true);
1989 out << " >::get().getTypeLibType()";
1991 out << ", " << entity_->getDirectMembers().size() << ", the_members, 0);\n";
1992 dec();
1993 out << indent() << "}\n" << indent()
1994 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
1995 "&the_type);\n");
1996 dumpGetCppuTypePostamble(out);
1999 void PlainStructType::dumpComprehensiveGetCppuType(FileStream & out) {
2000 OUString staticTypeClass("the" + id_ + "Type");
2001 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
2002 out << " namespace detail {\n\n" << indent() << "struct "
2003 << staticTypeClass
2004 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2005 << staticTypeClass << " >\n" << indent() << "{\n";
2006 inc();
2007 out << indent() << "::com::sun::star::uno::Type * operator()() const\n"
2008 << indent() << "{\n";
2009 inc();
2010 out << indent() << "::rtl::OUString the_name( \"" << name_ << "\" );\n";
2011 std::map< OUString, sal_uInt32 > types;
2012 std::vector< unoidl::PlainStructTypeEntity::Member >::size_type n = 0;
2013 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
2014 entity_->getDirectMembers().begin());
2015 i != entity_->getDirectMembers().end(); ++i)
2017 if (types.insert(
2018 std::map< OUString, sal_uInt32 >::value_type(
2019 i->type, static_cast< sal_uInt32 >(types.size()))).
2020 second)
2022 dumpCppuGetType(out, i->type, &name_);
2023 // For typedefs, use the resolved type name, as there will be no
2024 // information available about the typedef itself at runtime (the
2025 // above getCppuType call will make available information about the
2026 // resolved type); no extra #include for the resolved type is
2027 // needed, as the header for the typedef includes it already:
2028 out << indent() << "::rtl::OUString the_tname"
2029 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
2030 << resolveAllTypedefs(i->type) << "\" );\n";
2032 out << indent() << "::rtl::OUString the_name" << n++ << "( \""
2033 << i->name << "\" );\n";
2035 out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
2036 inc();
2037 n = 0;
2038 for (std::vector< unoidl::PlainStructTypeEntity::Member >::const_iterator i(
2039 entity_->getDirectMembers().begin());
2040 i != entity_->getDirectMembers().end();)
2042 out << indent() << "{ { " << getTypeClass(i->type, true)
2043 << ", the_tname" << types.find(i->type)->second
2044 << ".pData, the_name" << n++ << ".pData }, false }";
2045 ++i;
2046 out << (i == entity_->getDirectMembers().end() ? " };" : ",") << "\n";
2048 dec();
2049 out << indent() << "::typelib_TypeDescription * the_newType = 0;\n"
2050 << indent()
2051 << "::typelib_typedescription_newStruct(&the_newType, the_name.pData, ";
2052 if (entity_->getDirectBase().isEmpty()) {
2053 out << "0";
2054 } else {
2055 out << "::cppu::UnoType< ";
2056 dumpType(out, entity_->getDirectBase(), false, false, false, true);
2057 out << " >::get().getTypeLibType()";
2059 out << ", " << entity_->getDirectMembers().size() << ", the_members);\n"
2060 << indent() << "::typelib_typedescription_register(&the_newType);\n"
2061 << indent() << "::typelib_typedescription_release(the_newType);\n"
2062 << indent() << "return new ::com::sun::star::uno::Type("
2063 << getTypeClass(name_) << ", the_name); // leaked\n";
2064 dec();
2065 out << indent() << "}\n";
2066 dec();
2067 out << indent() << "};\n";
2068 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
2069 out << " }\n\n";
2070 dumpGetCppuTypePreamble(out);
2071 out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
2072 dumpGetCppuTypePostamble(out);
2075 bool PlainStructType::dumpBaseMembers(
2076 FileStream & out, OUString const & base, bool withType)
2078 bool hasMember = false;
2079 if (!base.isEmpty()) {
2080 rtl::Reference< unoidl::Entity > ent;
2081 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
2082 if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
2083 throw CannotDumpException(
2084 "plain struct type base " + base
2085 + " is not a plain struct type");
2087 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
2088 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
2089 assert(ent2.is());
2090 hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
2091 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
2092 const_iterator i(ent2->getDirectMembers().begin());
2093 i != ent2->getDirectMembers().end(); ++i)
2095 if (hasMember) {
2096 out << ", ";
2098 if (withType) {
2099 dumpType(out, i->type, true, true);
2100 out << " ";
2102 out << i->name << "_";
2103 hasMember = true;
2106 return hasMember;
2109 void PlainStructType::addLightGetCppuTypeIncludes(
2110 codemaker::cppumaker::Includes & includes) const
2112 includes.addType();
2113 includes.addCppuUnotypeHxx();
2114 includes.addSalTypesH();
2115 includes.addTypelibTypeclassH();
2116 includes.addTypelibTypedescriptionH();
2119 void PlainStructType::addNormalGetCppuTypeIncludes(
2120 codemaker::cppumaker::Includes & includes) const
2122 includes.addType();
2123 includes.addCppuUnotypeHxx();
2124 includes.addSalTypesH();
2125 includes.addTypelibTypeclassH();
2126 includes.addTypelibTypedescriptionH();
2129 void PlainStructType::addComprehensiveGetCppuTypeIncludes(
2130 codemaker::cppumaker::Includes & includes) const
2132 includes.addType();
2133 includes.addCppuUnotypeHxx();
2134 includes.addRtlInstanceHxx();
2135 includes.addOslMutexHxx();
2136 includes.addRtlUstringH();
2137 includes.addRtlUstringHxx();
2138 includes.addSalTypesH();
2139 includes.addTypelibTypeclassH();
2140 includes.addTypelibTypedescriptionH();
2143 sal_uInt32 PlainStructType::getTotalMemberCount(OUString const & base) const {
2144 if (base.isEmpty()) {
2145 return 0;
2147 rtl::Reference< unoidl::Entity > ent;
2148 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
2149 if (sort != codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE) {
2150 throw CannotDumpException(
2151 "plain struct type base " + base + " is not a plain struct type");
2153 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
2154 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()));
2155 assert(ent2.is());
2156 return getTotalMemberCount(ent2->getDirectBase())
2157 + ent2->getDirectMembers().size(); //TODO: overflow
2160 class PolyStructType: public CppuType {
2161 public:
2162 PolyStructType(
2163 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
2164 entity,
2165 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
2166 CppuType(name, typeMgr), entity_(entity)
2167 { assert(entity.is()); }
2169 private:
2170 virtual void dumpDeclaration(FileStream& o);
2172 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes);
2174 virtual void dumpLightGetCppuType(FileStream & out);
2176 virtual void dumpNormalGetCppuType(FileStream & out);
2178 virtual void dumpComprehensiveGetCppuType(FileStream & out);
2180 virtual void addLightGetCppuTypeIncludes(
2181 codemaker::cppumaker::Includes & includes) const;
2183 virtual void addNormalGetCppuTypeIncludes(
2184 codemaker::cppumaker::Includes & includes) const;
2186 virtual void addComprehensiveGetCppuTypeIncludes(
2187 codemaker::cppumaker::Includes & includes) const;
2189 virtual bool isPolymorphic() const { return true; }
2191 virtual void dumpTemplateHead(FileStream & out) const;
2193 virtual void dumpTemplateParameters(FileStream & out) const;
2195 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
2198 void PolyStructType::dumpDeclaration(FileStream & out) {
2199 out << "\n#ifdef SAL_W32\n# pragma pack(push, 8)\n#endif\n\n" << indent();
2200 dumpTemplateHead(out);
2201 out << "struct " << id_ << " {\n";
2202 inc();
2203 out << indent() << "inline " << id_ << "() SAL_THROW(());\n";
2204 if (!entity_->getMembers().empty()) {
2205 out << "\n" << indent() << "inline " << id_ << "(";
2206 for (std::vector<
2207 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2208 const_iterator i(entity_->getMembers().begin());
2209 i != entity_->getMembers().end(); ++i)
2211 if (i != entity_->getMembers().begin()) {
2212 out << ", ";
2214 if (i->parameterized) {
2215 dumpTypeParameterName(out, i->type);
2216 out << " const &";
2217 } else {
2218 dumpType(out, i->type, true, true);
2220 out << " " << i->name << "_";
2222 out << ") SAL_THROW(());\n\n";
2223 for (std::vector<
2224 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2225 const_iterator i(entity_->getMembers().begin());
2226 i != entity_->getMembers().end(); ++i)
2228 out << indent();
2229 if (i->parameterized) {
2230 dumpTypeParameterName(out, i->type);
2231 } else {
2232 dumpType(out, i->type);
2234 out << " " << i->name << ";\n";
2237 dec();
2238 out << "};\n\n#ifdef SAL_W32\n# pragma pack(pop)\n#endif\n\n";
2241 void PolyStructType::dumpHxxFile(
2242 FileStream & out, codemaker::cppumaker::Includes & includes)
2244 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
2245 out << "\n";
2246 includes.dump(out, &name_);
2247 out << "\n";
2248 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
2249 out << "\n";
2251 out << "\n";
2252 dumpTemplateHead(out);
2253 out << "inline " << id_;
2254 dumpTemplateParameters(out);
2255 out << "::" << id_ << "() SAL_THROW(())\n";
2256 inc();
2257 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2258 const_iterator i(entity_->getMembers().begin());
2259 i != entity_->getMembers().end(); ++i)
2261 out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
2262 << " " << i->name;
2263 dumpInitializer(out, i->parameterized, i->type);
2264 out << "\n";
2266 dec();
2267 out << "{\n}\n\n";
2268 if (!entity_->getMembers().empty()) {
2269 dumpTemplateHead(out);
2270 out << "inline " << id_;
2271 dumpTemplateParameters(out);
2272 out << "::" << id_ << "(";
2273 for (std::vector<
2274 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2275 const_iterator i(entity_->getMembers().begin());
2276 i != entity_->getMembers().end(); ++i)
2278 if (i != entity_->getMembers().begin()) {
2279 out << ", ";
2281 if (i->parameterized) {
2282 dumpTypeParameterName(out, i->type);
2283 out << " const &";
2284 } else {
2285 dumpType(out, i->type, true, true);
2287 out << " " << i->name << "_";
2289 out << ") SAL_THROW(())\n";
2290 inc();
2291 for (std::vector<
2292 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2293 const_iterator i(entity_->getMembers().begin());
2294 i != entity_->getMembers().end(); ++i)
2296 out << indent() << (i == entity_->getMembers().begin() ? ":" : ",")
2297 << " " << i->name << "(" << i->name << "_)\n";
2299 dec();
2300 out << "{\n}\n\n" << indent();
2301 dumpTemplateHead(out);
2302 out << "\n" << indent() << "inline " << id_;
2303 dumpTemplateParameters(out);
2304 out << "\n" << indent() << "make_" << id_ << "(";
2305 for (std::vector<
2306 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2307 const_iterator i(entity_->getMembers().begin());
2308 i != entity_->getMembers().end(); ++i)
2310 if (i != entity_->getMembers().begin()) {
2311 out << ", ";
2313 if (i->parameterized) {
2314 dumpTypeParameterName(out, i->type);
2315 out << " const &";
2316 } else {
2317 dumpType(out, i->type, true, true);
2319 out << " " << i->name << "_";
2321 out << ") SAL_THROW(())\n" << indent() << "{\n";
2322 inc();
2323 out << indent() << "return " << id_;
2324 dumpTemplateParameters(out);
2325 out << "(";
2326 for (std::vector<
2327 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2328 const_iterator i(entity_->getMembers().begin());
2329 i != entity_->getMembers().end(); ++i)
2331 if (i != entity_->getMembers().begin()) {
2332 out << ", ";
2334 out << i->name << "_";
2336 out << ");\n";
2337 dec();
2338 out << indent() << "}\n\n";
2340 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
2341 out << "\n";
2343 out << "\n";
2344 dumpGetCppuType(out);
2345 out << "\n#endif // "<< headerDefine << "\n";
2348 void PolyStructType::dumpLightGetCppuType(FileStream & out) {
2349 dumpGetCppuTypePreamble(out);
2350 out << indent()
2351 << ("//TODO: On certain platforms with weak memory models, the"
2352 " following code can result in some threads observing that the_type"
2353 " points to garbage\n")
2354 << indent()
2355 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2356 << indent() << "if (the_type == 0) {\n";
2357 inc();
2358 out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2359 << "<\");\n";
2360 for (std::vector< OUString >::const_iterator i(
2361 entity_->getTypeParameters().begin());
2362 i != entity_->getTypeParameters().end();)
2364 out << indent()
2365 << ("the_buffer.append(::rtl::OUStringToOString("
2366 "::cppu::getTypeFavourChar(static_cast< ");
2367 dumpTypeParameterName(out, *i);
2368 out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
2369 ++i;
2370 if (i != entity_->getTypeParameters().end()) {
2371 out << indent() << "the_buffer.append(',');\n";
2374 out << indent() << "the_buffer.append('>');\n" << indent()
2375 << "::typelib_static_type_init(&the_type, " << getTypeClass(name_, true)
2376 << ", the_buffer.getStr());\n";
2377 dec();
2378 out << indent() << "}\n" << indent()
2379 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
2380 "&the_type);\n");
2381 dumpGetCppuTypePostamble(out);
2384 void PolyStructType::dumpNormalGetCppuType(FileStream & out) {
2385 dumpGetCppuTypePreamble(out);
2386 out << indent()
2387 << ("//TODO: On certain platforms with weak memory models, the"
2388 " following code can result in some threads observing that the_type"
2389 " points to garbage\n")
2390 << indent()
2391 << "static ::typelib_TypeDescriptionReference * the_type = 0;\n"
2392 << indent() << "if (the_type == 0) {\n";
2393 inc();
2394 out << indent() << "::rtl::OStringBuffer the_buffer(\"" << name_
2395 << "<\");\n";
2396 for (std::vector< OUString >::const_iterator i(
2397 entity_->getTypeParameters().begin());
2398 i != entity_->getTypeParameters().end();)
2400 out << indent()
2401 << ("the_buffer.append(::rtl::OUStringToOString("
2402 "::cppu::getTypeFavourChar(static_cast< ");
2403 dumpTypeParameterName(out, *i);
2404 out << " * >(0)).getTypeName(), RTL_TEXTENCODING_UTF8));\n";
2405 ++i;
2406 if (i != entity_->getTypeParameters().end()) {
2407 out << indent() << "the_buffer.append(',');\n";
2410 out << indent() << "the_buffer.append('>');\n" << indent()
2411 << "::typelib_TypeDescriptionReference * the_members[] = {\n";
2412 inc();
2413 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2414 const_iterator i(entity_->getMembers().begin());
2415 i != entity_->getMembers().end();)
2417 out << indent();
2418 if (i->parameterized) {
2419 out << "::cppu::getTypeFavourChar(static_cast< ";
2420 dumpTypeParameterName(out, i->type);
2421 out << " * >(0))";
2422 } else {
2423 out << "::cppu::UnoType< ";
2424 dumpType(out, i->type, false, false, false, true);
2425 out << " >::get()";
2427 ++i;
2428 out << ".getTypeLibType()"
2429 << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
2431 dec();
2432 out << indent() << "static ::sal_Bool const the_parameterizedTypes[] = { ";
2433 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2434 const_iterator i(entity_->getMembers().begin());
2435 i != entity_->getMembers().end(); ++i)
2437 if (i != entity_->getMembers().begin()) {
2438 out << ", ";
2440 out << (i->parameterized ? "true" : "false");
2442 out << " };\n" << indent()
2443 << ("::typelib_static_struct_type_init(&the_type, the_buffer.getStr(),"
2444 " 0, ")
2445 << entity_->getMembers().size()
2446 << ", the_members, the_parameterizedTypes);\n";
2447 dec();
2448 out << indent() << "}\n" << indent()
2449 << ("return *reinterpret_cast< ::com::sun::star::uno::Type * >("
2450 "&the_type);\n");
2451 dumpGetCppuTypePostamble(out);
2454 void PolyStructType::dumpComprehensiveGetCppuType(FileStream & out) {
2455 out << "namespace cppu { namespace detail {\n\n" << indent();
2456 dumpTemplateHead(out);
2457 OUString staticTypeClass("the" + id_ + "Type");
2458 out << "struct " << staticTypeClass
2459 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2460 << staticTypeClass;
2461 dumpTemplateParameters(out);
2462 out << " >\n" << indent() << "{\n";
2463 inc();
2464 out << indent() << "::com::sun::star::uno::Type * operator()() const\n"
2465 << indent() << "{\n";
2466 inc();
2467 out << indent() << "::rtl::OUStringBuffer the_buffer;\n" << indent()
2468 << "the_buffer.append(\"" << name_ << "<\");\n";
2469 for (std::vector< OUString >::const_iterator i(
2470 entity_->getTypeParameters().begin());
2471 i != entity_->getTypeParameters().end();)
2473 out << indent()
2474 << "the_buffer.append(::cppu::getTypeFavourChar(static_cast< ";
2475 dumpTypeParameterName(out, *i);
2476 out << " * >(0)).getTypeName());\n";
2477 ++i;
2478 if (i != entity_->getTypeParameters().end()) {
2479 out << indent()
2480 << ("the_buffer.append("
2481 "static_cast< ::sal_Unicode >(','));\n");
2484 out << indent() << "the_buffer.append(static_cast< ::sal_Unicode >('>'));\n"
2485 << indent()
2486 << "::rtl::OUString the_name(the_buffer.makeStringAndClear());\n";
2487 std::map< OUString, sal_uInt32 > parameters;
2488 std::map< OUString, sal_uInt32 > types;
2489 std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2490 size_type n = 0;
2491 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2492 const_iterator i(entity_->getMembers().begin());
2493 i != entity_->getMembers().end(); ++i)
2495 if (i->parameterized) {
2496 if (parameters.insert(
2497 std::map< OUString, sal_uInt32 >::value_type(
2498 i->type, static_cast< sal_uInt32 >(parameters.size()))).
2499 second)
2501 sal_uInt32 k = static_cast< sal_uInt32 >(parameters.size() - 1);
2502 out << indent()
2503 << "::com::sun::star::uno::Type const & the_ptype" << k
2504 << " = ::cppu::getTypeFavourChar(static_cast< ";
2505 dumpTypeParameterName(out, i->type);
2506 out << " * >(0));\n" << indent()
2507 << "::typelib_TypeClass the_pclass" << k
2508 << " = (::typelib_TypeClass) the_ptype" << k
2509 << ".getTypeClass();\n" << indent()
2510 << "::rtl::OUString the_pname" << k << "(the_ptype" << k
2511 << ".getTypeName());\n";
2513 } else if (types.insert(
2514 std::map< OUString, sal_uInt32 >::value_type(
2515 i->type, static_cast< sal_uInt32 >(types.size()))).
2516 second)
2518 dumpCppuGetType(out, i->type, &name_);
2519 // For typedefs, use the resolved type name, as there will be no
2520 // information available about the typedef itself at runtime (the
2521 // above getCppuType call will make available information about the
2522 // resolved type); no extra #include for the resolved type is
2523 // needed, as the header for the typedef includes it already:
2524 out << indent() << "::rtl::OUString the_tname"
2525 << static_cast< sal_uInt32 >(types.size() - 1) << "( \""
2526 << resolveAllTypedefs(i->type) << "\" );\n";
2528 out << indent() << "::rtl::OUString the_name" << n++ << "( \""
2529 << i->name << "\" );\n";
2531 out << indent() << "::typelib_StructMember_Init the_members[] = {\n";
2532 inc();
2533 n = 0;
2534 for (std::vector< unoidl::PolymorphicStructTypeTemplateEntity::Member >::
2535 const_iterator i(entity_->getMembers().begin());
2536 i != entity_->getMembers().end();)
2538 out << indent() << "{ { ";
2539 if (i->parameterized) {
2540 sal_uInt32 k = parameters.find(i->type)->second;
2541 out << "the_pclass" << k << ", the_pname" << k << ".pData";
2542 } else {
2543 out << getTypeClass(i->type, true) << ", the_tname"
2544 << types.find(i->type)->second << ".pData";
2546 out << ", the_name" << n++ << ".pData }, "
2547 << (i->parameterized ? "true" : "false") << " }";
2548 ++i;
2549 out << (i == entity_->getMembers().end() ? " };" : ",") << "\n";
2551 dec();
2552 out << indent() << "::typelib_TypeDescription * the_newType = 0;\n";
2553 out << indent()
2554 << ("::typelib_typedescription_newStruct(&the_newType, the_name.pData,"
2555 " 0, ")
2556 << entity_->getMembers().size() << ", the_members);\n" << indent()
2557 << "::typelib_typedescription_register(&the_newType);\n" << indent()
2558 << "::typelib_typedescription_release(the_newType);\n" << indent()
2559 << "return new ::com::sun::star::uno::Type(" << getTypeClass(name_)
2560 << ", the_name); // leaked\n";
2561 dec();
2562 out << indent() << "}\n";
2563 dec();
2564 out << indent() << "};\n" << " }" << " }\n\n";
2565 dumpGetCppuTypePreamble(out);
2566 out << indent() << "return *detail::" << staticTypeClass;
2567 dumpTemplateParameters(out);
2568 out << "::get();\n";
2569 dumpGetCppuTypePostamble(out);
2572 void PolyStructType::addLightGetCppuTypeIncludes(
2573 codemaker::cppumaker::Includes & includes) const
2575 includes.addType();
2576 includes.addCppuUnotypeHxx();
2577 includes.addSalTypesH();
2578 includes.addTypelibTypeclassH();
2579 includes.addTypelibTypedescriptionH();
2580 includes.addRtlStrbufHxx();
2581 includes.addRtlTextencH();
2582 includes.addRtlUstringHxx();
2585 void PolyStructType::addNormalGetCppuTypeIncludes(
2586 codemaker::cppumaker::Includes & includes) const
2588 includes.addType();
2589 includes.addCppuUnotypeHxx();
2590 includes.addSalTypesH();
2591 includes.addTypelibTypeclassH();
2592 includes.addTypelibTypedescriptionH();
2593 includes.addRtlStrbufHxx();
2594 includes.addRtlTextencH();
2595 includes.addRtlUstringHxx();
2598 void PolyStructType::addComprehensiveGetCppuTypeIncludes(
2599 codemaker::cppumaker::Includes & includes) const
2601 includes.addType();
2602 includes.addCppuUnotypeHxx();
2603 includes.addRtlInstanceHxx();
2604 includes.addOslMutexHxx();
2605 includes.addRtlUstringH();
2606 includes.addRtlUstringHxx();
2607 includes.addSalTypesH();
2608 includes.addTypelibTypeclassH();
2609 includes.addTypelibTypedescriptionH();
2610 includes.addRtlStringH();
2611 includes.addRtlUstrbufHxx();
2614 void PolyStructType::dumpTemplateHead(FileStream & out) const {
2615 out << "template< ";
2616 for (std::vector< OUString >::const_iterator i(
2617 entity_->getTypeParameters().begin());
2618 i != entity_->getTypeParameters().end(); ++i)
2620 if (i != entity_->getTypeParameters().begin()) {
2621 out << ", ";
2623 out << "typename ";
2624 dumpTypeParameterName(out, *i);
2626 out << " > ";
2629 void PolyStructType::dumpTemplateParameters(FileStream & out) const {
2630 out << "< ";
2631 for (std::vector< OUString >::const_iterator i(
2632 entity_->getTypeParameters().begin());
2633 i != entity_->getTypeParameters().end(); ++i)
2635 if (i != entity_->getTypeParameters().begin()) {
2636 out << ", ";
2638 dumpTypeParameterName(out, *i);
2640 out << " >";
2643 OUString typeToIdentifier(OUString const & name) {
2644 sal_Int32 k;
2645 OUString n(b2u(codemaker::UnoType::decompose(u2b(name), &k)));
2646 OUStringBuffer b;
2647 for (sal_Int32 i = 0; i != k; ++i) {
2648 b.append("seq_");
2650 b.append(n);
2651 b.replace(' ', '_');
2652 b.replace(',', '_');
2653 b.replace('.', '_');
2654 b.replace('<', '_');
2655 b.replace('>', '_');
2656 return b.makeStringAndClear();
2659 class ExceptionType: public CppuType {
2660 public:
2661 ExceptionType(
2662 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity,
2663 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
2664 CppuType(name, typeMgr), entity_(entity)
2665 { assert(entity.is()); }
2667 private:
2668 virtual void dumpHxxFile(
2669 FileStream & out, codemaker::cppumaker::Includes & includes);
2671 virtual void dumpLightGetCppuType(FileStream & out);
2673 virtual void dumpNormalGetCppuType(FileStream & out);
2675 virtual void dumpComprehensiveGetCppuType(FileStream & out);
2677 virtual sal_uInt32 checkInheritedMemberCount() const
2678 { return getTotalMemberCount(entity_->getDirectBase()); }
2680 virtual void dumpDeclaration(FileStream & out);
2682 bool dumpBaseMembers(
2683 FileStream & out, OUString const & base, bool withType);
2685 sal_uInt32 getTotalMemberCount(OUString const & base) const;
2687 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
2690 void ExceptionType::dumpHxxFile(
2691 FileStream & out, codemaker::cppumaker::Includes & includes)
2693 OUString headerDefine(dumpHeaderDefine(out, "HPP"));
2694 out << "\n";
2695 addDefaultHxxIncludes(includes);
2696 includes.dump(out, &name_);
2697 out << "\n";
2698 if (codemaker::cppumaker::dumpNamespaceOpen(out, name_, false)) {
2699 out << "\n";
2701 out << "\ninline " << id_ << "::" << id_ << "() SAL_THROW(())\n";
2702 inc();
2703 OUString base(entity_->getDirectBase());
2704 bool first = true;
2705 if (!base.isEmpty()) {
2706 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
2707 << "()\n";
2708 first = false;
2710 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2711 entity_->getDirectMembers().begin());
2712 i != entity_->getDirectMembers().end(); ++i)
2714 out << indent() << (first ? ":" : ",") << " ";
2715 out << i->name;
2716 dumpInitializer(out, false, i->type);
2717 out << "\n";
2718 first = false;
2720 dec();
2721 out << "{";
2722 if (!m_cppuTypeDynamic) {
2723 out << "\n";
2724 inc();
2725 dumpCppuGetType(out, name_);
2726 dec();
2727 } else {
2728 out << " ";
2730 out << "}\n\n";
2731 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2732 out << indent() << "inline " << id_ << "::" << id_ << "(";
2733 first = !dumpBaseMembers(out, base, true);
2734 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2735 i(entity_->getDirectMembers().begin());
2736 i != entity_->getDirectMembers().end(); ++i)
2738 if (!first) {
2739 out << ", ";
2741 dumpType(out, i->type, true, true);
2742 out << " " << i->name << "_";
2743 first = false;
2745 out << ") SAL_THROW(())\n";
2746 inc();
2747 first = true;
2748 if (!base.isEmpty()) {
2749 out << indent() << ": " << codemaker::cpp::scopedCppName(u2b(base))
2750 << "(";
2751 dumpBaseMembers(out, base, false);
2752 out << ")\n";
2753 first = false;
2755 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2756 i(entity_->getDirectMembers().begin());
2757 i != entity_->getDirectMembers().end(); ++i)
2759 out << indent() << (first ? ":" : ",") << " " << i->name << "("
2760 << i->name << "_)\n";
2761 first = false;
2763 dec();
2764 out << "{";
2765 if (!m_cppuTypeDynamic) {
2766 out << "\n";
2767 inc();
2768 dumpCppuGetType(out, name_);
2769 dec();
2770 } else {
2771 out << " ";
2773 out << "}\n\n";
2775 out << indent() << id_ << "::" << id_ << "(" << id_
2776 << " const & the_other)";
2777 first = true;
2778 if (!base.isEmpty()) {
2779 out << ": " << codemaker::cpp::scopedCppName(u2b(base))
2780 << "(the_other)";
2781 first = false;
2783 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2784 entity_->getDirectMembers().begin());
2785 i != entity_->getDirectMembers().end(); ++i)
2787 out << (first ? ":" : ",") << " " << i->name << "(the_other." << i->name
2788 << ")";
2789 first = false;
2791 out << indent() << " {}\n\n" << indent() << id_ << "::~" << id_
2792 << "() {}\n\n" << indent() << id_ << " & " << id_ << "::operator =("
2793 << id_ << " const & the_other) {\n";
2794 inc();
2795 out << indent()
2796 << ("//TODO: Just like its implicitly-defined counterpart, this"
2797 " function definition is not exception-safe\n");
2798 if (!base.isEmpty()) {
2799 out << indent() << codemaker::cpp::scopedCppName(u2b(base))
2800 << "::operator =(the_other);\n";
2802 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2803 entity_->getDirectMembers().begin());
2804 i != entity_->getDirectMembers().end(); ++i)
2806 out << indent() << i->name << " = the_other." << i->name << ";\n";
2808 out << indent() << "return *this;\n";
2809 dec();
2810 out << indent() << "}\n\n";
2811 if (codemaker::cppumaker::dumpNamespaceClose(out, name_, false)) {
2812 out << "\n";
2814 out << "\n";
2815 dumpGetCppuType(out);
2816 out << "\n#endif // "<< headerDefine << "\n";
2819 void ExceptionType::dumpLightGetCppuType(FileStream & out) {
2820 dumpGetCppuTypePreamble(out);
2821 out << indent()
2822 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2823 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2824 inc();
2825 out << indent() << "typelib_static_type_init( &the_type, "
2826 << getTypeClass(name_, true) << ", \"" << name_ << "\" );\n";
2827 dec();
2828 out << indent() << "}\n" << indent()
2829 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
2830 " &the_type );\n");
2831 dumpGetCppuTypePostamble(out);
2834 void ExceptionType::dumpNormalGetCppuType(FileStream & out) {
2835 dumpGetCppuTypePreamble(out);
2836 out << indent()
2837 << "static typelib_TypeDescriptionReference * the_type = 0;\n"
2838 << indent() << "if ( !the_type )\n" << indent() << "{\n";
2839 inc();
2840 OUString base(entity_->getDirectBase());
2841 bool baseException = false;
2842 if (!base.isEmpty()) {
2843 if (base == "com.sun.star.uno.Exception") {
2844 baseException = true;
2845 } else {
2846 out << indent()
2847 << ("const ::com::sun::star::uno::Type& rBaseType ="
2848 " ::cppu::UnoType< ");
2849 dumpType(out, base, true, false, false, true);
2850 out << " >::get();\n\n";
2853 if (!entity_->getDirectMembers().empty()) {
2854 out << indent() << "typelib_TypeDescriptionReference * aMemberRefs["
2855 << entity_->getDirectMembers().size() << "];\n";
2856 std::set< OUString > seen;
2857 std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
2858 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2859 i(entity_->getDirectMembers().begin());
2860 i != entity_->getDirectMembers().end(); ++i)
2862 OUString type(resolveAllTypedefs(i->type));
2863 OUString modType(typeToIdentifier(type));
2864 if (seen.insert(type).second) {
2865 out << indent()
2866 << "const ::com::sun::star::uno::Type& rMemberType_"
2867 << modType << " = ::cppu::UnoType< ";
2868 dumpType(out, type, false, false, false, true);
2869 out << " >::get();\n";
2871 out << indent() << "aMemberRefs[" << n++ << "] = rMemberType_"
2872 << modType << ".getTypeLibType();\n";
2874 out << "\n";
2876 out << indent() << "typelib_static_compound_type_init( &the_type, "
2877 << getTypeClass(name_, true) << ", \"" << name_ << "\", ";
2878 if (baseException) {
2879 out << ("* ::typelib_static_type_getByTypeClass("
2880 " typelib_TypeClass_EXCEPTION )");
2881 } else if (base.isEmpty()) {
2882 out << "0";
2883 } else {
2884 out << "rBaseType.getTypeLibType()";
2886 out << ", " << entity_->getDirectMembers().size() << ", "
2887 << (entity_->getDirectMembers().empty() ? "0" : "aMemberRefs")
2888 << " );\n";
2889 dec();
2890 out << indent() << "}\n" << indent()
2891 << ("return * reinterpret_cast< const ::com::sun::star::uno::Type * >("
2892 " &the_type );\n");
2893 dumpGetCppuTypePostamble(out);
2896 void ExceptionType::dumpComprehensiveGetCppuType(FileStream & out) {
2897 codemaker::cppumaker::dumpNamespaceOpen(out, name_, false);
2898 out << " namespace detail {\n\n";
2899 OUString staticTypeClass("the" + id_ + "Type");
2900 out << indent() << "struct " << staticTypeClass
2901 << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, "
2902 << staticTypeClass << " >\n" << indent() << "{\n";
2903 inc();
2904 out << indent() << "::com::sun::star::uno::Type * operator()() const\n"
2905 << indent() << "{\n";
2906 inc();
2907 out << indent() << "::rtl::OUString sTypeName( \"" << name_ << "\" );\n\n"
2908 << indent() << "// Start inline typedescription generation\n"
2909 << indent() << "typelib_TypeDescription * pTD = 0;\n";
2910 OUString base(entity_->getDirectBase());
2911 if (!base.isEmpty()) {
2912 out << indent()
2913 << ("const ::com::sun::star::uno::Type& rSuperType ="
2914 " ::cppu::UnoType< ");
2915 dumpType(out, base, false, false, false, true);
2916 out << " >::get();\n";
2918 std::set< OUString > seen;
2919 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
2920 entity_->getDirectMembers().begin());
2921 i != entity_->getDirectMembers().end(); ++i)
2923 if (seen.insert(i->type).second) {
2924 dumpCppuGetType(out, i->type);
2927 if (!entity_->getDirectMembers().empty()) {
2928 out << "\n" << indent() << "typelib_CompoundMember_Init aMembers["
2929 << entity_->getDirectMembers().size() << "];\n";
2930 std::vector< unoidl::ExceptionTypeEntity::Member >::size_type n = 0;
2931 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2932 i(entity_->getDirectMembers().begin());
2933 i != entity_->getDirectMembers().end(); ++i)
2935 OUString type(resolveAllTypedefs(i->type));
2936 out << indent() << "::rtl::OUString sMemberType" << n << "( \""
2937 << type << "\" );\n" << indent()
2938 << "::rtl::OUString sMemberName" << n << "( \"" << i->name
2939 << "\" );\n" << indent() << "aMembers[" << n
2940 << "].eTypeClass = (typelib_TypeClass)" << getTypeClass(type)
2941 << ";\n" << indent() << "aMembers[" << n
2942 << "].pTypeName = sMemberType" << n << ".pData;\n" << indent()
2943 << "aMembers[" << n << "].pMemberName = sMemberName" << n
2944 << ".pData;\n";
2945 ++n;
2948 out << "\n" << indent() << "typelib_typedescription_new(\n";
2949 inc();
2950 out << indent() << "&pTD,\n" << indent() << "(typelib_TypeClass)"
2951 << getTypeClass(name_) << ", sTypeName.pData,\n" << indent()
2952 << (base.isEmpty() ? "0" : "rSuperType.getTypeLibType()") << ",\n"
2953 << indent() << entity_->getDirectMembers().size() << ",\n" << indent()
2954 << (entity_->getDirectMembers().empty() ? "0" : "aMembers")
2955 << " );\n\n";
2956 dec();
2957 out << indent()
2958 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
2959 " );\n\n")
2960 << indent() << "typelib_typedescription_release( pTD );\n" << indent()
2961 << "// End inline typedescription generation\n\n" << indent()
2962 << "return new ::com::sun::star::uno::Type( " << getTypeClass(name_)
2963 << ", sTypeName ); // leaked\n";
2964 dec();
2965 out << indent() << "}\n";
2966 dec();
2967 out << indent() << "};\n\n";
2968 codemaker::cppumaker::dumpNamespaceClose(out, name_, false);
2969 out << " }\n\n";
2970 dumpGetCppuTypePreamble(out);
2971 out << indent() << "return *detail::" << staticTypeClass << "::get();\n";
2972 dumpGetCppuTypePostamble(out);
2975 void ExceptionType::dumpDeclaration(FileStream & out) {
2976 out << "\nclass CPPU_GCC_DLLPUBLIC_EXPORT " << id_;
2977 OUString base(entity_->getDirectBase());
2978 if (!base.isEmpty()) {
2979 out << " : public " << codemaker::cpp::scopedCppName(u2b(base));
2981 out << "\n{\npublic:\n";
2982 inc();
2983 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
2984 << "() SAL_THROW(());\n\n";
2985 if (!entity_->getDirectMembers().empty() || getInheritedMemberCount() > 0) {
2986 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(";
2987 bool first = !dumpBaseMembers(out, base, true);
2988 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
2989 i(entity_->getDirectMembers().begin());
2990 i != entity_->getDirectMembers().end(); ++i)
2992 if (!first) {
2993 out << ", ";
2995 dumpType(out, i->type, true, true);
2996 out << " " << i->name << "_";
2997 first = false;
2999 out << ") SAL_THROW(());\n\n";
3001 out << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_ << "(" << id_
3002 << " const &);\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE ~"
3003 << id_ << "();\n\n" << indent() << "inline CPPU_GCC_DLLPRIVATE " << id_
3004 << " & operator =(" << id_ << " const &);\n\n";
3005 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator i(
3006 entity_->getDirectMembers().begin());
3007 i != entity_->getDirectMembers().end(); ++i)
3009 out << indent();
3010 dumpType(out, i->type);
3011 out << " " << i->name;
3012 if (i == entity_->getDirectMembers().begin() && !base.isEmpty()
3013 && i->type != "hyper" && i->type != "unsigned hyper"
3014 && i->type != "double")
3016 out << " CPPU_GCC3_ALIGN( "
3017 << codemaker::cpp::scopedCppName(u2b(base)) << " )";
3019 out << ";\n";
3021 dec();
3022 out << "};\n\n";
3025 bool ExceptionType::dumpBaseMembers(
3026 FileStream & out, OUString const & base, bool withType)
3028 bool hasMember = false;
3029 if (!base.isEmpty()) {
3030 rtl::Reference< unoidl::Entity > ent;
3031 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
3032 if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
3033 throw CannotDumpException(
3034 "exception type base " + base + " is not an exception type");
3036 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
3037 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
3038 assert(ent2.is());
3039 hasMember = dumpBaseMembers(out, ent2->getDirectBase(), withType);
3040 for (std::vector< unoidl::ExceptionTypeEntity::Member >::const_iterator
3041 i(ent2->getDirectMembers().begin());
3042 i != ent2->getDirectMembers().end(); ++i)
3044 if (hasMember) {
3045 out << ", ";
3047 if (withType) {
3048 dumpType(out, i->type, true, true);
3049 out << " ";
3051 out << i->name << "_";
3052 hasMember = true;
3055 return hasMember;
3058 sal_uInt32 ExceptionType::getTotalMemberCount(OUString const & base) const {
3059 if (base.isEmpty()) {
3060 return 0;
3062 rtl::Reference< unoidl::Entity > ent;
3063 codemaker::UnoType::Sort sort = m_typeMgr->getSort(base, &ent);
3064 if (sort != codemaker::UnoType::SORT_EXCEPTION_TYPE) {
3065 throw CannotDumpException(
3066 "exception type base " + base + " is not an exception type");
3068 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
3069 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()));
3070 assert(ent2.is());
3071 return getTotalMemberCount(ent2->getDirectBase())
3072 + ent2->getDirectMembers().size(); //TODO: overflow
3075 class EnumType: public CppuType {
3076 public:
3077 EnumType(
3078 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
3079 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
3080 CppuType(name, typeMgr), entity_(entity)
3081 { assert(entity.is()); }
3083 private:
3084 virtual void dumpDeclaration(FileStream& o);
3086 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes);
3088 void dumpNormalGetCppuType(FileStream& o);
3089 void dumpComprehensiveGetCppuType(FileStream& o);
3091 rtl::Reference< unoidl::EnumTypeEntity > entity_;
3094 void EnumType::dumpDeclaration(FileStream& o)
3096 o << "\nenum " << id_ << "\n{\n";
3097 inc();
3099 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3100 entity_->getMembers().begin());
3101 i != entity_->getMembers().end(); ++i)
3103 o << indent() << id_ << "_" << u2b(i->name) << " = " << i->value
3104 << ",\n";
3107 o << indent() << id_ << "_MAKE_FIXED_SIZE = SAL_MAX_ENUM\n";
3109 dec();
3110 o << "};\n\n";
3113 void EnumType::dumpHxxFile(
3114 FileStream& o, codemaker::cppumaker::Includes & includes)
3116 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3117 o << "\n";
3119 addDefaultHxxIncludes(includes);
3120 includes.dump(o, &name_);
3121 o << "\n";
3123 dumpGetCppuType(o);
3125 o << "\n#endif // "<< headerDefine << "\n";
3128 void EnumType::dumpNormalGetCppuType(FileStream& o)
3130 dumpGetCppuTypePreamble(o);
3132 o << indent()
3133 << "static typelib_TypeDescriptionReference * the_type = 0;\n";
3135 o << indent() << "if ( !the_type )\n" << indent() << "{\n";
3136 inc();
3138 o << indent() << "typelib_static_enum_type_init( &the_type,\n";
3139 inc(31);
3140 o << indent() << "\"" << name_ << "\",\n"
3141 << indent() << codemaker::cpp::scopedCppName(u2b(name_)) << "_"
3142 << u2b(entity_->getMembers()[0].name) << " );\n";
3143 dec(31);
3144 dec();
3145 o << indent() << "}\n";
3146 o << indent()
3147 << ("return * reinterpret_cast< ::com::sun::star::uno::Type * >("
3148 " &the_type );\n");
3149 dumpGetCppuTypePostamble(o);
3152 void EnumType::dumpComprehensiveGetCppuType(FileStream& o)
3154 if (!isPolymorphic())
3155 codemaker::cppumaker::dumpNamespaceOpen(o, name_, false);
3156 else
3157 o << "namespace cppu { ";
3158 o << " namespace detail {\n\n";
3160 OUString sStaticTypeClass("the" + id_ + "Type");
3161 o << indent() << "struct " << sStaticTypeClass << " : public rtl::StaticWithInit< ::com::sun::star::uno::Type *, " << sStaticTypeClass << " >\n";
3162 o << indent() << "{\n";
3163 inc();
3164 o << indent() << "::com::sun::star::uno::Type * operator()() const\n";
3165 o << indent() << "{\n";
3167 inc();
3168 o << indent() << "::rtl::OUString sTypeName( \"" << name_
3169 << "\" );\n\n";
3171 o << indent() << "// Start inline typedescription generation\n"
3172 << indent() << "typelib_TypeDescription * pTD = 0;\n\n";
3174 o << indent() << "rtl_uString* enumValueNames["
3175 << entity_->getMembers().size() << "];\n";
3176 std::vector< unoidl::EnumTypeEntity::Member >::size_type n = 0;
3177 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3178 entity_->getMembers().begin());
3179 i != entity_->getMembers().end(); ++i)
3181 o << indent() << "::rtl::OUString sEnumValue" << n << "( \""
3182 << u2b(i->name) << "\" );\n";
3183 o << indent() << "enumValueNames[" << n << "] = sEnumValue" << n
3184 << ".pData;\n";
3185 ++n;
3188 o << "\n" << indent() << "sal_Int32 enumValues["
3189 << entity_->getMembers().size() << "];\n";
3190 n = 0;
3191 for (std::vector< unoidl::EnumTypeEntity::Member >::const_iterator i(
3192 entity_->getMembers().begin());
3193 i != entity_->getMembers().end(); ++i)
3195 o << indent() << "enumValues[" << n++ << "] = " << i->value << ";\n";
3198 o << "\n" << indent() << "typelib_typedescription_newEnum( &pTD,\n";
3199 inc();
3200 o << indent() << "sTypeName.pData,\n"
3201 << indent() << "(sal_Int32)"
3202 << codemaker::cpp::scopedCppName(u2b(name_), false) << "_"
3203 << u2b(entity_->getMembers()[0].name) << ",\n"
3204 << indent() << entity_->getMembers().size()
3205 << ", enumValueNames, enumValues );\n\n";
3206 dec();
3208 o << indent()
3209 << ("typelib_typedescription_register( (typelib_TypeDescription**)&pTD"
3210 " );\n");
3211 o << indent() << "typelib_typedescription_release( pTD );\n"
3212 << indent() << "// End inline typedescription generation\n\n";
3214 o << indent() << "return new ::com::sun::star::uno::Type( "
3215 << getTypeClass(name_) << ", sTypeName ); // leaked\n";
3217 dec();
3218 o << indent() << "}\n";
3219 dec();
3220 o << indent() << "};\n\n";
3222 if (!isPolymorphic())
3223 codemaker::cppumaker::dumpNamespaceClose(o, name_, false);
3224 else
3225 o << " }";
3226 o << " }\n\n";
3228 dumpGetCppuTypePreamble(o);
3229 o << indent() << "return *detail::" << sStaticTypeClass << "::get();\n";
3230 dumpGetCppuTypePostamble(o);
3233 class Typedef: public CppuType {
3234 public:
3235 Typedef(
3236 rtl::Reference< unoidl::TypedefEntity > const & entity,
3237 OUString const & name, rtl::Reference< TypeManager > const & typeMgr):
3238 CppuType(name, typeMgr), entity_(entity)
3239 { assert(entity.is()); }
3241 private:
3242 virtual void dumpDeclaration(FileStream& o);
3244 void dumpHFile(FileStream& o, codemaker::cppumaker::Includes & includes);
3246 void dumpHxxFile(FileStream& o, codemaker::cppumaker::Includes & includes);
3248 rtl::Reference< unoidl::TypedefEntity > entity_;
3251 void Typedef::dumpHFile(
3252 FileStream& o, codemaker::cppumaker::Includes & includes)
3254 OUString headerDefine(dumpHeaderDefine(o, "HDL"));
3255 o << "\n";
3257 addDefaultHIncludes(includes);
3258 includes.dump(o, 0);
3259 o << "\n";
3261 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3262 o << "\n";
3265 dumpDeclaration(o);
3267 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3268 o << "\n";
3271 o << "#endif // "<< headerDefine << "\n";
3274 void Typedef::dumpDeclaration(FileStream& o)
3276 o << "\ntypedef ";
3277 dumpType(o, entity_->getType());
3278 o << " " << id_ << ";\n\n";
3281 void Typedef::dumpHxxFile(
3282 FileStream& o, codemaker::cppumaker::Includes & includes)
3284 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3285 o << "\n";
3287 addDefaultHxxIncludes(includes);
3288 includes.dump(o, &name_);
3289 o << "\n";
3291 o << "\n#endif // "<< headerDefine << "\n";
3294 class ConstructiveType: public CppuType {
3295 public:
3296 ConstructiveType(
3297 OUString const & name, rtl::Reference< TypeManager > const & manager):
3298 CppuType(name, manager) {}
3300 private:
3301 virtual void dumpHFile(FileStream &, codemaker::cppumaker::Includes &)
3302 { assert(false); } // this cannot happen
3304 virtual void dumpFiles(OUString const & uri, CppuOptions const & options)
3305 { dumpFile(uri, name_, true, options); }
3308 bool hasRestParameter(
3309 unoidl::SingleInterfaceBasedServiceEntity::Constructor const & constructor)
3311 return !constructor.parameters.empty()
3312 && constructor.parameters.back().rest;
3315 void includeExceptions(
3316 codemaker::cppumaker::Includes & includes,
3317 codemaker::ExceptionTreeNode const * node)
3319 if (node->present) {
3320 includes.add(node->name);
3321 } else {
3322 for (codemaker::ExceptionTreeNode::Children::const_iterator i(
3323 node->children.begin());
3324 i != node->children.end(); ++i)
3326 includeExceptions(includes, *i);
3331 class ServiceType: public ConstructiveType {
3332 public:
3333 ServiceType(
3334 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
3335 entity,
3336 OUString const & name, rtl::Reference< TypeManager > const & manager):
3337 ConstructiveType(name, manager), entity_(entity)
3338 { assert(entity.is()); }
3340 private:
3341 virtual void dumpHxxFile(
3342 FileStream & o, codemaker::cppumaker::Includes & includes);
3344 void dumpCatchClauses(
3345 FileStream & out, codemaker::ExceptionTreeNode const * node);
3347 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
3350 void ServiceType::dumpHxxFile(
3351 FileStream & o, codemaker::cppumaker::Includes & includes)
3353 if (!entity_->getConstructors().empty()) {
3354 //TODO: Decide whether the types added to includes should rather be
3355 // added to m_dependencies (and thus be generated during
3356 // dumpDependedTypes):
3357 includes.addCassert();
3358 includes.addReference();
3359 includes.addRtlUstringH();
3360 includes.addRtlUstringHxx();
3361 includes.add("com.sun.star.uno.DeploymentException");
3362 includes.add("com.sun.star.uno.XComponentContext");
3363 for (std::vector<
3364 unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
3365 const_iterator i(entity_->getConstructors().begin());
3366 i != entity_->getConstructors().end(); ++i)
3368 if (i->defaultConstructor) {
3369 includes.add("com.sun.star.uno.Exception");
3370 includes.add("com.sun.star.uno.RuntimeException");
3371 } else {
3372 if (!hasRestParameter(*i)) {
3373 includes.addAny();
3374 includes.addSequence();
3375 for (std::vector<
3376 unoidl::SingleInterfaceBasedServiceEntity::
3377 Constructor::Parameter >::const_iterator j(
3378 i->parameters.begin());
3379 j != i->parameters.end(); ++j)
3381 if (m_typeMgr->getSort(
3382 b2u(codemaker::UnoType::decompose(
3383 u2b(j->type), 0, 0)))
3384 == codemaker::UnoType::SORT_CHAR)
3386 includes.addCppuUnotypeHxx();
3387 break;
3391 codemaker::ExceptionTree tree;
3392 for (std::vector< OUString >::const_iterator j(
3393 i->exceptions.begin());
3394 j != i->exceptions.end(); ++j)
3396 tree.add(u2b(*j), m_typeMgr);
3398 if (!tree.getRoot()->present) {
3399 includes.add("com.sun.star.uno.Exception");
3400 includes.add("com.sun.star.uno.RuntimeException");
3401 includeExceptions(includes, tree.getRoot());
3406 OString cppName(
3407 codemaker::cpp::translateUnoToCppIdentifier(
3408 u2b(id_), "service", isGlobal()));
3409 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3410 o << "\n";
3411 includes.dump(o, 0);
3412 o << "\n";
3413 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3414 o << "\n";
3416 o << "\nclass " << cppName << " {\n";
3417 inc();
3418 if (!entity_->getConstructors().empty()) {
3419 OString baseName(u2b(entity_->getBase()));
3420 OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
3421 o << "public:\n";
3422 for (std::vector<
3423 unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
3424 const_iterator i(entity_->getConstructors().begin());
3425 i != entity_->getConstructors().end(); ++i)
3427 if (i->defaultConstructor) {
3428 o << indent() << "static ::com::sun::star::uno::Reference< "
3429 << scopedBaseName << " > "
3430 << codemaker::cpp::translateUnoToCppIdentifier(
3431 "create", "method", codemaker::cpp::ITM_NONGLOBAL,
3432 &cppName)
3433 << ("(::com::sun::star::uno::Reference<"
3434 " ::com::sun::star::uno::XComponentContext > const &"
3435 " the_context) {\n");
3436 inc();
3437 o << indent() << "assert(the_context.is());\n" << indent()
3438 << "::com::sun::star::uno::Reference< " << scopedBaseName
3439 << " > the_instance;\n" << indent() << "try {\n";
3440 inc();
3441 o << indent()
3442 << "the_instance = ::com::sun::star::uno::Reference< "
3443 << scopedBaseName
3444 << (" >(the_context->getServiceManager()->"
3445 "createInstanceWithContext(::rtl::OUString("
3446 " \"")
3447 << name_
3448 << "\" ), the_context), ::com::sun::star::uno::UNO_QUERY);\n";
3449 dec();
3450 o << indent()
3451 << "} catch (const ::com::sun::star::uno::RuntimeException &) {\n";
3452 inc();
3453 o << indent() << "throw;\n";
3454 dec();
3455 o << indent()
3456 << ("} catch (const ::com::sun::star::uno::Exception &"
3457 " the_exception) {\n");
3458 inc();
3459 o << indent()
3460 << ("throw ::com::sun::star::uno::DeploymentException("
3461 "::rtl::OUString( "
3462 "\"component context fails to supply service ")
3463 << name_ << " of type " << baseName
3464 << ": \" ) + the_exception.Message, the_context);\n";
3465 dec();
3466 o << indent() << "}\n" << indent()
3467 << "if (!the_instance.is()) {\n";
3468 inc();
3469 o << indent()
3470 << ("throw ::com::sun::star::uno::DeploymentException("
3471 "::rtl::OUString( "
3472 "\"component context fails to supply service ")
3473 << name_ << " of type " << baseName
3474 << "\" ), the_context);\n";
3475 dec();
3476 o << indent() << "}\n" << indent() << "return the_instance;\n";
3477 dec();
3478 o << indent() << "}\n\n";
3479 } else {
3480 o << indent() << "static ::com::sun::star::uno::Reference< "
3481 << scopedBaseName << " > "
3482 << codemaker::cpp::translateUnoToCppIdentifier(
3483 u2b(i->name), "method", codemaker::cpp::ITM_NONGLOBAL,
3484 &cppName)
3485 << ("(::com::sun::star::uno::Reference<"
3486 " ::com::sun::star::uno::XComponentContext > const &"
3487 " the_context");
3488 bool rest = hasRestParameter(*i);
3489 for (std::vector<
3490 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3491 Parameter >::const_iterator j(i->parameters.begin());
3492 j != i->parameters.end(); ++j)
3494 o << ", ";
3495 OUStringBuffer buf;
3496 if (j->rest) {
3497 buf.append("[]");
3499 buf.append(j->type);
3500 OUString type(buf.makeStringAndClear());
3501 bool byRef = passByReference(type);
3502 dumpType(o, type, byRef, byRef);
3503 o << " "
3504 << codemaker::cpp::translateUnoToCppIdentifier(
3505 u2b(j->name), "param", codemaker::cpp::ITM_NONGLOBAL);
3507 o << ") {\n";
3508 inc();
3509 o << indent() << "assert(the_context.is());\n";
3510 if (!rest && !i->parameters.empty()) {
3511 o << indent()
3512 << ("::com::sun::star::uno::Sequence<"
3513 " ::com::sun::star::uno::Any > the_arguments(")
3514 << i->parameters.size() << ");\n";
3515 std::vector<
3516 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
3517 Parameter >::size_type n = 0;
3518 for (std::vector<
3519 unoidl::SingleInterfaceBasedServiceEntity::
3520 Constructor::Parameter >::const_iterator j(
3521 i->parameters.begin());
3522 j != i->parameters.end(); ++j)
3524 o << indent() << "the_arguments[" << n++ << "] ";
3525 OString param(
3526 codemaker::cpp::translateUnoToCppIdentifier(
3527 u2b(j->name), "param",
3528 codemaker::cpp::ITM_NONGLOBAL));
3529 sal_Int32 rank;
3530 if (m_typeMgr->getSort(
3531 b2u(codemaker::UnoType::decompose(
3532 u2b(j->type), &rank, 0)))
3533 == codemaker::UnoType::SORT_CHAR)
3535 o << "= ::com::sun::star::uno::Any(&" << param
3536 << ", ::cppu::UnoType< ";
3537 for (sal_Int32 k = 0; k < rank; ++k) {
3538 o << "::cppu::UnoSequenceType< ";
3540 o << "::cppu::UnoCharType";
3541 for (sal_Int32 k = 0; k < rank; ++k) {
3542 o << " >";
3544 o << " >::get())";
3545 } else {
3546 o << "<<= " << param;
3548 o << ";\n";
3551 o << indent() << "::com::sun::star::uno::Reference< "
3552 << scopedBaseName << " > the_instance;\n";
3553 codemaker::ExceptionTree tree;
3554 for (std::vector< OUString >::const_iterator j(
3555 i->exceptions.begin());
3556 j != i->exceptions.end(); ++j)
3558 tree.add(u2b(*j), m_typeMgr);
3560 if (!tree.getRoot()->present) {
3561 o << indent() << "try {\n";
3562 inc();
3564 o << indent()
3565 << "the_instance = ::com::sun::star::uno::Reference< "
3566 << scopedBaseName
3567 << (" >(the_context->getServiceManager()->"
3568 "createInstanceWithArgumentsAndContext(::rtl::OUString("
3569 " \"")
3570 << name_ << "\" ), ";
3571 if (rest) {
3572 o << codemaker::cpp::translateUnoToCppIdentifier(
3573 u2b(i->parameters.back().name), "param",
3574 codemaker::cpp::ITM_NONGLOBAL);
3575 } else if (i->parameters.empty()) {
3576 o << ("::com::sun::star::uno::Sequence<"
3577 " ::com::sun::star::uno::Any >()");
3578 } else {
3579 o << "the_arguments";
3581 o << ", the_context), ::com::sun::star::uno::UNO_QUERY);\n";
3582 if (!tree.getRoot()->present) {
3583 dec();
3584 o << indent()
3585 << ("} catch (const ::com::sun::star::uno::RuntimeException &)"
3586 " {\n");
3587 inc();
3588 o << indent() << "throw;\n";
3589 dec();
3590 dumpCatchClauses(o, tree.getRoot());
3591 o << indent()
3592 << ("} catch (const ::com::sun::star::uno::Exception &"
3593 " the_exception) {\n");
3594 inc();
3595 o << indent()
3596 << ("throw ::com::sun::star::uno::DeploymentException("
3597 "::rtl::OUString( "
3598 "\"component context fails to supply service ")
3599 << name_ << " of type " << baseName
3600 << ": \" ) + the_exception.Message, the_context);\n";
3601 dec();
3602 o << indent() << "}\n";
3604 o << indent() << "if (!the_instance.is()) {\n";
3605 inc();
3606 o << indent()
3607 << ("throw ::com::sun::star::uno::DeploymentException("
3608 "::rtl::OUString( "
3609 "\"component context fails to supply service ")
3610 << name_ << " of type " << baseName
3611 << "\" ), the_context);\n";
3612 dec();
3613 o << indent() << "}\n" << indent() << "return the_instance;\n";
3614 dec();
3615 o << indent() << "}\n\n";
3619 o << "private:\n";
3620 o << indent() << cppName << "(); // not implemented\n"
3621 << indent() << cppName << "(" << cppName << " &); // not implemented\n"
3622 << indent() << "~" << cppName << "(); // not implemented\n"
3623 << indent() << "void operator =(" << cppName << "); // not implemented\n";
3624 dec();
3625 o << "};\n\n";
3626 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3627 o << "\n";
3629 o << "\n#endif // "<< headerDefine << "\n";
3632 void ServiceType::dumpCatchClauses(
3633 FileStream & out, codemaker::ExceptionTreeNode const * node)
3635 if (node->present) {
3636 out << indent() << "} catch (const ";
3637 dumpType(out, b2u(node->name));
3638 out << " &) {\n";
3639 inc();
3640 out << indent() << "throw;\n";
3641 dec();
3642 } else {
3643 for (codemaker::ExceptionTreeNode::Children::const_iterator i(
3644 node->children.begin());
3645 i != node->children.end(); ++i)
3647 dumpCatchClauses(out, *i);
3652 class SingletonType: public ConstructiveType {
3653 public:
3654 SingletonType(
3655 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity,
3656 OUString const & name, rtl::Reference< TypeManager > const & manager):
3657 ConstructiveType(name, manager), entity_(entity)
3658 { assert(entity.is()); }
3660 private:
3661 virtual void dumpHxxFile(
3662 FileStream & o, codemaker::cppumaker::Includes & includes);
3664 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
3667 void SingletonType::dumpHxxFile(
3668 FileStream & o, codemaker::cppumaker::Includes & includes)
3670 OString cppName(
3671 codemaker::cpp::translateUnoToCppIdentifier(
3672 u2b(id_), "singleton", isGlobal()));
3673 OString baseName(u2b(entity_->getBase()));
3674 OString scopedBaseName(codemaker::cpp::scopedCppName(baseName));
3675 OUString headerDefine(dumpHeaderDefine(o, "HPP"));
3676 o << "\n";
3677 //TODO: Decide whether the types added to includes should rather be added to
3678 // m_dependencies (and thus be generated during dumpDependedTypes):
3679 includes.add("com.sun.star.uno.DeploymentException");
3680 includes.add("com.sun.star.uno.XComponentContext");
3681 includes.addCassert();
3682 includes.addAny();
3683 includes.addReference();
3684 includes.addRtlUstringH();
3685 includes.addRtlUstringHxx();
3686 includes.dump(o, 0);
3687 o << "\n";
3688 if (codemaker::cppumaker::dumpNamespaceOpen(o, name_, false)) {
3689 o << "\n";
3691 o << "\nclass " << cppName << " {\npublic:\n";
3692 inc();
3693 o << indent() << "static ::com::sun::star::uno::Reference< "
3694 << scopedBaseName << " > "
3695 << codemaker::cpp::translateUnoToCppIdentifier(
3696 "get", "method", codemaker::cpp::ITM_NONGLOBAL, &cppName)
3697 << ("(::com::sun::star::uno::Reference<"
3698 " ::com::sun::star::uno::XComponentContext > const & the_context)"
3699 " {\n");
3700 inc();
3701 o << indent() << "assert(the_context.is());\n" << indent()
3702 << "::com::sun::star::uno::Reference< " << scopedBaseName
3703 << " > instance;\n" << indent()
3704 << ("if (!(the_context->getValueByName("
3705 "::rtl::OUString( \"/singletons/")
3706 << name_ << "\" )) >>= instance) || !instance.is()) {\n";
3707 inc();
3708 o << indent()
3709 << ("throw ::com::sun::star::uno::DeploymentException("
3710 "::rtl::OUString( \"component context"
3711 " fails to supply singleton ")
3712 << name_ << " of type " << baseName << "\" ), the_context);\n";
3713 dec();
3714 o << indent() << "}\n" << indent() << "return instance;\n";
3715 dec();
3716 o << indent() << "}\n\n";
3717 o << "private:\n";
3718 o << indent() << cppName << "(); // not implemented\n"
3719 << indent() << cppName << "(" << cppName << " &); // not implemented\n"
3720 << indent() << "~" << cppName << "(); // not implemented\n"
3721 << indent() << "void operator =(" << cppName << "); // not implemented\n";
3722 dec();
3723 o << "};\n\n";
3724 if (codemaker::cppumaker::dumpNamespaceClose(o, name_, false)) {
3725 o << "\n";
3727 o << "\n#endif // "<< headerDefine << "\n";
3732 void produce(
3733 OUString const & name, rtl::Reference< TypeManager > const & manager,
3734 codemaker::GeneratedTypeSet & generated, CppuOptions const & options)
3736 if (generated.contains(u2b(name))) {
3737 return;
3739 generated.add(u2b(name));
3740 if (!manager->foundAtPrimaryProvider(name)) {
3741 return;
3743 rtl::Reference< unoidl::Entity > ent;
3744 rtl::Reference< unoidl::MapCursor > cur;
3745 switch (manager->getSort(name, &ent, &cur)) {
3746 case codemaker::UnoType::SORT_MODULE:
3748 OUString prefix;
3749 if (!name.isEmpty()) {
3750 prefix = name + ".";
3752 for (;;) {
3753 OUString mem;
3754 if (!cur->getNext(&mem).is()) {
3755 break;
3757 produce(prefix + mem, manager, generated, options);
3759 break;
3761 case codemaker::UnoType::SORT_ENUM_TYPE:
3763 EnumType t(
3764 dynamic_cast< unoidl::EnumTypeEntity * >(ent.get()), name,
3765 manager);
3766 t.dump(options);
3767 t.dumpDependedTypes(generated, options);
3768 break;
3770 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
3772 PlainStructType t(
3773 dynamic_cast< unoidl::PlainStructTypeEntity * >(ent.get()),
3774 name, manager);
3775 t.dump(options);
3776 t.dumpDependedTypes(generated, options);
3777 break;
3779 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
3781 PolyStructType t(
3782 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
3783 ent.get()),
3784 name, manager);
3785 t.dump(options);
3786 t.dumpDependedTypes(generated, options);
3787 break;
3789 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
3791 ExceptionType t(
3792 dynamic_cast< unoidl::ExceptionTypeEntity * >(ent.get()), name,
3793 manager);
3794 t.dump(options);
3795 t.dumpDependedTypes(generated, options);
3796 break;
3798 case codemaker::UnoType::SORT_INTERFACE_TYPE:
3800 InterfaceType t(
3801 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()), name,
3802 manager);
3803 t.dump(options);
3804 t.dumpDependedTypes(generated, options);
3805 break;
3807 case codemaker::UnoType::SORT_TYPEDEF:
3809 Typedef t(
3810 dynamic_cast< unoidl::TypedefEntity * >(ent.get()), name,
3811 manager);
3812 t.dump(options);
3813 t.dumpDependedTypes(generated, options);
3814 break;
3816 case codemaker::UnoType::SORT_CONSTANT_GROUP:
3818 ConstantGroup t(
3819 dynamic_cast< unoidl::ConstantGroupEntity * >(ent.get()), name,
3820 manager);
3821 if (t.hasConstants()) {
3822 t.dump(options);
3824 break;
3826 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
3828 ServiceType t(
3829 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
3830 ent.get()),
3831 name, manager);
3832 t.dump(options);
3833 t.dumpDependedTypes(generated, options);
3834 break;
3836 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
3838 SingletonType t(
3839 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
3840 ent.get()),
3841 name, manager);
3842 t.dump(options);
3843 t.dumpDependedTypes(generated, options);
3844 break;
3846 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
3847 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
3848 break;
3849 default:
3850 throw CannotDumpException(
3851 "unexpected entity \"" + name + "\" in call to produce");
3855 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */