Branch libreoffice-5-0-4
[LibreOffice.git] / include / unoidl / unoidl.hxx
blob9694be73a33d3cea667be876e7e53489889ca937
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 #ifndef INCLUDED_UNOIDL_UNOIDL_HXX
11 #define INCLUDED_UNOIDL_UNOIDL_HXX
13 #include <sal/config.h>
15 #include <cassert>
16 #include <vector>
18 #include <osl/mutex.hxx>
19 #include <rtl/ref.hxx>
20 #include <rtl/ustring.hxx>
21 #include <sal/types.h>
22 #include <salhelper/simplereferenceobject.hxx>
23 #include <unoidl/detail/dllapi.hxx>
25 namespace unoidl {
27 class LO_DLLPUBLIC_UNOIDL NoSuchFileException {
28 public:
29 SAL_DLLPRIVATE NoSuchFileException(rtl::OUString const & uri): uri_(uri) {}
31 SAL_DLLPRIVATE NoSuchFileException(NoSuchFileException const & other):
32 uri_(other.uri_) {}
34 virtual SAL_DLLPRIVATE ~NoSuchFileException() throw ();
36 rtl::OUString getUri() const { return uri_; }
38 private:
39 void operator =(NoSuchFileException) SAL_DELETED_FUNCTION;
41 rtl::OUString uri_;
44 class LO_DLLPUBLIC_UNOIDL FileFormatException {
45 public:
46 SAL_DLLPRIVATE FileFormatException(
47 rtl::OUString const & uri, rtl::OUString const & detail):
48 uri_(uri), detail_(detail)
51 SAL_DLLPRIVATE FileFormatException(FileFormatException const & other):
52 uri_(other.uri_), detail_(other.detail_)
55 virtual SAL_DLLPRIVATE ~FileFormatException() throw ();
57 rtl::OUString getUri() const { return uri_; }
59 rtl::OUString getDetail() const { return detail_; }
61 private:
62 void operator =(FileFormatException) SAL_DELETED_FUNCTION;
64 rtl::OUString uri_;
65 rtl::OUString detail_;
68 struct AnnotatedReference {
69 AnnotatedReference(
70 rtl::OUString const & theName,
71 std::vector< rtl::OUString > const & theAnnotations):
72 name(theName), annotations(theAnnotations)
75 rtl::OUString name;
77 std::vector< rtl::OUString > annotations;
80 class LO_DLLPUBLIC_UNOIDL Entity: public salhelper::SimpleReferenceObject {
81 public:
82 enum Sort {
83 SORT_MODULE, SORT_ENUM_TYPE, SORT_PLAIN_STRUCT_TYPE,
84 SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE, SORT_EXCEPTION_TYPE,
85 SORT_INTERFACE_TYPE, SORT_TYPEDEF, SORT_CONSTANT_GROUP,
86 SORT_SINGLE_INTERFACE_BASED_SERVICE, SORT_ACCUMULATION_BASED_SERVICE,
87 SORT_INTERFACE_BASED_SINGLETON, SORT_SERVICE_BASED_SINGLETON
90 Sort getSort() const { return sort_; }
92 protected:
93 explicit SAL_DLLPRIVATE Entity(Sort sort): sort_(sort) {}
95 virtual SAL_DLLPRIVATE ~Entity() throw ();
97 private:
98 Sort sort_;
101 class LO_DLLPUBLIC_UNOIDL MapCursor: public salhelper::SimpleReferenceObject {
102 public:
103 // throws FileFormatException:
104 virtual rtl::Reference< Entity > getNext(rtl::OUString * name) = 0;
106 protected:
107 SAL_DLLPRIVATE MapCursor() {}
109 virtual SAL_DLLPRIVATE ~MapCursor() throw();
112 class LO_DLLPUBLIC_UNOIDL ModuleEntity: public Entity {
113 public:
114 // throws FileFormatException:
115 virtual std::vector< rtl::OUString > getMemberNames() const = 0;
117 // throws FileFormatException:
118 virtual rtl::Reference< MapCursor > createCursor() const = 0;
120 protected:
121 SAL_DLLPRIVATE ModuleEntity(): Entity(SORT_MODULE) {}
123 virtual SAL_DLLPRIVATE ~ModuleEntity() throw ();
126 class LO_DLLPUBLIC_UNOIDL PublishableEntity: public Entity {
127 public:
128 bool isPublished() const { return published_; }
130 std::vector< rtl::OUString > const & getAnnotations() const
131 { return annotations_; }
133 protected:
134 SAL_DLLPRIVATE PublishableEntity(
135 Sort sort, bool published,
136 std::vector< rtl::OUString > const & annotations):
137 Entity(sort), published_(published), annotations_(annotations)
140 virtual SAL_DLLPRIVATE ~PublishableEntity() throw ();
142 private:
143 bool published_;
145 std::vector< rtl::OUString > annotations_;
148 class LO_DLLPUBLIC_UNOIDL EnumTypeEntity: public PublishableEntity {
149 public:
150 struct Member {
151 Member(
152 rtl::OUString const & theName, sal_Int32 theValue,
153 std::vector< rtl::OUString > const & theAnnotations):
154 name(theName), value(theValue), annotations(theAnnotations)
157 rtl::OUString name;
159 sal_Int32 value;
161 std::vector< rtl::OUString > annotations;
164 SAL_DLLPRIVATE EnumTypeEntity(
165 bool published, std::vector< Member > const & members,
166 std::vector< rtl::OUString > const & annotations):
167 PublishableEntity(SORT_ENUM_TYPE, published, annotations),
168 members_(members)
169 { assert(!members.empty()); }
171 std::vector< Member > const & getMembers() const { return members_; }
173 private:
174 virtual SAL_DLLPRIVATE ~EnumTypeEntity() throw ();
176 std::vector< Member > members_;
179 class LO_DLLPUBLIC_UNOIDL PlainStructTypeEntity: public PublishableEntity {
180 public:
181 struct Member {
182 Member(rtl::OUString const & theName, rtl::OUString const & theType,
183 std::vector< rtl::OUString > const & theAnnotations):
184 name(theName), type(theType), annotations(theAnnotations)
187 rtl::OUString name;
189 rtl::OUString type;
191 std::vector< rtl::OUString > annotations;
194 SAL_DLLPRIVATE PlainStructTypeEntity(
195 bool published, rtl::OUString const & directBase,
196 std::vector< Member > const & directMembers,
197 std::vector< rtl::OUString > const & annotations):
198 PublishableEntity(SORT_PLAIN_STRUCT_TYPE, published, annotations),
199 directBase_(directBase), directMembers_(directMembers)
202 rtl::OUString getDirectBase() const { return directBase_; }
204 std::vector< Member > const & getDirectMembers() const
205 { return directMembers_; }
207 private:
208 virtual SAL_DLLPRIVATE ~PlainStructTypeEntity() throw ();
210 rtl::OUString directBase_;
211 std::vector< Member > directMembers_;
214 class LO_DLLPUBLIC_UNOIDL PolymorphicStructTypeTemplateEntity:
215 public PublishableEntity
217 public:
218 struct Member {
219 Member(
220 rtl::OUString const & theName, rtl::OUString const & theType,
221 bool theParameterized,
222 std::vector< rtl::OUString > const & theAnnotations):
223 name(theName), type(theType), parameterized(theParameterized),
224 annotations(theAnnotations)
227 rtl::OUString name;
229 rtl::OUString type;
231 bool parameterized;
233 std::vector< rtl::OUString > annotations;
236 SAL_DLLPRIVATE PolymorphicStructTypeTemplateEntity(
237 bool published, std::vector< rtl::OUString > const & typeParameters,
238 std::vector< Member > const & members,
239 std::vector< rtl::OUString > const & annotations):
240 PublishableEntity(
241 SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE, published, annotations),
242 typeParameters_(typeParameters), members_(members)
245 std::vector< rtl::OUString > const & getTypeParameters() const
246 { return typeParameters_; }
248 std::vector< Member > const & getMembers() const { return members_; }
250 private:
251 virtual SAL_DLLPRIVATE ~PolymorphicStructTypeTemplateEntity() throw ();
253 std::vector< rtl::OUString > typeParameters_;
254 std::vector< Member > members_;
257 class LO_DLLPUBLIC_UNOIDL ExceptionTypeEntity: public PublishableEntity {
258 public:
259 struct Member {
260 Member(
261 rtl::OUString const & theName, rtl::OUString const & theType,
262 std::vector< rtl::OUString > const & theAnnotations):
263 name(theName), type(theType), annotations(theAnnotations)
266 rtl::OUString name;
268 rtl::OUString type;
270 std::vector< rtl::OUString > annotations;
273 SAL_DLLPRIVATE ExceptionTypeEntity(
274 bool published, rtl::OUString const & directBase,
275 std::vector< Member > const & directMembers,
276 std::vector< rtl::OUString > const & annotations):
277 PublishableEntity(SORT_EXCEPTION_TYPE, published, annotations),
278 directBase_(directBase), directMembers_(directMembers)
281 rtl::OUString getDirectBase() const { return directBase_; }
283 std::vector< Member > const & getDirectMembers() const
284 { return directMembers_; }
286 private:
287 virtual SAL_DLLPRIVATE ~ExceptionTypeEntity() throw ();
289 rtl::OUString directBase_;
290 std::vector< Member > directMembers_;
293 class LO_DLLPUBLIC_UNOIDL InterfaceTypeEntity: public PublishableEntity {
294 public:
295 struct Attribute {
296 Attribute(
297 rtl::OUString const & theName, rtl::OUString const & theType,
298 bool theBound, bool theReadOnly,
299 std::vector< rtl::OUString > const & theGetExceptions,
300 std::vector< rtl::OUString > const & theSetExceptions,
301 std::vector< rtl::OUString > const & theAnnotations):
302 name(theName), type(theType), bound(theBound),
303 readOnly(theReadOnly), getExceptions(theGetExceptions),
304 setExceptions(theSetExceptions), annotations(theAnnotations)
305 { assert(!theReadOnly || theSetExceptions.empty()); }
307 rtl::OUString name;
309 rtl::OUString type;
311 bool bound;
313 bool readOnly;
315 std::vector< rtl::OUString > getExceptions;
317 std::vector< rtl::OUString > setExceptions;
319 std::vector< rtl::OUString > annotations;
322 struct Method {
323 struct Parameter {
324 enum Direction { DIRECTION_IN, DIRECTION_OUT, DIRECTION_IN_OUT };
326 Parameter(
327 rtl::OUString const & theName, rtl::OUString const & theType,
328 Direction theDirection):
329 name(theName), type(theType), direction(theDirection)
332 rtl::OUString name;
334 rtl::OUString type;
336 Direction direction;
339 Method(
340 rtl::OUString const & theName, rtl::OUString const & theReturnType,
341 std::vector< Parameter > const & theParameters,
342 std::vector< rtl::OUString > const & theExceptions,
343 std::vector< rtl::OUString > const & theAnnotations):
344 name(theName), returnType(theReturnType), parameters(theParameters),
345 exceptions(theExceptions), annotations(theAnnotations)
348 rtl::OUString name;
350 rtl::OUString returnType;
352 std::vector< Parameter > parameters;
354 std::vector< rtl::OUString > exceptions;
356 std::vector< rtl::OUString > annotations;
359 SAL_DLLPRIVATE InterfaceTypeEntity(
360 bool published,
361 std::vector< AnnotatedReference > const & directMandatoryBases,
362 std::vector< AnnotatedReference > const & directOptionalBases,
363 std::vector< Attribute > const & directAttributes,
364 std::vector< Method > const & directMethods,
365 std::vector< rtl::OUString > const & annotations):
366 PublishableEntity(SORT_INTERFACE_TYPE, published, annotations),
367 directMandatoryBases_(directMandatoryBases),
368 directOptionalBases_(directOptionalBases),
369 directAttributes_(directAttributes), directMethods_(directMethods)
372 std::vector< AnnotatedReference > const & getDirectMandatoryBases() const
373 { return directMandatoryBases_; }
375 std::vector< AnnotatedReference > const & getDirectOptionalBases() const
376 { return directOptionalBases_; }
378 std::vector< Attribute > const & getDirectAttributes() const
379 { return directAttributes_; }
381 std::vector< Method > const & getDirectMethods() const
382 { return directMethods_; }
384 private:
385 virtual SAL_DLLPRIVATE ~InterfaceTypeEntity() throw ();
387 std::vector< AnnotatedReference > directMandatoryBases_;
388 std::vector< AnnotatedReference > directOptionalBases_;
389 std::vector< Attribute > directAttributes_;
390 std::vector< Method > directMethods_;
393 class LO_DLLPUBLIC_UNOIDL TypedefEntity: public PublishableEntity {
394 public:
395 SAL_DLLPRIVATE TypedefEntity(
396 bool published, rtl::OUString const & type,
397 std::vector< rtl::OUString > const & annotations):
398 PublishableEntity(SORT_TYPEDEF, published, annotations), type_(type)
401 rtl::OUString getType() const { return type_; }
403 private:
404 virtual SAL_DLLPRIVATE ~TypedefEntity() throw ();
406 rtl::OUString type_;
409 struct LO_DLLPUBLIC_UNOIDL ConstantValue {
410 enum Type {
411 TYPE_BOOLEAN, TYPE_BYTE, TYPE_SHORT, TYPE_UNSIGNED_SHORT, TYPE_LONG,
412 TYPE_UNSIGNED_LONG, TYPE_HYPER, TYPE_UNSIGNED_HYPER, TYPE_FLOAT,
413 TYPE_DOUBLE };
415 ConstantValue(bool value): type(TYPE_BOOLEAN), booleanValue(value) {}
417 ConstantValue(sal_Int8 value): type(TYPE_BYTE), byteValue(value) {}
419 ConstantValue(sal_Int16 value): type(TYPE_SHORT), shortValue(value) {}
421 ConstantValue(sal_uInt16 value):
422 type(TYPE_UNSIGNED_SHORT), unsignedShortValue(value)
425 ConstantValue(sal_Int32 value): type(TYPE_LONG), longValue(value) {}
427 ConstantValue(sal_uInt32 value):
428 type(TYPE_UNSIGNED_LONG), unsignedLongValue(value)
431 ConstantValue(sal_Int64 value): type(TYPE_HYPER), hyperValue(value) {}
433 ConstantValue(sal_uInt64 value):
434 type(TYPE_UNSIGNED_HYPER), unsignedHyperValue(value)
437 ConstantValue(float value): type(TYPE_FLOAT), floatValue(value) {}
439 ConstantValue(double value): type(TYPE_DOUBLE), doubleValue(value) {}
441 Type type;
443 union {
444 bool booleanValue;
445 sal_Int8 byteValue;
446 sal_Int16 shortValue;
447 sal_uInt16 unsignedShortValue;
448 sal_Int32 longValue;
449 sal_uInt32 unsignedLongValue;
450 sal_Int64 hyperValue;
451 sal_uInt64 unsignedHyperValue;
452 float floatValue;
453 double doubleValue;
457 class LO_DLLPUBLIC_UNOIDL ConstantGroupEntity: public PublishableEntity {
458 public:
459 struct Member {
460 Member(
461 rtl::OUString const & theName, ConstantValue const & theValue,
462 std::vector< rtl::OUString > const & theAnnotations):
463 name(theName), value(theValue), annotations(theAnnotations)
466 rtl::OUString name;
468 ConstantValue value;
470 std::vector< rtl::OUString > annotations;
473 SAL_DLLPRIVATE ConstantGroupEntity(
474 bool published, std::vector< Member > const & members,
475 std::vector< rtl::OUString > const & annotations):
476 PublishableEntity(SORT_CONSTANT_GROUP, published, annotations),
477 members_(members)
480 std::vector< Member > const & getMembers() const { return members_; }
482 private:
483 virtual SAL_DLLPRIVATE ~ConstantGroupEntity() throw ();
485 std::vector< Member > members_;
488 class LO_DLLPUBLIC_UNOIDL SingleInterfaceBasedServiceEntity:
489 public PublishableEntity
491 public:
492 struct Constructor {
493 struct Parameter {
494 Parameter(
495 rtl::OUString const & theName, rtl::OUString const & theType,
496 bool theRest):
497 name(theName), type(theType), rest(theRest)
500 rtl::OUString name;
502 rtl::OUString type;
504 bool rest;
507 Constructor(): defaultConstructor(true) {}
509 Constructor(
510 rtl::OUString const & theName,
511 std::vector< Parameter > const & theParameters,
512 std::vector< rtl::OUString > const & theExceptions,
513 std::vector< rtl::OUString > const & theAnnotations):
514 name(theName), parameters(theParameters), exceptions(theExceptions),
515 annotations(theAnnotations), defaultConstructor(false)
518 rtl::OUString name;
520 std::vector< Parameter > parameters;
522 std::vector< rtl::OUString > exceptions;
524 std::vector< rtl::OUString > annotations;
526 bool defaultConstructor;
529 SAL_DLLPRIVATE SingleInterfaceBasedServiceEntity(
530 bool published, rtl::OUString const & base,
531 std::vector< Constructor > const & constructors,
532 std::vector< rtl::OUString > const & annotations):
533 PublishableEntity(
534 SORT_SINGLE_INTERFACE_BASED_SERVICE, published, annotations),
535 base_(base), constructors_(constructors)
538 rtl::OUString getBase() const { return base_; }
540 std::vector< Constructor > const & getConstructors() const
541 { return constructors_; }
543 private:
544 virtual SAL_DLLPRIVATE ~SingleInterfaceBasedServiceEntity() throw ();
546 rtl::OUString base_;
547 std::vector< Constructor > constructors_;
550 class LO_DLLPUBLIC_UNOIDL AccumulationBasedServiceEntity:
551 public PublishableEntity
553 public:
554 struct Property {
555 enum Attributes {
556 ATTRIBUTE_MAYBE_VOID = 0x001,
557 ATTRIBUTE_BOUND = 0x002,
558 ATTRIBUTE_CONSTRAINED = 0x004,
559 ATTRIBUTE_TRANSIENT = 0x008,
560 ATTRIBUTE_READ_ONLY = 0x010,
561 ATTRIBUTE_MAYBE_AMBIGUOUS = 0x020,
562 ATTRIBUTE_MAYBE_DEFAULT = 0x040,
563 ATTRIBUTE_REMOVABLE = 0x080,
564 ATTRIBUTE_OPTIONAL = 0x100
567 Property(
568 rtl::OUString const & theName, rtl::OUString const & theType,
569 Attributes theAttributes,
570 std::vector< rtl::OUString > const & theAnnotations):
571 name(theName), type(theType), attributes(theAttributes),
572 annotations(theAnnotations)
575 rtl::OUString name;
577 rtl::OUString type;
579 Attributes attributes;
581 std::vector< rtl::OUString > annotations;
584 SAL_DLLPRIVATE AccumulationBasedServiceEntity(
585 bool published,
586 std::vector< AnnotatedReference > const & directMandatoryBaseServices,
587 std::vector< AnnotatedReference > const & directOptionalBaseServices,
588 std::vector< AnnotatedReference > const & directMandatoryBaseInterfaces,
589 std::vector< AnnotatedReference > const & directOptionalBaseInterfaces,
590 std::vector< Property > const & directProperties,
591 std::vector< rtl::OUString > const & annotations):
592 PublishableEntity(
593 SORT_ACCUMULATION_BASED_SERVICE, published, annotations),
594 directMandatoryBaseServices_(directMandatoryBaseServices),
595 directOptionalBaseServices_(directOptionalBaseServices),
596 directMandatoryBaseInterfaces_(directMandatoryBaseInterfaces),
597 directOptionalBaseInterfaces_(directOptionalBaseInterfaces),
598 directProperties_(directProperties)
601 std::vector< AnnotatedReference > const & getDirectMandatoryBaseServices()
602 const
603 { return directMandatoryBaseServices_; }
605 std::vector< AnnotatedReference > const & getDirectOptionalBaseServices()
606 const
607 { return directOptionalBaseServices_; }
609 std::vector< AnnotatedReference > const & getDirectMandatoryBaseInterfaces()
610 const
611 { return directMandatoryBaseInterfaces_; }
613 std::vector< AnnotatedReference > const & getDirectOptionalBaseInterfaces()
614 const
615 { return directOptionalBaseInterfaces_; }
617 std::vector< Property > const & getDirectProperties() const
618 { return directProperties_; }
620 private:
621 virtual SAL_DLLPRIVATE ~AccumulationBasedServiceEntity() throw ();
623 std::vector< AnnotatedReference > directMandatoryBaseServices_;
624 std::vector< AnnotatedReference > directOptionalBaseServices_;
625 std::vector< AnnotatedReference > directMandatoryBaseInterfaces_;
626 std::vector< AnnotatedReference > directOptionalBaseInterfaces_;
627 std::vector< Property > directProperties_;
630 class LO_DLLPUBLIC_UNOIDL InterfaceBasedSingletonEntity:
631 public PublishableEntity
633 public:
634 SAL_DLLPRIVATE InterfaceBasedSingletonEntity(
635 bool published, rtl::OUString const & base,
636 std::vector< rtl::OUString > const & annotations):
637 PublishableEntity(
638 SORT_INTERFACE_BASED_SINGLETON, published, annotations),
639 base_(base)
642 rtl::OUString getBase() const { return base_; }
644 private:
645 virtual SAL_DLLPRIVATE ~InterfaceBasedSingletonEntity() throw ();
647 rtl::OUString base_;
650 class LO_DLLPUBLIC_UNOIDL ServiceBasedSingletonEntity: public PublishableEntity
652 public:
653 SAL_DLLPRIVATE ServiceBasedSingletonEntity(
654 bool published, rtl::OUString const & base,
655 std::vector< rtl::OUString > const & annotations):
656 PublishableEntity(SORT_SERVICE_BASED_SINGLETON, published, annotations),
657 base_(base)
660 rtl::OUString getBase() const { return base_; }
662 private:
663 virtual SAL_DLLPRIVATE ~ServiceBasedSingletonEntity() throw ();
665 rtl::OUString base_;
668 class LO_DLLPUBLIC_UNOIDL Provider: public salhelper::SimpleReferenceObject {
669 public:
670 // throws FileFormatException:
671 virtual rtl::Reference< MapCursor > createRootCursor() const = 0;
673 // throws FileFormatException:
674 virtual rtl::Reference< Entity > findEntity(rtl::OUString const & name)
675 const = 0;
677 protected:
678 SAL_DLLPRIVATE Provider() {}
680 virtual SAL_DLLPRIVATE ~Provider() throw ();
683 class LO_DLLPUBLIC_UNOIDL Manager: public salhelper::SimpleReferenceObject {
684 public:
685 Manager() {}
687 // throws FileFormatException, NoSuchFileException:
688 rtl::Reference< Provider > addProvider(rtl::OUString const & uri);
690 // throws FileFormatException:
691 rtl::Reference< Entity > findEntity(rtl::OUString const & name) const;
693 // throws FileFormatException:
694 rtl::Reference< MapCursor > createCursor(rtl::OUString const & name) const;
696 private:
697 virtual SAL_DLLPRIVATE ~Manager() throw ();
699 SAL_DLLPRIVATE rtl::Reference< Provider > loadProvider(
700 rtl::OUString const & uri);
702 mutable osl::Mutex mutex_;
703 std::vector< rtl::Reference< Provider > > providers_;
708 #endif
710 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */