1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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"
39 inline OString
toByteString(rtl_uString
const * str
) {
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;
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;
93 sal_uInt8
* buff
= const_cast<sal_uInt8
*>(buffer
);
100 for (i
= 0; i
< (len
- 1); i
++)
104 buff
+= readUINT16(buff
, aChar
);
106 v
[i
] = (sal_Unicode
) aChar
;
111 return (buff
- buffer
);
114 sal_uInt32
writeFloat(sal_uInt8
* buffer
, float v
)
124 #ifdef REGTYPE_IEEE_NATIVE
125 writeUINT32(buffer
, x
.b
);
130 return sizeof(sal_uInt32
);
133 sal_uInt32
writeDouble(sal_uInt8
* buffer
, double 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
);
152 writeUINT32(buffer
, x
.b
.b2
);
153 writeUINT32(buffer
+ sizeof(sal_uInt32
), x
.b
.b1
);
159 return (sizeof(sal_uInt32
) + sizeof(sal_uInt32
));
162 /**************************************************************************
164 buffer write functions
166 **************************************************************************/
169 /**************************************************************************
173 **************************************************************************/
180 const sal_Char
* aUtf8
;
182 RTConstValueUnion aConst
;
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
)
202 m_index
= prev
->m_index
+ 1;
207 sal_uInt32
CPInfo::getBlopSize()
209 sal_uInt32 size
= sizeof(sal_uInt32
) /* size */ + sizeof(sal_uInt16
) /* tag */;
213 case CP_TAG_CONST_BOOL
:
214 size
+= sizeof(sal_uInt8
);
216 case CP_TAG_CONST_BYTE
:
217 size
+= sizeof(sal_uInt8
);
219 case CP_TAG_CONST_INT16
:
220 size
+= sizeof(sal_Int16
);
222 case CP_TAG_CONST_UINT16
:
223 size
+= sizeof(sal_uInt16
);
225 case CP_TAG_CONST_INT32
:
226 size
+= sizeof(sal_Int32
);
228 case CP_TAG_CONST_UINT32
:
229 size
+= sizeof(sal_uInt32
);
231 case CP_TAG_CONST_INT64
:
232 size
+= sizeof(sal_Int64
);
234 case CP_TAG_CONST_UINT64
:
235 size
+= sizeof(sal_uInt64
);
237 case CP_TAG_CONST_FLOAT
:
238 size
+= sizeof(sal_uInt32
);
240 case CP_TAG_CONST_DOUBLE
:
241 size
+= sizeof(sal_uInt32
) + sizeof(sal_uInt32
);
243 case CP_TAG_CONST_STRING
:
244 size
+= (rtl_ustr_getLength(m_value
.aConst
.aString
) + 1) * sizeof(sal_uInt16
);
246 case CP_TAG_UTF8_NAME
:
247 size
+= strlen(m_value
.aUtf8
) + 1;
250 size
+= sizeof(sal_uInt32
) + sizeof(sal_uInt16
) + sizeof(sal_uInt16
) + sizeof(sal_uInt32
) + sizeof(sal_uInt32
);
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
);
269 case CP_TAG_CONST_BOOL
:
270 buff
+= writeBYTE(buff
, (sal_uInt8
) m_value
.aConst
.aBool
);
272 case CP_TAG_CONST_BYTE
:
274 buff
, static_cast< sal_uInt8
>(m_value
.aConst
.aByte
));
276 case CP_TAG_CONST_INT16
:
277 buff
+= writeINT16(buff
, m_value
.aConst
.aShort
);
279 case CP_TAG_CONST_UINT16
:
280 buff
+= writeINT16(buff
, m_value
.aConst
.aUShort
);
282 case CP_TAG_CONST_INT32
:
283 buff
+= writeINT32(buff
, m_value
.aConst
.aLong
);
285 case CP_TAG_CONST_UINT32
:
286 buff
+= writeUINT32(buff
, m_value
.aConst
.aULong
);
288 case CP_TAG_CONST_INT64
:
289 buff
+= writeUINT64(buff
, m_value
.aConst
.aHyper
);
291 case CP_TAG_CONST_UINT64
:
292 buff
+= writeUINT64(buff
, m_value
.aConst
.aUHyper
);
294 case CP_TAG_CONST_FLOAT
:
295 buff
+= writeFloat(buff
, m_value
.aConst
.aFloat
);
297 case CP_TAG_CONST_DOUBLE
:
298 buff
+= writeDouble(buff
, m_value
.aConst
.aDouble
);
300 case CP_TAG_CONST_STRING
:
301 buff
+= writeString(buff
, m_value
.aConst
.aString
);
303 case CP_TAG_UTF8_NAME
:
304 buff
+= writeUtf8(buff
, m_value
.aUtf8
);
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
);
317 return (buff
- buffer
);
321 /**************************************************************************
325 **************************************************************************/
336 RTFieldAccess m_access
;
337 RTValueType m_constValueType
;
338 RTConstValueUnion m_constValue
;
343 void setData(const OString
& name
,
344 const OString
& typeName
,
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()
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
,
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
));
387 m_typeName
= typeName
;
389 m_fileName
= fileName
;
392 (m_constValueType
== RT_TYPE_STRING
) &&
393 m_constValue
.aString
&&
394 (m_constValue
.aString
!= NULL_WSTRING
)
397 delete[] m_constValue
.aString
;
401 m_constValueType
= constValueType
;
403 if (m_constValueType
== RT_TYPE_STRING
)
405 if (constValue
.aString
== NULL
)
406 m_constValue
.aString
= NULL_WSTRING
;
409 m_constValue
.aString
= newValue
;
414 m_constValue
= constValue
;
418 /**************************************************************************
422 **************************************************************************/
435 void setData(const OString
& typeName
,
440 ParamEntry::ParamEntry()
441 : m_mode(RT_PARAM_INVALID
)
445 ParamEntry::~ParamEntry()
449 void ParamEntry::setData(const OString
& typeName
,
454 m_typeName
= typeName
;
458 /**************************************************************************
462 **************************************************************************/
470 RTReferenceType m_type
;
471 RTFieldAccess m_access
;
476 void setData(const OString
& name
,
477 RTReferenceType refType
,
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
,
495 RTFieldAccess access
)
503 /**************************************************************************
507 **************************************************************************/
514 OString m_returnTypeName
;
516 sal_uInt16 m_paramCount
;
517 ParamEntry
* m_params
;
518 sal_uInt16 m_excCount
;
525 void setData(const OString
& name
,
526 const OString
& returnTypeName
,
528 sal_uInt16 paramCount
,
530 const OString
& doku
);
532 void setExcName(sal_uInt16 excIndex
, const OString
& name
);
536 void reallocParams(sal_uInt16 size
);
537 void reallocExcs(sal_uInt16 size
);
540 MethodEntry::MethodEntry()
541 : m_mode(RTMethodMode::INVALID
)
549 MethodEntry::~MethodEntry()
558 void MethodEntry::setData(const OString
& name
,
559 const OString
& returnTypeName
,
561 sal_uInt16 paramCount
,
566 m_returnTypeName
= returnTypeName
;
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
;
588 newParams
= new ParamEntry
[size
];
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
);
606 m_params
= newParams
;
609 void MethodEntry::reallocExcs(sal_uInt16 size
)
611 OString
* newExcNames
;
614 newExcNames
= new OString
[size
];
619 sal_uInt16 mn
= size
< m_excCount
? size
: m_excCount
;
621 for (i
= 0; i
< mn
; i
++)
623 newExcNames
[i
] = m_excNames
[i
];
629 m_excNames
= newExcNames
;
633 /**************************************************************************
635 class TypeRegistryEntry
637 **************************************************************************/
644 sal_uInt32 m_refCount
;
645 typereg_Version m_version
;
646 RTTypeClass m_typeClass
;
648 sal_uInt16 m_nSuperTypes
;
649 OString
* m_superTypeNames
;
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
;
661 sal_uInt32 m_blopSize
;
663 TypeWriter(typereg_Version version
,
664 OString
const & documentation
,
665 OString
const & fileName
,
666 RTTypeClass RTTypeClass
,
668 const OString
& typeName
,
669 sal_uInt16 superTypeCount
,
670 sal_uInt16 FieldCount
,
671 sal_uInt16 methodCount
,
672 sal_uInt16 referenceCount
);
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
,
686 const OString
& typeName
,
687 sal_uInt16 superTypeCount
,
688 sal_uInt16 fieldCount
,
689 sal_uInt16 methodCount
,
690 sal_uInt16 referenceCount
)
694 static_cast< enum RTTypeClass
>(
695 RTTypeClass
| (published
? RT_TYPE_PUBLISHED
: 0)))
696 , m_typeName(typeName
)
697 , m_nSuperTypes(superTypeCount
)
699 , m_doku(documentation
)
700 , m_fileName(fileName
)
701 , m_fieldCount(fieldCount
)
703 , m_methodCount(methodCount
)
705 , m_referenceCount(referenceCount
)
710 if (m_nSuperTypes
> 0)
712 m_superTypeNames
= new OString
[m_nSuperTypes
];
715 m_superTypeNames
= NULL
;
719 m_fields
= new FieldEntry
[fieldCount
];
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
;
742 if (m_referenceCount
)
743 delete[] m_references
;
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
;
789 blopSize
+= entrySize
;
791 // create CP entry for super names
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
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
;
831 blopSize
+= sizeof(sal_uInt16
); // fieldCount + nFieldEntries
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
++)
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
);
904 blopSize
+= sizeof(sal_uInt16
); // 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
++)
942 pBuffer
+= writeUINT16(pBuffer
, pMethodEntrySize
[i
]);
943 pBuffer
+= writeUINT16(
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
);
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
);
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
);
987 pBuffer
+= writeUINT16(
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
);
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
);
1017 delete[] pMethodEntrySize
;
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(
1042 sal::static_int_cast
< sal_uInt16
>(m_references
[i
].m_type
));
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;
1075 cpBlopSize
+= pInfo
->getBlopSize();
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
];
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
);
1104 pBuffer
+= writeUINT16(pBuffer
, 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
;
1121 CPInfo
* pNextInfo
= pInfo
->m_next
;
1123 pBuffer
+= pInfo
->toBlop(pBuffer
);
1130 pBuffer
+= writeUINT16(pBuffer
, m_fieldCount
);
1133 memcpy(pBuffer
, pBlopFields
, blopFieldsSize
);
1134 pBuffer
+= blopFieldsSize
;
1138 pBuffer
+= writeUINT16(pBuffer
, m_methodCount
);
1139 if (blopMethodsSize
)
1141 memcpy(pBuffer
, pBlopMethods
, blopMethodsSize
);
1142 pBuffer
+= blopMethodsSize
;
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
;
1159 m_blopSize
= blopSize
;
1163 /**************************************************************************
1167 **************************************************************************/
1171 static void TYPEREG_CALLTYPE
acquire(TypeWriterImpl hEntry
)
1173 TypeWriter
* pEntry
= static_cast<TypeWriter
*>(hEntry
);
1176 pEntry
->m_refCount
++;
1179 static void TYPEREG_CALLTYPE
release(TypeWriterImpl hEntry
)
1181 TypeWriter
* pEntry
= static_cast<TypeWriter
*>(hEntry
);
1185 if (--pEntry
->m_refCount
== 0)
1190 static void TYPEREG_CALLTYPE
setUik(TypeWriterImpl hEntry
, const RTUik
* uik
)
1192 TypeWriter
* pEntry
= static_cast<TypeWriter
*>(hEntry
);
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
;
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()
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
&) {
1237 static void TYPEREG_CALLTYPE
setFieldData(TypeWriterImpl hEntry
,
1240 rtl_uString
* typeName
,
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
,
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()
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
&) {
1269 static void TYPEREG_CALLTYPE
setMethodData(TypeWriterImpl hEntry
,
1272 rtl_uString
* returnTypeName
,
1274 sal_uInt16 paramCount
,
1275 sal_uInt16 excCount
,
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()
1288 static_cast< TypeWriter
* >(handle
)->
1289 m_methods
[methodIndex
].m_params
[parameterIndex
].setData(
1290 toByteString(typeName
), toByteString(name
), flags
);
1291 } catch (std::bad_alloc
&) {
1297 static void TYPEREG_CALLTYPE
setParamData(TypeWriterImpl hEntry
,
1299 sal_uInt16 paramIndex
,
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()
1314 static_cast< TypeWriter
* >(handle
)->m_methods
[methodIndex
].setExcName(
1315 exceptionIndex
, toByteString(typeName
));
1316 } catch (std::bad_alloc
&) {
1322 static void TYPEREG_CALLTYPE
setExcData(TypeWriterImpl hEntry
,
1324 sal_uInt16 excIndex
,
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) {
1336 writer
->createBlop();
1337 } catch (std::bad_alloc
&) {
1341 *size
= writer
->m_blopSize
;
1342 return writer
->m_blop
;
1345 static const sal_uInt8
* TYPEREG_CALLTYPE
getBlop(TypeWriterImpl hEntry
)
1348 return static_cast< sal_uInt8
const * >(
1349 typereg_writer_getBlob(hEntry
, &size
));
1352 static sal_uInt32 TYPEREG_CALLTYPE
getBlopSize(TypeWriterImpl hEntry
)
1355 typereg_writer_getBlob(hEntry
, &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()
1365 static_cast< TypeWriter
* >(handle
)->m_references
[index
].setData(
1366 toByteString(typeName
), sort
, toByteString(documentation
), flags
);
1367 } catch (std::bad_alloc
&) {
1373 static void TYPEREG_CALLTYPE
setReferenceData(TypeWriterImpl hEntry
,
1376 RTReferenceType refType
,
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()
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
&) {
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()
1409 static_cast< TypeWriter
* >(handle
)->setSuperType(
1410 index
, toByteString(typeName
));
1411 } catch (std::bad_alloc
&) {
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
)
1422 sal_uInt16 superTypeCount
= rtl_uString_getLength(superTypeName
) == 0
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
);
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};
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
;
1462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */