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 :
21 : #include <new>
22 : #include <sal/types.h>
23 : #include <sal/macros.h>
24 : #include <osl/endian.h>
25 : #include <rtl/alloc.h>
26 : #include "rtl/string.hxx"
27 : #include "rtl/ustring.hxx"
28 :
29 : #include "registry/reflwrit.hxx"
30 : #include "registry/version.h"
31 : #include "registry/writer.h"
32 :
33 : #include "reflcnst.hxx"
34 :
35 :
36 :
37 : namespace {
38 :
39 0 : inline OString toByteString(rtl_uString const * str) {
40 : return OString(
41 : str->buffer, str->length, RTL_TEXTENCODING_UTF8,
42 0 : OUSTRING_TO_OSTRING_CVTFLAGS);
43 : }
44 :
45 : }
46 :
47 : static sal_Unicode NULL_WSTRING[1] = { 0 };
48 :
49 : #define BLOP_OFFSET_MAGIC 0
50 : #define BLOP_OFFSET_SIZE (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32))
51 : #define BLOP_OFFSET_MINOR (BLOP_OFFSET_SIZE + sizeof(sal_uInt32))
52 : #define BLOP_OFFSET_MAJOR (BLOP_OFFSET_MINOR + sizeof(sal_uInt16))
53 : #define BLOP_OFFSET_N_ENTRIES (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16))
54 : #define BLOP_HEADER_N_ENTRIES 6
55 :
56 : #define BLOP_FIELD_N_ENTRIES 6
57 :
58 : #define BLOP_METHOD_N_ENTRIES 5
59 :
60 : #define BLOP_PARAM_N_ENTRIES 3
61 :
62 : #define BLOP_REFERENCE_N_ENTRIES 4
63 :
64 0 : sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
65 : {
66 0 : if (!wstring) return 0;
67 :
68 0 : const sal_uInt8* b = wstring;
69 :
70 0 : while (b[0] || b[1]) b += sizeof(sal_uInt16);
71 :
72 0 : return ((b - wstring) / sizeof(sal_uInt16));
73 : }
74 :
75 0 : sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
76 : {
77 0 : sal_uInt32 len = rtl_ustr_getLength(v) + 1;
78 : sal_uInt32 i;
79 0 : sal_uInt8* buff = buffer;
80 :
81 0 : for (i = 0; i < len; i++)
82 : {
83 0 : buff += writeUINT16(buff, (sal_uInt16) v[i]);
84 : }
85 :
86 0 : return (buff - buffer);
87 : }
88 :
89 0 : sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
90 : {
91 0 : sal_uInt32 len = UINT16StringLen(buffer) + 1;
92 : sal_uInt32 i;
93 0 : sal_uInt8* buff = (sal_uInt8*)buffer;
94 :
95 0 : if(len > maxSize / 2)
96 : {
97 0 : len = maxSize / 2;
98 : }
99 :
100 0 : for (i = 0; i < (len - 1); i++)
101 : {
102 : sal_uInt16 aChar;
103 :
104 0 : buff += readUINT16(buff, aChar);
105 :
106 0 : v[i] = (sal_Unicode) aChar;
107 : }
108 :
109 0 : v[len - 1] = L'\0';
110 :
111 0 : return (buff - ((sal_uInt8*)buffer));
112 : }
113 :
114 0 : sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
115 : {
116 : union
117 : {
118 : float v;
119 : sal_uInt32 b;
120 : } x;
121 :
122 0 : x.v = v;
123 :
124 : #ifdef REGTYPE_IEEE_NATIVE
125 0 : writeUINT32(buffer, x.b);
126 : #else
127 : # error no IEEE
128 : #endif
129 :
130 0 : return sizeof(sal_uInt32);
131 : }
132 :
133 0 : sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
134 : {
135 : union
136 : {
137 : double v;
138 : struct
139 : {
140 : sal_uInt32 b1;
141 : sal_uInt32 b2;
142 : } b;
143 : } x;
144 :
145 0 : x.v = v;
146 :
147 : #ifdef REGTYPE_IEEE_NATIVE
148 : # ifdef OSL_BIGENDIAN
149 : writeUINT32(buffer, x.b.b1);
150 : writeUINT32(buffer + sizeof(sal_uInt32), x.b.b2);
151 : # else
152 0 : writeUINT32(buffer, x.b.b2);
153 0 : writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
154 : # endif
155 : #else
156 : # error no IEEE
157 : #endif
158 :
159 0 : return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
160 : }
161 :
162 : /**************************************************************************
163 :
164 : buffer write functions
165 :
166 : **************************************************************************/
167 :
168 :
169 : /**************************************************************************
170 :
171 : struct CPInfo
172 :
173 : **************************************************************************/
174 :
175 : struct CPInfo
176 : {
177 : CPInfoTag m_tag;
178 : union
179 : {
180 : const sal_Char* aUtf8;
181 : RTUik* aUik;
182 : RTConstValueUnion aConst;
183 : } m_value;
184 :
185 : sal_uInt16 m_index;
186 : struct CPInfo* m_next;
187 :
188 : CPInfo(CPInfoTag tag, struct CPInfo* prev);
189 :
190 : sal_uInt32 getBlopSize();
191 :
192 : sal_uInt32 toBlop(sal_uInt8* buffer);
193 : };
194 :
195 0 : CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
196 : : m_tag(tag)
197 : , m_index(0)
198 0 : , m_next(NULL)
199 : {
200 0 : if (prev)
201 : {
202 0 : m_index = prev->m_index + 1;
203 0 : prev->m_next = this;
204 : }
205 0 : }
206 :
207 0 : sal_uInt32 CPInfo::getBlopSize()
208 : {
209 0 : sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
210 :
211 0 : switch (m_tag)
212 : {
213 : case CP_TAG_CONST_BOOL:
214 0 : size += sizeof(sal_uInt8);
215 0 : break;
216 : case CP_TAG_CONST_BYTE:
217 0 : size += sizeof(sal_uInt8);
218 0 : break;
219 : case CP_TAG_CONST_INT16:
220 0 : size += sizeof(sal_Int16);
221 0 : break;
222 : case CP_TAG_CONST_UINT16:
223 0 : size += sizeof(sal_uInt16);
224 0 : break;
225 : case CP_TAG_CONST_INT32:
226 0 : size += sizeof(sal_Int32);
227 0 : break;
228 : case CP_TAG_CONST_UINT32:
229 0 : size += sizeof(sal_uInt32);
230 0 : break;
231 : case CP_TAG_CONST_INT64:
232 0 : size += sizeof(sal_Int64);
233 0 : break;
234 : case CP_TAG_CONST_UINT64:
235 0 : size += sizeof(sal_uInt64);
236 0 : break;
237 : case CP_TAG_CONST_FLOAT:
238 0 : size += sizeof(sal_uInt32);
239 0 : break;
240 : case CP_TAG_CONST_DOUBLE:
241 0 : size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
242 0 : break;
243 : case CP_TAG_CONST_STRING:
244 0 : size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
245 0 : break;
246 : case CP_TAG_UTF8_NAME:
247 0 : size += strlen(m_value.aUtf8) + 1;
248 0 : break;
249 : case CP_TAG_UIK:
250 0 : size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
251 0 : break;
252 : default:
253 0 : break;
254 : }
255 :
256 0 : return size;
257 : }
258 :
259 :
260 0 : sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
261 : {
262 0 : sal_uInt8* buff = buffer;
263 :
264 0 : buff += writeUINT32(buff, getBlopSize());
265 0 : buff += writeUINT16(buff, (sal_uInt16) m_tag);
266 :
267 0 : switch (m_tag)
268 : {
269 : case CP_TAG_CONST_BOOL:
270 0 : buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool);
271 0 : break;
272 : case CP_TAG_CONST_BYTE:
273 : buff += writeBYTE(
274 0 : buff, static_cast< sal_uInt8 >(m_value.aConst.aByte));
275 0 : break;
276 : case CP_TAG_CONST_INT16:
277 0 : buff += writeINT16(buff, m_value.aConst.aShort);
278 0 : break;
279 : case CP_TAG_CONST_UINT16:
280 0 : buff += writeINT16(buff, m_value.aConst.aUShort);
281 0 : break;
282 : case CP_TAG_CONST_INT32:
283 0 : buff += writeINT32(buff, m_value.aConst.aLong);
284 0 : break;
285 : case CP_TAG_CONST_UINT32:
286 0 : buff += writeUINT32(buff, m_value.aConst.aULong);
287 0 : break;
288 : case CP_TAG_CONST_INT64:
289 0 : buff += writeUINT64(buff, m_value.aConst.aHyper);
290 0 : break;
291 : case CP_TAG_CONST_UINT64:
292 0 : buff += writeUINT64(buff, m_value.aConst.aUHyper);
293 0 : break;
294 : case CP_TAG_CONST_FLOAT:
295 0 : buff += writeFloat(buff, m_value.aConst.aFloat);
296 0 : break;
297 : case CP_TAG_CONST_DOUBLE:
298 0 : buff += writeDouble(buff, m_value.aConst.aDouble);
299 0 : break;
300 : case CP_TAG_CONST_STRING:
301 0 : buff += writeString(buff, m_value.aConst.aString);
302 0 : break;
303 : case CP_TAG_UTF8_NAME:
304 0 : buff += writeUtf8(buff, m_value.aUtf8);
305 0 : break;
306 : case CP_TAG_UIK:
307 0 : buff += writeUINT32(buff, m_value.aUik->m_Data1);
308 0 : buff += writeUINT16(buff, m_value.aUik->m_Data2);
309 0 : buff += writeUINT16(buff, m_value.aUik->m_Data3);
310 0 : buff += writeUINT32(buff, m_value.aUik->m_Data4);
311 0 : buff += writeUINT32(buff, m_value.aUik->m_Data5);
312 0 : break;
313 : default:
314 0 : break;
315 : }
316 :
317 0 : return (buff - buffer);
318 : }
319 :
320 :
321 : /**************************************************************************
322 :
323 : class FieldEntry
324 :
325 : **************************************************************************/
326 :
327 : class FieldEntry
328 : {
329 :
330 : public:
331 :
332 : OString m_name;
333 : OString m_typeName;
334 : OString m_doku;
335 : OString m_fileName;
336 : RTFieldAccess m_access;
337 : RTValueType m_constValueType;
338 : RTConstValueUnion m_constValue;
339 :
340 : FieldEntry();
341 : ~FieldEntry();
342 :
343 : void setData(const OString& name,
344 : const OString& typeName,
345 : const OString& doku,
346 : const OString& fileName,
347 : RTFieldAccess access,
348 : RTValueType constValueType,
349 : RTConstValueUnion constValue);
350 : // throws std::bad_alloc
351 : };
352 :
353 0 : FieldEntry::FieldEntry()
354 : : m_access(RT_ACCESS_INVALID)
355 0 : , m_constValueType(RT_TYPE_NONE)
356 : {
357 0 : }
358 :
359 0 : FieldEntry::~FieldEntry()
360 : {
361 0 : if (
362 0 : (m_constValueType == RT_TYPE_STRING) &&
363 0 : m_constValue.aString &&
364 0 : (m_constValue.aString != NULL_WSTRING)
365 : )
366 : {
367 0 : delete[] (sal_Unicode*)m_constValue.aString;
368 : }
369 0 : }
370 :
371 0 : void FieldEntry::setData(const OString& name,
372 : const OString& typeName,
373 : const OString& doku,
374 : const OString& fileName,
375 : RTFieldAccess access,
376 : RTValueType constValueType,
377 : RTConstValueUnion constValue)
378 : {
379 0 : sal_Unicode * newValue = 0;
380 0 : if (constValueType == RT_TYPE_STRING && constValue.aString != 0) {
381 0 : sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
382 0 : newValue = new sal_Unicode[n];
383 0 : memcpy(newValue, constValue.aString, n * sizeof (sal_Unicode));
384 : }
385 :
386 0 : m_name = name;
387 0 : m_typeName = typeName;
388 0 : m_doku = doku;
389 0 : m_fileName = fileName;
390 :
391 0 : if (
392 0 : (m_constValueType == RT_TYPE_STRING) &&
393 0 : m_constValue.aString &&
394 0 : (m_constValue.aString != NULL_WSTRING)
395 : )
396 : {
397 0 : delete[] (sal_Unicode*)m_constValue.aString;
398 : }
399 :
400 0 : m_access = access;
401 0 : m_constValueType = constValueType;
402 :
403 0 : if (m_constValueType == RT_TYPE_STRING)
404 : {
405 0 : if (constValue.aString == NULL)
406 0 : m_constValue.aString = NULL_WSTRING;
407 : else
408 : {
409 0 : m_constValue.aString = newValue;
410 : }
411 : }
412 : else
413 : {
414 0 : m_constValue = constValue;
415 : }
416 0 : }
417 :
418 : /**************************************************************************
419 :
420 : class ParamEntry
421 :
422 : **************************************************************************/
423 :
424 : class ParamEntry
425 : {
426 : public:
427 :
428 : OString m_typeName;
429 : OString m_name;
430 : RTParamMode m_mode;
431 :
432 : ParamEntry();
433 : ~ParamEntry();
434 :
435 : void setData(const OString& typeName,
436 : const OString& name,
437 : RTParamMode mode);
438 : };
439 :
440 0 : ParamEntry::ParamEntry()
441 0 : : m_mode(RT_PARAM_INVALID)
442 : {
443 0 : }
444 :
445 0 : ParamEntry::~ParamEntry()
446 : {
447 0 : }
448 :
449 0 : void ParamEntry::setData(const OString& typeName,
450 : const OString& name,
451 : RTParamMode mode)
452 : {
453 0 : m_name = name;
454 0 : m_typeName = typeName;
455 0 : m_mode = mode;
456 0 : }
457 :
458 : /**************************************************************************
459 :
460 : class ReferenceEntry
461 :
462 : **************************************************************************/
463 :
464 : class ReferenceEntry
465 : {
466 : public:
467 :
468 : OString m_name;
469 : OString m_doku;
470 : RTReferenceType m_type;
471 : RTFieldAccess m_access;
472 :
473 : ReferenceEntry();
474 : ~ReferenceEntry();
475 :
476 : void setData(const OString& name,
477 : RTReferenceType refType,
478 : const OString& doku,
479 : RTFieldAccess access);
480 : };
481 :
482 0 : ReferenceEntry::ReferenceEntry()
483 : : m_type(RT_REF_INVALID)
484 0 : , m_access(RT_ACCESS_INVALID)
485 : {
486 0 : }
487 :
488 0 : ReferenceEntry::~ReferenceEntry()
489 : {
490 0 : }
491 :
492 0 : void ReferenceEntry::setData(const OString& name,
493 : RTReferenceType refType,
494 : const OString& doku,
495 : RTFieldAccess access)
496 : {
497 0 : m_name = name;
498 0 : m_doku = doku;
499 0 : m_type = refType;
500 0 : m_access = access;
501 0 : }
502 :
503 : /**************************************************************************
504 :
505 : class MethodEntry
506 :
507 : **************************************************************************/
508 :
509 : class MethodEntry
510 : {
511 : public:
512 :
513 : OString m_name;
514 : OString m_returnTypeName;
515 : RTMethodMode m_mode;
516 : sal_uInt16 m_paramCount;
517 : ParamEntry* m_params;
518 : sal_uInt16 m_excCount;
519 : OString* m_excNames;
520 : OString m_doku;
521 :
522 : MethodEntry();
523 : ~MethodEntry();
524 :
525 : void setData(const OString& name,
526 : const OString& returnTypeName,
527 : RTMethodMode mode,
528 : sal_uInt16 paramCount,
529 : sal_uInt16 excCount,
530 : const OString& doku);
531 :
532 : void setExcName(sal_uInt16 excIndex, const OString& name);
533 :
534 : protected:
535 :
536 : void reallocParams(sal_uInt16 size);
537 : void reallocExcs(sal_uInt16 size);
538 : };
539 :
540 0 : MethodEntry::MethodEntry()
541 : : m_mode(RT_MODE_INVALID)
542 : , m_paramCount(0)
543 : , m_params(NULL)
544 : , m_excCount(0)
545 0 : , m_excNames(NULL)
546 : {
547 0 : }
548 :
549 0 : MethodEntry::~MethodEntry()
550 : {
551 0 : if (m_params)
552 0 : delete[] m_params;
553 :
554 0 : if (m_excNames)
555 0 : delete[] m_excNames;
556 0 : }
557 :
558 0 : void MethodEntry::setData(const OString& name,
559 : const OString& returnTypeName,
560 : RTMethodMode mode,
561 : sal_uInt16 paramCount,
562 : sal_uInt16 excCount,
563 : const OString& doku)
564 : {
565 0 : m_name = name;
566 0 : m_returnTypeName = returnTypeName;
567 0 : m_doku = doku;
568 :
569 0 : m_mode = mode;
570 :
571 0 : reallocParams(paramCount);
572 0 : reallocExcs(excCount);
573 0 : }
574 :
575 0 : void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name)
576 : {
577 0 : if (excIndex < m_excCount)
578 : {
579 0 : m_excNames[excIndex] = name;
580 : }
581 0 : }
582 :
583 0 : void MethodEntry::reallocParams(sal_uInt16 size)
584 : {
585 : ParamEntry* newParams;
586 :
587 0 : if (size)
588 0 : newParams = new ParamEntry[size];
589 : else
590 0 : newParams = NULL;
591 :
592 0 : if (m_paramCount)
593 : {
594 : sal_uInt16 i;
595 0 : sal_uInt16 mn = size < m_paramCount ? size : m_paramCount;
596 :
597 0 : for (i = 0; i < mn; i++)
598 : {
599 0 : newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
600 : }
601 :
602 0 : delete[] m_params;
603 : }
604 :
605 0 : m_paramCount = size;
606 0 : m_params = newParams;
607 0 : }
608 :
609 0 : void MethodEntry::reallocExcs(sal_uInt16 size)
610 : {
611 : OString* newExcNames;
612 :
613 0 : if (size)
614 0 : newExcNames = new OString[size];
615 : else
616 0 : newExcNames = NULL;
617 :
618 : sal_uInt16 i;
619 0 : sal_uInt16 mn = size < m_excCount ? size : m_excCount;
620 :
621 0 : for (i = 0; i < mn; i++)
622 : {
623 0 : newExcNames[i] = m_excNames[i];
624 : }
625 :
626 0 : delete[] m_excNames;
627 :
628 0 : m_excCount = size;
629 0 : m_excNames = newExcNames;
630 0 : }
631 :
632 :
633 : /**************************************************************************
634 :
635 : class TypeRegistryEntry
636 :
637 : **************************************************************************/
638 :
639 : class TypeWriter
640 : {
641 :
642 : public:
643 :
644 : sal_uInt32 m_refCount;
645 : typereg_Version m_version;
646 : RTTypeClass m_typeClass;
647 : OString m_typeName;
648 : sal_uInt16 m_nSuperTypes;
649 : OString* m_superTypeNames;
650 : RTUik* m_pUik;
651 : OString m_doku;
652 : OString m_fileName;
653 : sal_uInt16 m_fieldCount;
654 : FieldEntry* m_fields;
655 : sal_uInt16 m_methodCount;
656 : MethodEntry* m_methods;
657 : sal_uInt16 m_referenceCount;
658 : ReferenceEntry* m_references;
659 :
660 : sal_uInt8* m_blop;
661 : sal_uInt32 m_blopSize;
662 :
663 : TypeWriter(typereg_Version version,
664 : OString const & documentation,
665 : OString const & fileName,
666 : RTTypeClass RTTypeClass,
667 : bool published,
668 : const OString& typeName,
669 : sal_uInt16 superTypeCount,
670 : sal_uInt16 FieldCount,
671 : sal_uInt16 methodCount,
672 : sal_uInt16 referenceCount);
673 :
674 : ~TypeWriter();
675 :
676 : void setSuperType(sal_uInt16 index, OString const & name);
677 :
678 : void createBlop(); // throws std::bad_alloc
679 : };
680 :
681 0 : TypeWriter::TypeWriter(typereg_Version version,
682 : OString const & documentation,
683 : OString const & fileName,
684 : RTTypeClass RTTypeClass,
685 : bool published,
686 : const OString& typeName,
687 : sal_uInt16 superTypeCount,
688 : sal_uInt16 fieldCount,
689 : sal_uInt16 methodCount,
690 : sal_uInt16 referenceCount)
691 : : m_refCount(1)
692 : , m_version(version)
693 : , m_typeClass(
694 : static_cast< enum RTTypeClass >(
695 0 : RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
696 : , m_typeName(typeName)
697 : , m_nSuperTypes(superTypeCount)
698 : , m_pUik(NULL)
699 : , m_doku(documentation)
700 : , m_fileName(fileName)
701 : , m_fieldCount(fieldCount)
702 : , m_methodCount(methodCount)
703 : , m_referenceCount(referenceCount)
704 : , m_references(NULL)
705 : , m_blop(NULL)
706 0 : , m_blopSize(0)
707 : {
708 0 : if (m_nSuperTypes > 0)
709 : {
710 0 : m_superTypeNames = new OString[m_nSuperTypes];
711 : } else
712 : {
713 0 : m_superTypeNames = NULL;
714 : }
715 :
716 0 : if (m_fieldCount)
717 0 : m_fields = new FieldEntry[fieldCount];
718 :
719 0 : if (m_methodCount)
720 0 : m_methods = new MethodEntry[methodCount];
721 :
722 0 : if (m_referenceCount)
723 0 : m_references = new ReferenceEntry[referenceCount];
724 0 : }
725 :
726 0 : TypeWriter::~TypeWriter()
727 : {
728 0 : if (m_superTypeNames)
729 0 : delete[] m_superTypeNames;
730 :
731 0 : if (m_blop)
732 0 : delete[] m_blop;
733 :
734 0 : if (m_fieldCount)
735 0 : delete[] m_fields;
736 :
737 0 : if (m_methodCount)
738 0 : delete[] m_methods;
739 :
740 0 : if (m_referenceCount)
741 0 : delete[] m_references;
742 :
743 0 : if (m_pUik)
744 0 : delete m_pUik;
745 0 : }
746 :
747 0 : void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
748 : {
749 0 : m_superTypeNames[index] = name;
750 0 : }
751 :
752 0 : void TypeWriter::createBlop()
753 : {
754 : //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
755 :
756 0 : sal_uInt8* pBlopFields = NULL;
757 0 : sal_uInt8* pBlopMethods = NULL;
758 0 : sal_uInt8* pBlopReferences = NULL;
759 0 : sal_uInt8* pBuffer = NULL;
760 0 : sal_uInt32 blopFieldsSize = 0;
761 0 : sal_uInt32 blopMethodsSize = 0;
762 0 : sal_uInt32 blopReferenceSize = 0;
763 :
764 0 : CPInfo root(CP_TAG_INVALID, NULL);
765 0 : sal_uInt16 cpIndexThisName = 0;
766 0 : sal_uInt16* cpIndexSuperNames = NULL;
767 0 : sal_uInt16 cpIndexUik = 0;
768 0 : sal_uInt16 cpIndexDoku = 0;
769 0 : sal_uInt16 cpIndexFileName = 0;
770 0 : CPInfo* pInfo = NULL;
771 :
772 0 : sal_uInt16 entrySize = sizeof(sal_uInt16);
773 0 : sal_uInt32 blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES + entrySize + (BLOP_HEADER_N_ENTRIES * entrySize);
774 0 : sal_uInt32 blopFieldEntrySize = BLOP_FIELD_N_ENTRIES * entrySize;
775 0 : sal_uInt32 blopMethodEntrySize = BLOP_METHOD_N_ENTRIES * entrySize;
776 0 : sal_uInt32 blopParamEntrySize = BLOP_PARAM_N_ENTRIES * entrySize;
777 0 : sal_uInt32 blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES * entrySize;
778 :
779 0 : sal_uInt32 blopSize = blopHeaderEntrySize;
780 :
781 : // create CP entry for this name
782 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
783 0 : pInfo->m_value.aUtf8 = m_typeName.getStr();
784 0 : cpIndexThisName = pInfo->m_index;
785 :
786 : // nSuperTypes
787 0 : blopSize += entrySize;
788 :
789 : // create CP entry for super names
790 0 : if (m_nSuperTypes)
791 : {
792 0 : blopSize += m_nSuperTypes * entrySize;
793 :
794 0 : cpIndexSuperNames = new sal_uInt16[m_nSuperTypes];
795 :
796 0 : for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
797 : {
798 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
799 0 : pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
800 0 : cpIndexSuperNames[i] = pInfo->m_index;
801 : }
802 : }
803 :
804 : // create CP entry for uik
805 0 : if (m_pUik != NULL)
806 : {
807 0 : pInfo = new CPInfo(CP_TAG_UIK, pInfo);
808 0 : pInfo->m_value.aUik = m_pUik;
809 0 : cpIndexUik = pInfo->m_index;
810 : }
811 :
812 : // create CP entry for doku
813 0 : if (!m_doku.isEmpty())
814 : {
815 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
816 0 : pInfo->m_value.aUtf8 = m_doku.getStr();
817 0 : cpIndexDoku = pInfo->m_index;
818 : }
819 :
820 : // create CP entry for idl source filename
821 0 : if (!m_fileName.isEmpty())
822 : {
823 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
824 0 : pInfo->m_value.aUtf8 = m_fileName.getStr();
825 0 : cpIndexFileName = pInfo->m_index;
826 : }
827 :
828 : // fields blop
829 0 : blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
830 :
831 0 : if (m_fieldCount)
832 : {
833 0 : sal_uInt16 cpIndexName = 0;
834 0 : sal_uInt16 cpIndexTypeName = 0;
835 0 : sal_uInt16 cpIndexValue = 0;
836 0 : sal_uInt16 cpIndexDoku2 = 0;
837 0 : sal_uInt16 cpIndexFileName2 = 0;
838 :
839 : // nFieldEntries + n fields
840 0 : blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
841 :
842 0 : blopSize += blopFieldsSize;
843 :
844 0 : pBlopFields = new sal_uInt8[blopFieldsSize];
845 0 : pBuffer = pBlopFields;
846 :
847 0 : pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES);
848 :
849 0 : for (sal_uInt16 i = 0; i < m_fieldCount; i++)
850 : {
851 0 : cpIndexName = 0;
852 0 : cpIndexTypeName = 0;
853 0 : cpIndexValue = 0;
854 0 : cpIndexDoku2 = 0;
855 0 : cpIndexFileName2 = 0;
856 :
857 0 : pBuffer += writeUINT16(pBuffer, m_fields[i].m_access);
858 :
859 0 : if (!m_fields[i].m_name.isEmpty())
860 : {
861 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
862 0 : pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
863 0 : cpIndexName = pInfo->m_index;
864 : }
865 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
866 :
867 0 : if (!m_fields[i].m_typeName.isEmpty())
868 : {
869 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
870 0 : pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
871 0 : cpIndexTypeName = pInfo->m_index;
872 : }
873 0 : pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
874 :
875 0 : if (m_fields[i].m_constValueType != RT_TYPE_NONE)
876 : {
877 0 : pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo);
878 0 : pInfo->m_value.aConst = m_fields[i].m_constValue;
879 0 : cpIndexValue = pInfo->m_index;
880 : }
881 0 : pBuffer += writeUINT16(pBuffer, cpIndexValue);
882 :
883 0 : if (!m_fields[i].m_doku.isEmpty())
884 : {
885 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
886 0 : pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
887 0 : cpIndexDoku2 = pInfo->m_index;
888 : }
889 0 : pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
890 :
891 0 : if (!m_fields[i].m_fileName.isEmpty())
892 : {
893 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
894 0 : pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
895 0 : cpIndexFileName2 = pInfo->m_index;
896 : }
897 0 : pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
898 : }
899 : }
900 :
901 : // methods blop
902 0 : blopSize += sizeof(sal_uInt16); // methodCount
903 :
904 0 : if (m_methodCount)
905 : {
906 0 : sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount];
907 0 : sal_uInt16 cpIndexName = 0;
908 0 : sal_uInt16 cpIndexReturn = 0;
909 0 : sal_uInt16 cpIndexDoku2 = 0;
910 :
911 : // nMethodEntries + nParamEntries
912 0 : blopMethodsSize = (2 * sizeof(sal_uInt16));
913 :
914 0 : for (sal_uInt16 i = 0; i < m_methodCount; i++)
915 : {
916 0 : pMethodEntrySize[i] = (sal_uInt16)
917 : ( blopMethodEntrySize + // header
918 : sizeof(sal_uInt16) + // parameterCount
919 0 : (m_methods[i].m_paramCount * blopParamEntrySize) + // exceptions
920 : sizeof(sal_uInt16) + // exceptionCount
921 0 : (m_methods[i].m_excCount * sizeof(sal_uInt16)) ); // exceptions
922 :
923 0 : blopMethodsSize += pMethodEntrySize[i];
924 : }
925 :
926 0 : pBlopMethods = new sal_uInt8[blopMethodsSize];
927 :
928 0 : blopSize += blopMethodsSize;
929 :
930 0 : pBuffer = pBlopMethods;
931 :
932 0 : pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES);
933 0 : pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES );
934 :
935 0 : for (sal_uInt16 i = 0; i < m_methodCount; i++)
936 : {
937 0 : cpIndexReturn = 0;
938 0 : cpIndexDoku2 = 0;
939 :
940 0 : pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
941 : pBuffer += writeUINT16(
942 : pBuffer,
943 0 : sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
944 :
945 0 : if (!m_methods[i].m_name.isEmpty())
946 : {
947 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
948 0 : pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
949 0 : cpIndexName = pInfo->m_index;
950 : }
951 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
952 0 : cpIndexName = 0;
953 :
954 0 : if (!m_methods[i].m_returnTypeName.isEmpty())
955 : {
956 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
957 0 : pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
958 0 : cpIndexReturn = pInfo->m_index;
959 : }
960 0 : pBuffer += writeUINT16(pBuffer, cpIndexReturn);
961 :
962 0 : if (!m_methods[i].m_doku.isEmpty())
963 : {
964 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
965 0 : pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
966 0 : cpIndexDoku2 = pInfo->m_index;
967 : }
968 0 : pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
969 :
970 : sal_uInt16 j;
971 :
972 0 : pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
973 :
974 0 : for (j = 0; j < m_methods[i].m_paramCount; j++)
975 : {
976 0 : if (!m_methods[i].m_params[j].m_typeName.isEmpty())
977 : {
978 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
979 0 : pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
980 0 : cpIndexName = pInfo->m_index;
981 : }
982 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
983 0 : cpIndexName = 0;
984 :
985 : pBuffer += writeUINT16(
986 : pBuffer,
987 : sal::static_int_cast< sal_uInt16 >(
988 0 : m_methods[i].m_params[j].m_mode));
989 :
990 0 : if (!m_methods[i].m_params[j].m_name.isEmpty())
991 : {
992 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
993 0 : pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
994 0 : cpIndexName = pInfo->m_index;
995 : }
996 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
997 0 : cpIndexName = 0;
998 : }
999 :
1000 0 : pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
1001 :
1002 0 : for (j = 0; j < m_methods[i].m_excCount; j++)
1003 : {
1004 0 : if (!m_methods[i].m_excNames[j].isEmpty())
1005 : {
1006 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1007 0 : pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
1008 0 : cpIndexName = pInfo->m_index;
1009 : }
1010 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
1011 0 : cpIndexName = 0;
1012 : }
1013 : }
1014 :
1015 0 : delete[] pMethodEntrySize;
1016 : }
1017 :
1018 : // reference blop
1019 0 : blopSize += entrySize; // referenceCount
1020 :
1021 0 : if (m_referenceCount)
1022 : {
1023 0 : sal_uInt16 cpIndexName = 0;
1024 0 : sal_uInt16 cpIndexDoku2 = 0;
1025 :
1026 : // nReferenceEntries + n references
1027 0 : blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
1028 :
1029 0 : blopSize += blopReferenceSize;
1030 :
1031 0 : pBlopReferences = new sal_uInt8[blopReferenceSize];
1032 0 : pBuffer = pBlopReferences;
1033 :
1034 0 : pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES);
1035 :
1036 0 : for (sal_uInt16 i = 0; i < m_referenceCount; i++)
1037 : {
1038 : pBuffer += writeUINT16(
1039 : pBuffer,
1040 0 : sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
1041 :
1042 0 : cpIndexName = 0;
1043 0 : cpIndexDoku2 = 0;
1044 :
1045 0 : if (!m_references[i].m_name.isEmpty())
1046 : {
1047 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1048 0 : pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
1049 0 : cpIndexName = pInfo->m_index;
1050 : }
1051 0 : pBuffer += writeUINT16(pBuffer, cpIndexName);
1052 :
1053 0 : if (!m_references[i].m_doku.isEmpty())
1054 : {
1055 0 : pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1056 0 : pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
1057 0 : cpIndexDoku2 = pInfo->m_index;
1058 : }
1059 0 : pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
1060 :
1061 0 : pBuffer += writeUINT16(pBuffer, m_references[i].m_access);
1062 : }
1063 : }
1064 :
1065 :
1066 : // get CP infos blop-length
1067 0 : pInfo = root.m_next;
1068 0 : sal_uInt32 cpBlopSize = 0;
1069 0 : sal_uInt16 cpCount = 0;
1070 :
1071 0 : while (pInfo)
1072 : {
1073 0 : cpBlopSize += pInfo->getBlopSize();
1074 0 : cpCount++;
1075 0 : pInfo = pInfo->m_next;
1076 : }
1077 :
1078 0 : blopSize += cpBlopSize;
1079 0 : blopSize += sizeof(sal_uInt16); // constantPoolCount
1080 :
1081 : // write all in flat buffer
1082 :
1083 0 : sal_uInt8 * blop = new sal_uInt8[blopSize];
1084 :
1085 0 : pBuffer = blop;
1086 :
1087 : // Assumes two's complement arithmetic with modulo-semantics:
1088 0 : pBuffer += writeUINT32(pBuffer, magic + m_version);
1089 0 : pBuffer += writeUINT32(pBuffer, blopSize);
1090 0 : pBuffer += writeUINT16(pBuffer, minorVersion);
1091 0 : pBuffer += writeUINT16(pBuffer, majorVersion);
1092 0 : pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES);
1093 :
1094 0 : pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
1095 0 : pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
1096 0 : pBuffer += writeUINT16(pBuffer, cpIndexThisName);
1097 0 : pBuffer += writeUINT16(pBuffer, cpIndexUik);
1098 0 : pBuffer += writeUINT16(pBuffer, cpIndexDoku);
1099 0 : pBuffer += writeUINT16(pBuffer, cpIndexFileName);
1100 :
1101 : // write supertypes
1102 0 : pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
1103 0 : if (m_nSuperTypes)
1104 : {
1105 0 : for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
1106 : {
1107 0 : pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
1108 : }
1109 0 : delete[] cpIndexSuperNames;
1110 : }
1111 :
1112 0 : pBuffer += writeUINT16(pBuffer, cpCount);
1113 :
1114 : // write and delete CP infos
1115 0 : pInfo = root.m_next;
1116 :
1117 0 : while (pInfo)
1118 : {
1119 0 : CPInfo* pNextInfo = pInfo->m_next;
1120 :
1121 0 : pBuffer += pInfo->toBlop(pBuffer);
1122 0 : delete pInfo;
1123 :
1124 0 : pInfo = pNextInfo;
1125 : }
1126 :
1127 : // write fields
1128 0 : pBuffer += writeUINT16(pBuffer, m_fieldCount);
1129 0 : if (blopFieldsSize)
1130 : {
1131 0 : memcpy(pBuffer, pBlopFields, blopFieldsSize);
1132 0 : pBuffer += blopFieldsSize;
1133 : }
1134 :
1135 : // write methods
1136 0 : pBuffer += writeUINT16(pBuffer, m_methodCount);
1137 0 : if (blopMethodsSize)
1138 : {
1139 0 : memcpy(pBuffer, pBlopMethods, blopMethodsSize);
1140 0 : pBuffer += blopMethodsSize;
1141 : }
1142 :
1143 : // write references
1144 0 : pBuffer += writeUINT16(pBuffer, m_referenceCount);
1145 0 : if (blopReferenceSize)
1146 : {
1147 0 : memcpy(pBuffer, pBlopReferences, blopReferenceSize);
1148 0 : pBuffer += blopReferenceSize;
1149 : }
1150 :
1151 0 : delete[] pBlopFields;
1152 0 : delete[] pBlopMethods;
1153 0 : delete[] pBlopReferences;
1154 :
1155 0 : delete[] m_blop;
1156 0 : m_blop = blop;
1157 0 : m_blopSize = blopSize;
1158 0 : }
1159 :
1160 :
1161 : /**************************************************************************
1162 :
1163 : C-API
1164 :
1165 : **************************************************************************/
1166 :
1167 : extern "C" {
1168 :
1169 0 : static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry)
1170 : {
1171 0 : TypeWriter* pEntry = (TypeWriter*) hEntry;
1172 :
1173 0 : if (pEntry != NULL)
1174 0 : pEntry->m_refCount++;
1175 0 : }
1176 :
1177 0 : static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
1178 : {
1179 0 : TypeWriter* pEntry = (TypeWriter*) hEntry;
1180 :
1181 0 : if (pEntry != NULL)
1182 : {
1183 0 : if (--pEntry->m_refCount == 0)
1184 0 : delete pEntry;
1185 : }
1186 0 : }
1187 :
1188 0 : static void TYPEREG_CALLTYPE setUik(TypeWriterImpl hEntry, const RTUik* uik)
1189 : {
1190 0 : TypeWriter* pEntry = (TypeWriter*) hEntry;
1191 :
1192 0 : if (pEntry != NULL)
1193 : {
1194 0 : if (pEntry->m_pUik)
1195 : {
1196 0 : pEntry->m_pUik->m_Data1 = uik->m_Data1;
1197 0 : pEntry->m_pUik->m_Data2 = uik->m_Data2;
1198 0 : pEntry->m_pUik->m_Data3 = uik->m_Data3;
1199 0 : pEntry->m_pUik->m_Data4 = uik->m_Data4;
1200 0 : pEntry->m_pUik->m_Data5 = uik->m_Data5;
1201 : }
1202 : else
1203 0 : pEntry->m_pUik = new RTUik(*uik);
1204 : }
1205 0 : }
1206 :
1207 0 : static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku)
1208 : {
1209 0 : static_cast< TypeWriter * >(hEntry)->m_doku = toByteString(doku);
1210 0 : }
1211 :
1212 0 : static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName)
1213 : {
1214 0 : static_cast< TypeWriter * >(hEntry)->m_fileName = toByteString(fileName);
1215 0 : }
1216 :
1217 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setFieldData(
1218 : void * handle, sal_uInt16 index, rtl_uString const * documentation,
1219 : rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
1220 : rtl_uString const * typeName, RTValueType valueType,
1221 : RTConstValueUnion valueValue)
1222 : SAL_THROW_EXTERN_C()
1223 : {
1224 : try {
1225 : static_cast< TypeWriter * >(handle)->m_fields[index].setData(
1226 : toByteString(name), toByteString(typeName),
1227 : toByteString(documentation), toByteString(fileName), flags,
1228 0 : valueType, valueValue);
1229 0 : } catch (std::bad_alloc &) {
1230 0 : return false;
1231 : }
1232 0 : return true;
1233 : }
1234 :
1235 0 : static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry,
1236 : sal_uInt16 index,
1237 : rtl_uString* name,
1238 : rtl_uString* typeName,
1239 : rtl_uString* doku,
1240 : rtl_uString* fileName,
1241 : RTFieldAccess access,
1242 : RTValueType valueType,
1243 : RTConstValueUnion constValue)
1244 : {
1245 : typereg_writer_setFieldData(
1246 : hEntry, index, doku, fileName, access, name, typeName, valueType,
1247 0 : constValue);
1248 0 : }
1249 :
1250 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodData(
1251 : void * handle, sal_uInt16 index, rtl_uString const * documentation,
1252 : RTMethodMode flags, rtl_uString const * name,
1253 : rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
1254 : sal_uInt16 exceptionCount)
1255 : SAL_THROW_EXTERN_C()
1256 : {
1257 : try {
1258 : static_cast< TypeWriter * >(handle)->m_methods[index].setData(
1259 : toByteString(name), toByteString(returnTypeName), flags,
1260 0 : parameterCount, exceptionCount, toByteString(documentation));
1261 0 : } catch (std::bad_alloc &) {
1262 0 : return false;
1263 : }
1264 0 : return true;
1265 : }
1266 :
1267 0 : static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl hEntry,
1268 : sal_uInt16 index,
1269 : rtl_uString* name,
1270 : rtl_uString* returnTypeName,
1271 : RTMethodMode mode,
1272 : sal_uInt16 paramCount,
1273 : sal_uInt16 excCount,
1274 : rtl_uString* doku)
1275 : {
1276 : typereg_writer_setMethodData(
1277 0 : hEntry, index, doku, mode, name, returnTypeName, paramCount, excCount);
1278 0 : }
1279 :
1280 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodParameterData(
1281 : void * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
1282 : RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
1283 : SAL_THROW_EXTERN_C()
1284 : {
1285 : try {
1286 : static_cast< TypeWriter * >(handle)->
1287 0 : m_methods[methodIndex].m_params[parameterIndex].setData(
1288 0 : toByteString(typeName), toByteString(name), flags);
1289 0 : } catch (std::bad_alloc &) {
1290 0 : return false;
1291 : }
1292 0 : return true;
1293 : }
1294 :
1295 0 : static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl hEntry,
1296 : sal_uInt16 index,
1297 : sal_uInt16 paramIndex,
1298 : rtl_uString* type,
1299 : rtl_uString* name,
1300 : RTParamMode mode)
1301 : {
1302 : typereg_writer_setMethodParameterData(
1303 0 : hEntry, index, paramIndex, mode, name, type);
1304 0 : }
1305 :
1306 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodExceptionTypeName(
1307 : void * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
1308 : rtl_uString const * typeName)
1309 : SAL_THROW_EXTERN_C()
1310 : {
1311 : try {
1312 : static_cast< TypeWriter * >(handle)->m_methods[methodIndex].setExcName(
1313 0 : exceptionIndex, toByteString(typeName));
1314 0 : } catch (std::bad_alloc &) {
1315 0 : return false;
1316 : }
1317 0 : return true;
1318 : }
1319 :
1320 0 : static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl hEntry,
1321 : sal_uInt16 index,
1322 : sal_uInt16 excIndex,
1323 : rtl_uString* type)
1324 : {
1325 0 : typereg_writer_setMethodExceptionTypeName(hEntry, index, excIndex, type);
1326 0 : }
1327 :
1328 0 : REG_DLLPUBLIC void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * size)
1329 : SAL_THROW_EXTERN_C()
1330 : {
1331 0 : TypeWriter * writer = static_cast< TypeWriter * >(handle);
1332 0 : if (writer->m_blop == 0) {
1333 : try {
1334 0 : writer->createBlop();
1335 0 : } catch (std::bad_alloc &) {
1336 0 : return 0;
1337 : }
1338 : }
1339 0 : *size = writer->m_blopSize;
1340 0 : return writer->m_blop;
1341 : }
1342 :
1343 0 : static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
1344 : {
1345 : sal_uInt32 size;
1346 : return static_cast< sal_uInt8 const * >(
1347 0 : typereg_writer_getBlob(hEntry, &size));
1348 : }
1349 :
1350 0 : static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
1351 : {
1352 : sal_uInt32 size;
1353 0 : typereg_writer_getBlob(hEntry, &size);
1354 0 : return size;
1355 : }
1356 :
1357 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setReferenceData(
1358 : void * handle, sal_uInt16 index, rtl_uString const * documentation,
1359 : RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
1360 : SAL_THROW_EXTERN_C()
1361 : {
1362 : try {
1363 : static_cast< TypeWriter * >(handle)->m_references[index].setData(
1364 0 : toByteString(typeName), sort, toByteString(documentation), flags);
1365 0 : } catch (std::bad_alloc &) {
1366 0 : return false;
1367 : }
1368 0 : return true;
1369 : }
1370 :
1371 0 : static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl hEntry,
1372 : sal_uInt16 index,
1373 : rtl_uString* name,
1374 : RTReferenceType refType,
1375 : rtl_uString* doku,
1376 : RTFieldAccess access)
1377 : {
1378 0 : typereg_writer_setReferenceData(hEntry, index, doku, refType, access, name);
1379 0 : }
1380 :
1381 0 : REG_DLLPUBLIC void * TYPEREG_CALLTYPE typereg_writer_create(
1382 : typereg_Version version, rtl_uString const * documentation,
1383 : rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
1384 : rtl_uString const * typeName, sal_uInt16 superTypeCount,
1385 : sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1386 : SAL_THROW_EXTERN_C()
1387 : {
1388 : try {
1389 : return new TypeWriter(
1390 : version, toByteString(documentation), toByteString(fileName),
1391 : typeClass, published, toByteString(typeName), superTypeCount,
1392 0 : fieldCount, methodCount, referenceCount);
1393 0 : } catch (std::bad_alloc &) {
1394 0 : return 0;
1395 : }
1396 : }
1397 :
1398 0 : REG_DLLPUBLIC void TYPEREG_CALLTYPE typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C() {
1399 0 : delete static_cast< TypeWriter * >(handle);
1400 0 : }
1401 :
1402 0 : REG_DLLPUBLIC sal_Bool TYPEREG_CALLTYPE typereg_writer_setSuperTypeName(
1403 : void * handle, sal_uInt16 index, rtl_uString const * typeName)
1404 : SAL_THROW_EXTERN_C()
1405 : {
1406 : try {
1407 : static_cast< TypeWriter * >(handle)->setSuperType(
1408 0 : index, toByteString(typeName));
1409 0 : } catch (std::bad_alloc &) {
1410 0 : return false;
1411 : }
1412 0 : return true;
1413 : }
1414 :
1415 0 : static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
1416 : RTTypeClass typeClass, rtl_uString * typeName, rtl_uString * superTypeName,
1417 : sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1418 : {
1419 0 : OUString empty;
1420 0 : sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
1421 0 : ? 0 : 1;
1422 : TypeWriterImpl t = typereg_writer_create(
1423 : TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
1424 0 : superTypeCount, fieldCount, methodCount, referenceCount);
1425 0 : if (superTypeCount > 0) {
1426 0 : typereg_writer_setSuperTypeName(t, 0, superTypeName);
1427 : }
1428 0 : return t;
1429 : }
1430 :
1431 0 : REG_DLLPUBLIC RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api(void)
1432 : {
1433 : static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0};
1434 0 : if (!aApi.acquire)
1435 : {
1436 0 : aApi.createEntry = &createEntry;
1437 0 : aApi.acquire = &acquire;
1438 0 : aApi.release = &release;
1439 0 : aApi.setUik = &setUik;
1440 0 : aApi.setDoku = &setDoku;
1441 0 : aApi.setFileName = &setFileName;
1442 0 : aApi.setFieldData = &setFieldData;
1443 0 : aApi.setMethodData = &setMethodData;
1444 0 : aApi.setParamData = &setParamData;
1445 0 : aApi.setExcData = &setExcData;
1446 0 : aApi.getBlop = &getBlop;
1447 0 : aApi.getBlopSize = &getBlopSize;
1448 0 : aApi.setReferenceData = &setReferenceData;
1449 :
1450 0 : return (&aApi);
1451 : }
1452 : else
1453 : {
1454 0 : return (&aApi);
1455 : }
1456 : }
1457 :
1458 : }
1459 :
1460 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|