Branch data 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 : 357667 : 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 : 304310 : Reader(
75 : : void const * buffer, sal_uInt32 length, bool copy,
76 : : typereg_Version maxVersion)
77 : : {
78 [ - + ]: 304310 : if (!typereg_reader_create(buffer, length, copy, maxVersion, &m_handle))
79 : : {
80 : 0 : throw std::bad_alloc();
81 : : }
82 : 304310 : }
83 : :
84 : : /**
85 : : Shares a type reader between two <code>Reader</code> instances.
86 : :
87 : : @param other another <code>Reader</code> instance
88 : : */
89 : 108869 : Reader(Reader const & other): m_handle(other.m_handle) {
90 : 108869 : typereg_reader_acquire(m_handle);
91 : 108869 : }
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 : 770846 : ~Reader() {
100 : 770846 : typereg_reader_release(m_handle);
101 : 770846 : }
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 : 88115 : Reader & operator =(Reader const & other) {
111 : 88115 : Reader temp(other);
112 : 88115 : std::swap(this->m_handle, temp.m_handle);
113 : 88115 : 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 : 70172 : bool isValid() const {
122 : 70172 : 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 : 0 : rtl::OUString getDocumentation() const {
145 : 0 : rtl_uString * s = 0;
146 : 0 : typereg_reader_getDocumentation(m_handle, &s);
147 [ # # ]: 0 : if (s == 0) {
148 : 0 : throw std::bad_alloc();
149 : : }
150 : 0 : 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 : 163108 : RTTypeClass getTypeClass() const {
182 : 163108 : 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 : 65792 : bool isPublished() const {
192 : 65792 : 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 : 79005 : rtl::OUString getTypeName() const {
204 : 79005 : rtl_uString * s = 0;
205 : 79005 : typereg_reader_getTypeName(m_handle, &s);
206 [ - + ]: 79005 : if (s == 0) {
207 : 0 : throw std::bad_alloc();
208 : : }
209 : 79005 : 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 : 162682 : sal_uInt16 getSuperTypeCount() const {
219 : 162682 : 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 : 102109 : rtl::OUString getSuperTypeName(sal_uInt16 index) const {
233 : 102109 : rtl_uString * s = 0;
234 : 102109 : typereg_reader_getSuperTypeName(m_handle, &s, index);
235 [ - + ]: 102109 : if (s == 0) {
236 : 0 : throw std::bad_alloc();
237 : : }
238 : 102109 : 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 : 206115 : sal_uInt16 getFieldCount() const {
248 : 206115 : 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 : 0 : rtl::OUString getFieldDocumentation(sal_uInt16 index) const {
261 : 0 : rtl_uString * s = 0;
262 : 0 : typereg_reader_getFieldDocumentation(m_handle, &s, index);
263 [ # # ]: 0 : if (s == 0) {
264 : 0 : throw std::bad_alloc();
265 : : }
266 : 0 : 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 : 206987 : RTFieldAccess getFieldFlags(sal_uInt16 index) const {
296 : 206987 : 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 : 230887 : rtl::OUString getFieldName(sal_uInt16 index) const {
309 : 230887 : rtl_uString * s = 0;
310 : 230887 : typereg_reader_getFieldName(m_handle, &s, index);
311 [ - + ]: 230887 : if (s == 0) {
312 : 0 : throw std::bad_alloc();
313 : : }
314 : 230887 : 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 : 221785 : rtl::OUString getFieldTypeName(sal_uInt16 index) const {
327 : 221785 : rtl_uString * s = 0;
328 : 221785 : typereg_reader_getFieldTypeName(m_handle, &s, index);
329 [ - + ]: 221785 : if (s == 0) {
330 : 0 : throw std::bad_alloc();
331 : : }
332 : 221785 : 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 : 98639 : RTConstValue getFieldValue(sal_uInt16 index) const {
345 : 98639 : RTConstValue v;
346 [ - + ]: 98639 : if (!typereg_reader_getFieldValue(
347 : 98639 : m_handle, index, &v.m_type, &v.m_value))
348 : : {
349 : 0 : throw std::bad_alloc();
350 : : }
351 : 98639 : 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 : 177459 : sal_uInt16 getMethodCount() const {
361 : 177459 : 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 : 0 : rtl::OUString getMethodDocumentation(sal_uInt16 index) const {
374 : 0 : rtl_uString * s = 0;
375 : 0 : typereg_reader_getMethodDocumentation(m_handle, &s, index);
376 [ # # ]: 0 : if (s == 0) {
377 : 0 : throw std::bad_alloc();
378 : : }
379 : 0 : 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 : 536936 : RTMethodMode getMethodFlags(sal_uInt16 index) const {
390 : 536936 : 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 : 327644 : rtl::OUString getMethodName(sal_uInt16 index) const {
403 : 327644 : rtl_uString * s = 0;
404 : 327644 : typereg_reader_getMethodName(m_handle, &s, index);
405 [ - + ]: 327644 : if (s == 0) {
406 : 0 : throw std::bad_alloc();
407 : : }
408 : 327644 : 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 : 256570 : rtl::OUString getMethodReturnTypeName(sal_uInt16 index) const {
421 : 256570 : rtl_uString * s = 0;
422 : 256570 : typereg_reader_getMethodReturnTypeName(m_handle, &s, index);
423 [ - + ]: 256570 : if (s == 0) {
424 : 0 : throw std::bad_alloc();
425 : : }
426 : 256570 : 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 : 158634 : sal_uInt16 getMethodParameterCount(sal_uInt16 index) const {
437 : 158634 : 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 : 106251 : RTParamMode getMethodParameterFlags(
452 : : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
453 : : {
454 : : return typereg_reader_getMethodParameterFlags(
455 : 106251 : 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 : 67476 : rtl::OUString getMethodParameterName(
472 : : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
473 : : {
474 : 67476 : rtl_uString * s = 0;
475 : : typereg_reader_getMethodParameterName(
476 : 67476 : m_handle, &s, methodIndex, parameterIndex);
477 [ - + ]: 67476 : if (s == 0) {
478 : 0 : throw std::bad_alloc();
479 : : }
480 : 67476 : 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 : 120001 : rtl::OUString getMethodParameterTypeName(
497 : : sal_uInt16 methodIndex, sal_uInt16 parameterIndex) const
498 : : {
499 : 120001 : rtl_uString * s = 0;
500 : : typereg_reader_getMethodParameterTypeName(
501 : 120001 : m_handle, &s, methodIndex, parameterIndex);
502 [ - + ]: 120001 : if (s == 0) {
503 : 0 : throw std::bad_alloc();
504 : : }
505 : 120001 : 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 : 132641 : sal_uInt16 getMethodExceptionCount(sal_uInt16 index) const {
516 : 132641 : 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 : 61620 : rtl::OUString getMethodExceptionTypeName(
533 : : sal_uInt16 methodIndex, sal_uInt16 exceptionIndex) const
534 : : {
535 : 61620 : rtl_uString * s = 0;
536 : : typereg_reader_getMethodExceptionTypeName(
537 : 61620 : m_handle, &s, methodIndex, exceptionIndex);
538 [ - + ]: 61620 : if (s == 0) {
539 : 0 : throw std::bad_alloc();
540 : : }
541 : 61620 : 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 : 135920 : sal_uInt16 getReferenceCount() const {
551 : 135920 : 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 : 1175 : RTFieldAccess getReferenceFlags(sal_uInt16 index) const {
582 : 1175 : 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 : 12943 : RTReferenceType getReferenceSort(sal_uInt16 index) const {
594 : 12943 : 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 : 13498 : rtl::OUString getReferenceTypeName(sal_uInt16 index) const {
608 : 13498 : rtl_uString * s = 0;
609 : 13498 : typereg_reader_getReferenceTypeName(m_handle, &s, index);
610 [ - + ]: 13498 : if (s == 0) {
611 : 0 : throw std::bad_alloc();
612 : : }
613 : 13498 : 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: */
|