Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / unodevtools / source / skeletonmaker / cpptypemaker.cxx
blob1fdeabd15201c4e4f9a9b354b70207e6d1a6c38d
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 "codemaker/codemaker.hxx"
23 #include "codemaker/commoncpp.hxx"
24 #include "codemaker/global.hxx"
26 #include "skeletoncommon.hxx"
27 #include "skeletoncpp.hxx"
29 using namespace ::codemaker::cpp;
31 namespace skeletonmaker { namespace cpp {
33 void printType(
34 std::ostream & o, ProgramOptions const & options,
35 rtl::Reference< TypeManager > const & manager,
36 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
37 std::vector< OUString > const & arguments,
38 rtl::Reference< unoidl::Entity > const & entity, short referenceType,
39 bool defaultvalue)
41 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::Sort::Char) {
42 switch (sort) {
43 case codemaker::UnoType::Sort::Boolean:
44 o << "sal_False";
45 return;
46 case codemaker::UnoType::Sort::Char:
47 case codemaker::UnoType::Sort::Byte:
48 case codemaker::UnoType::Sort::Short:
49 case codemaker::UnoType::Sort::UnsignedShort:
50 case codemaker::UnoType::Sort::Long:
51 case codemaker::UnoType::Sort::UnsignedLong:
52 case codemaker::UnoType::Sort::Hyper:
53 case codemaker::UnoType::Sort::UnsignedHyper:
54 case codemaker::UnoType::Sort::Float:
55 case codemaker::UnoType::Sort::Double:
56 o << "0";
57 return;
58 default:
59 break;
63 if (defaultvalue && referenceType == 16) {
64 if (sort == codemaker::UnoType::Sort::Enum) {
65 o << nucleus.copy(nucleus.lastIndexOf('.') + 1) << "_"
66 << dynamic_cast< unoidl::EnumTypeEntity * >(entity.get())->
67 getMembers()[0].name;
69 return;
71 bool bReference = false;
72 if (((sort > codemaker::UnoType::Sort::Char ||
73 rank > 0) && referenceType != 8 &&
74 !(sort == codemaker::UnoType::Sort::Enum && referenceType == 4 && rank == 0)) ||
75 (sort <= codemaker::UnoType::Sort::Char && referenceType == 2))
77 bReference = true;
80 if (bReference && referenceType == 4)
81 o << "const ";
83 for (sal_Int32 i = 0; i < rank; ++i) {
84 o << ((options.shortnames) ? "css::uno::Sequence< " :
85 "::com::sun::star::uno::Sequence< ");
87 if (sort == codemaker::UnoType::Sort::Interface && referenceType > 0) {
88 o << ((options.shortnames) ? "css::uno::Reference< " :
89 "::com::sun::star::uno::Reference< ");
92 o << scopedCppName(codemaker::cpp::translateUnoToCppType(sort, nucleus),
93 options.shortnames && referenceType > 0);
95 if (sort == codemaker::UnoType::Sort::Interface && referenceType > 0)
96 o << " >";
98 if (!arguments.empty()) {
99 o << "< ";
100 for (std::vector< OUString >::const_iterator i(arguments.begin());
101 i != arguments.end(); ++i)
103 if (i != arguments.begin())
104 o << ", ";
106 printType(o, options, manager, *i, 1);
108 o << " >";
111 for (sal_Int32 i = 0; i < rank; ++i)
112 o << " >";
114 if (bReference && referenceType > 1)
115 o << " &";
117 if (referenceType == 8 && (sort > codemaker::UnoType::Sort::Char || rank > 0))
118 o << "()";
121 void printType(
122 std::ostream & o, ProgramOptions const & options,
123 rtl::Reference< TypeManager > const & manager, OUString const & name,
124 short referenceType, bool defaultvalue)
126 OUString nucleus;
127 sal_Int32 rank;
128 std::vector< OUString > arguments;
129 rtl::Reference< unoidl::Entity > entity;
130 codemaker::UnoType::Sort sort = manager->decompose(
131 name, true, &nucleus, &rank, &arguments, &entity);
132 printType(
133 o, options, manager, sort, nucleus, rank, arguments, entity,
134 referenceType, defaultvalue);
137 bool printConstructorParameters(
138 std::ostream & o, ProgramOptions const & options,
139 rtl::Reference< TypeManager > const & manager,
140 codemaker::UnoType::Sort sort,
141 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
142 std::vector< OUString > const & arguments)
144 bool previous = false;
145 switch (sort) {
146 case codemaker::UnoType::Sort::PlainStruct:
148 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
149 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
150 assert(ent2.is());
151 if (!ent2->getDirectBase().isEmpty()) {
152 rtl::Reference< unoidl::Entity > baseEnt;
153 codemaker::UnoType::Sort baseSort = manager->getSort(
154 ent2->getDirectBase(), &baseEnt);
155 previous = printConstructorParameters(
156 o, options, manager, baseSort, baseEnt,
157 ent2->getDirectBase(), std::vector< OUString >());
159 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
160 const_iterator i(ent2->getDirectMembers().begin());
161 i != ent2->getDirectMembers().end(); ++i)
163 if (previous) {
164 o << ", ";
166 previous = true;
167 printType(o, options, manager, i->type, 4);
168 o << ' '
169 << codemaker::cpp::translateUnoToCppIdentifier(
170 u2b(i->name), "param");
172 break;
174 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
176 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
177 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
178 entity.get()));
179 assert(ent2.is());
180 for (std::vector<
181 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
182 const_iterator i(ent2->getMembers().begin());
183 i != ent2->getMembers().end(); ++i)
185 if (previous) {
186 o << ", ";
188 previous = true;
189 if (i->parameterized) {
190 o << i->type;
191 } else {
192 printType(o, options, manager, i->type, 4);
194 o << ' '
195 << codemaker::cpp::translateUnoToCppIdentifier(
196 u2b(i->name), "param");
198 break;
200 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
202 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
203 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
204 entity.get()));
205 assert(ent2.is());
206 for (std::vector<
207 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
208 const_iterator i(ent2->getMembers().begin());
209 i != ent2->getMembers().end(); ++i)
211 if (previous) {
212 o << ", ";
214 previous = true;
215 if (i->parameterized) {
216 for (std::vector< OUString >::const_iterator j(
217 ent2->getTypeParameters().begin());
218 j != ent2->getTypeParameters().end(); ++j)
220 if (i->type == *j) {
221 o << arguments[
222 j - ent2->getTypeParameters().begin()];
223 break;
226 } else {
227 printType(o, options, manager, i->type, 4);
229 o << ' '
230 << codemaker::cpp::translateUnoToCppIdentifier(
231 u2b(i->name), "param");
233 break;
235 case codemaker::UnoType::Sort::Exception:
237 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
238 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
239 assert(ent2.is());
240 if (!ent2->getDirectBase().isEmpty()) {
241 rtl::Reference< unoidl::Entity > baseEnt;
242 codemaker::UnoType::Sort baseSort = manager->getSort(
243 ent2->getDirectBase(), &baseEnt);
244 previous = printConstructorParameters(
245 o, options, manager, baseSort, baseEnt,
246 ent2->getDirectBase(), std::vector< OUString >());
248 for (std::vector< unoidl::ExceptionTypeEntity::Member >::
249 const_iterator i(ent2->getDirectMembers().begin());
250 i != ent2->getDirectMembers().end(); ++i)
252 if (previous) {
253 o << ", ";
255 previous = true;
256 printType(o, options, manager, i->type, 4);
257 o << ' '
258 << codemaker::cpp::translateUnoToCppIdentifier(
259 u2b(i->name), "param");
261 break;
263 default:
264 throw CannotDumpException(
265 "unexpected entity \"" + name
266 + "\" in call to skeletonmaker::cpp::printConstructorParameters");
268 return previous;
271 void printConstructor(
272 std::ostream & o, ProgramOptions const & options,
273 rtl::Reference< TypeManager > const & manager,
274 codemaker::UnoType::Sort sort,
275 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
276 std::vector< OUString > const & arguments)
278 o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
279 printConstructorParameters(
280 o, options, manager, sort, entity, name, arguments);
281 o << ");\n";
284 void printMethodParameters(
285 std::ostream & o, ProgramOptions const & options,
286 rtl::Reference< TypeManager > const & manager,
287 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
288 parameters,
289 bool withType)
291 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
292 const_iterator i(parameters.begin());
293 i != parameters.end(); ++i)
295 if (i != parameters.begin()) {
296 o << ", ";
298 if (withType) {
299 short referenceType;
300 if (i->direction
301 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
303 referenceType = 4;
304 } else {
305 referenceType = 2;
307 printType(o, options, manager, i->type, referenceType);
308 o << ' ';
310 o << codemaker::cpp::translateUnoToCppIdentifier(u2b(i->name), "param");
314 void printExceptionSpecification(
315 std::ostream & o,
316 ProgramOptions const & options,
317 rtl::Reference< TypeManager > const & manager,
318 std::vector< OUString > const & exceptions)
320 o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
321 " throw (::com::sun::star::uno::RuntimeException");
322 for (std::vector< OUString >::const_iterator i(exceptions.begin());
323 i != exceptions.end(); ++i)
325 o << ", ";
326 printType(o, options, manager, *i, 1);
328 o << ")";
331 void printSetPropertyMixinBody(
332 std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute)
334 unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
335 = checkAdditionalPropertyFlags(attribute);
337 o << "\n{\n";
339 if (attribute.bound)
340 o << " BoundListeners l;\n";
342 if (propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED) {
343 OString fieldtype = codemaker::convertString(attribute.type);
345 sal_Int32 index = fieldtype.lastIndexOf('<');
346 sal_Int32 nPos=0;
347 bool single = true;
348 bool optional = false;
349 OStringBuffer buffer1(64);
350 OStringBuffer buffer2(64);
353 OString s(fieldtype.getToken(0, '<', nPos));
354 OString t = s.copy(s.lastIndexOf('/')+1);
356 if (t.equals("Optional")) {
357 optional=true;
358 if (single) {
359 single=false;
360 buffer1.append("the_value.IsPresent");
361 buffer2.append("the_value.Value");
362 } else {
363 buffer1.insert(0, t);
364 buffer1.append(".IsPresent");
365 buffer2.insert(0, t);
366 buffer2.append(".Value");
368 } else {
369 if (single) {
370 single=false;
371 if (!optional)
372 buffer1.append("the_value.Value");
374 buffer2.append("the_value.Value");
375 } else {
376 if (!optional) {
377 buffer1.insert(0, t);
378 buffer1.append(".Value");
380 buffer2.insert(0, t);
381 buffer2.append(".Value");
384 } while( nPos <= index );
386 o << " css::uno::Any v;\n";
387 if (optional) {
388 o << " if(" << buffer1.makeStringAndClear() << ")\n {\n v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
389 } else {
390 o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
393 o << " prepareSet(\n rtl::OUString(\""
394 << attribute.name << "\"),\n css::uno::Any(), v, ";
395 } else {
396 o << " prepareSet(\n rtl::OUString(\""
397 << attribute.name << "\"),\n css::uno::Any(), css::uno::Any(), ";
400 if (attribute.bound)
401 o << "&l);\n";
402 else
403 o << "0);\n";
405 o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
406 << attribute.name << " = the_value;\n }\n";
408 if (attribute.bound)
409 o << " l.notify();\n";
411 o << "}\n\n";
414 void printMethods(std::ostream & o,
415 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
416 OUString const & name, codemaker::GeneratedTypeSet & generated,
417 OString const & delegate, OString const & classname,
418 OString const & indentation, bool defaultvalue,
419 OUString const & propertyhelper)
421 if (generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
422 (defaultvalue &&
423 ( name == "com.sun.star.lang.XComponent" ||
424 name == "com.sun.star.lang.XTypeProvider" ||
425 name == "com.sun.star.uno.XWeak" ) ) )
427 return;
430 static OString sd("_");
431 bool body = !delegate.isEmpty();
432 bool defaultbody = delegate.equals(sd);
434 if (body && propertyhelper.getLength() > 1) {
435 if (name == "com.sun.star.beans.XPropertySet") {
436 generated.add(u2b(name));
437 generateXPropertySetBodies(
438 o, classname, scopedCppName(u2b(propertyhelper)));
439 return;
440 } else if (name == "com.sun.star.beans.XFastPropertySet") {
441 generated.add(u2b(name));
442 generateXFastPropertySetBodies(
443 o, classname, scopedCppName(u2b(propertyhelper)));
444 return;
445 } else if (name == "com.sun.star.beans.XPropertyAccess") {
446 generated.add(u2b(name));
447 generateXPropertyAccessBodies(
448 o, classname, scopedCppName(u2b(propertyhelper)));
449 return;
453 if (body && options.componenttype == 2) {
454 if (name == "com.sun.star.lang.XServiceName") {
455 o << "// ::com::sun::star::lang::XServiceName:\n"
456 "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
457 "throw (css::uno::RuntimeException)\n{\n "
458 "return ::rtl::OUString("
459 "sADDIN_SERVICENAME);\n}\n";
460 generated.add(u2b(name));
461 return;
462 } else if (name == "com.sun.star.sheet.XAddIn") {
463 generateXAddInBodies(o, classname);
464 generated.add(u2b(name));
466 // special handling of XLocalizable -> parent of XAddIn
467 if (!generated.contains("com.sun.star.lang.XLocalizable")) {
468 generateXLocalizable(o, classname);
469 generated.add("com.sun.star.lang.XLocalizable");
471 return;
472 } else if (name == "com.sun.star.lang.XLocalizable") {
473 generateXLocalizable(o, classname);
474 generated.add(u2b(name));
475 return;
476 } else if (name == "com.sun.star.sheet.XCompatibilityNames") {
477 generateXCompatibilityNamesBodies(o, classname);
478 generated.add(u2b(name));
479 return;
483 if (body && options.componenttype == 3) {
484 if (name == "com.sun.star.lang.XInitialization") {
485 generateXInitialization(o, classname);
486 generated.add(u2b(name));
487 return;
488 } else if (name == "com.sun.star.frame.XDispatch") {
489 generateXDispatch(o, classname, options.protocolCmdMap);
490 generated.add(u2b(name));
491 return;
492 } else if (name == "com.sun.star.frame.XDispatchProvider") {
493 generateXDispatchProvider(o, classname, options.protocolCmdMap);
494 generated.add(u2b(name));
495 return;
499 generated.add(u2b(name));
500 rtl::Reference< unoidl::Entity > ent;
501 if (manager->getSort(name, &ent) != codemaker::UnoType::Sort::Interface)
503 throw CannotDumpException(
504 "unexpected entity \"" + name
505 + "\" in call to skeletonmaker::cpp::printMethods");
507 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
508 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
509 assert(ent2.is());
510 if (options.all || defaultvalue) {
511 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
512 ent2->getDirectMandatoryBases().begin());
513 i != ent2->getDirectMandatoryBases().end(); ++i)
515 printMethods(
516 o, options, manager, i->name, generated, delegate, classname,
517 indentation, defaultvalue, propertyhelper);
519 if (!(ent2->getDirectAttributes().empty()
520 && ent2->getDirectMethods().empty()))
522 o << indentation << "// ";
523 printType(o, options, manager, name, 0);
524 o << ":\n";
527 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
528 i(ent2->getDirectAttributes().begin());
529 i != ent2->getDirectAttributes().end(); ++i)
531 o << indentation;
532 if (!body)
533 o << "virtual ";
535 printType(o, options, manager, i->type, 1);
536 o << " SAL_CALL ";
537 if (!classname.isEmpty())
538 o << classname;
540 o << "get" << i->name << "()";
541 printExceptionSpecification(o, options, manager, i->getExceptions);
542 if (body) {
543 if (defaultbody) {
544 if (!propertyhelper.isEmpty()) {
545 o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
546 << i->name << ";\n}\n\n";
547 } else {
548 o << "\n{\n return ";
549 if (options.componenttype == 1) {
550 o << "m_" << i->name;
551 } else {
552 printType(o, options, manager, i->type, 8, true);
554 o << ";\n}\n\n";
556 } else {
557 o << "\n" << indentation << "{\n" << indentation << " return "
558 << delegate.getStr() << "get" << i->name << "();\n"
559 << indentation << "}\n\n";
561 } else {
562 o << ";\n";
565 if (!i->readOnly) {
566 o << indentation;
567 if (!body)
568 o << "virtual ";
570 o << "void SAL_CALL ";
571 if (!classname.isEmpty())
572 o << classname;
574 o << "set" << i->name << '(';
575 printType(o, options, manager, i->type, 4);
576 o << " the_value)";
577 printExceptionSpecification(o, options, manager, i->setExceptions);
578 if (body) {
579 if (defaultbody) {
580 if (!propertyhelper.isEmpty()) {
581 printSetPropertyMixinBody(o, *i);
582 } else {
583 if (options.componenttype == 1) {
584 o << "\n{\n m_" << i->name
585 << " = the_value;\n}\n\n";
586 } else {
587 o << "\n{\n\n}\n\n";
590 } else {
591 o << "\n" << indentation << "{\n" << indentation << " "
592 << delegate.getStr() << "set" << i->name
593 << "(the_value);\n" << indentation << "}\n\n";
595 } else {
596 o << ";\n";
600 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
601 ent2->getDirectMethods().begin());
602 i != ent2->getDirectMethods().end(); ++i)
604 o << indentation;
605 if (!body)
606 o << "virtual ";
608 printType(o, options, manager, i->returnType, 1);
609 o << " SAL_CALL ";
610 if (!classname.isEmpty())
611 o << classname;
613 o << i->name << '(';
614 printMethodParameters(o, options, manager, i->parameters, true);
615 o << ')';
616 printExceptionSpecification(o, options, manager, i->exceptions);
617 if (body) {
618 if (defaultbody) {
619 o << "\n{\n";
620 if (i->returnType != "void") {
621 o << " // TODO: Exchange the default return implementation for \""
622 << i->name << "\" !!!\n";
623 o << " // Exchange the default return implementation.\n"
624 " // NOTE: Default initialized polymorphic structs "
625 "can cause problems because of\n // missing default "
626 "initialization of primitive types of some C++ compilers or"
627 "\n // different Any initialization in Java and C++ "
628 "polymorphic structs.\n return ";
629 printType(o, options, manager, i->returnType, 8, true);
630 o << ";";
631 } else {
632 o << " // TODO: Insert your implementation for \""
633 << i->name << "\" here.";
635 o << "\n}\n\n";
636 } else {
637 o << "\n" << indentation << "{\n" << indentation << " ";
638 if (i->returnType != "void")
639 o << "return ";
641 o << delegate.getStr() << i->name << '(';
642 printMethodParameters(
643 o, options, manager, i->parameters, false);
644 o << ");\n" << indentation << "}\n\n";
646 } else {
647 o << ";\n";
651 if (!body)
652 o << "\n";
655 void printConstructors(
656 std::ostream & o, ProgramOptions const & options,
657 rtl::Reference< TypeManager > const & manager, OUString const & name)
659 rtl::Reference< unoidl::Entity > ent;
660 if (manager->getSort(name, &ent)
661 != codemaker::UnoType::Sort::SingleInterfaceBasedService)
663 throw CannotDumpException(
664 "unexpected entity \"" + name
665 + "\" in call to skeletonmaker::java::printConstructors");
667 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
668 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
669 assert(ent2.is());
670 for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
671 const_iterator i(ent2->getConstructors().begin());
672 i != ent2->getConstructors().end(); ++i)
674 o << "static ";
675 printType(o, options, manager, ent2->getBase(), 1);
676 o << ' ';
677 if (i->defaultConstructor) {
678 o << "create";
679 } else {
680 o << codemaker::cpp::translateUnoToCppIdentifier(
681 u2b(i->name), "method");
683 o << ((options.shortnames) ? "(css::uno::Reference< css" :
684 "(::com::sun::star::uno::Reference< ::com::sun::star")
685 << "::uno::XComponentContext > const & the_context";
686 for (std::vector<
687 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
688 Parameter >::const_iterator j(i->parameters.begin());
689 j != i->parameters.end(); ++j)
691 o << ", ";
692 printType(o, options, manager, j->type, 4);
693 o << ' '
694 << codemaker::cpp::translateUnoToCppIdentifier(
695 u2b(j->name), "param");
697 o << ')';
698 printExceptionSpecification(o, options, manager, i->exceptions);
699 o << ";\n";
703 void printServiceMembers(
704 std::ostream & o, ProgramOptions const & options,
705 rtl::Reference< TypeManager > const & manager,
706 OUString const & name,
707 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
708 OString const & delegate)
710 assert(entity.is());
711 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
712 entity->getDirectMandatoryBaseServices().begin());
713 i != entity->getDirectMandatoryBaseServices().end(); ++i)
715 o << "\n// exported service " << i->name << "\n";
716 generateDocumentation(o, options, manager, u2b(i->name), delegate);
717 o << "\n// end of exported service " << i->name << "\n";
719 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
720 entity->getDirectMandatoryBaseInterfaces().begin());
721 i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
723 o << "\n// supported interface " << i->name << "\n";
724 generateDocumentation(o, options, manager, u2b(i->name), delegate);
726 if (delegate.isEmpty()) {
727 o << "\n// properties of service \""<< name << "\"\n";
728 for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
729 const_iterator i(entity->getDirectProperties().begin());
730 i != entity->getDirectProperties().end(); ++i)
732 o << "// private ";
733 printType(o, options, manager, i->type, 1);
734 o << " "
735 << codemaker::cpp::translateUnoToCppIdentifier(
736 u2b(i->name), "property")
737 << ";\n";
742 void printMapsToCppType(
743 std::ostream & o, ProgramOptions const & options,
744 rtl::Reference< TypeManager > const & manager,
745 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
746 std::vector< OUString > const & arguments,
747 rtl::Reference< unoidl::Entity > const & entity, const char * cppTypeSort)
749 o << "maps to C++ ";
750 if (cppTypeSort != nullptr)
751 o << cppTypeSort << ' ';
753 o << "type \"";
754 if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
755 o << "Reference< com::sun::star::uno::XInterface >";
756 } else {
757 printType(
758 o, options, manager, sort, nucleus, rank, arguments, entity, 0,
759 false);
761 o << '"';
764 void generateDocumentation(std::ostream & o,
765 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
766 OString const & type, OString const & delegate)
768 OUString nucleus;
769 sal_Int32 rank;
770 codemaker::UnoType::Sort sort = manager->decompose(
771 b2u(type), false, &nucleus, &rank, nullptr, nullptr);
773 bool comment = true;
774 if (!delegate.isEmpty()) {
775 if (sort != codemaker::UnoType::Sort::Interface &&
776 sort != codemaker::UnoType::Sort::SingleInterfaceBasedService &&
777 sort != codemaker::UnoType::Sort::AccumulationBasedService )
779 return;
781 comment = false;
784 if (comment) {
785 o << "\n// UNO";
786 if (rank != 0) {
787 o << " sequence type";
788 } else if (sort <= codemaker::UnoType::Sort::Any) {
789 o << " simple type";
790 } else {
791 switch (sort) {
792 case codemaker::UnoType::Sort::Interface:
793 o << " interface type";
794 break;
796 case codemaker::UnoType::Sort::Module:
797 o << "IDL module";
798 break;
800 case codemaker::UnoType::Sort::PlainStruct:
801 o << " simple struct type";
802 break;
804 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
805 o << " polymorphic struct type template";
806 break;
808 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
809 o << " instantiated polymorphic struct type";
810 break;
812 case codemaker::UnoType::Sort::Enum:
813 o << " enum type";
814 break;
816 case codemaker::UnoType::Sort::Exception:
817 o << " exception type";
818 break;
820 case codemaker::UnoType::Sort::Typedef:
821 o << "IDL typedef";
822 break;
824 case codemaker::UnoType::Sort::SingleInterfaceBasedService:
825 o << " single-inheritance--based service";
826 break;
828 case codemaker::UnoType::Sort::AccumulationBasedService:
829 o << "IDL accumulation-based service";
830 break;
832 case codemaker::UnoType::Sort::InterfaceBasedSingleton:
833 o << " inheritance-based singleton";
834 break;
836 case codemaker::UnoType::Sort::ServiceBasedSingleton:
837 o << "IDL service-based singleton";
838 break;
840 case codemaker::UnoType::Sort::ConstantGroup:
841 o << "IDL constant group";
842 break;
844 default:
845 OSL_ASSERT(false);
846 break;
849 o << " \"" << type << "\" ";
851 std::vector< OUString > arguments;
852 rtl::Reference< unoidl::Entity > entity;
853 sort = manager->decompose(
854 b2u(type), true, &nucleus, &rank, &arguments, &entity);
855 if (rank != 0) {
856 if (comment) {
857 printMapsToCppType(
858 o, options, manager, sort, nucleus, rank, arguments, entity,
859 "array");
860 o << '\n';
862 } else if (sort <= codemaker::UnoType::Sort::Any) {
863 if (comment) {
864 printMapsToCppType(
865 o, options, manager, sort, nucleus, rank, arguments, entity, nullptr);
866 o << '\n';
868 } else {
869 switch (sort) {
870 case codemaker::UnoType::Sort::Interface:
871 if (comment)
872 printMapsToCppType(
873 o, options, manager, sort, nucleus, rank, arguments, entity,
874 "interface");
875 if (nucleus == "com.sun.star.uno.XInterface") {
876 if (comment)
877 o << '\n';
878 } else {
879 if (comment)
880 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
882 codemaker::GeneratedTypeSet generated;
883 printMethods(
884 o, options, manager, nucleus, generated, delegate,
885 options.implname, "");
887 break;
889 case codemaker::UnoType::Sort::Module:
890 printMapsToCppType(
891 o, options, manager, sort, nucleus, rank, arguments, entity,
892 "namespace");
893 o << '\n';
894 break;
896 case codemaker::UnoType::Sort::PlainStruct:
897 printMapsToCppType(
898 o, options, manager, sort, nucleus, rank, arguments, entity,
899 "class");
900 o << "; full constructor:\n";
901 printConstructor(
902 o, options, manager, codemaker::UnoType::Sort::PlainStruct,
903 entity, nucleus, arguments);
904 break;
906 case codemaker::UnoType::Sort::PolymorphicStructTemplate:
907 printMapsToCppType(
908 o, options, manager, sort, nucleus, rank, arguments, entity,
909 "class template");
910 o << "; full constructor:\n";
911 printConstructor(
912 o, options, manager,
913 codemaker::UnoType::Sort::PolymorphicStructTemplate,
914 entity, nucleus, arguments);
915 break;
917 case codemaker::UnoType::Sort::InstantiatedPolymorphicStruct:
918 printMapsToCppType(
919 o, options, manager, sort, nucleus, rank, arguments, entity,
920 "class template instantiation");
921 o << "; full constructor:\n";
922 printConstructor(
923 o, options, manager,
924 codemaker::UnoType::Sort::InstantiatedPolymorphicStruct,
925 entity, nucleus, arguments);
926 break;
928 case codemaker::UnoType::Sort::Enum:
929 printMapsToCppType(
930 o, options, manager, sort, nucleus, rank, arguments, entity,
931 "enum");
932 o << '\n';
933 break;
935 case codemaker::UnoType::Sort::ConstantGroup:
936 printMapsToCppType(
937 o, options, manager, sort, nucleus, rank, arguments, entity,
938 "namespace");
939 o << '\n';
940 break;
942 case codemaker::UnoType::Sort::Exception:
943 printMapsToCppType(
944 o, options, manager, sort, nucleus, rank, arguments, entity,
945 "exception class");
946 o << "; full constructor:\n";
947 printConstructor(
948 o, options, manager, codemaker::UnoType::Sort::Exception,
949 entity, nucleus, arguments);
950 break;
952 case codemaker::UnoType::Sort::SingleInterfaceBasedService:
953 if (comment) {
954 printMapsToCppType(
955 o, options, manager, sort, nucleus, rank, arguments, entity,
956 "class");
957 o << "; construction methods:\n";
958 printConstructors(o, options, manager, nucleus);
960 generateDocumentation(
961 o, options, manager,
962 u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
963 entity.get())->getBase()),
964 delegate);
965 break;
967 case codemaker::UnoType::Sort::AccumulationBasedService:
968 if (comment)
969 o << ("does not map to C++\n"
970 "// the service members are generated instead\n");
971 printServiceMembers(
972 o, options, manager, nucleus,
973 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
974 entity.get()),
975 delegate);
976 break;
978 case codemaker::UnoType::Sort::InterfaceBasedSingleton:
979 printMapsToCppType(
980 o, options, manager, sort, nucleus, rank, arguments, entity,
981 "class");
982 o << "; get method:\nstatic ";
983 printType(
984 o, options, manager,
985 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
986 entity.get())->getBase(),
988 o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
989 break;
991 case codemaker::UnoType::Sort::ServiceBasedSingleton:
992 o << "does not map to C++\n";
993 break;
995 default:
996 OSL_ASSERT(false);
997 break;
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */