Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_registry_reader_hxx
21 : #define INCLUDED_registry_reader_hxx
22 :
23 : #include "registry/reader.h"
24 : #include "registry/refltype.hxx"
25 : #include "registry/types.h"
26 : #include "registry/version.h"
27 :
28 : #include "rtl/ustring.hxx"
29 : #include "sal/types.h"
30 :
31 : #include <algorithm>
32 : #include <new>
33 :
34 : namespace typereg {
35 :
36 : /**
37 : A type reader working on a binary blob that represents a UNOIDL type.
38 :
39 : <p>Instances of this class are not multi-thread–safe.</p>
40 :
41 : @since UDK 3.2.0
42 : */
43 : class Reader {
44 : public:
45 : /**
46 : Creates an invalid type reader.
47 : */
48 177197 : Reader(): m_handle(0) {}
49 :
50 : /**
51 : Creates a type reader.
52 :
53 : <p>If the given binary blob is malformed, or of a version larger than
54 : <code>maxVersion</code>, the created type reader is flagged as
55 : invalid.</p>
56 :
57 : @param buffer the binary blob representing the type; must point to at
58 : least <code>length</code> bytes, and need only be byte-aligned
59 :
60 : @param length the size in bytes of the binary blob representing the type
61 :
62 : @param copy if true, the type reader creates an internal copy of the
63 : given buffer, and the given buffer is not accessed after this constructor
64 : returns; if false, the type reader works directly on the given buffer,
65 : which must remain available unmodified until the underlying type reader
66 : is destroyed (note that the lifetime of the underlying type reader can be
67 : different from the lifetime of this <code>Reader</code> instance)
68 :
69 : @param maxVersion the maximum binary blob version the client is prepared
70 : to handle; must not be negative
71 :
72 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
73 : */
74 61495 : Reader(
75 : void const * buffer, sal_uInt32 length, bool copy,
76 : typereg_Version maxVersion)
77 : {
78 61495 : if (!typereg_reader_create(buffer, length, copy, maxVersion, &m_handle))
79 : {
80 0 : throw std::bad_alloc();
81 : }
82 61495 : }
83 :
84 : /**
85 : Shares a type reader between two <code>Reader</code> instances.
86 :
87 : @param other another <code>Reader</code> instance
88 : */
89 54012 : Reader(Reader const & other): m_handle(other.m_handle) {
90 54012 : typereg_reader_acquire(m_handle);
91 54012 : }
92 :
93 : /**
94 : Destroys this <code>Reader</code> instance.
95 :
96 : <p>The underlying type reader is only destroyed if this instance was its
97 : last user.</p>
98 : */
99 292704 : ~Reader() {
100 292704 : typereg_reader_release(m_handle);
101 292704 : }
102 :
103 : /**
104 : Replaces the underlying type reader.
105 :
106 : @param other any <code>Reader</code> instance
107 :
108 : @return this <code>Reader</code> instance
109 : */
110 43568 : Reader & operator =(Reader const & other) {
111 43568 : Reader temp(other);
112 43568 : std::swap(this->m_handle, temp.m_handle);
113 43568 : return *this;
114 : }
115 :
116 : /**
117 : Returns whether this type reader is valid.
118 :
119 : @return true iff this type reader is valid
120 : */
121 34801 : bool isValid() const {
122 34801 : return m_handle != 0;
123 : }
124 :
125 : /**
126 : Returns the binary blob version of this type reader.
127 :
128 : @return the version of the binary blob from which this type reader was
129 : constructed; if this type reader is invalid,
130 : <code>TYPEREG_VERSION_0</code> is returned
131 : */
132 0 : typereg_Version getVersion() const {
133 0 : return typereg_reader_getVersion(m_handle);
134 : }
135 :
136 : /**
137 : Returns the documentation of this type reader.
138 :
139 : @return the documentation of this type reader; if this type reader is
140 : invalid, an empty string is returned
141 :
142 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
143 : */
144 3731 : rtl::OUString getDocumentation() const {
145 3731 : rtl_uString * s = 0;
146 3731 : typereg_reader_getDocumentation(m_handle, &s);
147 3731 : if (s == 0) {
148 0 : throw std::bad_alloc();
149 : }
150 3731 : return rtl::OUString(s, SAL_NO_ACQUIRE);
151 : }
152 :
153 : /**
154 : Returns the file name of this type reader.
155 :
156 : @return the file name of this type reader; if this type reader is
157 : invalid, an empty string is returned
158 :
159 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
160 : @deprecated
161 : */
162 0 : rtl::OUString getFileName() const {
163 0 : rtl_uString * s = 0;
164 0 : typereg_reader_getFileName(m_handle, &s);
165 0 : if (s == 0) {
166 0 : throw std::bad_alloc();
167 : }
168 0 : return rtl::OUString(s, SAL_NO_ACQUIRE);
169 : }
170 :
171 : /**
172 : Returns the type class of this type reader.
173 :
174 : <p>This function will always return the type class without the internal
175 : <code>RT_TYPE_PUBLISHED</code> flag set. Use <code>isPublished</code> to
176 : determine whether this type reader is published.</p>
177 :
178 : @return the type class of this type reader; if this type reader is
179 : invalid, <code>RT_TYPE_INVALID</code> is returned
180 : */
181 49463 : RTTypeClass getTypeClass() const {
182 49463 : return typereg_reader_getTypeClass(m_handle);
183 : }
184 :
185 : /**
186 : Returns whether this type reader is published.
187 :
188 : @return whether this type reader is published; if this type reader is
189 : invalid, <code>false</code> is returned
190 : */
191 4165 : bool isPublished() const {
192 4165 : return typereg_reader_isPublished(m_handle);
193 : }
194 :
195 : /**
196 : Returns the type name of this type reader.
197 :
198 : @return the type name of this type reader; if this type reader is
199 : invalid, an empty string is returned
200 :
201 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
202 : */
203 10717 : rtl::OUString getTypeName() const {
204 10717 : rtl_uString * s = 0;
205 10717 : typereg_reader_getTypeName(m_handle, &s);
206 10717 : if (s == 0) {
207 0 : throw std::bad_alloc();
208 : }
209 10717 : return rtl::OUString(s, SAL_NO_ACQUIRE);
210 : }
211 :
212 : /**
213 : Returns the number of super types of this type reader.
214 :
215 : @return the number of super types of this type reader; if this type
216 : reader is invalid, zero is returned
217 : */
218 55118 : sal_uInt16 getSuperTypeCount() const {
219 55118 : return typereg_reader_getSuperTypeCount(m_handle);
220 : }
221 :
222 : /**
223 : Returns the type name of a super type of this type reader.
224 :
225 : @param index a valid index into the range of super types of this type
226 : reader
227 :
228 : @return the type name of the given super type
229 :
230 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
231 : */
232 27409 : rtl::OUString getSuperTypeName(sal_uInt16 index) const {
233 27409 : rtl_uString * s = 0;
234 27409 : typereg_reader_getSuperTypeName(m_handle, &s, index);
235 27409 : if (s == 0) {
236 0 : throw std::bad_alloc();
237 : }
238 27409 : return rtl::OUString(s, SAL_NO_ACQUIRE);
239 : }
240 :
241 : /**
242 : Returns the number of fields of this type reader.
243 :
244 : @return the number of fields of this type reader; if this type reader is
245 : invalid, zero is returned
246 : */
247 71393 : sal_uInt16 getFieldCount() const {
248 71393 : return typereg_reader_getFieldCount(m_handle);
249 : }
250 :
251 : /**
252 : Returns the documentation of a field of this type reader.
253 :
254 : @param index a valid index into the range of fields of this type reader
255 :
256 : @return the documentation of the given field
257 :
258 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
259 : */
260 1622 : rtl::OUString getFieldDocumentation(sal_uInt16 index) const {
261 1622 : rtl_uString * s = 0;
262 1622 : typereg_reader_getFieldDocumentation(m_handle, &s, index);
263 1622 : if (s == 0) {
264 0 : throw std::bad_alloc();
265 : }
266 1622 : return rtl::OUString(s, SAL_NO_ACQUIRE);
267 : }
268 :
269 : /**
270 : Returns the file name of a field of this type reader.
271 :
272 : @param index a valid index into the range of fields of this type reader
273 :
274 : @return the file name of the given field
275 :
276 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
277 : @deprecated
278 : */
279 0 : rtl::OUString getFieldFileName(sal_uInt16 index) const {
280 0 : rtl_uString * s = 0;
281 0 : typereg_reader_getFieldFileName(m_handle, &s, index);
282 0 : if (s == 0) {
283 0 : throw std::bad_alloc();
284 : }
285 0 : return rtl::OUString(s, SAL_NO_ACQUIRE);
286 : }
287 :
288 : /**
289 : Returns the flags of a field of this type reader.
290 :
291 : @param index a valid index into the range of fields of this type reader
292 :
293 : @return the flags of the given field
294 : */
295 73808 : RTFieldAccess getFieldFlags(sal_uInt16 index) const {
296 73808 : return typereg_reader_getFieldFlags(m_handle, index);
297 : }
298 :
299 : /**
300 : Returns the name of a field of this type reader.
301 :
302 : @param index a valid index into the range of fields of this type reader
303 :
304 : @return the name of the given field
305 :
306 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
307 : */
308 67329 : rtl::OUString getFieldName(sal_uInt16 index) const {
309 67329 : rtl_uString * s = 0;
310 67329 : typereg_reader_getFieldName(m_handle, &s, index);
311 67329 : if (s == 0) {
312 0 : throw std::bad_alloc();
313 : }
314 67329 : return rtl::OUString(s, SAL_NO_ACQUIRE);
315 : }
316 :
317 : /**
318 : Returns the type name of a field of this type reader.
319 :
320 : @param index a valid index into the range of fields of this type reader
321 :
322 : @return the type name of the given field
323 :
324 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
325 : */
326 82019 : rtl::OUString getFieldTypeName(sal_uInt16 index) const {
327 82019 : rtl_uString * s = 0;
328 82019 : typereg_reader_getFieldTypeName(m_handle, &s, index);
329 82019 : if (s == 0) {
330 0 : throw std::bad_alloc();
331 : }
332 82019 : return rtl::OUString(s, SAL_NO_ACQUIRE);
333 : }
334 :
335 : /**
336 : Returns the value of a field of this type reader.
337 :
338 : @param index a valid index into the range of fields of this type reader
339 :
340 : @return the value of the given field
341 :
342 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
343 : */
344 30199 : RTConstValue getFieldValue(sal_uInt16 index) const {
345 30199 : RTConstValue v;
346 30199 : if (!typereg_reader_getFieldValue(
347 30199 : m_handle, index, &v.m_type, &v.m_value))
348 : {
349 0 : throw std::bad_alloc();
350 : }
351 30199 : return v;
352 : }
353 :
354 : /**
355 : Returns the number of methods of this type reader.
356 :
357 : @return the number of methods of this type reader; if this type reader is
358 : invalid, zero is returned
359 : */
360 68151 : sal_uInt16 getMethodCount() const {
361 68151 : return typereg_reader_getMethodCount(m_handle);
362 : }
363 :
364 : /**
365 : Returns the documentation of a method of this type reader.
366 :
367 : @param index a valid index into the range of methods of this type reader
368 :
369 : @return the documentation of the given method
370 :
371 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
372 : */
373 11711 : rtl::OUString getMethodDocumentation(sal_uInt16 index) const {
374 11711 : rtl_uString * s = 0;
375 11711 : typereg_reader_getMethodDocumentation(m_handle, &s, index);
376 11711 : if (s == 0) {
377 0 : throw std::bad_alloc();
378 : }
379 11711 : return rtl::OUString(s, SAL_NO_ACQUIRE);
380 : }
381 :
382 : /**
383 : Returns the flags of a method of this type reader.
384 :
385 : @param index a valid index into the range of methods of this type reader
386 :
387 : @return the flags of the given method
388 : */
389 115908 : RTMethodMode getMethodFlags(sal_uInt16 index) const {
390 115908 : return typereg_reader_getMethodFlags(m_handle, index);
391 : }
392 :
393 : /**
394 : Returns the name of a method of this type reader.
395 :
396 : @param index a valid index into the range of methods of this type reader
397 :
398 : @return the name of the given method
399 :
400 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
401 : */
402 67819 : rtl::OUString getMethodName(sal_uInt16 index) const {
403 67819 : rtl_uString * s = 0;
404 67819 : typereg_reader_getMethodName(m_handle, &s, index);
405 67819 : if (s == 0) {
406 0 : throw std::bad_alloc();
407 : }
408 67819 : return rtl::OUString(s, SAL_NO_ACQUIRE);
409 : }
410 :
411 : /**
412 : Returns the return type name of a method of this type reader.
413 :
414 : @param index a valid index into the range of methods of this type reader
415 :
416 : @return the return type name of the given method
417 :
418 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
419 : */
420 54140 : rtl::OUString getMethodReturnTypeName(sal_uInt16 index) const {
421 54140 : rtl_uString * s = 0;
422 54140 : typereg_reader_getMethodReturnTypeName(m_handle, &s, index);
423 54140 : if (s == 0) {
424 0 : throw std::bad_alloc();
425 : }
426 54140 : return rtl::OUString(s, SAL_NO_ACQUIRE);
427 : }
428 :
429 : /**
430 : Returns the number of parameters of a method of this type reader.
431 :
432 : @param index a valid index into the range of methods of this type reader
433 :
434 : @return the number of parameters of the given method
435 : */
436 66159 : sal_uInt16 getMethodParameterCount(sal_uInt16 index) const {
437 66159 : return typereg_reader_getMethodParameterCount(m_handle, index);
438 : }
439 :
440 : /**
441 : Returns the flags of a parameter of a method of this type reader.
442 :
443 : @param methodIndex a valid index into the range of methods of this type
444 : reader
445 :
446 : @param parameterIndex a valid index into the range of parameters of the
447 : given method
448 :
449 : @return the flags of the given method parameter
450 : */
451 41160 : RTParamMode getMethodParameterFlags(
452 : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
453 : {
454 : return typereg_reader_getMethodParameterFlags(
455 41160 : m_handle, methodIndex, parameterIndex);
456 : }
457 :
458 : /**
459 : Returns the name of a parameter of a method of this type reader.
460 :
461 : @param methodIndex a valid index into the range of methods of this type
462 : reader
463 :
464 : @param parameterIndex a valid index into the range of parameters of the
465 : given method
466 :
467 : @return the name of the given method parameter
468 :
469 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
470 : */
471 21922 : rtl::OUString getMethodParameterName(
472 : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
473 : {
474 21922 : rtl_uString * s = 0;
475 : typereg_reader_getMethodParameterName(
476 21922 : m_handle, &s, methodIndex, parameterIndex);
477 21922 : if (s == 0) {
478 0 : throw std::bad_alloc();
479 : }
480 21922 : return rtl::OUString(s, SAL_NO_ACQUIRE);
481 : }
482 :
483 : /**
484 : Returns the type name of a parameter of a method of this type reader.
485 :
486 : @param methodIndex a valid index into the range of methods of this type
487 : reader
488 :
489 : @param parameterIndex a valid index into the range of parameters of the
490 : given method
491 :
492 : @return the type name of the given method parameter
493 :
494 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
495 : */
496 47937 : rtl::OUString getMethodParameterTypeName(
497 : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
498 : {
499 47937 : rtl_uString * s = 0;
500 : typereg_reader_getMethodParameterTypeName(
501 47937 : m_handle, &s, methodIndex, parameterIndex);
502 47937 : if (s == 0) {
503 0 : throw std::bad_alloc();
504 : }
505 47937 : return rtl::OUString(s, SAL_NO_ACQUIRE);
506 : }
507 :
508 : /**
509 : Returns the number of exceptions of a method of this type reader.
510 :
511 : @param index a valid index into the range of methods of this type reader
512 :
513 : @return the number of exceptions of the given method
514 : */
515 40520 : sal_uInt16 getMethodExceptionCount(sal_uInt16 index) const {
516 40520 : return typereg_reader_getMethodExceptionCount(m_handle, index);
517 : }
518 :
519 : /**
520 : Returns the type name of an exception of a method of this type reader.
521 :
522 : @param methodIndex a valid index into the range of methods of this type
523 : reader
524 :
525 : @param exceptionIndex a valid index into the range of exceptions of the
526 : given method
527 :
528 : @return the type name of the given method exception
529 :
530 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
531 : */
532 16820 : rtl::OUString getMethodExceptionTypeName(
533 : sal_uInt16 methodIndex, sal_uInt16 exceptionIndex) const
534 : {
535 16820 : rtl_uString * s = 0;
536 : typereg_reader_getMethodExceptionTypeName(
537 16820 : m_handle, &s, methodIndex, exceptionIndex);
538 16820 : if (s == 0) {
539 0 : throw std::bad_alloc();
540 : }
541 16820 : return rtl::OUString(s, SAL_NO_ACQUIRE);
542 : }
543 :
544 : /**
545 : Returns the number of references of this type reader.
546 :
547 : @return the number of references of this type reader; if this type reader
548 : is invalid, zero is returned
549 : */
550 41180 : sal_uInt16 getReferenceCount() const {
551 41180 : return typereg_reader_getReferenceCount(m_handle);
552 : }
553 :
554 : /**
555 : Returns the documentation of a reference of this type reader.
556 :
557 : @param index a valid index into the range of references of this type
558 : reader
559 :
560 : @return the documentation of the given reference
561 :
562 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
563 : */
564 0 : rtl::OUString getReferenceDocumentation(sal_uInt16 index) const {
565 0 : rtl_uString * s = 0;
566 0 : typereg_reader_getReferenceDocumentation(m_handle, &s, index);
567 0 : if (s == 0) {
568 0 : throw std::bad_alloc();
569 : }
570 0 : return rtl::OUString(s, SAL_NO_ACQUIRE);
571 : }
572 :
573 : /**
574 : Returns the flags of a reference of this type reader.
575 :
576 : @param index a valid index into the range of references of this type
577 : reader
578 :
579 : @return the flags of the given reference
580 : */
581 199 : RTFieldAccess getReferenceFlags(sal_uInt16 index) const {
582 199 : return typereg_reader_getReferenceFlags(m_handle, index);
583 : }
584 :
585 : /**
586 : Returns the sort of a reference of this type reader.
587 :
588 : @param index a valid index into the range of references of this type
589 : reader
590 :
591 : @return the sort of the given reference
592 : */
593 5820 : RTReferenceType getReferenceSort(sal_uInt16 index) const {
594 5820 : return typereg_reader_getReferenceSort(m_handle, index);
595 : }
596 :
597 : /**
598 : Returns the type name of a reference of this type reader.
599 :
600 : @param index a valid index into the range of references of this type
601 : reader
602 :
603 : @return the type name of the given reference
604 :
605 : @exception std::bad_alloc is raised if an out-of-memory condition occurs
606 : */
607 6227 : rtl::OUString getReferenceTypeName(sal_uInt16 index) const {
608 6227 : rtl_uString * s = 0;
609 6227 : typereg_reader_getReferenceTypeName(m_handle, &s, index);
610 6227 : if (s == 0) {
611 0 : throw std::bad_alloc();
612 : }
613 6227 : return rtl::OUString(s, SAL_NO_ACQUIRE);
614 : }
615 :
616 : private:
617 : void * m_handle;
618 : };
619 :
620 : }
621 :
622 : #endif
623 :
624 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|