fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / registry / source / reflwrit.cxx
blob7c1f440d5f779c76cf4333a60cf5583acf93aa8c
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
29 #include "registry/reflwrit.hxx"
30 #include "registry/version.h"
31 #include "registry/writer.h"
33 #include "reflcnst.hxx"
37 namespace {
39 inline OString toByteString(rtl_uString const * str) {
40 return OString(
41 str->buffer, str->length, RTL_TEXTENCODING_UTF8,
42 OUSTRING_TO_OSTRING_CVTFLAGS);
47 static sal_Unicode NULL_WSTRING[1] = { 0 };
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
56 #define BLOP_FIELD_N_ENTRIES 6
58 #define BLOP_METHOD_N_ENTRIES 5
60 #define BLOP_PARAM_N_ENTRIES 3
62 #define BLOP_REFERENCE_N_ENTRIES 4
64 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
66 if (!wstring) return 0;
68 const sal_uInt8* b = wstring;
70 while (b[0] || b[1]) b += sizeof(sal_uInt16);
72 return ((b - wstring) / sizeof(sal_uInt16));
75 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
77 sal_uInt32 len = rtl_ustr_getLength(v) + 1;
78 sal_uInt32 i;
79 sal_uInt8* buff = buffer;
81 for (i = 0; i < len; i++)
83 buff += writeUINT16(buff, (sal_uInt16) v[i]);
86 return (buff - buffer);
89 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
91 sal_uInt32 len = UINT16StringLen(buffer) + 1;
92 sal_uInt32 i;
93 sal_uInt8* buff = const_cast<sal_uInt8*>(buffer);
95 if(len > maxSize / 2)
97 len = maxSize / 2;
100 for (i = 0; i < (len - 1); i++)
102 sal_uInt16 aChar;
104 buff += readUINT16(buff, aChar);
106 v[i] = (sal_Unicode) aChar;
109 v[len - 1] = L'\0';
111 return (buff - buffer);
114 sal_uInt32 writeFloat(sal_uInt8* buffer, float v)
116 union
118 float v;
119 sal_uInt32 b;
120 } x;
122 x.v = v;
124 #ifdef REGTYPE_IEEE_NATIVE
125 writeUINT32(buffer, x.b);
126 #else
127 # error no IEEE
128 #endif
130 return sizeof(sal_uInt32);
133 sal_uInt32 writeDouble(sal_uInt8* buffer, double v)
135 union
137 double v;
138 struct
140 sal_uInt32 b1;
141 sal_uInt32 b2;
142 } b;
143 } x;
145 x.v = v;
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 writeUINT32(buffer, x.b.b2);
153 writeUINT32(buffer + sizeof(sal_uInt32), x.b.b1);
154 # endif
155 #else
156 # error no IEEE
157 #endif
159 return (sizeof(sal_uInt32) + sizeof(sal_uInt32));
162 /**************************************************************************
164 buffer write functions
166 **************************************************************************/
169 /**************************************************************************
171 struct CPInfo
173 **************************************************************************/
175 struct CPInfo
177 CPInfoTag m_tag;
178 union
180 const sal_Char* aUtf8;
181 RTUik* aUik;
182 RTConstValueUnion aConst;
183 } m_value;
185 sal_uInt16 m_index;
186 struct CPInfo* m_next;
188 CPInfo(CPInfoTag tag, struct CPInfo* prev);
190 sal_uInt32 getBlopSize();
192 sal_uInt32 toBlop(sal_uInt8* buffer);
195 CPInfo::CPInfo(CPInfoTag tag, struct CPInfo* prev)
196 : m_tag(tag)
197 , m_index(0)
198 , m_next(NULL)
200 if (prev)
202 m_index = prev->m_index + 1;
203 prev->m_next = this;
207 sal_uInt32 CPInfo::getBlopSize()
209 sal_uInt32 size = sizeof(sal_uInt32) /* size */ + sizeof(sal_uInt16) /* tag */;
211 switch (m_tag)
213 case CP_TAG_CONST_BOOL:
214 size += sizeof(sal_uInt8);
215 break;
216 case CP_TAG_CONST_BYTE:
217 size += sizeof(sal_uInt8);
218 break;
219 case CP_TAG_CONST_INT16:
220 size += sizeof(sal_Int16);
221 break;
222 case CP_TAG_CONST_UINT16:
223 size += sizeof(sal_uInt16);
224 break;
225 case CP_TAG_CONST_INT32:
226 size += sizeof(sal_Int32);
227 break;
228 case CP_TAG_CONST_UINT32:
229 size += sizeof(sal_uInt32);
230 break;
231 case CP_TAG_CONST_INT64:
232 size += sizeof(sal_Int64);
233 break;
234 case CP_TAG_CONST_UINT64:
235 size += sizeof(sal_uInt64);
236 break;
237 case CP_TAG_CONST_FLOAT:
238 size += sizeof(sal_uInt32);
239 break;
240 case CP_TAG_CONST_DOUBLE:
241 size += sizeof(sal_uInt32) + sizeof(sal_uInt32);
242 break;
243 case CP_TAG_CONST_STRING:
244 size += (rtl_ustr_getLength(m_value.aConst.aString) + 1) * sizeof(sal_uInt16);
245 break;
246 case CP_TAG_UTF8_NAME:
247 size += strlen(m_value.aUtf8) + 1;
248 break;
249 case CP_TAG_UIK:
250 size += sizeof(sal_uInt32) + sizeof(sal_uInt16) + sizeof(sal_uInt16) + sizeof(sal_uInt32) + sizeof(sal_uInt32);
251 break;
252 default:
253 break;
256 return size;
260 sal_uInt32 CPInfo::toBlop(sal_uInt8* buffer)
262 sal_uInt8* buff = buffer;
264 buff += writeUINT32(buff, getBlopSize());
265 buff += writeUINT16(buff, (sal_uInt16) m_tag);
267 switch (m_tag)
269 case CP_TAG_CONST_BOOL:
270 buff += writeBYTE(buff, (sal_uInt8) m_value.aConst.aBool);
271 break;
272 case CP_TAG_CONST_BYTE:
273 buff += writeBYTE(
274 buff, static_cast< sal_uInt8 >(m_value.aConst.aByte));
275 break;
276 case CP_TAG_CONST_INT16:
277 buff += writeINT16(buff, m_value.aConst.aShort);
278 break;
279 case CP_TAG_CONST_UINT16:
280 buff += writeINT16(buff, m_value.aConst.aUShort);
281 break;
282 case CP_TAG_CONST_INT32:
283 buff += writeINT32(buff, m_value.aConst.aLong);
284 break;
285 case CP_TAG_CONST_UINT32:
286 buff += writeUINT32(buff, m_value.aConst.aULong);
287 break;
288 case CP_TAG_CONST_INT64:
289 buff += writeUINT64(buff, m_value.aConst.aHyper);
290 break;
291 case CP_TAG_CONST_UINT64:
292 buff += writeUINT64(buff, m_value.aConst.aUHyper);
293 break;
294 case CP_TAG_CONST_FLOAT:
295 buff += writeFloat(buff, m_value.aConst.aFloat);
296 break;
297 case CP_TAG_CONST_DOUBLE:
298 buff += writeDouble(buff, m_value.aConst.aDouble);
299 break;
300 case CP_TAG_CONST_STRING:
301 buff += writeString(buff, m_value.aConst.aString);
302 break;
303 case CP_TAG_UTF8_NAME:
304 buff += writeUtf8(buff, m_value.aUtf8);
305 break;
306 case CP_TAG_UIK:
307 buff += writeUINT32(buff, m_value.aUik->m_Data1);
308 buff += writeUINT16(buff, m_value.aUik->m_Data2);
309 buff += writeUINT16(buff, m_value.aUik->m_Data3);
310 buff += writeUINT32(buff, m_value.aUik->m_Data4);
311 buff += writeUINT32(buff, m_value.aUik->m_Data5);
312 break;
313 default:
314 break;
317 return (buff - buffer);
321 /**************************************************************************
323 class FieldEntry
325 **************************************************************************/
327 class FieldEntry
330 public:
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;
340 FieldEntry();
341 ~FieldEntry();
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
353 FieldEntry::FieldEntry()
354 : m_access(RTFieldAccess::INVALID)
355 , m_constValueType(RT_TYPE_NONE)
359 FieldEntry::~FieldEntry()
361 if (
362 (m_constValueType == RT_TYPE_STRING) &&
363 m_constValue.aString &&
364 (m_constValue.aString != NULL_WSTRING)
367 delete[] m_constValue.aString;
371 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)
379 sal_Unicode * newValue = 0;
380 if (constValueType == RT_TYPE_STRING && constValue.aString != 0) {
381 sal_Int32 n = rtl_ustr_getLength(constValue.aString) + 1;
382 newValue = new sal_Unicode[n];
383 memcpy(newValue, constValue.aString, n * sizeof (sal_Unicode));
386 m_name = name;
387 m_typeName = typeName;
388 m_doku = doku;
389 m_fileName = fileName;
391 if (
392 (m_constValueType == RT_TYPE_STRING) &&
393 m_constValue.aString &&
394 (m_constValue.aString != NULL_WSTRING)
397 delete[] m_constValue.aString;
400 m_access = access;
401 m_constValueType = constValueType;
403 if (m_constValueType == RT_TYPE_STRING)
405 if (constValue.aString == NULL)
406 m_constValue.aString = NULL_WSTRING;
407 else
409 m_constValue.aString = newValue;
412 else
414 m_constValue = constValue;
418 /**************************************************************************
420 class ParamEntry
422 **************************************************************************/
424 class ParamEntry
426 public:
428 OString m_typeName;
429 OString m_name;
430 RTParamMode m_mode;
432 ParamEntry();
433 ~ParamEntry();
435 void setData(const OString& typeName,
436 const OString& name,
437 RTParamMode mode);
440 ParamEntry::ParamEntry()
441 : m_mode(RT_PARAM_INVALID)
445 ParamEntry::~ParamEntry()
449 void ParamEntry::setData(const OString& typeName,
450 const OString& name,
451 RTParamMode mode)
453 m_name = name;
454 m_typeName = typeName;
455 m_mode = mode;
458 /**************************************************************************
460 class ReferenceEntry
462 **************************************************************************/
464 class ReferenceEntry
466 public:
468 OString m_name;
469 OString m_doku;
470 RTReferenceType m_type;
471 RTFieldAccess m_access;
473 ReferenceEntry();
474 ~ReferenceEntry();
476 void setData(const OString& name,
477 RTReferenceType refType,
478 const OString& doku,
479 RTFieldAccess access);
482 ReferenceEntry::ReferenceEntry()
483 : m_type(RTReferenceType::INVALID)
484 , m_access(RTFieldAccess::INVALID)
488 ReferenceEntry::~ReferenceEntry()
492 void ReferenceEntry::setData(const OString& name,
493 RTReferenceType refType,
494 const OString& doku,
495 RTFieldAccess access)
497 m_name = name;
498 m_doku = doku;
499 m_type = refType;
500 m_access = access;
503 /**************************************************************************
505 class MethodEntry
507 **************************************************************************/
509 class MethodEntry
511 public:
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;
522 MethodEntry();
523 ~MethodEntry();
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);
532 void setExcName(sal_uInt16 excIndex, const OString& name);
534 protected:
536 void reallocParams(sal_uInt16 size);
537 void reallocExcs(sal_uInt16 size);
540 MethodEntry::MethodEntry()
541 : m_mode(RTMethodMode::INVALID)
542 , m_paramCount(0)
543 , m_params(NULL)
544 , m_excCount(0)
545 , m_excNames(NULL)
549 MethodEntry::~MethodEntry()
551 if (m_params)
552 delete[] m_params;
554 if (m_excNames)
555 delete[] m_excNames;
558 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)
565 m_name = name;
566 m_returnTypeName = returnTypeName;
567 m_doku = doku;
569 m_mode = mode;
571 reallocParams(paramCount);
572 reallocExcs(excCount);
575 void MethodEntry::setExcName(sal_uInt16 excIndex, const OString& name)
577 if (excIndex < m_excCount)
579 m_excNames[excIndex] = name;
583 void MethodEntry::reallocParams(sal_uInt16 size)
585 ParamEntry* newParams;
587 if (size)
588 newParams = new ParamEntry[size];
589 else
590 newParams = NULL;
592 if (m_paramCount)
594 sal_uInt16 i;
595 sal_uInt16 mn = size < m_paramCount ? size : m_paramCount;
597 for (i = 0; i < mn; i++)
599 newParams[i].setData(m_params[i].m_typeName, m_params[i].m_name, m_params[i].m_mode);
602 delete[] m_params;
605 m_paramCount = size;
606 m_params = newParams;
609 void MethodEntry::reallocExcs(sal_uInt16 size)
611 OString* newExcNames;
613 if (size)
614 newExcNames = new OString[size];
615 else
616 newExcNames = NULL;
618 sal_uInt16 i;
619 sal_uInt16 mn = size < m_excCount ? size : m_excCount;
621 for (i = 0; i < mn; i++)
623 newExcNames[i] = m_excNames[i];
626 delete[] m_excNames;
628 m_excCount = size;
629 m_excNames = newExcNames;
633 /**************************************************************************
635 class TypeRegistryEntry
637 **************************************************************************/
639 class TypeWriter
642 public:
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;
660 sal_uInt8* m_blop;
661 sal_uInt32 m_blopSize;
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);
674 ~TypeWriter();
676 void setSuperType(sal_uInt16 index, OString const & name);
678 void createBlop(); // throws std::bad_alloc
681 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 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_fields(NULL)
703 , m_methodCount(methodCount)
704 , m_methods(NULL)
705 , m_referenceCount(referenceCount)
706 , m_references(NULL)
707 , m_blop(NULL)
708 , m_blopSize(0)
710 if (m_nSuperTypes > 0)
712 m_superTypeNames = new OString[m_nSuperTypes];
713 } else
715 m_superTypeNames = NULL;
718 if (m_fieldCount)
719 m_fields = new FieldEntry[fieldCount];
721 if (m_methodCount)
722 m_methods = new MethodEntry[methodCount];
724 if (m_referenceCount)
725 m_references = new ReferenceEntry[referenceCount];
728 TypeWriter::~TypeWriter()
730 if (m_superTypeNames)
731 delete[] m_superTypeNames;
733 if (m_blop)
734 delete[] m_blop;
736 if (m_fieldCount)
737 delete[] m_fields;
739 if (m_methodCount)
740 delete[] m_methods;
742 if (m_referenceCount)
743 delete[] m_references;
745 if (m_pUik)
746 delete m_pUik;
749 void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
751 m_superTypeNames[index] = name;
754 void TypeWriter::createBlop()
756 //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
758 sal_uInt8* pBlopFields = NULL;
759 sal_uInt8* pBlopMethods = NULL;
760 sal_uInt8* pBlopReferences = NULL;
761 sal_uInt8* pBuffer = NULL;
762 sal_uInt32 blopFieldsSize = 0;
763 sal_uInt32 blopMethodsSize = 0;
764 sal_uInt32 blopReferenceSize = 0;
766 CPInfo root(CP_TAG_INVALID, NULL);
767 sal_uInt16 cpIndexThisName = 0;
768 sal_uInt16* cpIndexSuperNames = NULL;
769 sal_uInt16 cpIndexUik = 0;
770 sal_uInt16 cpIndexDoku = 0;
771 sal_uInt16 cpIndexFileName = 0;
772 CPInfo* pInfo = NULL;
774 sal_uInt16 entrySize = sizeof(sal_uInt16);
775 sal_uInt32 blopHeaderEntrySize = BLOP_OFFSET_N_ENTRIES + entrySize + (BLOP_HEADER_N_ENTRIES * entrySize);
776 sal_uInt32 blopFieldEntrySize = BLOP_FIELD_N_ENTRIES * entrySize;
777 sal_uInt32 blopMethodEntrySize = BLOP_METHOD_N_ENTRIES * entrySize;
778 sal_uInt32 blopParamEntrySize = BLOP_PARAM_N_ENTRIES * entrySize;
779 sal_uInt32 blopReferenceEntrySize = BLOP_REFERENCE_N_ENTRIES * entrySize;
781 sal_uInt32 blopSize = blopHeaderEntrySize;
783 // create CP entry for this name
784 pInfo = new CPInfo(CP_TAG_UTF8_NAME, &root);
785 pInfo->m_value.aUtf8 = m_typeName.getStr();
786 cpIndexThisName = pInfo->m_index;
788 // nSuperTypes
789 blopSize += entrySize;
791 // create CP entry for super names
792 if (m_nSuperTypes)
794 blopSize += m_nSuperTypes * entrySize;
796 cpIndexSuperNames = new sal_uInt16[m_nSuperTypes];
798 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
800 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
801 pInfo->m_value.aUtf8 = m_superTypeNames[i].getStr();
802 cpIndexSuperNames[i] = pInfo->m_index;
806 // create CP entry for uik
807 if (m_pUik != NULL)
809 pInfo = new CPInfo(CP_TAG_UIK, pInfo);
810 pInfo->m_value.aUik = m_pUik;
811 cpIndexUik = pInfo->m_index;
814 // create CP entry for doku
815 if (!m_doku.isEmpty())
817 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
818 pInfo->m_value.aUtf8 = m_doku.getStr();
819 cpIndexDoku = pInfo->m_index;
822 // create CP entry for idl source filename
823 if (!m_fileName.isEmpty())
825 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
826 pInfo->m_value.aUtf8 = m_fileName.getStr();
827 cpIndexFileName = pInfo->m_index;
830 // fields blop
831 blopSize += sizeof(sal_uInt16); // fieldCount + nFieldEntries
833 if (m_fieldCount)
835 sal_uInt16 cpIndexName = 0;
836 sal_uInt16 cpIndexTypeName = 0;
837 sal_uInt16 cpIndexValue = 0;
838 sal_uInt16 cpIndexDoku2 = 0;
839 sal_uInt16 cpIndexFileName2 = 0;
841 // nFieldEntries + n fields
842 blopFieldsSize = sizeof(sal_uInt16) + (m_fieldCount * blopFieldEntrySize);
844 blopSize += blopFieldsSize;
846 pBlopFields = new sal_uInt8[blopFieldsSize];
847 pBuffer = pBlopFields;
849 pBuffer += writeUINT16(pBuffer, BLOP_FIELD_N_ENTRIES);
851 for (sal_uInt16 i = 0; i < m_fieldCount; i++)
853 cpIndexName = 0;
854 cpIndexTypeName = 0;
855 cpIndexValue = 0;
856 cpIndexDoku2 = 0;
857 cpIndexFileName2 = 0;
859 pBuffer += writeUINT16(pBuffer, static_cast<sal_uInt16>(m_fields[i].m_access));
861 if (!m_fields[i].m_name.isEmpty())
863 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
864 pInfo->m_value.aUtf8 = m_fields[i].m_name.getStr();
865 cpIndexName = pInfo->m_index;
867 pBuffer += writeUINT16(pBuffer, cpIndexName);
869 if (!m_fields[i].m_typeName.isEmpty())
871 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
872 pInfo->m_value.aUtf8 = m_fields[i].m_typeName.getStr();
873 cpIndexTypeName = pInfo->m_index;
875 pBuffer += writeUINT16(pBuffer, cpIndexTypeName);
877 if (m_fields[i].m_constValueType != RT_TYPE_NONE)
879 pInfo = new CPInfo((CPInfoTag)m_fields[i].m_constValueType, pInfo);
880 pInfo->m_value.aConst = m_fields[i].m_constValue;
881 cpIndexValue = pInfo->m_index;
883 pBuffer += writeUINT16(pBuffer, cpIndexValue);
885 if (!m_fields[i].m_doku.isEmpty())
887 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
888 pInfo->m_value.aUtf8 = m_fields[i].m_doku.getStr();
889 cpIndexDoku2 = pInfo->m_index;
891 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
893 if (!m_fields[i].m_fileName.isEmpty())
895 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
896 pInfo->m_value.aUtf8 = m_fields[i].m_fileName.getStr();
897 cpIndexFileName2 = pInfo->m_index;
899 pBuffer += writeUINT16(pBuffer, cpIndexFileName2);
903 // methods blop
904 blopSize += sizeof(sal_uInt16); // methodCount
906 if (m_methodCount)
908 sal_uInt16* pMethodEntrySize = new sal_uInt16[m_methodCount];
909 sal_uInt16 cpIndexName = 0;
910 sal_uInt16 cpIndexReturn = 0;
911 sal_uInt16 cpIndexDoku2 = 0;
913 // nMethodEntries + nParamEntries
914 blopMethodsSize = (2 * sizeof(sal_uInt16));
916 for (sal_uInt16 i = 0; i < m_methodCount; i++)
918 pMethodEntrySize[i] = (sal_uInt16)
919 ( blopMethodEntrySize + // header
920 sizeof(sal_uInt16) + // parameterCount
921 (m_methods[i].m_paramCount * blopParamEntrySize) + // exceptions
922 sizeof(sal_uInt16) + // exceptionCount
923 (m_methods[i].m_excCount * sizeof(sal_uInt16)) ); // exceptions
925 blopMethodsSize += pMethodEntrySize[i];
928 pBlopMethods = new sal_uInt8[blopMethodsSize];
930 blopSize += blopMethodsSize;
932 pBuffer = pBlopMethods;
934 pBuffer += writeUINT16(pBuffer, BLOP_METHOD_N_ENTRIES);
935 pBuffer += writeUINT16(pBuffer, BLOP_PARAM_N_ENTRIES );
937 for (sal_uInt16 i = 0; i < m_methodCount; i++)
939 cpIndexReturn = 0;
940 cpIndexDoku2 = 0;
942 pBuffer += writeUINT16(pBuffer, pMethodEntrySize[i]);
943 pBuffer += writeUINT16(
944 pBuffer,
945 sal::static_int_cast< sal_uInt16 >(m_methods[i].m_mode));
947 if (!m_methods[i].m_name.isEmpty())
949 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
950 pInfo->m_value.aUtf8 = m_methods[i].m_name.getStr();
951 cpIndexName = pInfo->m_index;
953 pBuffer += writeUINT16(pBuffer, cpIndexName);
954 cpIndexName = 0;
956 if (!m_methods[i].m_returnTypeName.isEmpty())
958 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
959 pInfo->m_value.aUtf8 = m_methods[i].m_returnTypeName.getStr();
960 cpIndexReturn = pInfo->m_index;
962 pBuffer += writeUINT16(pBuffer, cpIndexReturn);
964 if (!m_methods[i].m_doku.isEmpty())
966 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
967 pInfo->m_value.aUtf8 = m_methods[i].m_doku.getStr();
968 cpIndexDoku2 = pInfo->m_index;
970 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
972 sal_uInt16 j;
974 pBuffer += writeUINT16(pBuffer, m_methods[i].m_paramCount);
976 for (j = 0; j < m_methods[i].m_paramCount; j++)
978 if (!m_methods[i].m_params[j].m_typeName.isEmpty())
980 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
981 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_typeName.getStr();
982 cpIndexName = pInfo->m_index;
984 pBuffer += writeUINT16(pBuffer, cpIndexName);
985 cpIndexName = 0;
987 pBuffer += writeUINT16(
988 pBuffer,
989 sal::static_int_cast< sal_uInt16 >(
990 m_methods[i].m_params[j].m_mode));
992 if (!m_methods[i].m_params[j].m_name.isEmpty())
994 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
995 pInfo->m_value.aUtf8 = m_methods[i].m_params[j].m_name.getStr();
996 cpIndexName = pInfo->m_index;
998 pBuffer += writeUINT16(pBuffer, cpIndexName);
999 cpIndexName = 0;
1002 pBuffer += writeUINT16(pBuffer, m_methods[i].m_excCount);
1004 for (j = 0; j < m_methods[i].m_excCount; j++)
1006 if (!m_methods[i].m_excNames[j].isEmpty())
1008 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1009 pInfo->m_value.aUtf8 = m_methods[i].m_excNames[j].getStr();
1010 cpIndexName = pInfo->m_index;
1012 pBuffer += writeUINT16(pBuffer, cpIndexName);
1013 cpIndexName = 0;
1017 delete[] pMethodEntrySize;
1020 // reference blop
1021 blopSize += entrySize; // referenceCount
1023 if (m_referenceCount)
1025 sal_uInt16 cpIndexName = 0;
1026 sal_uInt16 cpIndexDoku2 = 0;
1028 // nReferenceEntries + n references
1029 blopReferenceSize = entrySize + (m_referenceCount * blopReferenceEntrySize);
1031 blopSize += blopReferenceSize;
1033 pBlopReferences = new sal_uInt8[blopReferenceSize];
1034 pBuffer = pBlopReferences;
1036 pBuffer += writeUINT16(pBuffer, BLOP_REFERENCE_N_ENTRIES);
1038 for (sal_uInt16 i = 0; i < m_referenceCount; i++)
1040 pBuffer += writeUINT16(
1041 pBuffer,
1042 sal::static_int_cast< sal_uInt16 >(m_references[i].m_type));
1044 cpIndexName = 0;
1045 cpIndexDoku2 = 0;
1047 if (!m_references[i].m_name.isEmpty())
1049 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1050 pInfo->m_value.aUtf8 = m_references[i].m_name.getStr();
1051 cpIndexName = pInfo->m_index;
1053 pBuffer += writeUINT16(pBuffer, cpIndexName);
1055 if (!m_references[i].m_doku.isEmpty())
1057 pInfo = new CPInfo(CP_TAG_UTF8_NAME, pInfo);
1058 pInfo->m_value.aUtf8 = m_references[i].m_doku.getStr();
1059 cpIndexDoku2 = pInfo->m_index;
1061 pBuffer += writeUINT16(pBuffer, cpIndexDoku2);
1063 pBuffer += writeUINT16(pBuffer, static_cast<sal_uInt16>(m_references[i].m_access));
1068 // get CP infos blop-length
1069 pInfo = root.m_next;
1070 sal_uInt32 cpBlopSize = 0;
1071 sal_uInt16 cpCount = 0;
1073 while (pInfo)
1075 cpBlopSize += pInfo->getBlopSize();
1076 cpCount++;
1077 pInfo = pInfo->m_next;
1080 blopSize += cpBlopSize;
1081 blopSize += sizeof(sal_uInt16); // constantPoolCount
1083 // write all in flat buffer
1085 sal_uInt8 * blop = new sal_uInt8[blopSize];
1087 pBuffer = blop;
1089 // Assumes two's complement arithmetic with modulo-semantics:
1090 pBuffer += writeUINT32(pBuffer, magic + m_version);
1091 pBuffer += writeUINT32(pBuffer, blopSize);
1092 pBuffer += writeUINT16(pBuffer, minorVersion);
1093 pBuffer += writeUINT16(pBuffer, majorVersion);
1094 pBuffer += writeUINT16(pBuffer, BLOP_HEADER_N_ENTRIES);
1096 pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
1097 pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
1098 pBuffer += writeUINT16(pBuffer, cpIndexThisName);
1099 pBuffer += writeUINT16(pBuffer, cpIndexUik);
1100 pBuffer += writeUINT16(pBuffer, cpIndexDoku);
1101 pBuffer += writeUINT16(pBuffer, cpIndexFileName);
1103 // write supertypes
1104 pBuffer += writeUINT16(pBuffer, m_nSuperTypes);
1105 if (m_nSuperTypes)
1107 for (sal_uInt32 i=0; i < m_nSuperTypes; i++)
1109 pBuffer += writeUINT16(pBuffer, cpIndexSuperNames[i]);
1111 delete[] cpIndexSuperNames;
1114 pBuffer += writeUINT16(pBuffer, cpCount);
1116 // write and delete CP infos
1117 pInfo = root.m_next;
1119 while (pInfo)
1121 CPInfo* pNextInfo = pInfo->m_next;
1123 pBuffer += pInfo->toBlop(pBuffer);
1124 delete pInfo;
1126 pInfo = pNextInfo;
1129 // write fields
1130 pBuffer += writeUINT16(pBuffer, m_fieldCount);
1131 if (blopFieldsSize)
1133 memcpy(pBuffer, pBlopFields, blopFieldsSize);
1134 pBuffer += blopFieldsSize;
1137 // write methods
1138 pBuffer += writeUINT16(pBuffer, m_methodCount);
1139 if (blopMethodsSize)
1141 memcpy(pBuffer, pBlopMethods, blopMethodsSize);
1142 pBuffer += blopMethodsSize;
1145 // write references
1146 pBuffer += writeUINT16(pBuffer, m_referenceCount);
1147 if (blopReferenceSize)
1149 memcpy(pBuffer, pBlopReferences, blopReferenceSize);
1150 pBuffer += blopReferenceSize;
1153 delete[] pBlopFields;
1154 delete[] pBlopMethods;
1155 delete[] pBlopReferences;
1157 delete[] m_blop;
1158 m_blop = blop;
1159 m_blopSize = blopSize;
1163 /**************************************************************************
1165 C-API
1167 **************************************************************************/
1169 extern "C" {
1171 static void TYPEREG_CALLTYPE acquire(TypeWriterImpl hEntry)
1173 TypeWriter* pEntry = static_cast<TypeWriter*>(hEntry);
1175 if (pEntry != NULL)
1176 pEntry->m_refCount++;
1179 static void TYPEREG_CALLTYPE release(TypeWriterImpl hEntry)
1181 TypeWriter* pEntry = static_cast<TypeWriter*>(hEntry);
1183 if (pEntry != NULL)
1185 if (--pEntry->m_refCount == 0)
1186 delete pEntry;
1190 static void TYPEREG_CALLTYPE setUik(TypeWriterImpl hEntry, const RTUik* uik)
1192 TypeWriter* pEntry = static_cast<TypeWriter*>(hEntry);
1194 if (pEntry != NULL)
1196 if (pEntry->m_pUik)
1198 pEntry->m_pUik->m_Data1 = uik->m_Data1;
1199 pEntry->m_pUik->m_Data2 = uik->m_Data2;
1200 pEntry->m_pUik->m_Data3 = uik->m_Data3;
1201 pEntry->m_pUik->m_Data4 = uik->m_Data4;
1202 pEntry->m_pUik->m_Data5 = uik->m_Data5;
1204 else
1205 pEntry->m_pUik = new RTUik(*uik);
1209 static void TYPEREG_CALLTYPE setDoku(TypeWriterImpl hEntry, rtl_uString* doku)
1211 static_cast< TypeWriter * >(hEntry)->m_doku = toByteString(doku);
1214 static void TYPEREG_CALLTYPE setFileName(TypeWriterImpl hEntry, rtl_uString* fileName)
1216 static_cast< TypeWriter * >(hEntry)->m_fileName = toByteString(fileName);
1219 sal_Bool TYPEREG_CALLTYPE typereg_writer_setFieldData(
1220 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1221 rtl_uString const * fileName, RTFieldAccess flags, rtl_uString const * name,
1222 rtl_uString const * typeName, RTValueType valueType,
1223 RTConstValueUnion valueValue)
1224 SAL_THROW_EXTERN_C()
1226 try {
1227 static_cast< TypeWriter * >(handle)->m_fields[index].setData(
1228 toByteString(name), toByteString(typeName),
1229 toByteString(documentation), toByteString(fileName), flags,
1230 valueType, valueValue);
1231 } catch (std::bad_alloc &) {
1232 return false;
1234 return true;
1237 static void TYPEREG_CALLTYPE setFieldData(TypeWriterImpl hEntry,
1238 sal_uInt16 index,
1239 rtl_uString* name,
1240 rtl_uString* typeName,
1241 rtl_uString* doku,
1242 rtl_uString* fileName,
1243 RTFieldAccess access,
1244 RTValueType valueType,
1245 RTConstValueUnion constValue)
1247 typereg_writer_setFieldData(
1248 hEntry, index, doku, fileName, access, name, typeName, valueType,
1249 constValue);
1252 sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodData(
1253 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1254 RTMethodMode flags, rtl_uString const * name,
1255 rtl_uString const * returnTypeName, sal_uInt16 parameterCount,
1256 sal_uInt16 exceptionCount)
1257 SAL_THROW_EXTERN_C()
1259 try {
1260 static_cast< TypeWriter * >(handle)->m_methods[index].setData(
1261 toByteString(name), toByteString(returnTypeName), flags,
1262 parameterCount, exceptionCount, toByteString(documentation));
1263 } catch (std::bad_alloc &) {
1264 return false;
1266 return true;
1269 static void TYPEREG_CALLTYPE setMethodData(TypeWriterImpl hEntry,
1270 sal_uInt16 index,
1271 rtl_uString* name,
1272 rtl_uString* returnTypeName,
1273 RTMethodMode mode,
1274 sal_uInt16 paramCount,
1275 sal_uInt16 excCount,
1276 rtl_uString* doku)
1278 typereg_writer_setMethodData(
1279 hEntry, index, doku, mode, name, returnTypeName, paramCount, excCount);
1282 sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodParameterData(
1283 void * handle, sal_uInt16 methodIndex, sal_uInt16 parameterIndex,
1284 RTParamMode flags, rtl_uString const * name, rtl_uString const * typeName)
1285 SAL_THROW_EXTERN_C()
1287 try {
1288 static_cast< TypeWriter * >(handle)->
1289 m_methods[methodIndex].m_params[parameterIndex].setData(
1290 toByteString(typeName), toByteString(name), flags);
1291 } catch (std::bad_alloc &) {
1292 return false;
1294 return true;
1297 static void TYPEREG_CALLTYPE setParamData(TypeWriterImpl hEntry,
1298 sal_uInt16 index,
1299 sal_uInt16 paramIndex,
1300 rtl_uString* type,
1301 rtl_uString* name,
1302 RTParamMode mode)
1304 typereg_writer_setMethodParameterData(
1305 hEntry, index, paramIndex, mode, name, type);
1308 sal_Bool TYPEREG_CALLTYPE typereg_writer_setMethodExceptionTypeName(
1309 void * handle, sal_uInt16 methodIndex, sal_uInt16 exceptionIndex,
1310 rtl_uString const * typeName)
1311 SAL_THROW_EXTERN_C()
1313 try {
1314 static_cast< TypeWriter * >(handle)->m_methods[methodIndex].setExcName(
1315 exceptionIndex, toByteString(typeName));
1316 } catch (std::bad_alloc &) {
1317 return false;
1319 return true;
1322 static void TYPEREG_CALLTYPE setExcData(TypeWriterImpl hEntry,
1323 sal_uInt16 index,
1324 sal_uInt16 excIndex,
1325 rtl_uString* type)
1327 typereg_writer_setMethodExceptionTypeName(hEntry, index, excIndex, type);
1330 void const * TYPEREG_CALLTYPE typereg_writer_getBlob(void * handle, sal_uInt32 * size)
1331 SAL_THROW_EXTERN_C()
1333 TypeWriter * writer = static_cast< TypeWriter * >(handle);
1334 if (writer->m_blop == 0) {
1335 try {
1336 writer->createBlop();
1337 } catch (std::bad_alloc &) {
1338 return 0;
1341 *size = writer->m_blopSize;
1342 return writer->m_blop;
1345 static const sal_uInt8* TYPEREG_CALLTYPE getBlop(TypeWriterImpl hEntry)
1347 sal_uInt32 size;
1348 return static_cast< sal_uInt8 const * >(
1349 typereg_writer_getBlob(hEntry, &size));
1352 static sal_uInt32 TYPEREG_CALLTYPE getBlopSize(TypeWriterImpl hEntry)
1354 sal_uInt32 size;
1355 typereg_writer_getBlob(hEntry, &size);
1356 return size;
1359 sal_Bool TYPEREG_CALLTYPE typereg_writer_setReferenceData(
1360 void * handle, sal_uInt16 index, rtl_uString const * documentation,
1361 RTReferenceType sort, RTFieldAccess flags, rtl_uString const * typeName)
1362 SAL_THROW_EXTERN_C()
1364 try {
1365 static_cast< TypeWriter * >(handle)->m_references[index].setData(
1366 toByteString(typeName), sort, toByteString(documentation), flags);
1367 } catch (std::bad_alloc &) {
1368 return false;
1370 return true;
1373 static void TYPEREG_CALLTYPE setReferenceData(TypeWriterImpl hEntry,
1374 sal_uInt16 index,
1375 rtl_uString* name,
1376 RTReferenceType refType,
1377 rtl_uString* doku,
1378 RTFieldAccess access)
1380 typereg_writer_setReferenceData(hEntry, index, doku, refType, access, name);
1383 void * TYPEREG_CALLTYPE typereg_writer_create(
1384 typereg_Version version, rtl_uString const * documentation,
1385 rtl_uString const * fileName, RTTypeClass typeClass, sal_Bool published,
1386 rtl_uString const * typeName, sal_uInt16 superTypeCount,
1387 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1388 SAL_THROW_EXTERN_C()
1390 try {
1391 return new TypeWriter(
1392 version, toByteString(documentation), toByteString(fileName),
1393 typeClass, published, toByteString(typeName), superTypeCount,
1394 fieldCount, methodCount, referenceCount);
1395 } catch (std::bad_alloc &) {
1396 return 0;
1400 void TYPEREG_CALLTYPE typereg_writer_destroy(void * handle) SAL_THROW_EXTERN_C() {
1401 delete static_cast< TypeWriter * >(handle);
1404 sal_Bool TYPEREG_CALLTYPE typereg_writer_setSuperTypeName(
1405 void * handle, sal_uInt16 index, rtl_uString const * typeName)
1406 SAL_THROW_EXTERN_C()
1408 try {
1409 static_cast< TypeWriter * >(handle)->setSuperType(
1410 index, toByteString(typeName));
1411 } catch (std::bad_alloc &) {
1412 return false;
1414 return true;
1417 static TypeWriterImpl TYPEREG_CALLTYPE createEntry(
1418 RTTypeClass typeClass, rtl_uString * typeName, rtl_uString * superTypeName,
1419 sal_uInt16 fieldCount, sal_uInt16 methodCount, sal_uInt16 referenceCount)
1421 OUString empty;
1422 sal_uInt16 superTypeCount = rtl_uString_getLength(superTypeName) == 0
1423 ? 0 : 1;
1424 TypeWriterImpl t = typereg_writer_create(
1425 TYPEREG_VERSION_0, empty.pData, empty.pData, typeClass, false, typeName,
1426 superTypeCount, fieldCount, methodCount, referenceCount);
1427 if (superTypeCount > 0) {
1428 typereg_writer_setSuperTypeName(t, 0, superTypeName);
1430 return t;
1433 RegistryTypeWriter_Api* TYPEREG_CALLTYPE initRegistryTypeWriter_Api()
1435 static RegistryTypeWriter_Api aApi= {0,0,0,0,0,0,0,0,0,0,0,0,0};
1436 if (!aApi.acquire)
1438 aApi.createEntry = &createEntry;
1439 aApi.acquire = &acquire;
1440 aApi.release = &release;
1441 aApi.setUik = &setUik;
1442 aApi.setDoku = &setDoku;
1443 aApi.setFileName = &setFileName;
1444 aApi.setFieldData = &setFieldData;
1445 aApi.setMethodData = &setMethodData;
1446 aApi.setParamData = &setParamData;
1447 aApi.setExcData = &setExcData;
1448 aApi.getBlop = &getBlop;
1449 aApi.getBlopSize = &getBlopSize;
1450 aApi.setReferenceData = &setReferenceData;
1452 return (&aApi);
1454 else
1456 return (&aApi);
1462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */