update credits
[LibreOffice.git] / unodevtools / source / skeletonmaker / cpptypemaker.cxx
blob51a17c48b4bfff60ef354dbb39d5f75dc4bf97d5
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 ::rtl;
30 using namespace ::codemaker::cpp;
32 namespace skeletonmaker { namespace cpp {
34 void printType(
35 std::ostream & o, ProgramOptions const & options,
36 rtl::Reference< TypeManager > const & manager,
37 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
38 std::vector< OUString > const & arguments,
39 rtl::Reference< unoidl::Entity > const & entity, short referenceType,
40 bool defaultvalue)
42 if (defaultvalue && rank == 0 && sort <= codemaker::UnoType::SORT_CHAR) {
43 switch (sort) {
44 case codemaker::UnoType::SORT_BOOLEAN:
45 o << "sal_False";
46 return;
47 case codemaker::UnoType::SORT_CHAR:
48 case codemaker::UnoType::SORT_BYTE:
49 case codemaker::UnoType::SORT_SHORT:
50 case codemaker::UnoType::SORT_UNSIGNED_SHORT:
51 case codemaker::UnoType::SORT_LONG:
52 case codemaker::UnoType::SORT_UNSIGNED_LONG:
53 case codemaker::UnoType::SORT_HYPER:
54 case codemaker::UnoType::SORT_UNSIGNED_HYPER:
55 case codemaker::UnoType::SORT_FLOAT:
56 case codemaker::UnoType::SORT_DOUBLE:
57 o << "0";
58 return;
59 default:
60 break;
64 if (defaultvalue && referenceType == 16) {
65 if (sort == codemaker::UnoType::SORT_ENUM_TYPE) {
66 o << nucleus.copy(nucleus.lastIndexOf('.') + 1) << "_"
67 << dynamic_cast< unoidl::EnumTypeEntity * >(entity.get())->
68 getMembers()[0].name;
70 return;
72 bool bReference = false;
73 if (((sort > codemaker::UnoType::SORT_CHAR ||
74 rank > 0) && referenceType != 8 &&
75 !(sort == codemaker::UnoType::SORT_ENUM_TYPE && referenceType == 4 && rank == 0)) ||
76 (sort <= codemaker::UnoType::SORT_CHAR && referenceType == 2))
78 bReference = true;
81 if (bReference && referenceType == 4)
82 o << "const ";
84 for (sal_Int32 i = 0; i < rank; ++i) {
85 o << ((options.shortnames) ? "css::uno::Sequence< " :
86 "::com::sun::star::uno::Sequence< ");
88 if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0) {
89 o << ((options.shortnames) ? "css::uno::Reference< " :
90 "::com::sun::star::uno::Reference< ");
93 o << scopedCppName(codemaker::cpp::translateUnoToCppType(sort, nucleus),
94 options.shortnames && referenceType > 0);
96 if (sort == codemaker::UnoType::SORT_INTERFACE_TYPE && referenceType > 0)
97 o << " >";
99 if (!arguments.empty()) {
100 o << "< ";
101 for (std::vector< OUString >::const_iterator i(arguments.begin());
102 i != arguments.end(); ++i)
104 if (i != arguments.begin())
105 o << ", ";
107 printType(o, options, manager, *i, 1, false);
109 o << " >";
112 for (sal_Int32 i = 0; i < rank; ++i)
113 o << " >";
115 if (bReference && referenceType > 1)
116 o << " &";
118 if (referenceType == 8 && (sort > codemaker::UnoType::SORT_CHAR || rank > 0))
119 o << "()";
122 void printType(
123 std::ostream & o, ProgramOptions const & options,
124 rtl::Reference< TypeManager > const & manager, OUString const & name,
125 short referenceType, bool defaultvalue)
127 OUString nucleus;
128 sal_Int32 rank;
129 std::vector< OUString > arguments;
130 rtl::Reference< unoidl::Entity > entity;
131 codemaker::UnoType::Sort sort = manager->decompose(
132 name, true, &nucleus, &rank, &arguments, &entity);
133 printType(
134 o, options, manager, sort, nucleus, rank, arguments, entity,
135 referenceType, defaultvalue);
138 bool printConstructorParameters(
139 std::ostream & o, ProgramOptions const & options,
140 rtl::Reference< TypeManager > const & manager,
141 codemaker::UnoType::Sort sort,
142 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
143 std::vector< OUString > const & arguments)
145 bool previous = false;
146 switch (sort) {
147 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
149 rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
150 dynamic_cast< unoidl::PlainStructTypeEntity * >(entity.get()));
151 assert(ent2.is());
152 if (!ent2->getDirectBase().isEmpty()) {
153 rtl::Reference< unoidl::Entity > baseEnt;
154 codemaker::UnoType::Sort baseSort = manager->getSort(
155 ent2->getDirectBase(), &baseEnt);
156 previous = printConstructorParameters(
157 o, options, manager, baseSort, baseEnt,
158 ent2->getDirectBase(), std::vector< OUString >());
160 for (std::vector< unoidl::PlainStructTypeEntity::Member >::
161 const_iterator i(ent2->getDirectMembers().begin());
162 i != ent2->getDirectMembers().end(); ++i)
164 if (previous) {
165 o << ", ";
167 previous = true;
168 printType(o, options, manager, i->type, 4);
169 o << ' '
170 << codemaker::cpp::translateUnoToCppIdentifier(
171 u2b(i->name), "param");
173 break;
175 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
177 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
178 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
179 entity.get()));
180 assert(ent2.is());
181 for (std::vector<
182 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
183 const_iterator i(ent2->getMembers().begin());
184 i != ent2->getMembers().end(); ++i)
186 if (previous) {
187 o << ", ";
189 previous = true;
190 if (i->parameterized) {
191 o << i->type;
192 } else {
193 printType(o, options, manager, i->type, 4);
195 o << ' '
196 << codemaker::cpp::translateUnoToCppIdentifier(
197 u2b(i->name), "param");
199 break;
201 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
203 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
204 dynamic_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
205 entity.get()));
206 assert(ent2.is());
207 for (std::vector<
208 unoidl::PolymorphicStructTypeTemplateEntity::Member >::
209 const_iterator i(ent2->getMembers().begin());
210 i != ent2->getMembers().end(); ++i)
212 if (previous) {
213 o << ", ";
215 previous = true;
216 if (i->parameterized) {
217 for (std::vector< OUString >::const_iterator j(
218 ent2->getTypeParameters().begin());
219 j != ent2->getTypeParameters().end(); ++j)
221 if (i->type == *j) {
222 o << arguments[
223 j - ent2->getTypeParameters().begin()];
224 break;
227 } else {
228 printType(o, options, manager, i->type, 4);
230 o << ' '
231 << codemaker::cpp::translateUnoToCppIdentifier(
232 u2b(i->name), "param");
234 break;
236 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
238 rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
239 dynamic_cast< unoidl::ExceptionTypeEntity * >(entity.get()));
240 assert(ent2.is());
241 if (!ent2->getDirectBase().isEmpty()) {
242 rtl::Reference< unoidl::Entity > baseEnt;
243 codemaker::UnoType::Sort baseSort = manager->getSort(
244 ent2->getDirectBase(), &baseEnt);
245 previous = printConstructorParameters(
246 o, options, manager, baseSort, baseEnt,
247 ent2->getDirectBase(), std::vector< OUString >());
249 for (std::vector< unoidl::ExceptionTypeEntity::Member >::
250 const_iterator i(ent2->getDirectMembers().begin());
251 i != ent2->getDirectMembers().end(); ++i)
253 if (previous) {
254 o << ", ";
256 previous = true;
257 printType(o, options, manager, i->type, 4);
258 o << ' '
259 << codemaker::cpp::translateUnoToCppIdentifier(
260 u2b(i->name), "param");
262 break;
264 default:
265 throw CannotDumpException(
266 "unexpected entity \"" + name
267 + "\" in call to skeletonmaker::cpp::printConstructorParameters");
269 return previous;
272 void printConstructor(
273 std::ostream & o, ProgramOptions const & options,
274 rtl::Reference< TypeManager > const & manager,
275 codemaker::UnoType::Sort sort,
276 rtl::Reference< unoidl::Entity > const & entity, OUString const & name,
277 std::vector< OUString > const & arguments)
279 o << "public " << name.copy(name.lastIndexOf('.') + 1) << '(';
280 printConstructorParameters(
281 o, options, manager, sort, entity, name, arguments);
282 o << ");\n";
285 void printMethodParameters(
286 std::ostream & o, ProgramOptions const & options,
287 rtl::Reference< TypeManager > const & manager,
288 std::vector< unoidl::InterfaceTypeEntity::Method::Parameter > const &
289 parameters,
290 bool withType)
292 for (std::vector< unoidl::InterfaceTypeEntity::Method::Parameter >::
293 const_iterator i(parameters.begin());
294 i != parameters.end(); ++i)
296 if (i != parameters.begin()) {
297 o << ", ";
299 if (withType) {
300 short referenceType;
301 if (i->direction
302 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
304 referenceType = 4;
305 } else {
306 referenceType = 2;
308 printType(o, options, manager, i->type, referenceType);
309 o << ' ';
311 o << codemaker::cpp::translateUnoToCppIdentifier(u2b(i->name), "param");
315 void printExceptionSpecification(
316 std::ostream & o,
317 ProgramOptions const & options,
318 rtl::Reference< TypeManager > const & manager,
319 std::vector< OUString > const & exceptions)
321 o << ((options.shortnames) ? " throw (css::uno::RuntimeException" :
322 " throw (::com::sun::star::uno::RuntimeException");
323 for (std::vector< OUString >::const_iterator i(exceptions.begin());
324 i != exceptions.end(); ++i)
326 o << ", ";
327 printType(o, options, manager, *i, 1);
329 o << ")";
332 void printSetPropertyMixinBody(
333 std::ostream & o, unoidl::InterfaceTypeEntity::Attribute const & attribute)
335 unoidl::AccumulationBasedServiceEntity::Property::Attributes propFlags
336 = checkAdditionalPropertyFlags(attribute);
338 o << "\n{\n";
340 if (attribute.bound)
341 o << " BoundListeners l;\n";
343 if (propFlags & unoidl::AccumulationBasedServiceEntity::Property::ATTRIBUTE_CONSTRAINED) {
344 OString fieldtype = codemaker::convertString(attribute.type);
346 sal_Int32 index = fieldtype.lastIndexOf('<');
347 sal_Int32 nPos=0;
348 bool single = true;
349 bool optional = false;
350 OStringBuffer buffer1(64);
351 OStringBuffer buffer2(64);
354 OString s(fieldtype.getToken(0, '<', nPos));
355 OString t = s.copy(s.lastIndexOf('/')+1);
357 if (t.equals("Optional")) {
358 optional=true;
359 if (single) {
360 single=false;
361 buffer1.append("the_value.IsPresent");
362 buffer2.append("the_value.Value");
363 } else {
364 buffer1.insert(0, t);
365 buffer1.append(".IsPresent");
366 buffer2.insert(0, t);
367 buffer2.append(".Value");
369 } else {
370 if (single) {
371 single=false;
372 if (!optional)
373 buffer1.append("the_value.Value");
375 buffer2.append("the_value.Value");
376 } else {
377 if (!optional) {
378 buffer1.insert(0, t);
379 buffer1.append(".Value");
381 buffer2.insert(0, t);
382 buffer2.append(".Value");
385 } while( nPos <= index );
387 o << " css::uno::Any v;\n";
388 if (optional) {
389 o << " if(" << buffer1.makeStringAndClear() << ")\n {\n"
390 << " v <<= " << buffer2.makeStringAndClear() << ";\n }\n";
391 } else {
392 o << " v <<= " << buffer2.makeStringAndClear() << ";\n\n";
395 o << " prepareSet(\n rtl::OUString(\""
396 << attribute.name << "\"),\n css::uno::Any(), v, ";
397 } else {
398 o << " prepareSet(\n rtl::OUString(\""
399 << attribute.name << "\"),\n css::uno::Any(), css::uno::Any(), ";
402 if (attribute.bound)
403 o << "&l);\n";
404 else
405 o << "0);\n";
407 o << " {\n osl::MutexGuard g(m_aMutex);\n m_"
408 << attribute.name << " = the_value;\n }\n";
410 if (attribute.bound)
411 o << " l.notify();\n";
413 o << "}\n\n";
416 void generateXPropertySetBodies(std::ostream& o,
417 const OString & classname,
418 const OString & interfaceName);
419 void generateXFastPropertySetBodies(std::ostream& o,
420 const OString & classname,
421 const OString & interfaceName);
422 void generateXPropertyAccessBodies(std::ostream& o,
423 const OString & classname,
424 const OString & interfaceName);
426 void generateXAddInBodies(std::ostream& o, const OString & classname);
428 void generateXLocalizable(std::ostream& o, const OString & classname);
430 void generateXCompatibilityNamesBodies(std::ostream& o, const OString & classname);
432 void generateXInitialization(std::ostream& o, const OString & classname);
434 void generateXDispatch(std::ostream& o,
435 const OString & classname,
436 const ProtocolCmdMap & protocolCmdMap);
438 void generateXDispatchProvider(std::ostream& o,
439 const OString & classname,
440 const ProtocolCmdMap & protocolCmdMap);
443 void printMethods(std::ostream & o,
444 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
445 OUString const & name, codemaker::GeneratedTypeSet & generated,
446 OString const & delegate, OString const & classname,
447 OString const & indentation, bool defaultvalue,
448 OUString const & propertyhelper)
450 if (generated.contains(u2b(name)) || name == "com.sun.star.uno.XInterface" ||
451 (defaultvalue &&
452 ( name == "com.sun.star.lang.XComponent" ||
453 name == "com.sun.star.lang.XTypeProvider" ||
454 name == "com.sun.star.uno.XWeak" ) ) )
456 return;
459 static OString sd("_");
460 bool body = !delegate.isEmpty();
461 bool defaultbody = ((delegate.equals(sd)) ? true : false);
463 if (body && propertyhelper.getLength() > 1) {
464 if (name == "com.sun.star.beans.XPropertySet") {
465 generated.add(u2b(name));
466 generateXPropertySetBodies(
467 o, classname, scopedCppName(u2b(propertyhelper)));
468 return;
469 } else if (name == "com.sun.star.beans.XFastPropertySet") {
470 generated.add(u2b(name));
471 generateXFastPropertySetBodies(
472 o, classname, scopedCppName(u2b(propertyhelper)));
473 return;
474 } else if (name == "com.sun.star.beans.XPropertyAccess") {
475 generated.add(u2b(name));
476 generateXPropertyAccessBodies(
477 o, classname, scopedCppName(u2b(propertyhelper)));
478 return;
482 if (body && options.componenttype == 2) {
483 if (name == "com.sun.star.lang.XServiceName") {
484 o << "// ::com::sun::star::lang::XServiceName:\n"
485 "::rtl::OUString SAL_CALL " << classname << "getServiceName() "
486 "throw (css::uno::RuntimeException)\n{\n "
487 "return ::rtl::OUString("
488 "sADDIN_SERVICENAME);\n}\n";
489 generated.add(u2b(name));
490 return;
491 } else if (name == "com.sun.star.sheet.XAddIn") {
492 generateXAddInBodies(o, classname);
493 generated.add(u2b(name));
495 // special handling of XLocalizable -> parent of XAddIn
496 if (!generated.contains("com.sun.star.lang.XLocalizable")) {
497 generateXLocalizable(o, classname);
498 generated.add("com.sun.star.lang.XLocalizable");
500 return;
501 } else if (name == "com.sun.star.lang.XLocalizable") {
502 generateXLocalizable(o, classname);
503 generated.add(u2b(name));
504 return;
505 } else if (name == "com.sun.star.sheet.XCompatibilityNames") {
506 generateXCompatibilityNamesBodies(o, classname);
507 generated.add(u2b(name));
508 return;
512 if (body && options.componenttype == 3) {
513 if (name == "com.sun.star.lang.XInitialization") {
514 generateXInitialization(o, classname);
515 generated.add(u2b(name));
516 return;
517 } else if (name == "com.sun.star.frame.XDispatch") {
518 generateXDispatch(o, classname, options.protocolCmdMap);
519 generated.add(u2b(name));
520 return;
521 } else if (name == "com.sun.star.frame.XDispatchProvider") {
522 generateXDispatchProvider(o, classname, options.protocolCmdMap);
523 generated.add(u2b(name));
524 return;
528 generated.add(u2b(name));
529 rtl::Reference< unoidl::Entity > ent;
530 if (manager->getSort(name, &ent) != codemaker::UnoType::SORT_INTERFACE_TYPE)
532 throw CannotDumpException(
533 "unexpected entity \"" + name
534 + "\" in call to skeletonmaker::cpp::printMethods");
536 rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
537 dynamic_cast< unoidl::InterfaceTypeEntity * >(ent.get()));
538 assert(ent2.is());
539 if (options.all || defaultvalue) {
540 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
541 ent2->getDirectMandatoryBases().begin());
542 i != ent2->getDirectMandatoryBases().end(); ++i)
544 printMethods(
545 o, options, manager, i->name, generated, delegate, classname,
546 indentation, defaultvalue, propertyhelper);
548 if (!(ent2->getDirectAttributes().empty()
549 && ent2->getDirectMethods().empty()))
551 o << indentation << "// ";
552 printType(o, options, manager, name, 0);
553 o << ":\n";
556 for (std::vector< unoidl::InterfaceTypeEntity::Attribute >::const_iterator
557 i(ent2->getDirectAttributes().begin());
558 i != ent2->getDirectAttributes().end(); ++i)
560 o << indentation;
561 if (!body)
562 o << "virtual ";
564 printType(o, options, manager, i->type, 1);
565 o << " SAL_CALL ";
566 if (!classname.isEmpty())
567 o << classname;
569 o << "get" << i->name << "()";
570 printExceptionSpecification(o, options, manager, i->getExceptions);
571 if (body) {
572 if (defaultbody) {
573 if (!propertyhelper.isEmpty()) {
574 o << "\n{\n osl::MutexGuard g(m_aMutex);\n return m_"
575 << i->name << ";\n}\n\n";
576 } else {
577 o << "\n{\n return ";
578 if (options.componenttype == 1) {
579 o << "m_" << i->name;
580 } else {
581 printType(o, options, manager, i->type, 8, true);
583 o << ";\n}\n\n";
585 } else {
586 o << "\n" << indentation << "{\n" << indentation << " return "
587 << delegate.getStr() << "get" << i->name << "();\n"
588 << indentation << "}\n\n";
590 } else {
591 o << ";\n";
594 if (!i->readOnly) {
595 o << indentation;
596 if (!body)
597 o << "virtual ";
599 o << "void SAL_CALL ";
600 if (!classname.isEmpty())
601 o << classname;
603 o << "set" << i->name << '(';
604 printType(o, options, manager, i->type, 4);
605 o << " the_value)";
606 printExceptionSpecification(o, options, manager, i->setExceptions);
607 if (body) {
608 if (defaultbody) {
609 if (!propertyhelper.isEmpty()) {
610 printSetPropertyMixinBody(o, *i);
611 } else {
612 if (options.componenttype == 1) {
613 o << "\n{\n m_" << i->name
614 << " = the_value;\n}\n\n";
615 } else {
616 o << "\n{\n\n}\n\n";
619 } else {
620 o << "\n" << indentation << "{\n" << indentation << " "
621 << delegate.getStr() << "set" << i->name
622 << "(the_value);\n" << indentation << "}\n\n";
624 } else {
625 o << ";\n";
629 for (std::vector< unoidl::InterfaceTypeEntity::Method >::const_iterator i(
630 ent2->getDirectMethods().begin());
631 i != ent2->getDirectMethods().end(); ++i)
633 o << indentation;
634 if (!body)
635 o << "virtual ";
637 printType(o, options, manager, i->returnType, 1);
638 o << " SAL_CALL ";
639 if (!classname.isEmpty())
640 o << classname;
642 o << i->name << '(';
643 printMethodParameters(o, options, manager, i->parameters, true);
644 o << ')';
645 printExceptionSpecification(o, options, manager, i->exceptions);
646 if (body) {
647 if (defaultbody) {
648 o << "\n{\n";
649 if (i->returnType != "void") {
650 o << " // TODO: Exchange the default return implementation for \""
651 << i->name << "\" !!!\n";
652 o << " // Exchange the default return implementation.\n"
653 " // NOTE: Default initialized polymorphic structs "
654 "can cause problems because of\n // missing default "
655 "initialization of primitive types of some C++ compilers or"
656 "\n // different Any initialization in Java and C++ "
657 "polymorphic structs.\n return ";
658 printType(o, options, manager, i->returnType, 8, true);
659 o << ";";
660 } else {
661 o << " // TODO: Insert your implementation for \""
662 << i->name << "\" here.";
664 o << "\n}\n\n";
665 } else {
666 o << "\n" << indentation << "{\n" << indentation << " ";
667 if (i->returnType != "void")
668 o << "return ";
670 o << delegate.getStr() << i->name << '(';
671 printMethodParameters(
672 o, options, manager, i->parameters, false);
673 o << ");\n" << indentation << "}\n\n";
675 } else {
676 o << ";\n";
680 if (!body)
681 o << "\n";
684 void printConstructors(
685 std::ostream & o, ProgramOptions const & options,
686 rtl::Reference< TypeManager > const & manager, OUString const & name)
688 rtl::Reference< unoidl::Entity > ent;
689 if (manager->getSort(name, &ent)
690 != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE)
692 throw CannotDumpException(
693 "unexpected entity \"" + name
694 + "\" in call to skeletonmaker::java::printConstructors");
696 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > ent2(
697 dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(ent.get()));
698 assert(ent2.is());
699 for (std::vector< unoidl::SingleInterfaceBasedServiceEntity::Constructor >::
700 const_iterator i(ent2->getConstructors().begin());
701 i != ent2->getConstructors().end(); ++i)
703 o << "static ";
704 printType(o, options, manager, ent2->getBase(), 1);
705 o << ' ';
706 if (i->defaultConstructor) {
707 o << "create";
708 } else {
709 o << codemaker::cpp::translateUnoToCppIdentifier(
710 u2b(i->name), "method");
712 o << ((options.shortnames) ? "(css::uno::Reference< css" :
713 "(::com::sun::star::uno::Reference< ::com::sun::star")
714 << "::uno::XComponentContext > const & the_context";
715 for (std::vector<
716 unoidl::SingleInterfaceBasedServiceEntity::Constructor::
717 Parameter >::const_iterator j(i->parameters.begin());
718 j != i->parameters.end(); ++j)
720 o << ", ";
721 printType(o, options, manager, j->type, 4);
722 o << ' '
723 << codemaker::cpp::translateUnoToCppIdentifier(
724 u2b(j->name), "param");
726 o << ')';
727 printExceptionSpecification(o, options, manager, i->exceptions);
728 o << ";\n";
732 void printServiceMembers(
733 std::ostream & o, ProgramOptions const & options,
734 rtl::Reference< TypeManager > const & manager,
735 OUString const & name,
736 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity,
737 OString const & delegate)
739 assert(entity.is());
740 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
741 entity->getDirectMandatoryBaseServices().begin());
742 i != entity->getDirectMandatoryBaseServices().end(); ++i)
744 o << "\n// exported service " << i->name << "\n";
745 generateDocumentation(o, options, manager, u2b(i->name), delegate);
746 o << "\n// end of exported service " << i->name << "\n";
748 for (std::vector< unoidl::AnnotatedReference >::const_iterator i(
749 entity->getDirectMandatoryBaseInterfaces().begin());
750 i != entity->getDirectMandatoryBaseInterfaces().end(); ++i)
752 o << "\n// supported interface " << i->name << "\n";
753 generateDocumentation(o, options, manager, u2b(i->name), delegate);
755 if (delegate.isEmpty()) {
756 o << "\n// properties of service \""<< name << "\"\n";
757 for (std::vector< unoidl::AccumulationBasedServiceEntity::Property >::
758 const_iterator i(entity->getDirectProperties().begin());
759 i != entity->getDirectProperties().end(); ++i)
761 o << "// private ";
762 printType(o, options, manager, i->type, 1);
763 o << " "
764 << codemaker::cpp::translateUnoToCppIdentifier(
765 u2b(i->name), "property")
766 << ";\n";
771 void printMapsToCppType(
772 std::ostream & o, ProgramOptions const & options,
773 rtl::Reference< TypeManager > const & manager,
774 codemaker::UnoType::Sort sort, OUString const & nucleus, sal_Int32 rank,
775 std::vector< OUString > const & arguments,
776 rtl::Reference< unoidl::Entity > const & entity, const char * cppTypeSort)
778 o << "maps to C++ ";
779 if (cppTypeSort != 0)
780 o << cppTypeSort << ' ';
782 o << "type \"";
783 if (rank == 0 && nucleus == "com.sun.star.uno.XInterface") {
784 o << "Reference< com::sun::star::uno::XInterface >";
785 } else {
786 printType(
787 o, options, manager, sort, nucleus, rank, arguments, entity, 0,
788 false);
790 o << '"';
793 void generateDocumentation(std::ostream & o,
794 ProgramOptions const & options, rtl::Reference< TypeManager > const & manager,
795 OString const & type, OString const & delegate)
797 OUString nucleus;
798 sal_Int32 rank;
799 codemaker::UnoType::Sort sort = manager->decompose(
800 b2u(type), false, &nucleus, &rank, 0, 0);
802 bool comment = true;
803 if (!delegate.isEmpty()) {
804 if (sort != codemaker::UnoType::SORT_INTERFACE_TYPE &&
805 sort != codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE &&
806 sort != codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE )
808 return;
810 comment = false;
813 if (comment) {
814 o << "\n// UNO";
815 if (rank != 0) {
816 o << " sequence type";
817 } else if (sort <= codemaker::UnoType::SORT_ANY) {
818 o << " simple type";
819 } else {
820 switch (sort) {
821 case codemaker::UnoType::SORT_INTERFACE_TYPE:
822 o << " interface type";
823 break;
825 case codemaker::UnoType::SORT_MODULE:
826 o << "IDL module";
827 break;
829 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
830 o << " simple struct type";
831 break;
833 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
834 o << " polymorphic struct type template";
835 break;
837 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
838 o << " instantiated polymorphic struct type";
839 break;
841 case codemaker::UnoType::SORT_ENUM_TYPE:
842 o << " enum type";
843 break;
845 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
846 o << " exception type";
847 break;
849 case codemaker::UnoType::SORT_TYPEDEF:
850 o << "IDL typedef";
851 break;
853 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
854 o << " single-inheritance--based service";
855 break;
857 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
858 o << "IDL accumulation-based service";
859 break;
861 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
862 o << " inheritance-based singleton";
863 break;
865 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
866 o << "IDL service-based singleton";
867 break;
869 case codemaker::UnoType::SORT_CONSTANT_GROUP:
870 o << "IDL constant group";
871 break;
873 default:
874 OSL_ASSERT(false);
875 break;
878 o << " \"" << type << "\" ";
880 std::vector< OUString > arguments;
881 rtl::Reference< unoidl::Entity > entity;
882 sort = manager->decompose(
883 b2u(type), true, &nucleus, &rank, &arguments, &entity);
884 if (rank != 0) {
885 if (comment) {
886 printMapsToCppType(
887 o, options, manager, sort, nucleus, rank, arguments, entity,
888 "array");
889 o << '\n';
891 } else if (sort <= codemaker::UnoType::SORT_ANY) {
892 if (comment) {
893 printMapsToCppType(
894 o, options, manager, sort, nucleus, rank, arguments, entity, 0);
895 o << '\n';
897 } else {
898 switch (sort) {
899 case codemaker::UnoType::SORT_INTERFACE_TYPE:
900 if (comment)
901 printMapsToCppType(
902 o, options, manager, sort, nucleus, rank, arguments, entity,
903 "interface");
904 if (nucleus == "com.sun.star.uno.XInterface") {
905 if (comment)
906 o << '\n';
907 } else {
908 if (comment)
909 o << "; " << (options.all ? "all" : "direct") << " methods:\n";
911 codemaker::GeneratedTypeSet generated;
912 printMethods(
913 o, options, manager, nucleus, generated, delegate,
914 options.implname, "");
916 break;
918 case codemaker::UnoType::SORT_MODULE:
919 printMapsToCppType(
920 o, options, manager, sort, nucleus, rank, arguments, entity,
921 "namespace");
922 o << '\n';
923 break;
925 case codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE:
926 printMapsToCppType(
927 o, options, manager, sort, nucleus, rank, arguments, entity,
928 "class");
929 o << "; full constructor:\n";
930 printConstructor(
931 o, options, manager, codemaker::UnoType::SORT_PLAIN_STRUCT_TYPE,
932 entity, nucleus, arguments);
933 break;
935 case codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
936 printMapsToCppType(
937 o, options, manager, sort, nucleus, rank, arguments, entity,
938 options.java5 ? "generic class" : "class");
939 o << "; full constructor:\n";
940 printConstructor(
941 o, options, manager,
942 codemaker::UnoType::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE,
943 entity, nucleus, arguments);
944 break;
946 case codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE:
947 printMapsToCppType(
948 o, options, manager, sort, nucleus, rank, arguments, entity,
949 options.java5 ? "generic class instantiation" : "class");
950 o << "; full constructor:\n";
951 printConstructor(
952 o, options, manager,
953 codemaker::UnoType::SORT_INSTANTIATED_POLYMORPHIC_STRUCT_TYPE,
954 entity, nucleus, arguments);
955 break;
957 case codemaker::UnoType::SORT_ENUM_TYPE:
958 printMapsToCppType(
959 o, options, manager, sort, nucleus, rank, arguments, entity,
960 "enum");
961 o << '\n';
962 break;
964 case codemaker::UnoType::SORT_CONSTANT_GROUP:
965 printMapsToCppType(
966 o, options, manager, sort, nucleus, rank, arguments, entity,
967 "namespace");
968 o << '\n';
969 break;
971 case codemaker::UnoType::SORT_EXCEPTION_TYPE:
972 printMapsToCppType(
973 o, options, manager, sort, nucleus, rank, arguments, entity,
974 "exception class");
975 o << "; full constructor:\n";
976 printConstructor(
977 o, options, manager, codemaker::UnoType::SORT_EXCEPTION_TYPE,
978 entity, nucleus, arguments);
979 break;
981 case codemaker::UnoType::SORT_SINGLE_INTERFACE_BASED_SERVICE:
982 if (comment) {
983 printMapsToCppType(
984 o, options, manager, sort, nucleus, rank, arguments, entity,
985 "class");
986 o << "; construction methods:\n";
987 printConstructors(o, options, manager, nucleus);
989 generateDocumentation(
990 o, options, manager,
991 u2b(dynamic_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
992 entity.get())->getBase()),
993 delegate);
994 break;
996 case codemaker::UnoType::SORT_ACCUMULATION_BASED_SERVICE:
997 if (comment)
998 o << ("does not map to C++\n"
999 "// the service members are generated instead\n");
1000 printServiceMembers(
1001 o, options, manager, nucleus,
1002 dynamic_cast< unoidl::AccumulationBasedServiceEntity * >(
1003 entity.get()),
1004 delegate);
1005 break;
1007 case codemaker::UnoType::SORT_INTERFACE_BASED_SINGLETON:
1008 printMapsToCppType(
1009 o, options, manager, sort, nucleus, rank, arguments, entity,
1010 "class");
1011 o << "; get method:\nstatic ";
1012 printType(
1013 o, options, manager,
1014 dynamic_cast< unoidl::InterfaceBasedSingletonEntity * >(
1015 entity.get())->getBase(),
1017 o << " get(::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & context);\n";
1018 break;
1020 case codemaker::UnoType::SORT_SERVICE_BASED_SINGLETON:
1021 o << "does not map to C++\n";
1022 break;
1024 default:
1025 OSL_ASSERT(false);
1026 break;
1034 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */