Simplify a static array iteration
[LibreOffice.git] / cppuhelper / source / typemanager.cxx
blob30c1555de137e6c12901e906b9f9d6af5d256ce6
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/.
8 */
10 #include <sal/config.h>
12 #include <cassert>
13 #include <cstddef>
14 #include <cstdlib>
15 #include <cstring>
16 #include <mutex>
17 #include <set>
18 #include <stack>
19 #include <string_view>
20 #include <utility>
21 #include <vector>
23 #include <com/sun/star/container/NoSuchElementException.hpp>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
26 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
27 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
28 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
29 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
30 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
31 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
32 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
33 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
34 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
35 #include <com/sun/star/reflection/XPublished.hpp>
36 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
37 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
38 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
39 #include <com/sun/star/reflection/XTypeDescription.hpp>
40 #include <com/sun/star/uno/Any.hxx>
41 #include <com/sun/star/uno/DeploymentException.hpp>
42 #include <com/sun/star/uno/Reference.hxx>
43 #include <com/sun/star/uno/RuntimeException.hpp>
44 #include <com/sun/star/uno/Sequence.hxx>
45 #include <com/sun/star/uno/Type.hxx>
46 #include <com/sun/star/uno/TypeClass.hpp>
47 #include <cppu/unotype.hxx>
48 #include <cppuhelper/implbase.hxx>
49 #include <cppuhelper/supportsservice.hxx>
50 #include <osl/file.hxx>
51 #include <rtl/ref.hxx>
52 #include <rtl/ustring.hxx>
53 #include <sal/log.hxx>
54 #include <sal/macros.h>
55 #include <sal/types.h>
57 #include <unoidl/unoidl.hxx>
59 #include "paths.hxx"
60 #include "typemanager.hxx"
62 namespace {
64 OUString makePrefix(OUString const & name) {
65 return name.isEmpty() ? name : name + ".";
68 css::uno::Any resolveTypedefs(css::uno::Any const & type) {
69 for (css::uno::Any t(type);;) {
70 css::uno::Reference< css::reflection::XIndirectTypeDescription > ind(
71 type, css::uno::UNO_QUERY);
72 if (!ind.is() || ind->getTypeClass() != css::uno::TypeClass_TYPEDEF) {
73 return t;
75 t <<= ind->getReferencedType();
79 class SimpleTypeDescription:
80 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
82 public:
83 SimpleTypeDescription(
84 css::uno::TypeClass typeClass, OUString const & name):
85 typeClass_(typeClass), name_(name)
88 private:
89 virtual ~SimpleTypeDescription() override {}
91 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
92 { return typeClass_; }
94 virtual OUString SAL_CALL getName() override
95 { return name_; }
97 css::uno::TypeClass typeClass_;
98 OUString name_;
101 class SequenceTypeDescription:
102 public cppu::WeakImplHelper< css::reflection::XIndirectTypeDescription >
104 public:
105 SequenceTypeDescription(
106 rtl::Reference< cppuhelper::TypeManager > const & manager,
107 OUString const & name, OUString const & componentType):
108 manager_(manager), name_(name), componentType_(componentType)
109 { assert(manager.is()); }
111 private:
112 virtual ~SequenceTypeDescription() override {}
114 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
115 { return css::uno::TypeClass_SEQUENCE; }
117 virtual OUString SAL_CALL getName() override
118 { return name_; }
120 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
121 getReferencedType() override
122 { return manager_->resolve(componentType_); }
124 rtl::Reference< cppuhelper::TypeManager > manager_;
125 OUString name_;
126 OUString componentType_;
129 class PublishableDescription:
130 public cppu::WeakImplHelper< css::reflection::XPublished >
132 protected:
133 explicit PublishableDescription(bool published): published_(published) {}
135 virtual ~PublishableDescription() override {}
137 private:
138 virtual sal_Bool SAL_CALL isPublished() override
139 { return published_; }
141 bool published_;
144 class ModuleDescription:
145 public cppu::WeakImplHelper< css::reflection::XModuleTypeDescription >
147 public:
148 ModuleDescription(
149 rtl::Reference< cppuhelper::TypeManager > const & manager,
150 OUString const & name,
151 rtl::Reference< unoidl::ModuleEntity > const & entity):
152 manager_(manager), name_(name), entity_(entity)
153 { assert(manager.is()); assert(entity.is()); }
155 private:
156 virtual ~ModuleDescription() override {}
158 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
159 { return css::uno::TypeClass_MODULE; }
161 virtual OUString SAL_CALL getName() override
162 { return name_; }
164 virtual
165 css::uno::Sequence<
166 css::uno::Reference< css::reflection::XTypeDescription > >
167 SAL_CALL getMembers() override;
169 rtl::Reference< cppuhelper::TypeManager > manager_;
170 OUString name_;
171 rtl::Reference< unoidl::ModuleEntity > entity_;
174 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
175 ModuleDescription::getMembers() {
176 try {
177 std::vector< OUString > names(entity_->getMemberNames());
178 assert(names.size() <= SAL_MAX_INT32);
179 sal_Int32 n = static_cast< sal_Int32 >(names.size());
180 css::uno::Sequence<
181 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
182 auto r = asNonConstRange(s);
183 for (sal_Int32 i = 0; i != n; ++i) {
184 r[i] = manager_->resolve(makePrefix(name_) + names[i]);
186 return s;
187 } catch (unoidl::FileFormatException & e) {
188 throw css::uno::DeploymentException(
189 e.getUri() + ": " + e.getDetail(),
190 static_cast< cppu::OWeakObject * >(this));
194 typedef cppu::ImplInheritanceHelper<
195 PublishableDescription, css::reflection::XEnumTypeDescription >
196 EnumTypeDescription_Base;
198 class EnumTypeDescription: public EnumTypeDescription_Base {
199 public:
200 EnumTypeDescription(
201 OUString const & name,
202 rtl::Reference< unoidl::EnumTypeEntity > const & entity):
203 EnumTypeDescription_Base(entity->isPublished()), name_(name),
204 entity_(entity)
205 { assert(entity.is()); }
207 private:
208 virtual ~EnumTypeDescription() override {}
210 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
211 { return css::uno::TypeClass_ENUM; }
213 virtual OUString SAL_CALL getName() override
214 { return name_; }
216 virtual sal_Int32 SAL_CALL getDefaultEnumValue() override
217 { return entity_->getMembers()[0].value; }
219 virtual css::uno::Sequence< OUString > SAL_CALL getEnumNames() override;
221 virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues() override;
223 OUString name_;
224 rtl::Reference< unoidl::EnumTypeEntity > entity_;
227 css::uno::Sequence< OUString > EnumTypeDescription::getEnumNames()
229 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
230 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
231 css::uno::Sequence< OUString > s(n);
232 auto r = asNonConstRange(s);
233 for (sal_Int32 i = 0; i != n; ++i) {
234 r[i] = entity_->getMembers()[i].name;
236 return s;
239 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
241 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
242 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
243 css::uno::Sequence< sal_Int32 > s(n);
244 auto r = asNonConstRange(s);
245 for (sal_Int32 i = 0; i != n; ++i) {
246 r[i] = entity_->getMembers()[i].value;
248 return s;
251 typedef cppu::ImplInheritanceHelper<
252 PublishableDescription, css::reflection::XStructTypeDescription >
253 PlainStructTypeDescription_Base;
255 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
256 public:
257 PlainStructTypeDescription(
258 rtl::Reference< cppuhelper::TypeManager > const & manager,
259 OUString const & name,
260 rtl::Reference< unoidl::PlainStructTypeEntity > const & entity):
261 PlainStructTypeDescription_Base(entity->isPublished()),
262 manager_(manager), name_(name), entity_(entity)
263 { assert(manager.is()); assert(entity.is()); }
265 private:
266 virtual ~PlainStructTypeDescription() override {}
268 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
269 { return css::uno::TypeClass_STRUCT; }
271 virtual OUString SAL_CALL getName() override
272 { return name_; }
274 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
275 getBaseType() override {
276 return entity_->getDirectBase().isEmpty()
277 ? css::uno::Reference< css::reflection::XTypeDescription >()
278 : manager_->resolve(entity_->getDirectBase());
281 virtual
282 css::uno::Sequence<
283 css::uno::Reference< css::reflection::XTypeDescription > >
284 SAL_CALL getMemberTypes() override;
286 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
288 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
289 { return css::uno::Sequence< OUString >(); }
291 virtual
292 css::uno::Sequence<
293 css::uno::Reference< css::reflection::XTypeDescription > >
294 SAL_CALL getTypeArguments() override {
295 return css::uno::Sequence<
296 css::uno::Reference< css::reflection::XTypeDescription > >();
299 rtl::Reference< cppuhelper::TypeManager > manager_;
300 OUString name_;
301 rtl::Reference< unoidl::PlainStructTypeEntity > entity_;
304 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
305 PlainStructTypeDescription::getMemberTypes()
307 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
308 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
309 css::uno::Sequence<
310 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
311 auto r = asNonConstRange(s);
312 for (sal_Int32 i = 0; i != n; ++i) {
313 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
315 return s;
318 css::uno::Sequence< OUString > PlainStructTypeDescription::getMemberNames()
320 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
321 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
322 css::uno::Sequence< OUString > s(n);
323 auto r = asNonConstRange(s);
324 for (sal_Int32 i = 0; i != n; ++i) {
325 r[i] = entity_->getDirectMembers()[i].name;
327 return s;
330 class ParameterizedMemberTypeDescription:
331 public cppu::WeakImplHelper< css::reflection::XTypeDescription >
333 public:
334 explicit ParameterizedMemberTypeDescription(
335 OUString const & typeParameterName):
336 typeParameterName_(typeParameterName)
339 private:
340 virtual ~ParameterizedMemberTypeDescription() override {}
342 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
343 { return css::uno::TypeClass_UNKNOWN; }
345 virtual OUString SAL_CALL getName() override
346 { return typeParameterName_; }
348 OUString typeParameterName_;
351 typedef cppu::ImplInheritanceHelper<
352 PublishableDescription, css::reflection::XStructTypeDescription >
353 PolymorphicStructTypeTemplateDescription_Base;
355 class PolymorphicStructTypeTemplateDescription:
356 public PolymorphicStructTypeTemplateDescription_Base
358 public:
359 PolymorphicStructTypeTemplateDescription(
360 rtl::Reference< cppuhelper::TypeManager > const & manager,
361 OUString const & name,
362 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
363 entity):
364 PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
365 manager_(manager), name_(name), entity_(entity)
366 { assert(manager.is()); assert(entity.is()); }
368 private:
369 virtual ~PolymorphicStructTypeTemplateDescription() override {}
371 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
372 { return css::uno::TypeClass_STRUCT; }
374 virtual OUString SAL_CALL getName() override
375 { return name_; }
377 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
378 getBaseType() override
379 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
381 virtual
382 css::uno::Sequence<
383 css::uno::Reference< css::reflection::XTypeDescription > >
384 SAL_CALL getMemberTypes() override;
386 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
388 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override;
390 virtual
391 css::uno::Sequence<
392 css::uno::Reference< css::reflection::XTypeDescription > >
393 SAL_CALL getTypeArguments() override {
394 return css::uno::Sequence<
395 css::uno::Reference< css::reflection::XTypeDescription > >();
398 rtl::Reference< cppuhelper::TypeManager > manager_;
399 OUString name_;
400 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
403 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
404 PolymorphicStructTypeTemplateDescription::getMemberTypes()
406 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
407 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
408 css::uno::Sequence<
409 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
410 auto r = asNonConstRange(s);
411 for (sal_Int32 i = 0; i != n; ++i) {
412 r[i] = entity_->getMembers()[i].parameterized
413 ? new ParameterizedMemberTypeDescription(
414 entity_->getMembers()[i].type)
415 : manager_->resolve(entity_->getMembers()[i].type);
417 return s;
420 css::uno::Sequence< OUString >
421 PolymorphicStructTypeTemplateDescription::getMemberNames()
423 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
424 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
425 css::uno::Sequence< OUString > s(n);
426 auto r = asNonConstRange(s);
427 for (sal_Int32 i = 0; i != n; ++i) {
428 r[i] = entity_->getMembers()[i].name;
430 return s;
433 css::uno::Sequence< OUString >
434 PolymorphicStructTypeTemplateDescription::getTypeParameters()
436 assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
437 sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
438 css::uno::Sequence< OUString > s(n);
439 auto r = asNonConstRange(s);
440 for (sal_Int32 i = 0; i != n; ++i) {
441 r[i] = entity_->getTypeParameters()[i];
443 return s;
446 class InstantiatedPolymorphicStructTypeDescription:
447 public cppu::WeakImplHelper< css::reflection::XStructTypeDescription >
449 public:
450 InstantiatedPolymorphicStructTypeDescription(
451 rtl::Reference< cppuhelper::TypeManager > const & manager,
452 OUString const & name,
453 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const &
454 entity,
455 std::vector< OUString >&& arguments):
456 manager_(manager), name_(name), entity_(entity), arguments_(std::move(arguments))
458 assert(manager.is());
459 assert(entity.is());
460 assert(arguments_.size() == entity->getTypeParameters().size());
463 private:
464 virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
466 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
467 { return css::uno::TypeClass_STRUCT; }
469 virtual OUString SAL_CALL getName() override
470 { return name_; }
472 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
473 getBaseType() override
474 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
476 virtual
477 css::uno::Sequence<
478 css::uno::Reference< css::reflection::XTypeDescription > >
479 SAL_CALL getMemberTypes() override;
481 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
483 virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
484 { return css::uno::Sequence< OUString >(); }
486 virtual
487 css::uno::Sequence<
488 css::uno::Reference< css::reflection::XTypeDescription > >
489 SAL_CALL getTypeArguments() override;
491 rtl::Reference< cppuhelper::TypeManager > manager_;
492 OUString name_;
493 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > entity_;
494 std::vector< OUString > arguments_;
497 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
498 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
500 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
501 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
502 css::uno::Sequence<
503 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
504 auto r = asNonConstRange(s);
505 for (sal_Int32 i = 0; i != n; ++i) {
506 OUString type(entity_->getMembers()[i].type);
507 if (entity_->getMembers()[i].parameterized) {
508 auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
509 if (j != entity_->getTypeParameters().end()) {
510 type = arguments_[j - entity_->getTypeParameters().begin()];
511 goto found;
513 assert(false); // this cannot happen //TODO!
514 found:;
516 r[i] = manager_->resolve(type);
518 return s;
521 css::uno::Sequence< OUString >
522 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
524 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
525 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
526 css::uno::Sequence< OUString > s(n);
527 auto r = asNonConstRange(s);
528 for (sal_Int32 i = 0; i != n; ++i) {
529 r[i] = entity_->getMembers()[i].name;
531 return s;
533 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
534 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
536 assert(arguments_.size() <= SAL_MAX_INT32);
537 sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
538 css::uno::Sequence<
539 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
540 auto r = asNonConstRange(s);
541 for (sal_Int32 i = 0; i != n; ++i) {
542 r[i] = manager_->resolve(arguments_[i]);
544 return s;
547 typedef cppu::ImplInheritanceHelper<
548 PublishableDescription, css::reflection::XCompoundTypeDescription >
549 ExceptionTypeDescription_Base;
551 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
552 public:
553 ExceptionTypeDescription(
554 rtl::Reference< cppuhelper::TypeManager > const & manager,
555 OUString const & name,
556 rtl::Reference< unoidl::ExceptionTypeEntity > const & entity):
557 ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
558 name_(name), entity_(entity)
559 { assert(manager.is()); assert(entity.is()); }
561 private:
562 virtual ~ExceptionTypeDescription() override {}
564 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
565 { return css::uno::TypeClass_EXCEPTION; }
567 virtual OUString SAL_CALL getName() override
568 { return name_; }
570 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
571 getBaseType() override {
572 return entity_->getDirectBase().isEmpty()
573 ? css::uno::Reference< css::reflection::XTypeDescription >()
574 : manager_->resolve(entity_->getDirectBase());
577 virtual
578 css::uno::Sequence<
579 css::uno::Reference< css::reflection::XTypeDescription > >
580 SAL_CALL getMemberTypes() override;
582 virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
584 rtl::Reference< cppuhelper::TypeManager > manager_;
585 OUString name_;
586 rtl::Reference< unoidl::ExceptionTypeEntity > entity_;
589 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
590 ExceptionTypeDescription::getMemberTypes() {
591 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
592 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
593 css::uno::Sequence<
594 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
595 auto r = asNonConstRange(s);
596 for (sal_Int32 i = 0; i != n; ++i) {
597 r[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
599 return s;
602 css::uno::Sequence< OUString > ExceptionTypeDescription::getMemberNames()
604 assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
605 sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
606 css::uno::Sequence< OUString > s(n);
607 auto r = asNonConstRange(s);
608 for (sal_Int32 i = 0; i != n; ++i) {
609 r[i] = entity_->getDirectMembers()[i].name;
611 return s;
614 class AttributeDescription:
615 public cppu::WeakImplHelper<
616 css::reflection::XInterfaceAttributeTypeDescription2 >
618 public:
619 AttributeDescription(
620 rtl::Reference< cppuhelper::TypeManager > const & manager,
621 OUString const & name,
622 unoidl::InterfaceTypeEntity::Attribute const & attribute,
623 sal_Int32 position):
624 manager_(manager), name_(name), attribute_(attribute),
625 position_(position)
626 { assert(manager.is()); }
628 private:
629 virtual ~AttributeDescription() override {}
631 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
632 { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
634 virtual OUString SAL_CALL getName() override
635 { return name_; }
637 virtual OUString SAL_CALL getMemberName() override
638 { return attribute_.name; }
640 virtual sal_Int32 SAL_CALL getPosition() override
641 { return position_; }
643 virtual sal_Bool SAL_CALL isReadOnly() override
644 { return attribute_.readOnly; }
646 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
647 getType() override
648 { return manager_->resolve(attribute_.type); }
650 virtual sal_Bool SAL_CALL isBound() override
651 { return attribute_.bound; }
653 virtual
654 css::uno::Sequence<
655 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
656 SAL_CALL getGetExceptions() override;
658 virtual
659 css::uno::Sequence<
660 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
661 SAL_CALL getSetExceptions() override;
663 rtl::Reference< cppuhelper::TypeManager > manager_;
664 OUString name_;
665 unoidl::InterfaceTypeEntity::Attribute attribute_;
666 sal_Int32 position_;
669 css::uno::Sequence<
670 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
671 AttributeDescription::getGetExceptions() {
672 assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
673 sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
674 css::uno::Sequence<
675 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
676 auto r = asNonConstRange(s);
677 for (sal_Int32 i = 0; i != n; ++i) {
678 r[i].set(
679 manager_->resolve(attribute_.getExceptions[i]),
680 css::uno::UNO_QUERY_THROW);
682 return s;
685 css::uno::Sequence<
686 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
687 AttributeDescription::getSetExceptions() {
688 assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
689 sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
690 css::uno::Sequence<
691 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
692 auto r = asNonConstRange(s);
693 for (sal_Int32 i = 0; i != n; ++i) {
694 r[i].set(
695 manager_->resolve(attribute_.setExceptions[i]),
696 css::uno::UNO_QUERY_THROW);
698 return s;
701 class MethodParameter:
702 public cppu::WeakImplHelper< css::reflection::XMethodParameter >
704 public:
705 MethodParameter(
706 rtl::Reference< cppuhelper::TypeManager > const & manager,
707 unoidl::InterfaceTypeEntity::Method::Parameter const & parameter,
708 sal_Int32 position):
709 manager_(manager), parameter_(parameter), position_(position)
710 { assert(manager.is()); }
712 private:
713 virtual ~MethodParameter() override {}
715 virtual OUString SAL_CALL getName() override
716 { return parameter_.name; }
718 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
719 getType() override
720 { return manager_->resolve(parameter_.type); }
722 virtual sal_Bool SAL_CALL isIn() override {
723 return
724 (parameter_.direction
725 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_IN)
726 || (parameter_.direction
727 == unoidl::InterfaceTypeEntity::Method::Parameter::
728 DIRECTION_IN_OUT);
731 virtual sal_Bool SAL_CALL isOut() override {
732 return
733 (parameter_.direction
734 == unoidl::InterfaceTypeEntity::Method::Parameter::DIRECTION_OUT)
735 || (parameter_.direction
736 == unoidl::InterfaceTypeEntity::Method::Parameter::
737 DIRECTION_IN_OUT);
740 virtual sal_Int32 SAL_CALL getPosition() override
741 { return position_; }
743 rtl::Reference< cppuhelper::TypeManager > manager_;
744 unoidl::InterfaceTypeEntity::Method::Parameter parameter_;
745 sal_Int32 position_;
748 class MethodDescription:
749 public cppu::WeakImplHelper<
750 css::reflection::XInterfaceMethodTypeDescription >
752 public:
753 MethodDescription(
754 rtl::Reference< cppuhelper::TypeManager > const & manager,
755 OUString const & name,
756 unoidl::InterfaceTypeEntity::Method const & method, sal_Int32 position):
757 manager_(manager), name_(name), method_(method), position_(position)
758 { assert(manager.is()); }
760 private:
761 virtual ~MethodDescription() override {}
763 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
764 { return css::uno::TypeClass_INTERFACE_METHOD; }
766 virtual OUString SAL_CALL getName() override
767 { return name_; }
769 virtual OUString SAL_CALL getMemberName() override
770 { return method_.name; }
772 virtual sal_Int32 SAL_CALL getPosition() override
773 { return position_; }
775 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
776 getReturnType() override
777 { return manager_->resolve(method_.returnType); }
779 virtual sal_Bool SAL_CALL isOneway() override
780 { return false; }
782 virtual
783 css::uno::Sequence<
784 css::uno::Reference< css::reflection::XMethodParameter > >
785 SAL_CALL getParameters() override;
787 virtual
788 css::uno::Sequence<
789 css::uno::Reference< css::reflection::XTypeDescription > >
790 SAL_CALL getExceptions() override;
792 rtl::Reference< cppuhelper::TypeManager > manager_;
793 OUString name_;
794 unoidl::InterfaceTypeEntity::Method method_;
795 sal_Int32 position_;
798 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
799 MethodDescription::getParameters() {
800 assert(method_.parameters.size() <= SAL_MAX_INT32);
801 sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
802 css::uno::Sequence<
803 css::uno::Reference< css::reflection::XMethodParameter > > s(n);
804 auto r = asNonConstRange(s);
805 for (sal_Int32 i = 0; i != n; ++i) {
806 r[i] = new MethodParameter(manager_, method_.parameters[i], i);
808 return s;
811 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
812 MethodDescription::getExceptions() {
813 assert(method_.exceptions.size() <= SAL_MAX_INT32);
814 sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
815 css::uno::Sequence<
816 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
817 auto r = asNonConstRange(s);
818 for (sal_Int32 i = 0; i != n; ++i) {
819 r[i] = manager_->resolve(method_.exceptions[i]);
821 return s;
824 class BaseOffset {
825 public:
826 explicit BaseOffset(
827 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
828 const & description);
830 BaseOffset(const BaseOffset&) = delete;
831 const BaseOffset& operator=(const BaseOffset&) = delete;
833 sal_Int32 get() const { return offset_; }
835 private:
836 void calculateBases(
837 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
838 const & description);
840 void calculate(
841 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
842 const & description);
844 std::set< OUString > set_;
845 sal_Int32 offset_;
848 BaseOffset::BaseOffset(
849 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
850 description):
851 offset_(0)
853 calculateBases(description);
856 void BaseOffset::calculateBases(
857 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
858 description)
860 const css::uno::Sequence<
861 css::uno::Reference < css::reflection::XTypeDescription > > bases(
862 description->getBaseTypes());
863 for (const auto & i : bases) {
864 calculate(
865 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
866 resolveTypedefs(css::uno::makeAny(i)),
867 css::uno::UNO_QUERY_THROW));
871 void BaseOffset::calculate(
872 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
873 description)
875 if (set_.insert(description->getName()).second) {
876 calculateBases(description);
877 offset_ += description->getMembers().getLength();
881 typedef cppu::ImplInheritanceHelper<
882 PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
883 InterfaceTypeDescription_Base;
885 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
886 public:
887 InterfaceTypeDescription(
888 rtl::Reference< cppuhelper::TypeManager > const & manager,
889 OUString const & name,
890 rtl::Reference< unoidl::InterfaceTypeEntity > const & entity):
891 InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
892 name_(name), entity_(entity)
893 { assert(manager.is()); assert(entity.is()); }
895 private:
896 virtual ~InterfaceTypeDescription() override {}
898 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
899 { return css::uno::TypeClass_INTERFACE; }
901 virtual OUString SAL_CALL getName() override
902 { return name_; }
904 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
905 getBaseType() override {
906 return entity_->getDirectMandatoryBases().empty()
907 ? css::uno::Reference< css::reflection::XTypeDescription >()
908 : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
911 virtual css::uno::Uik SAL_CALL getUik() override
912 { return css::uno::Uik(); }
914 virtual
915 css::uno::Sequence<
916 css::uno::Reference<
917 css::reflection::XInterfaceMemberTypeDescription > >
918 SAL_CALL getMembers() override;
920 virtual
921 css::uno::Sequence<
922 css::uno::Reference< css::reflection::XTypeDescription > >
923 SAL_CALL getBaseTypes() override;
925 virtual
926 css::uno::Sequence<
927 css::uno::Reference< css::reflection::XTypeDescription > >
928 SAL_CALL getOptionalBaseTypes() override;
930 rtl::Reference< cppuhelper::TypeManager > manager_;
931 OUString name_;
932 rtl::Reference< unoidl::InterfaceTypeEntity > entity_;
935 css::uno::Sequence<
936 css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
937 InterfaceTypeDescription::getMembers() {
938 assert(
939 entity_->getDirectAttributes().size() <= SAL_MAX_INT32
940 && (entity_->getDirectMethods().size()
941 <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
942 sal_Int32 n1 = static_cast< sal_Int32 >(
943 entity_->getDirectAttributes().size());
944 sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
945 css::uno::Sequence<
946 css::uno::Reference<
947 css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
948 auto r = asNonConstRange(s);
949 sal_Int32 off = BaseOffset(this).get();
950 for (sal_Int32 i = 0; i != n1; ++i) {
951 r[i] = new AttributeDescription(
952 manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
953 entity_->getDirectAttributes()[i], off + i);
955 for (sal_Int32 i = 0; i != n2; ++i) {
956 r[n1 + i] = new MethodDescription(
957 manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
958 entity_->getDirectMethods()[i], off + n1 + i);
960 return s;
963 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
964 InterfaceTypeDescription::getBaseTypes() {
965 assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
966 sal_Int32 n = static_cast< sal_Int32 >(
967 entity_->getDirectMandatoryBases().size());
968 css::uno::Sequence<
969 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
970 auto r = asNonConstRange(s);
971 for (sal_Int32 i = 0; i != n; ++i) {
972 r[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
974 return s;
977 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
978 InterfaceTypeDescription::getOptionalBaseTypes()
980 assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
981 sal_Int32 n = static_cast< sal_Int32 >(
982 entity_->getDirectOptionalBases().size());
983 css::uno::Sequence<
984 css::uno::Reference< css::reflection::XTypeDescription > > s(n);
985 auto r = asNonConstRange(s);
986 for (sal_Int32 i = 0; i != n; ++i) {
987 r[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
989 return s;
992 class ConstantDescription:
993 public cppu::WeakImplHelper< css::reflection::XConstantTypeDescription >
995 public:
996 ConstantDescription(
997 OUString const & constantGroupName,
998 unoidl::ConstantGroupEntity::Member const & member);
1000 private:
1001 virtual ~ConstantDescription() override {}
1003 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1004 { return css::uno::TypeClass_CONSTANT; }
1006 virtual OUString SAL_CALL getName() override
1007 { return name_; }
1009 virtual css::uno::Any SAL_CALL getConstantValue() override
1010 { return value_; }
1012 OUString name_;
1013 css::uno::Any value_;
1016 ConstantDescription::ConstantDescription(
1017 OUString const & constantGroupName,
1018 unoidl::ConstantGroupEntity::Member const & member):
1019 name_(makePrefix(constantGroupName) + member.name)
1021 switch (member.value.type) {
1022 case unoidl::ConstantValue::TYPE_BOOLEAN:
1023 value_ <<= member.value.booleanValue;
1024 break;
1025 case unoidl::ConstantValue::TYPE_BYTE:
1026 value_ <<= member.value.byteValue;
1027 break;
1028 case unoidl::ConstantValue::TYPE_SHORT:
1029 value_ <<= member.value.shortValue;
1030 break;
1031 case unoidl::ConstantValue::TYPE_UNSIGNED_SHORT:
1032 value_ <<= member.value.unsignedShortValue;
1033 break;
1034 case unoidl::ConstantValue::TYPE_LONG:
1035 value_ <<= member.value.longValue;
1036 break;
1037 case unoidl::ConstantValue::TYPE_UNSIGNED_LONG:
1038 value_ <<= member.value.unsignedLongValue;
1039 break;
1040 case unoidl::ConstantValue::TYPE_HYPER:
1041 value_ <<= member.value.hyperValue;
1042 break;
1043 case unoidl::ConstantValue::TYPE_UNSIGNED_HYPER:
1044 value_ <<= member.value.unsignedHyperValue;
1045 break;
1046 case unoidl::ConstantValue::TYPE_FLOAT:
1047 value_ <<= member.value.floatValue;
1048 break;
1049 case unoidl::ConstantValue::TYPE_DOUBLE:
1050 value_ <<= member.value.doubleValue;
1051 break;
1052 default:
1053 for (;;) { std::abort(); } // this cannot happen
1057 typedef cppu::ImplInheritanceHelper<
1058 PublishableDescription, css::reflection::XConstantsTypeDescription >
1059 ConstantGroupDescription_Base;
1061 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1062 public:
1063 ConstantGroupDescription(
1064 OUString const & name,
1065 rtl::Reference< unoidl::ConstantGroupEntity > const & entity):
1066 ConstantGroupDescription_Base(entity->isPublished()), name_(name),
1067 entity_(entity)
1068 { assert(entity.is()); }
1070 private:
1071 virtual ~ConstantGroupDescription() override {}
1073 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1074 { return css::uno::TypeClass_CONSTANTS; }
1076 virtual OUString SAL_CALL getName() override
1077 { return name_; }
1079 virtual
1080 css::uno::Sequence<
1081 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1082 SAL_CALL getConstants() override;
1084 OUString name_;
1085 rtl::Reference< unoidl::ConstantGroupEntity > entity_;
1088 css::uno::Sequence<
1089 css::uno::Reference< css::reflection::XConstantTypeDescription > >
1090 ConstantGroupDescription::getConstants() {
1091 assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1092 sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1093 css::uno::Sequence<
1094 css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1095 auto r = asNonConstRange(s);
1096 for (sal_Int32 i = 0; i != n; ++i) {
1097 r[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1099 return s;
1102 typedef cppu::ImplInheritanceHelper<
1103 PublishableDescription, css::reflection::XIndirectTypeDescription >
1104 TypedefDescription_Base;
1106 class TypedefDescription: public TypedefDescription_Base {
1107 public:
1108 TypedefDescription(
1109 rtl::Reference< cppuhelper::TypeManager > const & manager,
1110 OUString const & name,
1111 rtl::Reference< unoidl::TypedefEntity > const & entity):
1112 TypedefDescription_Base(entity->isPublished()), manager_(manager),
1113 name_(name), entity_(entity)
1114 { assert(manager.is()); assert(entity.is()); }
1116 private:
1117 virtual ~TypedefDescription() override {}
1119 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1120 { return css::uno::TypeClass_TYPEDEF; }
1122 virtual OUString SAL_CALL getName() override
1123 { return name_; }
1125 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1126 getReferencedType() override
1127 { return manager_->resolve(entity_->getType()); }
1129 rtl::Reference< cppuhelper::TypeManager > manager_;
1130 OUString name_;
1131 rtl::Reference< unoidl::TypedefEntity > entity_;
1134 class ConstructorParameter:
1135 public cppu::WeakImplHelper< css::reflection::XParameter >
1137 public:
1138 ConstructorParameter(
1139 rtl::Reference< cppuhelper::TypeManager > const & manager,
1140 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1141 const & parameter,
1142 sal_Int32 position):
1143 manager_(manager), parameter_(parameter), position_(position)
1144 { assert(manager.is()); }
1146 private:
1147 virtual ~ConstructorParameter() override {}
1149 virtual OUString SAL_CALL getName() override
1150 { return parameter_.name; }
1152 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1153 getType() override
1154 { return manager_->resolve(parameter_.type); }
1156 virtual sal_Bool SAL_CALL isIn() override
1157 { return true; }
1159 virtual sal_Bool SAL_CALL isOut() override
1160 { return false; }
1162 virtual sal_Int32 SAL_CALL getPosition() override
1163 { return position_; }
1165 virtual sal_Bool SAL_CALL isRestParameter() override
1166 { return parameter_.rest; }
1168 rtl::Reference< cppuhelper::TypeManager > manager_;
1169 unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter
1170 parameter_;
1171 sal_Int32 position_;
1174 class ConstructorDescription:
1175 public cppu::WeakImplHelper<
1176 css::reflection::XServiceConstructorDescription >
1178 public:
1179 ConstructorDescription(
1180 rtl::Reference< cppuhelper::TypeManager > const & manager,
1181 unoidl::SingleInterfaceBasedServiceEntity::Constructor const &
1182 constructor):
1183 manager_(manager), constructor_(constructor)
1184 { assert(manager.is()); }
1186 private:
1187 virtual ~ConstructorDescription() override {}
1189 virtual sal_Bool SAL_CALL isDefaultConstructor() override
1190 { return constructor_.defaultConstructor; }
1192 virtual OUString SAL_CALL getName() override
1193 { return constructor_.name; }
1195 virtual
1196 css::uno::Sequence<
1197 css::uno::Reference< css::reflection::XParameter > >
1198 SAL_CALL getParameters() override;
1200 virtual
1201 css::uno::Sequence<
1202 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1203 SAL_CALL getExceptions() override;
1205 rtl::Reference< cppuhelper::TypeManager > manager_;
1206 unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor_;
1209 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1210 ConstructorDescription::getParameters() {
1211 assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1212 sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1213 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1215 auto r = asNonConstRange(s);
1216 for (sal_Int32 i = 0; i != n; ++i) {
1217 r[i] = new ConstructorParameter(
1218 manager_, constructor_.parameters[i], i);
1220 return s;
1223 css::uno::Sequence<
1224 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1225 ConstructorDescription::getExceptions() {
1226 assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1227 sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1228 css::uno::Sequence<
1229 css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1230 auto r = asNonConstRange(s);
1231 for (sal_Int32 i = 0; i != n; ++i) {
1232 r[i].set(
1233 manager_->resolve(constructor_.exceptions[i]),
1234 css::uno::UNO_QUERY_THROW);
1236 return s;
1239 typedef cppu::ImplInheritanceHelper<
1240 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1241 SingleInterfaceBasedServiceDescription_Base;
1243 class SingleInterfaceBasedServiceDescription:
1244 public SingleInterfaceBasedServiceDescription_Base
1246 public:
1247 SingleInterfaceBasedServiceDescription(
1248 rtl::Reference< cppuhelper::TypeManager > const & manager,
1249 OUString const & name,
1250 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const &
1251 entity):
1252 SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1253 manager_(manager), name_(name), entity_(entity)
1254 { assert(manager.is()); assert(entity.is()); }
1256 private:
1257 virtual ~SingleInterfaceBasedServiceDescription() override {}
1259 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1260 { return css::uno::TypeClass_SERVICE; }
1262 virtual OUString SAL_CALL getName() override
1263 { return name_; }
1265 virtual
1266 css::uno::Sequence<
1267 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1268 SAL_CALL getMandatoryServices() override
1270 return css::uno::Sequence<
1271 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1274 virtual
1275 css::uno::Sequence<
1276 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1277 SAL_CALL getOptionalServices() override
1279 return css::uno::Sequence<
1280 css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1283 virtual
1284 css::uno::Sequence<
1285 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1286 SAL_CALL getMandatoryInterfaces() override
1288 return css::uno::Sequence<
1289 css::uno::Reference<
1290 css::reflection::XInterfaceTypeDescription > >();
1293 virtual
1294 css::uno::Sequence<
1295 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1296 SAL_CALL getOptionalInterfaces() override
1298 return css::uno::Sequence<
1299 css::uno::Reference<
1300 css::reflection::XInterfaceTypeDescription > >();
1303 virtual
1304 css::uno::Sequence<
1305 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1306 SAL_CALL getProperties() override
1308 return css::uno::Sequence<
1309 css::uno::Reference<
1310 css::reflection::XPropertyTypeDescription > >();
1313 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1314 { return true; }
1316 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1317 getInterface() override
1318 { return manager_->resolve(entity_->getBase()); }
1320 virtual
1321 css::uno::Sequence<
1322 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1323 SAL_CALL getConstructors() override;
1325 rtl::Reference< cppuhelper::TypeManager > manager_;
1326 OUString name_;
1327 rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > entity_;
1330 css::uno::Sequence<
1331 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1332 SingleInterfaceBasedServiceDescription::getConstructors()
1334 assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1335 sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1336 css::uno::Sequence<
1337 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1338 s(n);
1339 auto r = asNonConstRange(s);
1340 for (sal_Int32 i = 0; i != n; ++i) {
1341 r[i] = new ConstructorDescription(
1342 manager_, entity_->getConstructors()[i]);
1344 return s;
1347 class PropertyDescription:
1348 public cppu::WeakImplHelper< css::reflection::XPropertyTypeDescription >
1350 public:
1351 PropertyDescription(
1352 rtl::Reference< cppuhelper::TypeManager > const & manager,
1353 unoidl::AccumulationBasedServiceEntity::Property const & property):
1354 manager_(manager), property_(property)
1355 { assert(manager.is()); }
1357 private:
1358 virtual ~PropertyDescription() override {}
1360 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1361 { return css::uno::TypeClass_PROPERTY; }
1363 virtual OUString SAL_CALL getName() override
1364 { return property_.name; }
1366 virtual sal_Int16 SAL_CALL getPropertyFlags() override
1367 { return property_.attributes; }
1369 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1370 getPropertyTypeDescription() override
1371 { return manager_->resolve(property_.type); }
1373 rtl::Reference< cppuhelper::TypeManager > manager_;
1374 unoidl::AccumulationBasedServiceEntity::Property property_;
1377 typedef cppu::ImplInheritanceHelper<
1378 PublishableDescription, css::reflection::XServiceTypeDescription2 >
1379 AccumulationBasedServiceDescription_Base;
1381 class AccumulationBasedServiceDescription:
1382 public AccumulationBasedServiceDescription_Base
1384 public:
1385 AccumulationBasedServiceDescription(
1386 rtl::Reference< cppuhelper::TypeManager > const & manager,
1387 OUString const & name,
1388 rtl::Reference< unoidl::AccumulationBasedServiceEntity > const &
1389 entity):
1390 AccumulationBasedServiceDescription_Base(entity->isPublished()),
1391 manager_(manager), name_(name), entity_(entity)
1392 { assert(manager.is()); assert(entity.is()); }
1394 private:
1395 virtual ~AccumulationBasedServiceDescription() override {}
1397 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1398 { return css::uno::TypeClass_SERVICE; }
1400 virtual OUString SAL_CALL getName() override
1401 { return name_; }
1403 virtual
1404 css::uno::Sequence<
1405 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1406 SAL_CALL getMandatoryServices() override;
1408 virtual
1409 css::uno::Sequence<
1410 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1411 SAL_CALL getOptionalServices() override;
1413 virtual
1414 css::uno::Sequence<
1415 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1416 SAL_CALL getMandatoryInterfaces() override;
1418 virtual
1419 css::uno::Sequence<
1420 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1421 SAL_CALL getOptionalInterfaces() override;
1423 virtual
1424 css::uno::Sequence<
1425 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1426 SAL_CALL getProperties() override;
1428 virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1429 { return false; }
1431 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1432 getInterface() override
1433 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1435 virtual
1436 css::uno::Sequence<
1437 css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1438 SAL_CALL getConstructors() override
1440 return css::uno::Sequence<
1441 css::uno::Reference<
1442 css::reflection::XServiceConstructorDescription > >();
1445 rtl::Reference< cppuhelper::TypeManager > manager_;
1446 OUString name_;
1447 rtl::Reference< unoidl::AccumulationBasedServiceEntity > entity_;
1450 css::uno::Sequence<
1451 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1452 AccumulationBasedServiceDescription::getMandatoryServices()
1454 assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1455 sal_Int32 n = static_cast< sal_Int32 >(
1456 entity_->getDirectMandatoryBaseServices().size());
1457 css::uno::Sequence<
1458 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1459 auto r = asNonConstRange(s);
1460 for (sal_Int32 i = 0; i != n; ++i) {
1461 r[i].set(
1462 manager_->resolve(
1463 entity_->getDirectMandatoryBaseServices()[i].name),
1464 css::uno::UNO_QUERY_THROW);
1466 return s;
1469 css::uno::Sequence<
1470 css::uno::Reference< css::reflection::XServiceTypeDescription > >
1471 AccumulationBasedServiceDescription::getOptionalServices()
1473 assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1474 sal_Int32 n = static_cast< sal_Int32 >(
1475 entity_->getDirectOptionalBaseServices().size());
1476 css::uno::Sequence<
1477 css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1478 auto r = asNonConstRange(s);
1479 for (sal_Int32 i = 0; i != n; ++i) {
1480 r[i].set(
1481 manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1482 css::uno::UNO_QUERY_THROW);
1484 return s;
1487 css::uno::Sequence<
1488 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1489 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1491 assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1492 sal_Int32 n = static_cast< sal_Int32 >(
1493 entity_->getDirectMandatoryBaseInterfaces().size());
1494 css::uno::Sequence<
1495 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1497 auto r = asNonConstRange(s);
1498 for (sal_Int32 i = 0; i != n; ++i) {
1499 r[i].set(
1500 resolveTypedefs(
1501 manager_->find(
1502 entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1503 css::uno::UNO_QUERY_THROW);
1505 return s;
1508 css::uno::Sequence<
1509 css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1510 AccumulationBasedServiceDescription::getOptionalInterfaces()
1512 assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1513 sal_Int32 n = static_cast< sal_Int32 >(
1514 entity_->getDirectOptionalBaseInterfaces().size());
1515 css::uno::Sequence<
1516 css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1518 auto r = asNonConstRange(s);
1519 for (sal_Int32 i = 0; i != n; ++i) {
1520 r[i].set(
1521 resolveTypedefs(
1522 manager_->find(
1523 entity_->getDirectOptionalBaseInterfaces()[i].name)),
1524 css::uno::UNO_QUERY_THROW);
1526 return s;
1529 css::uno::Sequence<
1530 css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1531 AccumulationBasedServiceDescription::getProperties()
1533 assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1534 sal_Int32 n = static_cast< sal_Int32 >(
1535 entity_->getDirectProperties().size());
1536 css::uno::Sequence<
1537 css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1538 auto r = asNonConstRange(s);
1539 for (sal_Int32 i = 0; i != n; ++i) {
1540 r[i] = new PropertyDescription(
1541 manager_, entity_->getDirectProperties()[i]);
1543 return s;
1546 typedef cppu::ImplInheritanceHelper<
1547 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1548 InterfaceBasedSingletonDescription_Base;
1550 class InterfaceBasedSingletonDescription:
1551 public InterfaceBasedSingletonDescription_Base
1553 public:
1554 InterfaceBasedSingletonDescription(
1555 rtl::Reference< cppuhelper::TypeManager > const & manager,
1556 OUString const & name,
1557 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity):
1558 InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1559 manager_(manager), name_(name), entity_(entity)
1560 { assert(manager.is()); assert(entity.is()); }
1562 private:
1563 virtual ~InterfaceBasedSingletonDescription() override {}
1565 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1566 { return css::uno::TypeClass_SINGLETON; }
1568 virtual OUString SAL_CALL getName() override
1569 { return name_; }
1571 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1572 SAL_CALL getService() override
1574 return
1575 css::uno::Reference< css::reflection::XServiceTypeDescription >();
1578 virtual sal_Bool SAL_CALL isInterfaceBased() override
1579 { return true; }
1581 virtual css::uno::Reference< css::reflection::XTypeDescription >
1582 SAL_CALL getInterface() override
1583 { return manager_->resolve(entity_->getBase()); }
1585 rtl::Reference< cppuhelper::TypeManager > manager_;
1586 OUString name_;
1587 rtl::Reference< unoidl::InterfaceBasedSingletonEntity > entity_;
1590 typedef cppu::ImplInheritanceHelper<
1591 PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1592 ServiceBasedSingletonDescription_Base;
1594 class ServiceBasedSingletonDescription:
1595 public ServiceBasedSingletonDescription_Base
1597 public:
1598 ServiceBasedSingletonDescription(
1599 rtl::Reference< cppuhelper::TypeManager > const & manager,
1600 OUString const & name,
1601 rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity):
1602 ServiceBasedSingletonDescription_Base(entity->isPublished()),
1603 manager_(manager), name_(name), entity_(entity)
1604 { assert(manager.is()); assert(entity.is()); }
1606 private:
1607 virtual ~ServiceBasedSingletonDescription() override {}
1609 virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1610 { return css::uno::TypeClass_SINGLETON; }
1612 virtual OUString SAL_CALL getName() override
1613 { return name_; }
1615 virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1616 SAL_CALL getService() override
1618 return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1619 manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1622 virtual sal_Bool SAL_CALL isInterfaceBased() override
1623 { return false; }
1625 virtual css::uno::Reference< css::reflection::XTypeDescription >
1626 SAL_CALL getInterface() override
1627 { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1629 rtl::Reference< cppuhelper::TypeManager > manager_;
1630 OUString name_;
1631 rtl::Reference< unoidl::ServiceBasedSingletonEntity > entity_;
1634 class Enumeration:
1635 public cppu::WeakImplHelper< css::reflection::XTypeDescriptionEnumeration >
1637 public:
1638 Enumeration(
1639 rtl::Reference< cppuhelper::TypeManager > const & manager,
1640 OUString const & prefix,
1641 rtl::Reference< unoidl::MapCursor > const & cursor,
1642 css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1643 manager_(manager), types_(types), deep_(deep)
1645 assert(manager.is());
1646 positions_.push(Position(prefix, cursor));
1647 findNextMatch();
1650 private:
1651 virtual ~Enumeration() override {}
1653 virtual sal_Bool SAL_CALL hasMoreElements() override
1654 { return !positions_.empty(); }
1656 virtual css::uno::Any SAL_CALL nextElement() override
1657 { return css::uno::makeAny(nextTypeDescription()); }
1659 virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1660 nextTypeDescription() override;
1662 bool matches(css::uno::TypeClass tc) const;
1664 void findNextMatch();
1666 struct Position {
1667 Position(
1668 OUString const & thePrefix,
1669 rtl::Reference< unoidl::MapCursor > const & theCursor):
1670 prefix(thePrefix), cursor(theCursor)
1671 { assert(theCursor.is()); }
1673 Position(
1674 OUString const & thePrefix,
1675 rtl::Reference< unoidl::ConstantGroupEntity > const &
1676 theConstantGroup):
1677 prefix(thePrefix), constantGroup(theConstantGroup),
1678 constantGroupIndex(constantGroup->getMembers().begin())
1679 { assert(theConstantGroup.is()); }
1681 Position(Position const & other):
1682 prefix(other.prefix), cursor(other.cursor),
1683 constantGroup(other.constantGroup)
1685 if (constantGroup.is()) {
1686 constantGroupIndex = other.constantGroupIndex;
1690 OUString prefix;
1691 rtl::Reference< unoidl::MapCursor > cursor;
1692 rtl::Reference< unoidl::ConstantGroupEntity > constantGroup;
1693 std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1694 constantGroupIndex;
1697 rtl::Reference< cppuhelper::TypeManager > manager_;
1698 css::uno::Sequence< css::uno::TypeClass > types_;
1699 bool deep_;
1701 std::mutex mutex_;
1702 std::stack< Position, std::vector<Position> > positions_;
1703 OUString current_;
1706 css::uno::Reference< css::reflection::XTypeDescription >
1707 Enumeration::nextTypeDescription()
1709 OUString name;
1711 std::scoped_lock g(mutex_);
1712 if (positions_.empty()) {
1713 throw css::container::NoSuchElementException(
1714 "exhausted XTypeDescriptionEnumeration",
1715 static_cast< cppu::OWeakObject * >(this));
1717 name = current_;
1718 findNextMatch();
1720 return manager_->resolve(name);
1723 bool Enumeration::matches(css::uno::TypeClass tc) const {
1724 if (!types_.hasElements()) {
1725 return true;
1727 for (const auto & i : types_) {
1728 if (i == tc) {
1729 return true;
1732 return false;
1735 void Enumeration::findNextMatch() {
1736 try {
1737 for (;;) {
1738 assert(!positions_.empty());
1739 OUString name;
1740 if (positions_.top().cursor.is()) { // root or module
1741 rtl::Reference< unoidl::Entity > ent(
1742 positions_.top().cursor->getNext(&name));
1743 if (!ent.is()) {
1744 positions_.pop();
1745 if (positions_.empty()) {
1746 break;
1748 continue;
1750 name = positions_.top().prefix + name;
1751 css::uno::TypeClass tc;
1752 switch (ent->getSort()) {
1753 case unoidl::Entity::SORT_MODULE:
1754 tc = css::uno::TypeClass_MODULE;
1755 if (deep_) {
1756 positions_.push(
1757 Position(
1758 makePrefix(name),
1759 static_cast< unoidl::ModuleEntity * >(
1760 ent.get())->createCursor()));
1762 break;
1763 case unoidl::Entity::SORT_ENUM_TYPE:
1764 tc = css::uno::TypeClass_ENUM;
1765 break;
1766 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
1767 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
1768 tc = css::uno::TypeClass_STRUCT;
1769 break;
1770 case unoidl::Entity::SORT_EXCEPTION_TYPE:
1771 tc = css::uno::TypeClass_EXCEPTION;
1772 break;
1773 case unoidl::Entity::SORT_INTERFACE_TYPE:
1774 tc = css::uno::TypeClass_INTERFACE;
1775 break;
1776 case unoidl::Entity::SORT_TYPEDEF:
1777 tc = css::uno::TypeClass_TYPEDEF;
1778 break;
1779 case unoidl::Entity::SORT_CONSTANT_GROUP:
1780 tc = css::uno::TypeClass_CONSTANTS;
1781 if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1782 positions_.push(
1783 Position(
1784 makePrefix(name),
1785 static_cast< unoidl::ConstantGroupEntity * >(
1786 ent.get())));
1788 break;
1789 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
1790 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
1791 tc = css::uno::TypeClass_SERVICE;
1792 break;
1793 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
1794 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
1795 tc = css::uno::TypeClass_SINGLETON;
1796 break;
1797 default:
1798 for (;;) { std::abort(); } // this cannot happen
1800 if (matches(tc)) {
1801 current_ = name;
1802 break;
1804 } else { // constant group
1805 if (positions_.top().constantGroupIndex
1806 == positions_.top().constantGroup->getMembers().end())
1808 positions_.pop();
1809 if (positions_.empty()) {
1810 break;
1812 continue;
1814 current_ = positions_.top().prefix
1815 + positions_.top().constantGroupIndex++->name;
1816 break;
1819 } catch (unoidl::FileFormatException & e) {
1820 throw css::uno::DeploymentException(
1821 e.getUri() + ": " + e.getDetail(),
1822 static_cast< cppu::OWeakObject * >(this));
1828 cppuhelper::TypeManager::TypeManager():
1829 TypeManager_Base(m_aMutex),
1830 manager_(new unoidl::Manager)
1833 css::uno::Any cppuhelper::TypeManager::find(OUString const & name) {
1834 //TODO: caching? (here or in unoidl::Manager?)
1835 static constexpr std::pair<std::u16string_view, css::uno::TypeClass> const simple[] = {
1836 { u"void", css::uno::TypeClass_VOID },
1837 { u"boolean", css::uno::TypeClass_BOOLEAN },
1838 { u"byte", css::uno::TypeClass_BYTE },
1839 { u"short", css::uno::TypeClass_SHORT },
1840 { u"unsigned short", css::uno::TypeClass_UNSIGNED_SHORT },
1841 { u"long", css::uno::TypeClass_LONG },
1842 { u"unsigned long", css::uno::TypeClass_UNSIGNED_LONG },
1843 { u"hyper", css::uno::TypeClass_HYPER },
1844 { u"unsigned hyper", css::uno::TypeClass_UNSIGNED_HYPER },
1845 { u"float", css::uno::TypeClass_FLOAT },
1846 { u"double", css::uno::TypeClass_DOUBLE },
1847 { u"char", css::uno::TypeClass_CHAR },
1848 { u"string", css::uno::TypeClass_STRING },
1849 { u"type", css::uno::TypeClass_TYPE },
1850 { u"any", css::uno::TypeClass_ANY } };
1851 for (const auto& [ rName, rTypeClass ] : simple) {
1852 if (name == rName) {
1853 return css::uno::makeAny<
1854 css::uno::Reference< css::reflection::XTypeDescription > >(
1855 new SimpleTypeDescription(rTypeClass, name));
1858 if (name.startsWith("[]")) {
1859 return getSequenceType(name);
1861 sal_Int32 i = name.indexOf('<');
1862 if (i != -1) {
1863 return getInstantiatedStruct(name, i);
1865 i = name.indexOf("::");
1866 if (i != -1) {
1867 return getInterfaceMember(name, i);
1869 rtl::Reference< unoidl::Entity > ent(findEntity(name));
1870 if (ent.is()) {
1871 return getNamed(name, ent);
1873 i = name.lastIndexOf('.');
1874 if (i != -1) {
1875 OUString parent(name.copy(0, i));
1876 ent = findEntity(parent);
1877 if (ent.is()) {
1878 switch (ent->getSort()) {
1879 case unoidl::Entity::SORT_ENUM_TYPE:
1880 return getEnumMember(
1881 static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1882 name.copy(i + 1));
1883 case unoidl::Entity::SORT_CONSTANT_GROUP:
1884 return getConstant(
1885 parent,
1886 static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1887 name.copy(i + 1));
1888 default:
1889 break;
1893 return css::uno::Any();
1896 css::uno::Reference< css::reflection::XTypeDescription >
1897 cppuhelper::TypeManager::resolve(OUString const & name) {
1898 css::uno::Reference< css::reflection::XTypeDescription > desc(
1899 find(name), css::uno::UNO_QUERY);
1900 if (!desc.is()) {
1901 throw css::uno::DeploymentException(
1902 "cannot resolve type \"" + name + "\"",
1903 static_cast< cppu::OWeakObject * >(this));
1905 return desc;
1908 cppuhelper::TypeManager::~TypeManager() noexcept {}
1910 void cppuhelper::TypeManager::disposing() {} //TODO
1912 OUString cppuhelper::TypeManager::getImplementationName()
1914 return
1915 "com.sun.star.comp.cppuhelper.bootstrap.TypeManager";
1918 sal_Bool cppuhelper::TypeManager::supportsService(
1919 OUString const & ServiceName)
1921 return cppu::supportsService(this, ServiceName);
1924 css::uno::Sequence< OUString >
1925 cppuhelper::TypeManager::getSupportedServiceNames()
1927 return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1930 css::uno::Any cppuhelper::TypeManager::getByHierarchicalName(
1931 OUString const & aName)
1933 css::uno::Any desc(find(aName));
1934 if (!desc.hasValue()) {
1935 throw css::container::NoSuchElementException(
1936 aName, static_cast< cppu::OWeakObject * >(this));
1938 return desc;
1941 sal_Bool cppuhelper::TypeManager::hasByHierarchicalName(
1942 OUString const & aName)
1944 return find(aName).hasValue();
1947 css::uno::Type cppuhelper::TypeManager::getElementType()
1949 return cppu::UnoType< OUString >::get();
1952 sal_Bool cppuhelper::TypeManager::hasElements()
1954 throw css::uno::RuntimeException(
1955 "TypeManager hasElements: method not supported",
1956 static_cast< cppu::OWeakObject * >(this));
1959 css::uno::Reference< css::container::XEnumeration >
1960 cppuhelper::TypeManager::createEnumeration()
1962 throw css::uno::RuntimeException(
1963 "TypeManager createEnumeration: method not supported",
1964 static_cast< cppu::OWeakObject * >(this));
1967 sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &)
1969 throw css::uno::RuntimeException(
1970 "TypeManager has: method not supported",
1971 static_cast< cppu::OWeakObject * >(this));
1974 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
1976 OUString uri;
1977 if (!(aElement >>= uri)) {
1978 throw css::lang::IllegalArgumentException(
1979 ("css.uno.theTypeDescriptionManager.insert expects a string URI"
1980 " argument"),
1981 static_cast< cppu::OWeakObject * >(this), 0);
1983 //TODO: check for ElementExistException
1984 //TODO: check for consistency with existing data
1985 readRdbFile(uri, false);
1988 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
1990 OUString uri;
1991 if (!(aElement >>= uri)) {
1992 throw css::lang::IllegalArgumentException(
1993 ("css.uno.theTypeDescriptionManager.remove expects a string URI"
1994 " argument"),
1995 static_cast< cppu::OWeakObject * >(this), 0);
1997 //TODO: remove requests are silently ignored for now
2000 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
2001 cppuhelper::TypeManager::createTypeDescriptionEnumeration(
2002 OUString const & moduleName,
2003 css::uno::Sequence< css::uno::TypeClass > const & types,
2004 css::reflection::TypeDescriptionSearchDepth depth)
2006 rtl::Reference< unoidl::MapCursor > cursor;
2007 try {
2008 cursor = manager_->createCursor(moduleName);
2009 } catch (unoidl::FileFormatException & e) {
2010 throw css::uno::DeploymentException(
2011 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2012 + e.getDetail()),
2013 static_cast< cppu::OWeakObject * >(this));
2015 if (!cursor.is()) {
2016 //TODO: css::reflection::InvalidTypeNameException if moduleName names a
2017 // non-module
2018 throw css::reflection::NoSuchTypeNameException(
2019 moduleName, static_cast< cppu::OWeakObject * >(this));
2021 return new Enumeration(
2022 this, makePrefix(moduleName), cursor, types,
2023 depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2026 void cppuhelper::TypeManager::init(OUString const & rdbUris) {
2027 for (sal_Int32 i = 0; i != -1;) {
2028 OUString uri(rdbUris.getToken(0, ' ', i));
2029 if (uri.isEmpty()) {
2030 continue;
2032 bool optional;
2033 bool directory;
2034 cppu::decodeRdbUri(&uri, &optional, &directory);
2035 if (directory) {
2036 readRdbDirectory(uri, optional);
2037 } else {
2038 readRdbFile(uri, optional);
2043 void cppuhelper::TypeManager::readRdbDirectory(
2044 OUString const & uri, bool optional)
2046 osl::Directory dir(uri);
2047 switch (dir.open()) {
2048 case osl::FileBase::E_None:
2049 break;
2050 case osl::FileBase::E_NOENT:
2051 if (optional) {
2052 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2053 return;
2055 [[fallthrough]];
2056 default:
2057 throw css::uno::DeploymentException(
2058 "Cannot open directory " + uri,
2059 static_cast< cppu::OWeakObject * >(this));
2061 for (;;) {
2062 OUString url;
2063 if (!cppu::nextDirectoryItem(dir, &url)) {
2064 break;
2066 readRdbFile(url, false);
2070 void cppuhelper::TypeManager::readRdbFile(
2071 OUString const & uri, bool optional)
2073 try {
2074 manager_->addProvider(uri);
2075 } catch (unoidl::NoSuchFileException &) {
2076 if (!optional) {
2077 throw css::uno::DeploymentException(
2078 uri + ": no such file",
2079 static_cast< cppu::OWeakObject * >(this));
2081 SAL_INFO("cppuhelper", "Ignored optional " << uri);
2082 } catch (unoidl::FileFormatException & e) {
2083 throw css::uno::DeploymentException(
2084 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2085 + e.getDetail()),
2086 static_cast< cppu::OWeakObject * >(this));
2090 css::uno::Any cppuhelper::TypeManager::getSequenceType(
2091 OUString const & name)
2093 assert(name.startsWith("[]"));
2094 return css::uno::makeAny<
2095 css::uno::Reference< css::reflection::XTypeDescription > >(
2096 new SequenceTypeDescription(
2097 this, name, name.copy(std::strlen("[]"))));
2100 css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct(
2101 OUString const & name, sal_Int32 separator)
2103 assert(name.indexOf('<') == separator && separator != -1);
2104 rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2105 if (!ent.is()
2106 || (ent->getSort()
2107 != unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE))
2109 return css::uno::Any();
2111 rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > ent2(
2112 static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2113 ent.get()));
2114 std::vector< OUString > args;
2115 sal_Int32 i = separator;
2116 do {
2117 ++i; // skip '<' or ','
2118 sal_Int32 j = i;
2119 for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2120 sal_Unicode c = name[j];
2121 if (c == ',') {
2122 if (level == 0) {
2123 break;
2125 } else if (c == '<') {
2126 ++level;
2127 } else if (c == '>') {
2128 if (level == 0) {
2129 break;
2131 --level;
2134 if (j != name.getLength()) {
2135 args.push_back(name.copy(i, j - i));
2137 i = j;
2138 } while (i != name.getLength() && name[i] != '>');
2139 if (i != name.getLength() - 1 || name[i] != '>'
2140 || args.size() != ent2->getTypeParameters().size())
2142 return css::uno::Any();
2144 return css::uno::makeAny<
2145 css::uno::Reference< css::reflection::XTypeDescription > >(
2146 new InstantiatedPolymorphicStructTypeDescription(
2147 this, name, ent2, std::move(args)));
2150 css::uno::Any cppuhelper::TypeManager::getInterfaceMember(
2151 OUString const & name, sal_Int32 separator)
2153 assert(name.indexOf("::") == separator && separator != -1);
2154 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2155 resolveTypedefs(find(name.copy(0, separator))), css::uno::UNO_QUERY);
2156 if (!ifc.is()) {
2157 return css::uno::Any();
2159 OUString member(name.copy(separator + std::strlen("::")));
2160 const css::uno::Sequence<
2161 css::uno::Reference<
2162 css::reflection::XInterfaceMemberTypeDescription > > mems(
2163 ifc->getMembers());
2164 for (const auto & m : mems) {
2165 if (m->getMemberName() == member) {
2166 return css::uno::makeAny<
2167 css::uno::Reference< css::reflection::XTypeDescription > >(m);
2170 return css::uno::Any();
2173 css::uno::Any cppuhelper::TypeManager::getNamed(
2174 OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2176 assert(entity.is());
2177 switch (entity->getSort()) {
2178 case unoidl::Entity::SORT_MODULE:
2179 return css::uno::makeAny<
2180 css::uno::Reference< css::reflection::XTypeDescription > >(
2181 new ModuleDescription(
2182 this, name,
2183 static_cast< unoidl::ModuleEntity * >(entity.get())));
2184 case unoidl::Entity::SORT_ENUM_TYPE:
2185 return css::uno::makeAny<
2186 css::uno::Reference< css::reflection::XTypeDescription > >(
2187 new EnumTypeDescription(
2188 name,
2189 static_cast< unoidl::EnumTypeEntity * >(entity.get())));
2190 case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE:
2191 return css::uno::makeAny<
2192 css::uno::Reference< css::reflection::XTypeDescription > >(
2193 new PlainStructTypeDescription(
2194 this, name,
2195 static_cast< unoidl::PlainStructTypeEntity * >(
2196 entity.get())));
2197 case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE:
2198 return css::uno::makeAny<
2199 css::uno::Reference< css::reflection::XTypeDescription > >(
2200 new PolymorphicStructTypeTemplateDescription(
2201 this, name,
2202 static_cast<
2203 unoidl::PolymorphicStructTypeTemplateEntity * >(
2204 entity.get())));
2205 case unoidl::Entity::SORT_EXCEPTION_TYPE:
2206 return css::uno::makeAny<
2207 css::uno::Reference< css::reflection::XTypeDescription > >(
2208 new ExceptionTypeDescription(
2209 this, name,
2210 static_cast< unoidl::ExceptionTypeEntity * >(
2211 entity.get())));
2212 case unoidl::Entity::SORT_INTERFACE_TYPE:
2213 return css::uno::makeAny<
2214 css::uno::Reference< css::reflection::XTypeDescription > >(
2215 new InterfaceTypeDescription(
2216 this, name,
2217 static_cast< unoidl::InterfaceTypeEntity * >(
2218 entity.get())));
2219 case unoidl::Entity::SORT_TYPEDEF:
2220 return css::uno::makeAny<
2221 css::uno::Reference< css::reflection::XTypeDescription > >(
2222 new TypedefDescription(
2223 this, name,
2224 static_cast< unoidl::TypedefEntity * >(entity.get())));
2225 case unoidl::Entity::SORT_CONSTANT_GROUP:
2226 return css::uno::makeAny<
2227 css::uno::Reference< css::reflection::XTypeDescription > >(
2228 new ConstantGroupDescription(
2229 name,
2230 static_cast< unoidl::ConstantGroupEntity * >(
2231 entity.get())));
2232 case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE:
2233 return css::uno::makeAny<
2234 css::uno::Reference< css::reflection::XTypeDescription > >(
2235 new SingleInterfaceBasedServiceDescription(
2236 this, name,
2237 static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2238 entity.get())));
2239 case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE:
2240 return css::uno::makeAny<
2241 css::uno::Reference< css::reflection::XTypeDescription > >(
2242 new AccumulationBasedServiceDescription(
2243 this, name,
2244 static_cast< unoidl::AccumulationBasedServiceEntity * >(
2245 entity.get())));
2246 case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON:
2247 return css::uno::makeAny<
2248 css::uno::Reference< css::reflection::XTypeDescription > >(
2249 new InterfaceBasedSingletonDescription(
2250 this, name,
2251 static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2252 entity.get())));
2253 case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON:
2254 return css::uno::makeAny<
2255 css::uno::Reference< css::reflection::XTypeDescription > >(
2256 new ServiceBasedSingletonDescription(
2257 this, name,
2258 static_cast< unoidl::ServiceBasedSingletonEntity * >(
2259 entity.get())));
2260 default:
2261 for (;;) { std::abort(); } // this cannot happen
2265 css::uno::Any cppuhelper::TypeManager::getEnumMember(
2266 rtl::Reference< unoidl::EnumTypeEntity > const & entity,
2267 OUString const & member)
2269 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2270 [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
2271 if (i != entity->getMembers().end())
2272 return css::uno::makeAny(i->value);
2273 return css::uno::Any();
2276 css::uno::Any cppuhelper::TypeManager::getConstant(
2277 OUString const & constantGroupName,
2278 rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
2279 OUString const & member)
2281 auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2282 [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
2283 if (i != entity->getMembers().end())
2284 return css::uno::makeAny<
2285 css::uno::Reference< css::reflection::XTypeDescription > >(
2286 new ConstantDescription(constantGroupName, *i));
2287 return css::uno::Any();
2290 rtl::Reference< unoidl::Entity > cppuhelper::TypeManager::findEntity(
2291 OUString const & name)
2293 try {
2294 return manager_->findEntity(name);
2295 } catch (unoidl::FileFormatException & e) {
2296 throw css::uno::DeploymentException(
2297 ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2298 + e.getDetail()),
2299 static_cast< cppu::OWeakObject * >(this));
2303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */