LibreOffice Module cppuhelper (master)  1
typemanager.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <sal/config.h>
11 
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 <vector>
21 
22 #include <com/sun/star/container/NoSuchElementException.hpp>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
24 #include <com/sun/star/reflection/NoSuchTypeNameException.hpp>
25 #include <com/sun/star/reflection/TypeDescriptionSearchDepth.hpp>
26 #include <com/sun/star/reflection/XConstantTypeDescription.hpp>
27 #include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
28 #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
29 #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
30 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
31 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
32 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
33 #include <com/sun/star/reflection/XModuleTypeDescription.hpp>
34 #include <com/sun/star/reflection/XPublished.hpp>
35 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
36 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
37 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
38 #include <com/sun/star/reflection/XTypeDescription.hpp>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/uno/DeploymentException.hpp>
41 #include <com/sun/star/uno/Reference.hxx>
42 #include <com/sun/star/uno/RuntimeException.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/uno/Type.hxx>
45 #include <com/sun/star/uno/TypeClass.hpp>
46 #include <cppu/unotype.hxx>
47 #include <cppuhelper/implbase.hxx>
49 #include <osl/file.hxx>
50 #include <osl/mutex.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>
56 
57 #include <unoidl/unoidl.hxx>
58 
59 #include "paths.hxx"
60 #include "typemanager.hxx"
61 
62 namespace {
63 
64 OUString makePrefix(OUString const & name) {
65  return name.isEmpty() ? name : name + ".";
66 }
67 
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;
74  }
75  t <<= ind->getReferencedType();
76  }
77 }
78 
79 class SimpleTypeDescription:
80  public cppu::WeakImplHelper< css::reflection::XTypeDescription >
81 {
82 public:
83  SimpleTypeDescription(
84  css::uno::TypeClass typeClass, OUString const & name):
85  typeClass_(typeClass), name_(name)
86  {}
87 
88 private:
89  virtual ~SimpleTypeDescription() override {}
90 
91  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
92  { return typeClass_; }
93 
94  virtual OUString SAL_CALL getName() override
95  { return name_; }
96 
97  css::uno::TypeClass typeClass_;
98  OUString name_;
99 };
100 
101 class SequenceTypeDescription:
102  public cppu::WeakImplHelper< css::reflection::XIndirectTypeDescription >
103 {
104 public:
105  SequenceTypeDescription(
107  OUString const & name, OUString const & componentType):
108  manager_(manager), name_(name), componentType_(componentType)
109  { assert(manager.is()); }
110 
111 private:
112  virtual ~SequenceTypeDescription() override {}
113 
114  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
115  { return css::uno::TypeClass_SEQUENCE; }
116 
117  virtual OUString SAL_CALL getName() override
118  { return name_; }
119 
120  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
121  getReferencedType() override
122  { return manager_->resolve(componentType_); }
123 
125  OUString name_;
126  OUString componentType_;
127 };
128 
129 class PublishableDescription:
130  public cppu::WeakImplHelper< css::reflection::XPublished >
131 {
132 protected:
133  explicit PublishableDescription(bool published): published_(published) {}
134 
135  virtual ~PublishableDescription() override {}
136 
137 private:
138  virtual sal_Bool SAL_CALL isPublished() override
139  { return published_; }
140 
141  bool published_;
142 };
143 
144 class ModuleDescription:
145  public cppu::WeakImplHelper< css::reflection::XModuleTypeDescription >
146 {
147 public:
148  ModuleDescription(
150  OUString const & name,
152  manager_(manager), name_(name), entity_(entity)
153  { assert(manager.is()); assert(entity.is()); }
154 
155 private:
156  virtual ~ModuleDescription() override {}
157 
158  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
159  { return css::uno::TypeClass_MODULE; }
160 
161  virtual OUString SAL_CALL getName() override
162  { return name_; }
163 
164  virtual
165  css::uno::Sequence<
166  css::uno::Reference< css::reflection::XTypeDescription > >
167  SAL_CALL getMembers() override;
168 
170  OUString name_;
172 };
173 
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  for (sal_Int32 i = 0; i != n; ++i) {
183  s[i] = manager_->resolve(makePrefix(name_) + names[i]);
184  }
185  return s;
186  } catch (unoidl::FileFormatException & e) {
187  throw css::uno::DeploymentException(
188  e.getUri() + ": " + e.getDetail(),
189  static_cast< cppu::OWeakObject * >(this));
190  }
191 }
192 
193 typedef cppu::ImplInheritanceHelper<
194  PublishableDescription, css::reflection::XEnumTypeDescription >
195 EnumTypeDescription_Base;
196 
197 class EnumTypeDescription: public EnumTypeDescription_Base {
198 public:
199  EnumTypeDescription(
200  OUString const & name,
202  EnumTypeDescription_Base(entity->isPublished()), name_(name),
203  entity_(entity)
204  { assert(entity.is()); }
205 
206 private:
207  virtual ~EnumTypeDescription() override {}
208 
209  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
210  { return css::uno::TypeClass_ENUM; }
211 
212  virtual OUString SAL_CALL getName() override
213  { return name_; }
214 
215  virtual sal_Int32 SAL_CALL getDefaultEnumValue() override
216  { return entity_->getMembers()[0].value; }
217 
218  virtual css::uno::Sequence< OUString > SAL_CALL getEnumNames() override;
219 
220  virtual css::uno::Sequence< sal_Int32 > SAL_CALL getEnumValues() override;
221 
222  OUString name_;
224 };
225 
226 css::uno::Sequence< OUString > EnumTypeDescription::getEnumNames()
227 {
228  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
229  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
230  css::uno::Sequence< OUString > s(n);
231  for (sal_Int32 i = 0; i != n; ++i) {
232  s[i] = entity_->getMembers()[i].name;
233  }
234  return s;
235 }
236 
237 css::uno::Sequence< sal_Int32 > EnumTypeDescription::getEnumValues()
238 {
239  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
240  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
241  css::uno::Sequence< sal_Int32 > s(n);
242  for (sal_Int32 i = 0; i != n; ++i) {
243  s[i] = entity_->getMembers()[i].value;
244  }
245  return s;
246 }
247 
248 typedef cppu::ImplInheritanceHelper<
249  PublishableDescription, css::reflection::XStructTypeDescription >
250 PlainStructTypeDescription_Base;
251 
252 class PlainStructTypeDescription: public PlainStructTypeDescription_Base {
253 public:
254  PlainStructTypeDescription(
256  OUString const & name,
258  PlainStructTypeDescription_Base(entity->isPublished()),
259  manager_(manager), name_(name), entity_(entity)
260  { assert(manager.is()); assert(entity.is()); }
261 
262 private:
263  virtual ~PlainStructTypeDescription() override {}
264 
265  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
266  { return css::uno::TypeClass_STRUCT; }
267 
268  virtual OUString SAL_CALL getName() override
269  { return name_; }
270 
271  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
272  getBaseType() override {
273  return entity_->getDirectBase().isEmpty()
274  ? css::uno::Reference< css::reflection::XTypeDescription >()
275  : manager_->resolve(entity_->getDirectBase());
276  }
277 
278  virtual
279  css::uno::Sequence<
280  css::uno::Reference< css::reflection::XTypeDescription > >
281  SAL_CALL getMemberTypes() override;
282 
283  virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
284 
285  virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
286  { return css::uno::Sequence< OUString >(); }
287 
288  virtual
289  css::uno::Sequence<
290  css::uno::Reference< css::reflection::XTypeDescription > >
291  SAL_CALL getTypeArguments() override {
292  return css::uno::Sequence<
293  css::uno::Reference< css::reflection::XTypeDescription > >();
294  }
295 
297  OUString name_;
299 };
300 
301 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
302 PlainStructTypeDescription::getMemberTypes()
303 {
304  assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
305  sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
306  css::uno::Sequence<
307  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
308  for (sal_Int32 i = 0; i != n; ++i) {
309  s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
310  }
311  return s;
312 }
313 
314 css::uno::Sequence< OUString > PlainStructTypeDescription::getMemberNames()
315 {
316  assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
317  sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
318  css::uno::Sequence< OUString > s(n);
319  for (sal_Int32 i = 0; i != n; ++i) {
320  s[i] = entity_->getDirectMembers()[i].name;
321  }
322  return s;
323 }
324 
325 class ParameterizedMemberTypeDescription:
326  public cppu::WeakImplHelper< css::reflection::XTypeDescription >
327 {
328 public:
329  explicit ParameterizedMemberTypeDescription(
330  OUString const & typeParameterName):
331  typeParameterName_(typeParameterName)
332  {}
333 
334 private:
335  virtual ~ParameterizedMemberTypeDescription() override {}
336 
337  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
338  { return css::uno::TypeClass_UNKNOWN; }
339 
340  virtual OUString SAL_CALL getName() override
341  { return typeParameterName_; }
342 
343  OUString typeParameterName_;
344 };
345 
346 typedef cppu::ImplInheritanceHelper<
347  PublishableDescription, css::reflection::XStructTypeDescription >
348 PolymorphicStructTypeTemplateDescription_Base;
349 
350 class PolymorphicStructTypeTemplateDescription:
351  public PolymorphicStructTypeTemplateDescription_Base
352 {
353 public:
354  PolymorphicStructTypeTemplateDescription(
356  OUString const & name,
358  entity):
359  PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()),
360  manager_(manager), name_(name), entity_(entity)
361  { assert(manager.is()); assert(entity.is()); }
362 
363 private:
364  virtual ~PolymorphicStructTypeTemplateDescription() override {}
365 
366  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
367  { return css::uno::TypeClass_STRUCT; }
368 
369  virtual OUString SAL_CALL getName() override
370  { return name_; }
371 
372  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
373  getBaseType() override
374  { return css::uno::Reference< css::reflection::XTypeDescription >(); }
375 
376  virtual
377  css::uno::Sequence<
378  css::uno::Reference< css::reflection::XTypeDescription > >
379  SAL_CALL getMemberTypes() override;
380 
381  virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
382 
383  virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override;
384 
385  virtual
386  css::uno::Sequence<
387  css::uno::Reference< css::reflection::XTypeDescription > >
388  SAL_CALL getTypeArguments() override {
389  return css::uno::Sequence<
390  css::uno::Reference< css::reflection::XTypeDescription > >();
391  }
392 
394  OUString name_;
396 };
397 
398 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
399 PolymorphicStructTypeTemplateDescription::getMemberTypes()
400 {
401  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
402  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
403  css::uno::Sequence<
404  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
405  for (sal_Int32 i = 0; i != n; ++i) {
406  s[i] = entity_->getMembers()[i].parameterized
407  ? new ParameterizedMemberTypeDescription(
408  entity_->getMembers()[i].type)
409  : manager_->resolve(entity_->getMembers()[i].type);
410  }
411  return s;
412 }
413 
414 css::uno::Sequence< OUString >
415 PolymorphicStructTypeTemplateDescription::getMemberNames()
416 {
417  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
418  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
419  css::uno::Sequence< OUString > s(n);
420  for (sal_Int32 i = 0; i != n; ++i) {
421  s[i] = entity_->getMembers()[i].name;
422  }
423  return s;
424 }
425 
426 css::uno::Sequence< OUString >
427 PolymorphicStructTypeTemplateDescription::getTypeParameters()
428 {
429  assert(entity_->getTypeParameters().size() <= SAL_MAX_INT32);
430  sal_Int32 n = static_cast< sal_Int32 >(entity_->getTypeParameters().size());
431  css::uno::Sequence< OUString > s(n);
432  for (sal_Int32 i = 0; i != n; ++i) {
433  s[i] = entity_->getTypeParameters()[i];
434  }
435  return s;
436 }
437 
438 class InstantiatedPolymorphicStructTypeDescription:
439  public cppu::WeakImplHelper< css::reflection::XStructTypeDescription >
440 {
441 public:
442  InstantiatedPolymorphicStructTypeDescription(
444  OUString const & name,
446  entity,
447  std::vector< OUString > const & arguments):
448  manager_(manager), name_(name), entity_(entity), arguments_(arguments)
449  {
450  assert(manager.is());
451  assert(entity.is());
452  assert(arguments.size() == entity->getTypeParameters().size());
453  }
454 
455 private:
456  virtual ~InstantiatedPolymorphicStructTypeDescription() override {}
457 
458  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
459  { return css::uno::TypeClass_STRUCT; }
460 
461  virtual OUString SAL_CALL getName() override
462  { return name_; }
463 
464  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
465  getBaseType() override
466  { return css::uno::Reference< css::reflection::XTypeDescription >(); }
467 
468  virtual
469  css::uno::Sequence<
470  css::uno::Reference< css::reflection::XTypeDescription > >
471  SAL_CALL getMemberTypes() override;
472 
473  virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
474 
475  virtual css::uno::Sequence< OUString > SAL_CALL getTypeParameters() override
476  { return css::uno::Sequence< OUString >(); }
477 
478  virtual
479  css::uno::Sequence<
480  css::uno::Reference< css::reflection::XTypeDescription > >
481  SAL_CALL getTypeArguments() override;
482 
484  OUString name_;
486  std::vector< OUString > arguments_;
487 };
488 
489 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
490 InstantiatedPolymorphicStructTypeDescription::getMemberTypes()
491 {
492  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
493  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
494  css::uno::Sequence<
495  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
496  for (sal_Int32 i = 0; i != n; ++i) {
497  OUString type(entity_->getMembers()[i].type);
498  if (entity_->getMembers()[i].parameterized) {
499  auto j = std::find(entity_->getTypeParameters().begin(), entity_->getTypeParameters().end(), type);
500  if (j != entity_->getTypeParameters().end()) {
501  type = arguments_[j - entity_->getTypeParameters().begin()];
502  goto found;
503  }
504  assert(false); // this cannot happen //TODO!
505  found:;
506  }
507  s[i] = manager_->resolve(type);
508  }
509  return s;
510 }
511 
512 css::uno::Sequence< OUString >
513 InstantiatedPolymorphicStructTypeDescription::getMemberNames()
514 {
515  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
516  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
517  css::uno::Sequence< OUString > s(n);
518  for (sal_Int32 i = 0; i != n; ++i) {
519  s[i] = entity_->getMembers()[i].name;
520  }
521  return s;
522 }
523 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
524 InstantiatedPolymorphicStructTypeDescription::getTypeArguments()
525 {
526  assert(arguments_.size() <= SAL_MAX_INT32);
527  sal_Int32 n = static_cast< sal_Int32 >(arguments_.size());
528  css::uno::Sequence<
529  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
530  for (sal_Int32 i = 0; i != n; ++i) {
531  s[i] = manager_->resolve(arguments_[i]);
532  }
533  return s;
534 }
535 
536 typedef cppu::ImplInheritanceHelper<
537  PublishableDescription, css::reflection::XCompoundTypeDescription >
538 ExceptionTypeDescription_Base;
539 
540 class ExceptionTypeDescription: public ExceptionTypeDescription_Base {
541 public:
542  ExceptionTypeDescription(
544  OUString const & name,
546  ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager),
547  name_(name), entity_(entity)
548  { assert(manager.is()); assert(entity.is()); }
549 
550 private:
551  virtual ~ExceptionTypeDescription() override {}
552 
553  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
554  { return css::uno::TypeClass_EXCEPTION; }
555 
556  virtual OUString SAL_CALL getName() override
557  { return name_; }
558 
559  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
560  getBaseType() override {
561  return entity_->getDirectBase().isEmpty()
562  ? css::uno::Reference< css::reflection::XTypeDescription >()
563  : manager_->resolve(entity_->getDirectBase());
564  }
565 
566  virtual
567  css::uno::Sequence<
568  css::uno::Reference< css::reflection::XTypeDescription > >
569  SAL_CALL getMemberTypes() override;
570 
571  virtual css::uno::Sequence< OUString > SAL_CALL getMemberNames() override;
572 
574  OUString name_;
576 };
577 
578 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
579 ExceptionTypeDescription::getMemberTypes() {
580  assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
581  sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
582  css::uno::Sequence<
583  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
584  for (sal_Int32 i = 0; i != n; ++i) {
585  s[i] = manager_->resolve(entity_->getDirectMembers()[i].type);
586  }
587  return s;
588 }
589 
590 css::uno::Sequence< OUString > ExceptionTypeDescription::getMemberNames()
591 {
592  assert(entity_->getDirectMembers().size() <= SAL_MAX_INT32);
593  sal_Int32 n = static_cast< sal_Int32 >(entity_->getDirectMembers().size());
594  css::uno::Sequence< OUString > s(n);
595  for (sal_Int32 i = 0; i != n; ++i) {
596  s[i] = entity_->getDirectMembers()[i].name;
597  }
598  return s;
599 }
600 
601 class AttributeDescription:
602  public cppu::WeakImplHelper<
603  css::reflection::XInterfaceAttributeTypeDescription2 >
604 {
605 public:
606  AttributeDescription(
608  OUString const & name,
609  unoidl::InterfaceTypeEntity::Attribute const & attribute,
610  sal_Int32 position):
611  manager_(manager), name_(name), attribute_(attribute),
612  position_(position)
613  { assert(manager.is()); }
614 
615 private:
616  virtual ~AttributeDescription() override {}
617 
618  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
619  { return css::uno::TypeClass_INTERFACE_ATTRIBUTE; }
620 
621  virtual OUString SAL_CALL getName() override
622  { return name_; }
623 
624  virtual OUString SAL_CALL getMemberName() override
625  { return attribute_.name; }
626 
627  virtual sal_Int32 SAL_CALL getPosition() override
628  { return position_; }
629 
630  virtual sal_Bool SAL_CALL isReadOnly() override
631  { return attribute_.readOnly; }
632 
633  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
634  getType() override
635  { return manager_->resolve(attribute_.type); }
636 
637  virtual sal_Bool SAL_CALL isBound() override
638  { return attribute_.bound; }
639 
640  virtual
641  css::uno::Sequence<
642  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
643  SAL_CALL getGetExceptions() override;
644 
645  virtual
646  css::uno::Sequence<
647  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
648  SAL_CALL getSetExceptions() override;
649 
651  OUString name_;
653  sal_Int32 position_;
654 };
655 
656 css::uno::Sequence<
657  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
658 AttributeDescription::getGetExceptions() {
659  assert(attribute_.getExceptions.size() <= SAL_MAX_INT32);
660  sal_Int32 n = static_cast< sal_Int32 >(attribute_.getExceptions.size());
661  css::uno::Sequence<
662  css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
663  for (sal_Int32 i = 0; i != n; ++i) {
664  s[i].set(
665  manager_->resolve(attribute_.getExceptions[i]),
666  css::uno::UNO_QUERY_THROW);
667  }
668  return s;
669 }
670 
671 css::uno::Sequence<
672  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
673 AttributeDescription::getSetExceptions() {
674  assert(attribute_.setExceptions.size() <= SAL_MAX_INT32);
675  sal_Int32 n = static_cast< sal_Int32 >(attribute_.setExceptions.size());
676  css::uno::Sequence<
677  css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
678  for (sal_Int32 i = 0; i != n; ++i) {
679  s[i].set(
680  manager_->resolve(attribute_.setExceptions[i]),
681  css::uno::UNO_QUERY_THROW);
682  }
683  return s;
684 }
685 
686 class MethodParameter:
687  public cppu::WeakImplHelper< css::reflection::XMethodParameter >
688 {
689 public:
690  MethodParameter(
693  sal_Int32 position):
694  manager_(manager), parameter_(parameter), position_(position)
695  { assert(manager.is()); }
696 
697 private:
698  virtual ~MethodParameter() override {}
699 
700  virtual OUString SAL_CALL getName() override
701  { return parameter_.name; }
702 
703  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
704  getType() override
705  { return manager_->resolve(parameter_.type); }
706 
707  virtual sal_Bool SAL_CALL isIn() override {
708  return
709  (parameter_.direction
711  || (parameter_.direction
714  }
715 
716  virtual sal_Bool SAL_CALL isOut() override {
717  return
718  (parameter_.direction
720  || (parameter_.direction
723  }
724 
725  virtual sal_Int32 SAL_CALL getPosition() override
726  { return position_; }
727 
730  sal_Int32 position_;
731 };
732 
733 class MethodDescription:
734  public cppu::WeakImplHelper<
735  css::reflection::XInterfaceMethodTypeDescription >
736 {
737 public:
738  MethodDescription(
740  OUString const & name,
741  unoidl::InterfaceTypeEntity::Method const & method, sal_Int32 position):
742  manager_(manager), name_(name), method_(method), position_(position)
743  { assert(manager.is()); }
744 
745 private:
746  virtual ~MethodDescription() override {}
747 
748  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
749  { return css::uno::TypeClass_INTERFACE_METHOD; }
750 
751  virtual OUString SAL_CALL getName() override
752  { return name_; }
753 
754  virtual OUString SAL_CALL getMemberName() override
755  { return method_.name; }
756 
757  virtual sal_Int32 SAL_CALL getPosition() override
758  { return position_; }
759 
760  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
761  getReturnType() override
762  { return manager_->resolve(method_.returnType); }
763 
764  virtual sal_Bool SAL_CALL isOneway() override
765  { return false; }
766 
767  virtual
768  css::uno::Sequence<
769  css::uno::Reference< css::reflection::XMethodParameter > >
770  SAL_CALL getParameters() override;
771 
772  virtual
773  css::uno::Sequence<
774  css::uno::Reference< css::reflection::XTypeDescription > >
775  SAL_CALL getExceptions() override;
776 
778  OUString name_;
780  sal_Int32 position_;
781 };
782 
783 css::uno::Sequence< css::uno::Reference< css::reflection::XMethodParameter > >
784 MethodDescription::getParameters() {
785  assert(method_.parameters.size() <= SAL_MAX_INT32);
786  sal_Int32 n = static_cast< sal_Int32 >(method_.parameters.size());
787  css::uno::Sequence<
788  css::uno::Reference< css::reflection::XMethodParameter > > s(n);
789  for (sal_Int32 i = 0; i != n; ++i) {
790  s[i] = new MethodParameter(manager_, method_.parameters[i], i);
791  }
792  return s;
793 }
794 
795 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
796 MethodDescription::getExceptions() {
797  assert(method_.exceptions.size() <= SAL_MAX_INT32);
798  sal_Int32 n = static_cast< sal_Int32 >(method_.exceptions.size());
799  css::uno::Sequence<
800  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
801  for (sal_Int32 i = 0; i != n; ++i) {
802  s[i] = manager_->resolve(method_.exceptions[i]);
803  }
804  return s;
805 }
806 
807 class BaseOffset {
808 public:
809  explicit BaseOffset(
810  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
811  const & description);
812 
813  BaseOffset(const BaseOffset&) = delete;
814  const BaseOffset& operator=(const BaseOffset&) = delete;
815 
816  sal_Int32 get() const { return offset_; }
817 
818 private:
819  void calculateBases(
820  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
821  const & description);
822 
823  void calculate(
824  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
825  const & description);
826 
827  std::set< OUString > set_;
828  sal_Int32 offset_;
829 };
830 
831 BaseOffset::BaseOffset(
832  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
833  description):
834  offset_(0)
835 {
836  calculateBases(description);
837 }
838 
839 void BaseOffset::calculateBases(
840  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
841  description)
842 {
843  const css::uno::Sequence<
844  css::uno::Reference < css::reflection::XTypeDescription > > bases(
845  description->getBaseTypes());
846  for (const auto & i : bases) {
847  calculate(
848  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >(
849  resolveTypedefs(css::uno::makeAny(i)),
850  css::uno::UNO_QUERY_THROW));
851  }
852 }
853 
854 void BaseOffset::calculate(
855  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > const &
856  description)
857 {
858  if (set_.insert(description->getName()).second) {
859  calculateBases(description);
860  offset_ += description->getMembers().getLength();
861  }
862 }
863 
864 typedef cppu::ImplInheritanceHelper<
865  PublishableDescription, css::reflection::XInterfaceTypeDescription2 >
866 InterfaceTypeDescription_Base;
867 
868 class InterfaceTypeDescription: public InterfaceTypeDescription_Base {
869 public:
870  InterfaceTypeDescription(
872  OUString const & name,
874  InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager),
875  name_(name), entity_(entity)
876  { assert(manager.is()); assert(entity.is()); }
877 
878 private:
879  virtual ~InterfaceTypeDescription() override {}
880 
881  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
882  { return css::uno::TypeClass_INTERFACE; }
883 
884  virtual OUString SAL_CALL getName() override
885  { return name_; }
886 
887  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
888  getBaseType() override {
889  return entity_->getDirectMandatoryBases().empty()
890  ? css::uno::Reference< css::reflection::XTypeDescription >()
891  : manager_->resolve(entity_->getDirectMandatoryBases()[0].name);
892  }
893 
894  virtual css::uno::Uik SAL_CALL getUik() override
895  { return css::uno::Uik(); }
896 
897  virtual
898  css::uno::Sequence<
899  css::uno::Reference<
900  css::reflection::XInterfaceMemberTypeDescription > >
901  SAL_CALL getMembers() override;
902 
903  virtual
904  css::uno::Sequence<
905  css::uno::Reference< css::reflection::XTypeDescription > >
906  SAL_CALL getBaseTypes() override;
907 
908  virtual
909  css::uno::Sequence<
910  css::uno::Reference< css::reflection::XTypeDescription > >
911  SAL_CALL getOptionalBaseTypes() override;
912 
914  OUString name_;
916 };
917 
918 css::uno::Sequence<
919  css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > >
920 InterfaceTypeDescription::getMembers() {
921  assert(
922  entity_->getDirectAttributes().size() <= SAL_MAX_INT32
923  && (entity_->getDirectMethods().size()
924  <= SAL_MAX_INT32 - entity_->getDirectAttributes().size()));
925  sal_Int32 n1 = static_cast< sal_Int32 >(
926  entity_->getDirectAttributes().size());
927  sal_Int32 n2 = static_cast< sal_Int32 >(entity_->getDirectMethods().size());
928  css::uno::Sequence<
929  css::uno::Reference<
930  css::reflection::XInterfaceMemberTypeDescription > > s(n1 + n2);
931  sal_Int32 off = BaseOffset(this).get();
932  for (sal_Int32 i = 0; i != n1; ++i) {
933  s[i] = new AttributeDescription(
934  manager_, name_ + "::" + entity_->getDirectAttributes()[i].name,
935  entity_->getDirectAttributes()[i], off + i);
936  }
937  for (sal_Int32 i = 0; i != n2; ++i) {
938  s[n1 + i] = new MethodDescription(
939  manager_, name_ + "::" + entity_->getDirectMethods()[i].name,
940  entity_->getDirectMethods()[i], off + n1 + i);
941  }
942  return s;
943 }
944 
945 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
946 InterfaceTypeDescription::getBaseTypes() {
947  assert(entity_->getDirectMandatoryBases().size() <= SAL_MAX_INT32);
948  sal_Int32 n = static_cast< sal_Int32 >(
949  entity_->getDirectMandatoryBases().size());
950  css::uno::Sequence<
951  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
952  for (sal_Int32 i = 0; i != n; ++i) {
953  s[i] = manager_->resolve(entity_->getDirectMandatoryBases()[i].name);
954  }
955  return s;
956 }
957 
958 css::uno::Sequence< css::uno::Reference< css::reflection::XTypeDescription > >
959 InterfaceTypeDescription::getOptionalBaseTypes()
960 {
961  assert(entity_->getDirectOptionalBases().size() <= SAL_MAX_INT32);
962  sal_Int32 n = static_cast< sal_Int32 >(
963  entity_->getDirectOptionalBases().size());
964  css::uno::Sequence<
965  css::uno::Reference< css::reflection::XTypeDescription > > s(n);
966  for (sal_Int32 i = 0; i != n; ++i) {
967  s[i] = manager_->resolve(entity_->getDirectOptionalBases()[i].name);
968  }
969  return s;
970 }
971 
972 class ConstantDescription:
973  public cppu::WeakImplHelper< css::reflection::XConstantTypeDescription >
974 {
975 public:
976  ConstantDescription(
977  OUString const & constantGroupName,
978  unoidl::ConstantGroupEntity::Member const & member);
979 
980 private:
981  virtual ~ConstantDescription() override {}
982 
983  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
984  { return css::uno::TypeClass_CONSTANT; }
985 
986  virtual OUString SAL_CALL getName() override
987  { return name_; }
988 
989  virtual css::uno::Any SAL_CALL getConstantValue() override
990  { return value_; }
991 
992  OUString name_;
993  css::uno::Any value_;
994 };
995 
996 ConstantDescription::ConstantDescription(
997  OUString const & constantGroupName,
998  unoidl::ConstantGroupEntity::Member const & member):
999  name_(makePrefix(constantGroupName) + member.name)
1000 {
1001  switch (member.value.type) {
1003  value_ <<= member.value.booleanValue;
1004  break;
1006  value_ <<= member.value.byteValue;
1007  break;
1009  value_ <<= member.value.shortValue;
1010  break;
1012  value_ <<= member.value.unsignedShortValue;
1013  break;
1015  value_ <<= member.value.longValue;
1016  break;
1018  value_ <<= member.value.unsignedLongValue;
1019  break;
1021  value_ <<= member.value.hyperValue;
1022  break;
1024  value_ <<= member.value.unsignedHyperValue;
1025  break;
1027  value_ <<= member.value.floatValue;
1028  break;
1030  value_ <<= member.value.doubleValue;
1031  break;
1032  default:
1033  for (;;) { std::abort(); } // this cannot happen
1034  }
1035 }
1036 
1037 typedef cppu::ImplInheritanceHelper<
1038  PublishableDescription, css::reflection::XConstantsTypeDescription >
1039 ConstantGroupDescription_Base;
1040 
1041 class ConstantGroupDescription: public ConstantGroupDescription_Base {
1042 public:
1043  ConstantGroupDescription(
1044  OUString const & name,
1046  ConstantGroupDescription_Base(entity->isPublished()), name_(name),
1047  entity_(entity)
1048  { assert(entity.is()); }
1049 
1050 private:
1051  virtual ~ConstantGroupDescription() override {}
1052 
1053  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1054  { return css::uno::TypeClass_CONSTANTS; }
1055 
1056  virtual OUString SAL_CALL getName() override
1057  { return name_; }
1058 
1059  virtual
1060  css::uno::Sequence<
1061  css::uno::Reference< css::reflection::XConstantTypeDescription > >
1062  SAL_CALL getConstants() override;
1063 
1064  OUString name_;
1066 };
1067 
1068 css::uno::Sequence<
1069  css::uno::Reference< css::reflection::XConstantTypeDescription > >
1070 ConstantGroupDescription::getConstants() {
1071  assert(entity_->getMembers().size() <= SAL_MAX_INT32);
1072  sal_Int32 n = static_cast< sal_Int32 >(entity_->getMembers().size());
1073  css::uno::Sequence<
1074  css::uno::Reference< css::reflection::XConstantTypeDescription > > s(n);
1075  for (sal_Int32 i = 0; i != n; ++i) {
1076  s[i] = new ConstantDescription(name_, entity_->getMembers()[i]);
1077  }
1078  return s;
1079 }
1080 
1081 typedef cppu::ImplInheritanceHelper<
1082  PublishableDescription, css::reflection::XIndirectTypeDescription >
1083 TypedefDescription_Base;
1084 
1085 class TypedefDescription: public TypedefDescription_Base {
1086 public:
1087  TypedefDescription(
1089  OUString const & name,
1091  TypedefDescription_Base(entity->isPublished()), manager_(manager),
1092  name_(name), entity_(entity)
1093  { assert(manager.is()); assert(entity.is()); }
1094 
1095 private:
1096  virtual ~TypedefDescription() override {}
1097 
1098  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1099  { return css::uno::TypeClass_TYPEDEF; }
1100 
1101  virtual OUString SAL_CALL getName() override
1102  { return name_; }
1103 
1104  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1105  getReferencedType() override
1106  { return manager_->resolve(entity_->getType()); }
1107 
1109  OUString name_;
1111 };
1112 
1113 class ConstructorParameter:
1114  public cppu::WeakImplHelper< css::reflection::XParameter >
1115 {
1116 public:
1117  ConstructorParameter(
1120  const & parameter,
1121  sal_Int32 position):
1122  manager_(manager), parameter_(parameter), position_(position)
1123  { assert(manager.is()); }
1124 
1125 private:
1126  virtual ~ConstructorParameter() override {}
1127 
1128  virtual OUString SAL_CALL getName() override
1129  { return parameter_.name; }
1130 
1131  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1132  getType() override
1133  { return manager_->resolve(parameter_.type); }
1134 
1135  virtual sal_Bool SAL_CALL isIn() override
1136  { return true; }
1137 
1138  virtual sal_Bool SAL_CALL isOut() override
1139  { return false; }
1140 
1141  virtual sal_Int32 SAL_CALL getPosition() override
1142  { return position_; }
1143 
1144  virtual sal_Bool SAL_CALL isRestParameter() override
1145  { return parameter_.rest; }
1146 
1149  parameter_;
1150  sal_Int32 position_;
1151 };
1152 
1153 class ConstructorDescription:
1154  public cppu::WeakImplHelper<
1155  css::reflection::XServiceConstructorDescription >
1156 {
1157 public:
1158  ConstructorDescription(
1161  constructor):
1162  manager_(manager), constructor_(constructor)
1163  { assert(manager.is()); }
1164 
1165 private:
1166  virtual ~ConstructorDescription() override {}
1167 
1168  virtual sal_Bool SAL_CALL isDefaultConstructor() override
1169  { return constructor_.defaultConstructor; }
1170 
1171  virtual OUString SAL_CALL getName() override
1172  { return constructor_.name; }
1173 
1174  virtual
1175  css::uno::Sequence<
1176  css::uno::Reference< css::reflection::XParameter > >
1177  SAL_CALL getParameters() override;
1178 
1179  virtual
1180  css::uno::Sequence<
1181  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1182  SAL_CALL getExceptions() override;
1183 
1186 };
1187 
1188 css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > >
1189 ConstructorDescription::getParameters() {
1190  assert(constructor_.parameters.size() <= SAL_MAX_INT32);
1191  sal_Int32 n = static_cast< sal_Int32 >(constructor_.parameters.size());
1192  css::uno::Sequence< css::uno::Reference< css::reflection::XParameter > > s(
1193  n);
1194  for (sal_Int32 i = 0; i != n; ++i) {
1195  s[i] = new ConstructorParameter(
1196  manager_, constructor_.parameters[i], i);
1197  }
1198  return s;
1199 }
1200 
1201 css::uno::Sequence<
1202  css::uno::Reference< css::reflection::XCompoundTypeDescription > >
1203 ConstructorDescription::getExceptions() {
1204  assert(constructor_.exceptions.size() <= SAL_MAX_INT32);
1205  sal_Int32 n = static_cast< sal_Int32 >(constructor_.exceptions.size());
1206  css::uno::Sequence<
1207  css::uno::Reference< css::reflection::XCompoundTypeDescription > > s(n);
1208  for (sal_Int32 i = 0; i != n; ++i) {
1209  s[i].set(
1210  manager_->resolve(constructor_.exceptions[i]),
1211  css::uno::UNO_QUERY_THROW);
1212  }
1213  return s;
1214 }
1215 
1216 typedef cppu::ImplInheritanceHelper<
1217  PublishableDescription, css::reflection::XServiceTypeDescription2 >
1218 SingleInterfaceBasedServiceDescription_Base;
1219 
1220 class SingleInterfaceBasedServiceDescription:
1221  public SingleInterfaceBasedServiceDescription_Base
1222 {
1223 public:
1224  SingleInterfaceBasedServiceDescription(
1226  OUString const & name,
1228  entity):
1229  SingleInterfaceBasedServiceDescription_Base(entity->isPublished()),
1230  manager_(manager), name_(name), entity_(entity)
1231  { assert(manager.is()); assert(entity.is()); }
1232 
1233 private:
1234  virtual ~SingleInterfaceBasedServiceDescription() override {}
1235 
1236  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1237  { return css::uno::TypeClass_SERVICE; }
1238 
1239  virtual OUString SAL_CALL getName() override
1240  { return name_; }
1241 
1242  virtual
1243  css::uno::Sequence<
1244  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1245  SAL_CALL getMandatoryServices() override
1246  {
1247  return css::uno::Sequence<
1248  css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1249  }
1250 
1251  virtual
1252  css::uno::Sequence<
1253  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1254  SAL_CALL getOptionalServices() override
1255  {
1256  return css::uno::Sequence<
1257  css::uno::Reference< css::reflection::XServiceTypeDescription > >();
1258  }
1259 
1260  virtual
1261  css::uno::Sequence<
1262  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1263  SAL_CALL getMandatoryInterfaces() override
1264  {
1265  return css::uno::Sequence<
1266  css::uno::Reference<
1267  css::reflection::XInterfaceTypeDescription > >();
1268  }
1269 
1270  virtual
1271  css::uno::Sequence<
1272  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1273  SAL_CALL getOptionalInterfaces() override
1274  {
1275  return css::uno::Sequence<
1276  css::uno::Reference<
1277  css::reflection::XInterfaceTypeDescription > >();
1278  }
1279 
1280  virtual
1281  css::uno::Sequence<
1282  css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1283  SAL_CALL getProperties() override
1284  {
1285  return css::uno::Sequence<
1286  css::uno::Reference<
1287  css::reflection::XPropertyTypeDescription > >();
1288  }
1289 
1290  virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1291  { return true; }
1292 
1293  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1294  getInterface() override
1295  { return manager_->resolve(entity_->getBase()); }
1296 
1297  virtual
1298  css::uno::Sequence<
1299  css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1300  SAL_CALL getConstructors() override;
1301 
1303  OUString name_;
1305 };
1306 
1307 css::uno::Sequence<
1308  css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1309 SingleInterfaceBasedServiceDescription::getConstructors()
1310 {
1311  assert(entity_->getConstructors().size() <= SAL_MAX_INT32);
1312  sal_Int32 n = static_cast< sal_Int32 >(entity_->getConstructors().size());
1313  css::uno::Sequence<
1314  css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1315  s(n);
1316  for (sal_Int32 i = 0; i != n; ++i) {
1317  s[i] = new ConstructorDescription(
1318  manager_, entity_->getConstructors()[i]);
1319  }
1320  return s;
1321 }
1322 
1323 class PropertyDescription:
1324  public cppu::WeakImplHelper< css::reflection::XPropertyTypeDescription >
1325 {
1326 public:
1327  PropertyDescription(
1330  manager_(manager), property_(property)
1331  { assert(manager.is()); }
1332 
1333 private:
1334  virtual ~PropertyDescription() override {}
1335 
1336  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1337  { return css::uno::TypeClass_PROPERTY; }
1338 
1339  virtual OUString SAL_CALL getName() override
1340  { return property_.name; }
1341 
1342  virtual sal_Int16 SAL_CALL getPropertyFlags() override
1343  { return property_.attributes; }
1344 
1345  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1346  getPropertyTypeDescription() override
1347  { return manager_->resolve(property_.type); }
1348 
1351 };
1352 
1353 typedef cppu::ImplInheritanceHelper<
1354  PublishableDescription, css::reflection::XServiceTypeDescription2 >
1355 AccumulationBasedServiceDescription_Base;
1356 
1357 class AccumulationBasedServiceDescription:
1358  public AccumulationBasedServiceDescription_Base
1359 {
1360 public:
1361  AccumulationBasedServiceDescription(
1363  OUString const & name,
1365  entity):
1366  AccumulationBasedServiceDescription_Base(entity->isPublished()),
1367  manager_(manager), name_(name), entity_(entity)
1368  { assert(manager.is()); assert(entity.is()); }
1369 
1370 private:
1371  virtual ~AccumulationBasedServiceDescription() override {}
1372 
1373  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1374  { return css::uno::TypeClass_SERVICE; }
1375 
1376  virtual OUString SAL_CALL getName() override
1377  { return name_; }
1378 
1379  virtual
1380  css::uno::Sequence<
1381  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1382  SAL_CALL getMandatoryServices() override;
1383 
1384  virtual
1385  css::uno::Sequence<
1386  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1387  SAL_CALL getOptionalServices() override;
1388 
1389  virtual
1390  css::uno::Sequence<
1391  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1392  SAL_CALL getMandatoryInterfaces() override;
1393 
1394  virtual
1395  css::uno::Sequence<
1396  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1397  SAL_CALL getOptionalInterfaces() override;
1398 
1399  virtual
1400  css::uno::Sequence<
1401  css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1402  SAL_CALL getProperties() override;
1403 
1404  virtual sal_Bool SAL_CALL isSingleInterfaceBased() override
1405  { return false; }
1406 
1407  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1408  getInterface() override
1409  { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1410 
1411  virtual
1412  css::uno::Sequence<
1413  css::uno::Reference< css::reflection::XServiceConstructorDescription > >
1414  SAL_CALL getConstructors() override
1415  {
1416  return css::uno::Sequence<
1417  css::uno::Reference<
1418  css::reflection::XServiceConstructorDescription > >();
1419  }
1420 
1422  OUString name_;
1424 };
1425 
1426 css::uno::Sequence<
1427  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1428 AccumulationBasedServiceDescription::getMandatoryServices()
1429 {
1430  assert(entity_->getDirectMandatoryBaseServices().size() <= SAL_MAX_INT32);
1431  sal_Int32 n = static_cast< sal_Int32 >(
1432  entity_->getDirectMandatoryBaseServices().size());
1433  css::uno::Sequence<
1434  css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1435  for (sal_Int32 i = 0; i != n; ++i) {
1436  s[i].set(
1437  manager_->resolve(
1438  entity_->getDirectMandatoryBaseServices()[i].name),
1439  css::uno::UNO_QUERY_THROW);
1440  }
1441  return s;
1442 }
1443 
1444 css::uno::Sequence<
1445  css::uno::Reference< css::reflection::XServiceTypeDescription > >
1446 AccumulationBasedServiceDescription::getOptionalServices()
1447 {
1448  assert(entity_->getDirectOptionalBaseServices().size() <= SAL_MAX_INT32);
1449  sal_Int32 n = static_cast< sal_Int32 >(
1450  entity_->getDirectOptionalBaseServices().size());
1451  css::uno::Sequence<
1452  css::uno::Reference< css::reflection::XServiceTypeDescription > > s(n);
1453  for (sal_Int32 i = 0; i != n; ++i) {
1454  s[i].set(
1455  manager_->resolve(entity_->getDirectOptionalBaseServices()[i].name),
1456  css::uno::UNO_QUERY_THROW);
1457  }
1458  return s;
1459 }
1460 
1461 css::uno::Sequence<
1462  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1463 AccumulationBasedServiceDescription::getMandatoryInterfaces()
1464 {
1465  assert(entity_->getDirectMandatoryBaseInterfaces().size() <= SAL_MAX_INT32);
1466  sal_Int32 n = static_cast< sal_Int32 >(
1467  entity_->getDirectMandatoryBaseInterfaces().size());
1468  css::uno::Sequence<
1469  css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1470  n);
1471  for (sal_Int32 i = 0; i != n; ++i) {
1472  s[i].set(
1474  manager_->find(
1475  entity_->getDirectMandatoryBaseInterfaces()[i].name)),
1476  css::uno::UNO_QUERY_THROW);
1477  }
1478  return s;
1479 }
1480 
1481 css::uno::Sequence<
1482  css::uno::Reference< css::reflection::XInterfaceTypeDescription > >
1483 AccumulationBasedServiceDescription::getOptionalInterfaces()
1484 {
1485  assert(entity_->getDirectOptionalBaseInterfaces().size() <= SAL_MAX_INT32);
1486  sal_Int32 n = static_cast< sal_Int32 >(
1487  entity_->getDirectOptionalBaseInterfaces().size());
1488  css::uno::Sequence<
1489  css::uno::Reference< css::reflection::XInterfaceTypeDescription > > s(
1490  n);
1491  for (sal_Int32 i = 0; i != n; ++i) {
1492  s[i].set(
1494  manager_->find(
1495  entity_->getDirectOptionalBaseInterfaces()[i].name)),
1496  css::uno::UNO_QUERY_THROW);
1497  }
1498  return s;
1499 }
1500 
1501 css::uno::Sequence<
1502  css::uno::Reference< css::reflection::XPropertyTypeDescription > >
1503 AccumulationBasedServiceDescription::getProperties()
1504 {
1505  assert(entity_->getDirectProperties().size() <= SAL_MAX_INT32);
1506  sal_Int32 n = static_cast< sal_Int32 >(
1507  entity_->getDirectProperties().size());
1508  css::uno::Sequence<
1509  css::uno::Reference< css::reflection::XPropertyTypeDescription > > s(n);
1510  for (sal_Int32 i = 0; i != n; ++i) {
1511  s[i] = new PropertyDescription(
1512  manager_, entity_->getDirectProperties()[i]);
1513  }
1514  return s;
1515 }
1516 
1517 typedef cppu::ImplInheritanceHelper<
1518  PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1519 InterfaceBasedSingletonDescription_Base;
1520 
1521 class InterfaceBasedSingletonDescription:
1522  public InterfaceBasedSingletonDescription_Base
1523 {
1524 public:
1525  InterfaceBasedSingletonDescription(
1527  OUString const & name,
1529  InterfaceBasedSingletonDescription_Base(entity->isPublished()),
1530  manager_(manager), name_(name), entity_(entity)
1531  { assert(manager.is()); assert(entity.is()); }
1532 
1533 private:
1534  virtual ~InterfaceBasedSingletonDescription() override {}
1535 
1536  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1537  { return css::uno::TypeClass_SINGLETON; }
1538 
1539  virtual OUString SAL_CALL getName() override
1540  { return name_; }
1541 
1542  virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1543  SAL_CALL getService() override
1544  {
1545  return
1546  css::uno::Reference< css::reflection::XServiceTypeDescription >();
1547  }
1548 
1549  virtual sal_Bool SAL_CALL isInterfaceBased() override
1550  { return true; }
1551 
1552  virtual css::uno::Reference< css::reflection::XTypeDescription >
1553  SAL_CALL getInterface() override
1554  { return manager_->resolve(entity_->getBase()); }
1555 
1557  OUString name_;
1559 };
1560 
1561 typedef cppu::ImplInheritanceHelper<
1562  PublishableDescription, css::reflection::XSingletonTypeDescription2 >
1563 ServiceBasedSingletonDescription_Base;
1564 
1565 class ServiceBasedSingletonDescription:
1566  public ServiceBasedSingletonDescription_Base
1567 {
1568 public:
1569  ServiceBasedSingletonDescription(
1571  OUString const & name,
1573  ServiceBasedSingletonDescription_Base(entity->isPublished()),
1574  manager_(manager), name_(name), entity_(entity)
1575  { assert(manager.is()); assert(entity.is()); }
1576 
1577 private:
1578  virtual ~ServiceBasedSingletonDescription() override {}
1579 
1580  virtual css::uno::TypeClass SAL_CALL getTypeClass() override
1581  { return css::uno::TypeClass_SINGLETON; }
1582 
1583  virtual OUString SAL_CALL getName() override
1584  { return name_; }
1585 
1586  virtual css::uno::Reference< css::reflection::XServiceTypeDescription >
1587  SAL_CALL getService() override
1588  {
1589  return css::uno::Reference< css::reflection::XServiceTypeDescription >(
1590  manager_->resolve(entity_->getBase()), css::uno::UNO_QUERY_THROW);
1591  }
1592 
1593  virtual sal_Bool SAL_CALL isInterfaceBased() override
1594  { return false; }
1595 
1596  virtual css::uno::Reference< css::reflection::XTypeDescription >
1597  SAL_CALL getInterface() override
1598  { return css::uno::Reference< css::reflection::XTypeDescription >(); }
1599 
1601  OUString name_;
1603 };
1604 
1605 class Enumeration:
1606  public cppu::WeakImplHelper< css::reflection::XTypeDescriptionEnumeration >
1607 {
1608 public:
1609  Enumeration(
1611  OUString const & prefix,
1612  rtl::Reference< unoidl::MapCursor > const & cursor,
1613  css::uno::Sequence< css::uno::TypeClass > const & types, bool deep):
1614  manager_(manager), types_(types), deep_(deep)
1615  {
1616  assert(manager.is());
1617  positions_.push(Position(prefix, cursor));
1618  findNextMatch();
1619  }
1620 
1621 private:
1622  virtual ~Enumeration() override {}
1623 
1624  virtual sal_Bool SAL_CALL hasMoreElements() override
1625  { return !positions_.empty(); }
1626 
1627  virtual css::uno::Any SAL_CALL nextElement() override
1628  { return css::uno::makeAny(nextTypeDescription()); }
1629 
1630  virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL
1631  nextTypeDescription() override;
1632 
1633  bool matches(css::uno::TypeClass tc) const;
1634 
1635  void findNextMatch();
1636 
1637  struct Position {
1638  Position(
1639  OUString const & thePrefix,
1640  rtl::Reference< unoidl::MapCursor > const & theCursor):
1641  prefix(thePrefix), cursor(theCursor)
1642  { assert(theCursor.is()); }
1643 
1644  Position(
1645  OUString const & thePrefix,
1647  theConstantGroup):
1648  prefix(thePrefix), constantGroup(theConstantGroup),
1649  constantGroupIndex(constantGroup->getMembers().begin())
1650  { assert(theConstantGroup.is()); }
1651 
1652  Position(Position const & other):
1653  prefix(other.prefix), cursor(other.cursor),
1654  constantGroup(other.constantGroup)
1655  {
1656  if (constantGroup.is()) {
1657  constantGroupIndex = other.constantGroupIndex;
1658  }
1659  }
1660 
1661  OUString prefix;
1664  std::vector< unoidl::ConstantGroupEntity::Member >::const_iterator
1665  constantGroupIndex;
1666  };
1667 
1669  css::uno::Sequence< css::uno::TypeClass > types_;
1670  bool deep_;
1671 
1672  std::mutex mutex_;
1673  std::stack< Position, std::vector<Position> > positions_;
1674  OUString current_;
1675 };
1676 
1677 css::uno::Reference< css::reflection::XTypeDescription >
1678 Enumeration::nextTypeDescription()
1679 {
1680  OUString name;
1681  {
1682  std::scoped_lock g(mutex_);
1683  if (positions_.empty()) {
1684  throw css::container::NoSuchElementException(
1685  "exhausted XTypeDescriptionEnumeration",
1686  static_cast< cppu::OWeakObject * >(this));
1687  }
1688  name = current_;
1689  findNextMatch();
1690  }
1691  return manager_->resolve(name);
1692 }
1693 
1694 bool Enumeration::matches(css::uno::TypeClass tc) const {
1695  if (!types_.hasElements()) {
1696  return true;
1697  }
1698  for (const auto & i : types_) {
1699  if (i == tc) {
1700  return true;
1701  }
1702  }
1703  return false;
1704 }
1705 
1706 void Enumeration::findNextMatch() {
1707  try {
1708  for (;;) {
1709  assert(!positions_.empty());
1710  OUString name;
1711  if (positions_.top().cursor.is()) { // root or module
1713  positions_.top().cursor->getNext(&name));
1714  if (!ent.is()) {
1715  positions_.pop();
1716  if (positions_.empty()) {
1717  break;
1718  }
1719  continue;
1720  }
1721  name = positions_.top().prefix + name;
1722  css::uno::TypeClass tc;
1723  switch (ent->getSort()) {
1725  tc = css::uno::TypeClass_MODULE;
1726  if (deep_) {
1727  positions_.push(
1728  Position(
1729  makePrefix(name),
1730  static_cast< unoidl::ModuleEntity * >(
1731  ent.get())->createCursor()));
1732  }
1733  break;
1735  tc = css::uno::TypeClass_ENUM;
1736  break;
1739  tc = css::uno::TypeClass_STRUCT;
1740  break;
1742  tc = css::uno::TypeClass_EXCEPTION;
1743  break;
1745  tc = css::uno::TypeClass_INTERFACE;
1746  break;
1748  tc = css::uno::TypeClass_TYPEDEF;
1749  break;
1751  tc = css::uno::TypeClass_CONSTANTS;
1752  if (deep_ && matches(css::uno::TypeClass_CONSTANT)) {
1753  positions_.push(
1754  Position(
1755  makePrefix(name),
1756  static_cast< unoidl::ConstantGroupEntity * >(
1757  ent.get())));
1758  }
1759  break;
1762  tc = css::uno::TypeClass_SERVICE;
1763  break;
1766  tc = css::uno::TypeClass_SINGLETON;
1767  break;
1768  default:
1769  for (;;) { std::abort(); } // this cannot happen
1770  }
1771  if (matches(tc)) {
1772  current_ = name;
1773  break;
1774  }
1775  } else { // constant group
1776  if (positions_.top().constantGroupIndex
1777  == positions_.top().constantGroup->getMembers().end())
1778  {
1779  positions_.pop();
1780  if (positions_.empty()) {
1781  break;
1782  }
1783  continue;
1784  }
1785  current_ = positions_.top().prefix
1786  + positions_.top().constantGroupIndex++->name;
1787  break;
1788  }
1789  }
1790  } catch (unoidl::FileFormatException & e) {
1791  throw css::uno::DeploymentException(
1792  e.getUri() + ": " + e.getDetail(),
1793  static_cast< cppu::OWeakObject * >(this));
1794  }
1795 }
1796 
1797 }
1798 
1801  manager_(new unoidl::Manager)
1802 {}
1803 
1804 css::uno::Any cppuhelper::TypeManager::find(OUString const & name) {
1805  //TODO: caching? (here or in unoidl::Manager?)
1806  struct Simple {
1807  std::u16string_view name;
1808  css::uno::TypeClass typeClass;
1809  };
1810  static Simple const simple[] = {
1811  { std::u16string_view(u"void"), css::uno::TypeClass_VOID },
1812  { std::u16string_view(u"boolean"), css::uno::TypeClass_BOOLEAN },
1813  { std::u16string_view(u"byte"), css::uno::TypeClass_BYTE },
1814  { std::u16string_view(u"short"), css::uno::TypeClass_SHORT },
1815  { std::u16string_view(u"unsigned short"),
1816  css::uno::TypeClass_UNSIGNED_SHORT },
1817  { std::u16string_view(u"long"), css::uno::TypeClass_LONG },
1818  { std::u16string_view(u"unsigned long"), css::uno::TypeClass_UNSIGNED_LONG },
1819  { std::u16string_view(u"hyper"), css::uno::TypeClass_HYPER },
1820  { std::u16string_view(u"unsigned hyper"),
1821  css::uno::TypeClass_UNSIGNED_HYPER },
1822  { std::u16string_view(u"float"), css::uno::TypeClass_FLOAT },
1823  { std::u16string_view(u"double"), css::uno::TypeClass_DOUBLE },
1824  { std::u16string_view(u"char"), css::uno::TypeClass_CHAR },
1825  { std::u16string_view(u"string"), css::uno::TypeClass_STRING },
1826  { std::u16string_view(u"type"), css::uno::TypeClass_TYPE },
1827  { std::u16string_view(u"any"), css::uno::TypeClass_ANY } };
1828  for (std::size_t i = 0; i != SAL_N_ELEMENTS(simple); ++i) {
1829  if (name == simple[i].name) {
1830  return css::uno::makeAny<
1831  css::uno::Reference< css::reflection::XTypeDescription > >(
1832  new SimpleTypeDescription(simple[i].typeClass, name));
1833  }
1834  }
1835  if (name.startsWith("[]")) {
1836  return getSequenceType(name);
1837  }
1838  sal_Int32 i = name.indexOf('<');
1839  if (i != -1) {
1840  return getInstantiatedStruct(name, i);
1841  }
1842  i = name.indexOf("::");
1843  if (i != -1) {
1844  return getInterfaceMember(name, i);
1845  }
1846  rtl::Reference< unoidl::Entity > ent(findEntity(name));
1847  if (ent.is()) {
1848  return getNamed(name, ent);
1849  }
1850  i = name.lastIndexOf('.');
1851  if (i != -1) {
1852  OUString parent(name.copy(0, i));
1853  ent = findEntity(parent);
1854  if (ent.is()) {
1855  switch (ent->getSort()) {
1857  return getEnumMember(
1858  static_cast< unoidl::EnumTypeEntity * >(ent.get()),
1859  name.copy(i + 1));
1861  return getConstant(
1862  parent,
1863  static_cast< unoidl::ConstantGroupEntity * >(ent.get()),
1864  name.copy(i + 1));
1865  default:
1866  break;
1867  }
1868  }
1869  }
1870  return css::uno::Any();
1871 }
1872 
1873 css::uno::Reference< css::reflection::XTypeDescription >
1874 cppuhelper::TypeManager::resolve(OUString const & name) {
1875  css::uno::Reference< css::reflection::XTypeDescription > desc(
1876  find(name), css::uno::UNO_QUERY);
1877  if (!desc.is()) {
1878  throw css::uno::DeploymentException(
1879  "cannot resolve type \"" + name + "\"",
1880  static_cast< cppu::OWeakObject * >(this));
1881  }
1882  return desc;
1883 }
1884 
1886 
1888 
1890 {
1891  return
1892  "com.sun.star.comp.cppuhelper.bootstrap.TypeManager";
1893 }
1894 
1896  OUString const & ServiceName)
1897 {
1898  return cppu::supportsService(this, ServiceName);
1899 }
1900 
1901 css::uno::Sequence< OUString >
1903 {
1904  return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO
1905 }
1906 
1908  OUString const & aName)
1909 {
1910  css::uno::Any desc(find(aName));
1911  if (!desc.hasValue()) {
1912  throw css::container::NoSuchElementException(
1913  aName, static_cast< cppu::OWeakObject * >(this));
1914  }
1915  return desc;
1916 }
1917 
1919  OUString const & aName)
1920 {
1921  return find(aName).hasValue();
1922 }
1923 
1925 {
1927 }
1928 
1930 {
1931  throw css::uno::RuntimeException(
1932  "TypeManager hasElements: method not supported",
1933  static_cast< cppu::OWeakObject * >(this));
1934 }
1935 
1936 css::uno::Reference< css::container::XEnumeration >
1938 {
1939  throw css::uno::RuntimeException(
1940  "TypeManager createEnumeration: method not supported",
1941  static_cast< cppu::OWeakObject * >(this));
1942 }
1943 
1945 {
1946  throw css::uno::RuntimeException(
1947  "TypeManager has: method not supported",
1948  static_cast< cppu::OWeakObject * >(this));
1949 }
1950 
1951 void cppuhelper::TypeManager::insert(css::uno::Any const & aElement)
1952 {
1953  OUString uri;
1954  if (!(aElement >>= uri)) {
1955  throw css::lang::IllegalArgumentException(
1956  ("css.uno.theTypeDescriptionManager.insert expects a string URI"
1957  " argument"),
1958  static_cast< cppu::OWeakObject * >(this), 0);
1959  }
1960  //TODO: check for ElementExistException
1961  //TODO: check for consistency with existing data
1962  readRdbFile(uri, false);
1963 }
1964 
1965 void cppuhelper::TypeManager::remove(css::uno::Any const & aElement)
1966 {
1967  OUString uri;
1968  if (!(aElement >>= uri)) {
1969  throw css::lang::IllegalArgumentException(
1970  ("css.uno.theTypeDescriptionManager.remove expects a string URI"
1971  " argument"),
1972  static_cast< cppu::OWeakObject * >(this), 0);
1973  }
1974  //TODO: remove requests are silently ignored for now
1975 }
1976 
1977 css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
1979  OUString const & moduleName,
1980  css::uno::Sequence< css::uno::TypeClass > const & types,
1981  css::reflection::TypeDescriptionSearchDepth depth)
1982 {
1984  try {
1985  cursor = manager_->createCursor(moduleName);
1986  } catch (unoidl::FileFormatException & e) {
1987  throw css::uno::DeploymentException(
1988  ("unoidl::FileFormatException for <" + e.getUri() + ">: "
1989  + e.getDetail()),
1990  static_cast< cppu::OWeakObject * >(this));
1991  }
1992  if (!cursor.is()) {
1993  //TODO: css::reflection::InvalidTypeNameException if moduleName names a
1994  // non-module
1995  throw css::reflection::NoSuchTypeNameException(
1996  moduleName, static_cast< cppu::OWeakObject * >(this));
1997  }
1998  return new Enumeration(
1999  this, makePrefix(moduleName), cursor, types,
2000  depth == css::reflection::TypeDescriptionSearchDepth_INFINITE);
2001 }
2002 
2003 void cppuhelper::TypeManager::init(OUString const & rdbUris) {
2004  for (sal_Int32 i = 0; i != -1;) {
2005  OUString uri(rdbUris.getToken(0, ' ', i));
2006  if (uri.isEmpty()) {
2007  continue;
2008  }
2009  bool optional;
2010  bool directory;
2011  cppu::decodeRdbUri(&uri, &optional, &directory);
2012  if (directory) {
2013  readRdbDirectory(uri, optional);
2014  } else {
2015  readRdbFile(uri, optional);
2016  }
2017  }
2018 }
2019 
2021  OUString const & uri, bool optional)
2022 {
2023  osl::Directory dir(uri);
2024  switch (dir.open()) {
2025  case osl::FileBase::E_None:
2026  break;
2027  case osl::FileBase::E_NOENT:
2028  if (optional) {
2029  SAL_INFO("cppuhelper", "Ignored optional " << uri);
2030  return;
2031  }
2032  [[fallthrough]];
2033  default:
2034  throw css::uno::DeploymentException(
2035  "Cannot open directory " + uri,
2036  static_cast< cppu::OWeakObject * >(this));
2037  }
2038  for (;;) {
2039  OUString url;
2040  if (!cppu::nextDirectoryItem(dir, &url)) {
2041  break;
2042  }
2043  readRdbFile(url, false);
2044  }
2045 }
2046 
2048  OUString const & uri, bool optional)
2049 {
2050  try {
2051  manager_->addProvider(uri);
2052  } catch (unoidl::NoSuchFileException &) {
2053  if (!optional) {
2054  throw css::uno::DeploymentException(
2055  uri + ": no such file",
2056  static_cast< cppu::OWeakObject * >(this));
2057  }
2058  SAL_INFO("cppuhelper", "Ignored optional " << uri);
2059  } catch (unoidl::FileFormatException & e) {
2060  throw css::uno::DeploymentException(
2061  ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2062  + e.getDetail()),
2063  static_cast< cppu::OWeakObject * >(this));
2064  }
2065 }
2066 
2068  OUString const & name)
2069 {
2070  assert(name.startsWith("[]"));
2071  return css::uno::makeAny<
2072  css::uno::Reference< css::reflection::XTypeDescription > >(
2073  new SequenceTypeDescription(
2074  this, name, name.copy(std::strlen("[]"))));
2075 }
2076 
2078  OUString const & name, sal_Int32 separator)
2079 {
2080  assert(name.indexOf('<') == separator && separator != -1);
2081  rtl::Reference< unoidl::Entity > ent(findEntity(name.copy(0, separator)));
2082  if (!ent.is()
2083  || (ent->getSort()
2085  {
2086  return css::uno::Any();
2087  }
2089  static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >(
2090  ent.get()));
2091  std::vector< OUString > args;
2092  sal_Int32 i = separator;
2093  do {
2094  ++i; // skip '<' or ','
2095  sal_Int32 j = i;
2096  for (sal_Int32 level = 0; j != name.getLength(); ++j) {
2097  sal_Unicode c = name[j];
2098  if (c == ',') {
2099  if (level == 0) {
2100  break;
2101  }
2102  } else if (c == '<') {
2103  ++level;
2104  } else if (c == '>') {
2105  if (level == 0) {
2106  break;
2107  }
2108  --level;
2109  }
2110  }
2111  if (j != name.getLength()) {
2112  args.push_back(name.copy(i, j - i));
2113  }
2114  i = j;
2115  } while (i != name.getLength() && name[i] != '>');
2116  if (i != name.getLength() - 1 || name[i] != '>'
2117  || args.size() != ent2->getTypeParameters().size())
2118  {
2119  return css::uno::Any();
2120  }
2121  return css::uno::makeAny<
2122  css::uno::Reference< css::reflection::XTypeDescription > >(
2123  new InstantiatedPolymorphicStructTypeDescription(
2124  this, name, ent2, args));
2125 }
2126 
2128  OUString const & name, sal_Int32 separator)
2129 {
2130  assert(name.indexOf("::") == separator && separator != -1);
2131  css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc(
2132  resolveTypedefs(find(name.copy(0, separator))), css::uno::UNO_QUERY);
2133  if (!ifc.is()) {
2134  return css::uno::Any();
2135  }
2136  OUString member(name.copy(separator + std::strlen("::")));
2137  const css::uno::Sequence<
2138  css::uno::Reference<
2139  css::reflection::XInterfaceMemberTypeDescription > > mems(
2140  ifc->getMembers());
2141  for (const auto & m : mems) {
2142  if (m->getMemberName() == member) {
2143  return css::uno::makeAny<
2144  css::uno::Reference< css::reflection::XTypeDescription > >(m);
2145  }
2146  }
2147  return css::uno::Any();
2148 }
2149 
2151  OUString const & name, rtl::Reference< unoidl::Entity > const & entity)
2152 {
2153  assert(entity.is());
2154  switch (entity->getSort()) {
2156  return css::uno::makeAny<
2157  css::uno::Reference< css::reflection::XTypeDescription > >(
2158  new ModuleDescription(
2159  this, name,
2160  static_cast< unoidl::ModuleEntity * >(entity.get())));
2162  return css::uno::makeAny<
2163  css::uno::Reference< css::reflection::XTypeDescription > >(
2164  new EnumTypeDescription(
2165  name,
2166  static_cast< unoidl::EnumTypeEntity * >(entity.get())));
2168  return css::uno::makeAny<
2169  css::uno::Reference< css::reflection::XTypeDescription > >(
2170  new PlainStructTypeDescription(
2171  this, name,
2172  static_cast< unoidl::PlainStructTypeEntity * >(
2173  entity.get())));
2175  return css::uno::makeAny<
2176  css::uno::Reference< css::reflection::XTypeDescription > >(
2177  new PolymorphicStructTypeTemplateDescription(
2178  this, name,
2179  static_cast<
2181  entity.get())));
2183  return css::uno::makeAny<
2184  css::uno::Reference< css::reflection::XTypeDescription > >(
2185  new ExceptionTypeDescription(
2186  this, name,
2187  static_cast< unoidl::ExceptionTypeEntity * >(
2188  entity.get())));
2190  return css::uno::makeAny<
2191  css::uno::Reference< css::reflection::XTypeDescription > >(
2192  new InterfaceTypeDescription(
2193  this, name,
2194  static_cast< unoidl::InterfaceTypeEntity * >(
2195  entity.get())));
2197  return css::uno::makeAny<
2198  css::uno::Reference< css::reflection::XTypeDescription > >(
2199  new TypedefDescription(
2200  this, name,
2201  static_cast< unoidl::TypedefEntity * >(entity.get())));
2203  return css::uno::makeAny<
2204  css::uno::Reference< css::reflection::XTypeDescription > >(
2205  new ConstantGroupDescription(
2206  name,
2207  static_cast< unoidl::ConstantGroupEntity * >(
2208  entity.get())));
2210  return css::uno::makeAny<
2211  css::uno::Reference< css::reflection::XTypeDescription > >(
2212  new SingleInterfaceBasedServiceDescription(
2213  this, name,
2214  static_cast< unoidl::SingleInterfaceBasedServiceEntity * >(
2215  entity.get())));
2217  return css::uno::makeAny<
2218  css::uno::Reference< css::reflection::XTypeDescription > >(
2219  new AccumulationBasedServiceDescription(
2220  this, name,
2221  static_cast< unoidl::AccumulationBasedServiceEntity * >(
2222  entity.get())));
2224  return css::uno::makeAny<
2225  css::uno::Reference< css::reflection::XTypeDescription > >(
2226  new InterfaceBasedSingletonDescription(
2227  this, name,
2228  static_cast< unoidl::InterfaceBasedSingletonEntity * >(
2229  entity.get())));
2231  return css::uno::makeAny<
2232  css::uno::Reference< css::reflection::XTypeDescription > >(
2233  new ServiceBasedSingletonDescription(
2234  this, name,
2235  static_cast< unoidl::ServiceBasedSingletonEntity * >(
2236  entity.get())));
2237  default:
2238  for (;;) { std::abort(); } // this cannot happen
2239  }
2240 }
2241 
2244  OUString const & member)
2245 {
2246  auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2247  [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; });
2248  if (i != entity->getMembers().end())
2249  return css::uno::makeAny(i->value);
2250  return css::uno::Any();
2251 }
2252 
2254  OUString const & constantGroupName,
2256  OUString const & member)
2257 {
2258  auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(),
2259  [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; });
2260  if (i != entity->getMembers().end())
2261  return css::uno::makeAny<
2262  css::uno::Reference< css::reflection::XTypeDescription > >(
2263  new ConstantDescription(constantGroupName, *i));
2264  return css::uno::Any();
2265 }
2266 
2268  OUString const & name)
2269 {
2270  try {
2271  return manager_->findEntity(name);
2272  } catch (unoidl::FileFormatException & e) {
2273  throw css::uno::DeploymentException(
2274  ("unoidl::FileFormatException for <" + e.getUri() + ">: "
2275  + e.getDetail()),
2276  static_cast< cppu::OWeakObject * >(this));
2277  }
2278 }
2279 
2280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const &aName) override
css::uno::Any value_
bool getType(BSTR name, Type &type)
virtual ~TypeManager() noexcept override
sal_uInt16 unsignedShortValue
int n1
virtual sal_Bool SAL_CALL hasElements() override
sal_Int64 n
tuple args
css::uno::Any find(OUString const &name)
rtl::Reference< unoidl::Entity > findEntity(OUString const &name)
static css::uno::Any getEnumMember(rtl::Reference< unoidl::EnumTypeEntity > const &entity, OUString const &member)
sal_uInt32 unsignedLongValue
virtual css::uno::Any SAL_CALL nextElement() override
css::uno::Any getInstantiatedStruct(OUString const &name, sal_Int32 separator)
SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE
css::uno::Any getInterfaceMember(OUString const &name, sal_Int32 separator)
OSQLColumns::const_iterator find(const OSQLColumns::const_iterator &first, const OSQLColumns::const_iterator &last, std::u16string_view _rVal, const ::comphelper::UStringMixEqual &_rCase)
virtual sal_Bool SAL_CALL has(css::uno::Any const &aElement) override
sal_uInt16 sal_Unicode
OUString name_
virtual sal_Bool SAL_CALL hasMoreElements() override
int n2
enumrange< T >::Iterator begin(enumrange< T >)
virtual void SAL_CALL disposing() override
css::uno::Any getNamed(OUString const &name, rtl::Reference< unoidl::Entity > const &entity)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
A helper for implementations of com.sun.star.lang.XServiceInfo.
std::mutex m_aMutex
osl::Mutex mutex_
bool nextDirectoryItem(osl::Directory &directory, OUString *url)
Definition: paths.cxx:83
virtual void SAL_CALL remove(css::uno::Any const &aElement) override
void readRdbDirectory(OUString const &uri, bool optional)
PyRef getTypeClass(const Runtime &)
const OUString & getDetail() const
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
void decodeRdbUri(OUString *uri, bool *optional, bool *directory)
Definition: paths.cxx:114
#define SAL_N_ELEMENTS(arr)
sal_uInt64 unsignedHyperValue
#define SAL_MAX_INT32
int i
virtual OUString SAL_CALL getImplementationName() override
float u
unsigned char sal_Bool
css::uno::Type const & get()
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
XPropertyListType t
virtual void SAL_CALL insert(css::uno::Any const &aElement) override
SORT_SINGLE_INTERFACE_BASED_SERVICE
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:47
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL getByHierarchicalName(OUString const &aName) override
AstDeclaration const * resolveTypedefs(AstDeclaration const *type)
void readRdbFile(OUString const &uri, bool optional)
css::uno::Any getSequenceType(OUString const &name)
#define SAL_INFO(area, stream)
void init(OUString const &rdbUris)
cppu::WeakComponentImplHelper< css::lang::XServiceInfo, css::container::XHierarchicalNameAccess, css::container::XSet, css::reflection::XTypeDescriptionEnumerationAccess > TypeManager_Base
Definition: typemanager.hxx:41
virtual css::uno::Reference< css::reflection::XTypeDescriptionEnumeration > SAL_CALL createTypeDescriptionEnumeration(OUString const &moduleName, css::uno::Sequence< css::uno::TypeClass > const &types, css::reflection::TypeDescriptionSearchDepth depth) override
tuple m
const OUString & getUri() const
css::uno::Reference< css::reflection::XTypeDescription > resolve(OUString const &name)
static css::uno::Any getConstant(OUString const &constantGroupName, rtl::Reference< unoidl::ConstantGroupEntity > const &entity, OUString const &member)
rtl::Reference< Manager > manager_
exports com.sun.star. uri
Enumeration(css::container::XIndexAccess *)