1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: reflwrit.cxx,v $
10 * $Revision: 1.15.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_registry.hxx"
35 #include <sal/types.h>
36 #include <sal/macros.h>
37 #include <osl/endian.h>
38 #include <rtl/alloc.h>
39 #include "rtl/string.hxx"
40 #include "rtl/ustring.hxx"
42 #include "registry/reflwrit.hxx"
43 #include "registry/version.h"
44 #include "registry/writer.h"
46 #include "reflcnst.hxx"
52 // Throws std::bad_alloc:
53 inline rtl::OString
toByteString(rtl_uString
const * str
) {
55 str
->buffer
, str
->length
, RTL_TEXTENCODING_UTF8
,
56 OUSTRING_TO_OSTRING_CVTFLAGS
);
61 static sal_Unicode NULL_WSTRING
[1] = { 0 };
63 #if defined ( GCC ) && ( defined ( SCO ) )
64 ORealDynamicLoader
* ODynamicLoader
<RegistryTypeWriter_Api
>::m_pLoader
= NULL
;
67 #define BLOP_OFFSET_MAGIC 0
68 #define BLOP_OFFSET_SIZE (BLOP_OFFSET_MAGIC + sizeof(sal_uInt32))
69 #define BLOP_OFFSET_MINOR (BLOP_OFFSET_SIZE + sizeof(sal_uInt32))
70 #define BLOP_OFFSET_MAJOR (BLOP_OFFSET_MINOR + sizeof(sal_uInt16))
71 #define BLOP_OFFSET_N_ENTRIES (BLOP_OFFSET_MAJOR + sizeof(sal_uInt16))
72 #define BLOP_OFFSET_TYPE_SOURCE (BLOP_OFFSET_N_ENTRIES + sizeof(sal_uInt16))
73 #define BLOP_OFFSET_TYPE_CLASS (BLOP_OFFSET_TYPE_SOURCE + sizeof(sal_uInt16))
74 #define BLOP_OFFSET_THIS (BLOP_OFFSET_TYPE_CLASS + sizeof(sal_uInt16))
75 #define BLOP_OFFSET_UIK (BLOP_OFFSET_THIS + sizeof(sal_uInt16))
76 #define BLOP_OFFSET_DOKU (BLOP_OFFSET_UIK + sizeof(sal_uInt16))
77 #define BLOP_OFFSET_FILENAME (BLOP_OFFSET_DOKU + sizeof(sal_uInt16))
78 #define BLOP_HEADER_N_ENTRIES 6
80 #define BLOP_OFFSET_N_SUPERTYPES 0
81 #define BLOP_OFFSET_SUPERTYPES (BLOP_OFFSET_N_SUPERTYPES + sizeof(sal_uInt16))
83 #define BLOP_FIELD_ENTRY_ACCESS 0
84 #define BLOP_FIELD_ENTRY_NAME (BLOP_FIELD_ENTRY_ACCESS + sizeof(sal_uInt16))
85 #define BLOP_FIELD_ENTRY_TYPE (BLOP_FIELD_ENTRY_NAME + sizeof(sal_uInt16))
86 #define BLOP_FIELD_ENTRY_VALUE (BLOP_FIELD_ENTRY_TYPE + sizeof(sal_uInt16))
87 #define BLOP_FIELD_ENTRY_DOKU (BLOP_FIELD_ENTRY_VALUE + sizeof(sal_uInt16))
88 #define BLOP_FIELD_ENTRY_FILENAME (BLOP_FIELD_ENTRY_DOKU + sizeof(sal_uInt16))
89 #define BLOP_FIELD_N_ENTRIES 6
91 #define BLOP_METHOD_SIZE 0
92 #define BLOP_METHOD_MODE (BLOP_METHOD_SIZE + sizeof(sal_uInt16))
93 #define BLOP_METHOD_NAME (BLOP_METHOD_MODE + sizeof(sal_uInt16))
94 #define BLOP_METHOD_RETURN (BLOP_METHOD_NAME + sizeof(sal_uInt16))
95 #define BLOP_METHOD_DOKU (BLOP_METHOD_RETURN + sizeof(sal_uInt16))
96 #define BLOP_METHOD_N_ENTRIES 5
98 #define BLOP_PARAM_TYPE 0
99 #define BLOP_PARAM_MODE (BLOP_PARAM_TYPE + sizeof(sal_uInt16))
100 #define BLOP_PARAM_NAME (BLOP_PARAM_MODE + sizeof(sal_uInt16))
101 #define BLOP_PARAM_N_ENTRIES 3
103 #define BLOP_REFERENCE_TYPE 0
104 #define BLOP_REFERENCE_NAME (BLOP_REFERENCE_TYPE + sizeof(sal_uInt16))
105 #define BLOP_REFERENCE_DOKU (BLOP_REFERENCE_NAME + sizeof(sal_uInt16))
106 #define BLOP_REFERENCE_ACCESS (BLOP_REFERENCE_DOKU + sizeof(sal_uInt16))
107 #define BLOP_REFERENCE_N_ENTRIES 4
109 sal_uInt32
UINT16StringLen(const sal_uInt8
* wstring
)
111 if (!wstring
) return 0;
113 const sal_uInt8
* b
= wstring
;
115 while (b
[0] || b
[1]) b
+= sizeof(sal_uInt16
);
117 return ((b
- wstring
) / sizeof(sal_uInt16
));
120 sal_uInt32
writeString(sal_uInt8
* buffer
, const sal_Unicode
* v
)
122 sal_uInt32 len
= rtl_ustr_getLength(v
) + 1;
124 sal_uInt8
* buff
= buffer
;
126 for (i
= 0; i
< len
; i
++)
128 buff
+= writeUINT16(buff
, (sal_uInt16
) v
[i
]);
131 return (buff
- buffer
);
134 sal_uInt32
readString(const sal_uInt8
* buffer
, sal_Unicode
* v
, sal_uInt32 maxSize
)
136 sal_uInt32 len
= SAL_MIN(UINT16StringLen(buffer
) + 1, maxSize
/ 2);
138 sal_uInt8
* buff
= (sal_uInt8
*)buffer
;
140 for (i
= 0; i
< (len
- 1); i
++)
144 buff
+= readUINT16(buff
, aChar
);
146 v
[i
] = (sal_Unicode
) aChar
;
151 return (buff
- ((sal_uInt8
*)buffer
));
154 sal_uInt32
writeFloat(sal_uInt8
* buffer
, float v
)
164 #ifdef REGTYPE_IEEE_NATIVE
165 writeUINT32(buffer
, x
.b
);
170 return sizeof(sal_uInt32
);
173 sal_uInt32
writeDouble(sal_uInt8
* buffer
, double v
)
187 #ifdef REGTYPE_IEEE_NATIVE
188 # ifdef OSL_BIGENDIAN
189 writeUINT32(buffer
, x
.b
.b1
);
190 writeUINT32(buffer
+ sizeof(sal_uInt32
), x
.b
.b2
);
192 writeUINT32(buffer
, x
.b
.b2
);
193 writeUINT32(buffer
+ sizeof(sal_uInt32
), x
.b
.b1
);
199 return (sizeof(sal_uInt32
) + sizeof(sal_uInt32
));
202 /**************************************************************************
204 buffer write functions
206 **************************************************************************/
209 /**************************************************************************
213 **************************************************************************/
220 const sal_Char
* aUtf8
;
222 RTConstValueUnion aConst
;
226 struct CPInfo
* m_next
;
228 CPInfo(CPInfoTag tag
, struct CPInfo
* prev
);
230 sal_uInt32
getBlopSize();
232 sal_uInt32
toBlop(sal_uInt8
* buffer
);
235 CPInfo::CPInfo(CPInfoTag tag
, struct CPInfo
* prev
)
242 m_index
= prev
->m_index
+ 1;
247 sal_uInt32
CPInfo::getBlopSize()
249 sal_uInt32 size
= sizeof(sal_uInt32
) /* size */ + sizeof(sal_uInt16
) /* tag */;
253 case CP_TAG_CONST_BOOL
:
254 size
+= sizeof(sal_uInt8
);
256 case CP_TAG_CONST_BYTE
:
257 size
+= sizeof(sal_uInt8
);
259 case CP_TAG_CONST_INT16
:
260 size
+= sizeof(sal_Int16
);
262 case CP_TAG_CONST_UINT16
:
263 size
+= sizeof(sal_uInt16
);
265 case CP_TAG_CONST_INT32
:
266 size
+= sizeof(sal_Int32
);
268 case CP_TAG_CONST_UINT32
:
269 size
+= sizeof(sal_uInt32
);
271 case CP_TAG_CONST_INT64
:
272 size
+= sizeof(sal_Int64
);
274 case CP_TAG_CONST_UINT64
:
275 size
+= sizeof(sal_uInt64
);
277 case CP_TAG_CONST_FLOAT
:
278 size
+= sizeof(sal_uInt32
);
280 case CP_TAG_CONST_DOUBLE
:
281 size
+= sizeof(sal_uInt32
) + sizeof(sal_uInt32
);
283 case CP_TAG_CONST_STRING
:
284 size
+= (rtl_ustr_getLength(m_value
.aConst
.aString
) + 1) * sizeof(sal_uInt16
);
286 case CP_TAG_UTF8_NAME
:
287 size
+= strlen(m_value
.aUtf8
) + 1;
290 size
+= sizeof(sal_uInt32
) + sizeof(sal_uInt16
) + sizeof(sal_uInt16
) + sizeof(sal_uInt32
) + sizeof(sal_uInt32
);
300 sal_uInt32
CPInfo::toBlop(sal_uInt8
* buffer
)
302 sal_uInt8
* buff
= buffer
;
304 buff
+= writeUINT32(buff
, getBlopSize());
305 buff
+= writeUINT16(buff
, (sal_uInt16
) m_tag
);
309 case CP_TAG_CONST_BOOL
:
310 buff
+= writeBYTE(buff
, (sal_uInt8
) m_value
.aConst
.aBool
);
312 case CP_TAG_CONST_BYTE
:
313 buff
+= writeBYTE(buff
, m_value
.aConst
.aByte
);
315 case CP_TAG_CONST_INT16
:
316 buff
+= writeINT16(buff
, m_value
.aConst
.aShort
);
318 case CP_TAG_CONST_UINT16
:
319 buff
+= writeINT16(buff
, m_value
.aConst
.aUShort
);
321 case CP_TAG_CONST_INT32
:
322 buff
+= writeINT32(buff
, m_value
.aConst
.aLong
);
324 case CP_TAG_CONST_UINT32
:
325 buff
+= writeUINT32(buff
, m_value
.aConst
.aULong
);
327 case CP_TAG_CONST_INT64
:
328 buff
+= writeUINT64(buff
, m_value
.aConst
.aHyper
);
330 case CP_TAG_CONST_UINT64
:
331 buff
+= writeUINT64(buff
, m_value
.aConst
.aUHyper
);
333 case CP_TAG_CONST_FLOAT
:
334 buff
+= writeFloat(buff
, m_value
.aConst
.aFloat
);
336 case CP_TAG_CONST_DOUBLE
:
337 buff
+= writeDouble(buff
, m_value
.aConst
.aDouble
);
339 case CP_TAG_CONST_STRING
:
340 buff
+= writeString(buff
, m_value
.aConst
.aString
);
342 case CP_TAG_UTF8_NAME
:
343 buff
+= writeUtf8(buff
, m_value
.aUtf8
);
346 buff
+= writeUINT32(buff
, m_value
.aUik
->m_Data1
);
347 buff
+= writeUINT16(buff
, m_value
.aUik
->m_Data2
);
348 buff
+= writeUINT16(buff
, m_value
.aUik
->m_Data3
);
349 buff
+= writeUINT32(buff
, m_value
.aUik
->m_Data4
);
350 buff
+= writeUINT32(buff
, m_value
.aUik
->m_Data5
);
356 return (buff
- buffer
);
360 /**************************************************************************
364 **************************************************************************/
375 RTFieldAccess m_access
;
376 RTValueType m_constValueType
;
377 RTConstValueUnion m_constValue
;
382 void setData(const OString
& name
,
383 const OString
& typeName
,
385 const OString
& fileName
,
386 RTFieldAccess access
,
387 RTValueType constValueType
,
388 RTConstValueUnion constValue
);
389 // throws std::bad_alloc
392 FieldEntry::FieldEntry()
393 : m_access(RT_ACCESS_INVALID
)
394 , m_constValueType(RT_TYPE_NONE
)
398 FieldEntry::~FieldEntry()
401 (m_constValueType
== RT_TYPE_STRING
) &&
402 m_constValue
.aString
&&
403 (m_constValue
.aString
!= NULL_WSTRING
)
406 delete[] (sal_Unicode
*)m_constValue
.aString
;
410 void FieldEntry::setData(const OString
& name
,
411 const OString
& typeName
,
413 const OString
& fileName
,
414 RTFieldAccess access
,
415 RTValueType constValueType
,
416 RTConstValueUnion constValue
)
418 sal_Unicode
* newValue
= 0;
419 if (constValueType
== RT_TYPE_STRING
&& constValue
.aString
!= 0) {
420 sal_Int32 n
= rtl_ustr_getLength(constValue
.aString
) + 1;
421 newValue
= new sal_Unicode
[n
];
422 rtl_copyMemory(newValue
, constValue
.aString
, n
* sizeof (sal_Unicode
));
426 m_typeName
= typeName
;
428 m_fileName
= fileName
;
431 (m_constValueType
== RT_TYPE_STRING
) &&
432 m_constValue
.aString
&&
433 (m_constValue
.aString
!= NULL_WSTRING
)
436 delete[] (sal_Unicode
*)m_constValue
.aString
;
440 m_constValueType
= constValueType
;
442 if (m_constValueType
== RT_TYPE_STRING
)
444 if (constValue
.aString
== NULL
)
445 m_constValue
.aString
= NULL_WSTRING
;
448 m_constValue
.aString
= newValue
;
453 m_constValue
= constValue
;
457 /**************************************************************************
461 **************************************************************************/
474 void setData(const OString
& typeName
,
479 ParamEntry::ParamEntry()
480 : m_mode(RT_PARAM_INVALID
)
484 ParamEntry::~ParamEntry()
488 void ParamEntry::setData(const OString
& typeName
,
493 m_typeName
= typeName
;
497 /**************************************************************************
501 **************************************************************************/
509 RTReferenceType m_type
;
510 RTFieldAccess m_access
;
515 void setData(const OString
& name
,
516 RTReferenceType refType
,
518 RTFieldAccess access
);
521 ReferenceEntry::ReferenceEntry()
522 : m_type(RT_REF_INVALID
)
523 , m_access(RT_ACCESS_INVALID
)
527 ReferenceEntry::~ReferenceEntry()
531 void ReferenceEntry::setData(const OString
& name
,
532 RTReferenceType refType
,
534 RTFieldAccess access
)
542 /**************************************************************************
546 **************************************************************************/
553 OString m_returnTypeName
;
555 sal_uInt16 m_paramCount
;
556 ParamEntry
* m_params
;
557 sal_uInt16 m_excCount
;
564 void setData(const OString
& name
,
565 const OString
& returnTypeName
,
567 sal_uInt16 paramCount
,
569 const OString
& doku
);
571 void setExcName(sal_uInt16 excIndex
, const OString
& name
);
575 void reallocParams(sal_uInt16 size
);
576 void reallocExcs(sal_uInt16 size
);
579 MethodEntry::MethodEntry()
580 : m_mode(RT_MODE_INVALID
)
588 MethodEntry::~MethodEntry()
597 void MethodEntry::setData(const OString
& name
,
598 const OString
& returnTypeName
,
600 sal_uInt16 paramCount
,
605 m_returnTypeName
= returnTypeName
;
610 reallocParams(paramCount
);
611 reallocExcs(excCount
);
614 void MethodEntry::setExcName(sal_uInt16 excIndex
, const OString
& name
)
616 if (excIndex
< m_excCount
)
618 m_excNames
[excIndex
] = name
;
622 void MethodEntry::reallocParams(sal_uInt16 size
)
624 ParamEntry
* newParams
;
627 newParams
= new ParamEntry
[size
];
635 for (i
= 0; i
< SAL_MIN(size
, m_paramCount
); i
++)
637 newParams
[i
].setData(m_params
[i
].m_typeName
, m_params
[i
].m_name
, m_params
[i
].m_mode
);
644 m_params
= newParams
;
647 void MethodEntry::reallocExcs(sal_uInt16 size
)
649 OString
* newExcNames
;
652 newExcNames
= new OString
[size
];
658 for (i
= 0; i
< SAL_MIN(size
, m_excCount
); i
++)
660 newExcNames
[i
] = m_excNames
[i
];
666 m_excNames
= newExcNames
;
670 /**************************************************************************
672 class TypeRegistryEntry
674 **************************************************************************/
681 sal_uInt32 m_refCount
;
682 typereg_Version m_version
;
683 RTTypeClass m_typeClass
;
685 sal_uInt16 m_nSuperTypes
;
686 OString
* m_superTypeNames
;
690 sal_uInt16 m_fieldCount
;
691 FieldEntry
* m_fields
;
692 sal_uInt16 m_methodCount
;
693 MethodEntry
* m_methods
;
694 sal_uInt16 m_referenceCount
;
695 ReferenceEntry
* m_references
;
698 sal_uInt32 m_blopSize
;
700 TypeWriter(typereg_Version version
,
701 rtl::OString
const & documentation
,
702 rtl::OString
const & fileName
,
703 RTTypeClass RTTypeClass
,
705 const OString
& typeName
,
706 sal_uInt16 superTypeCount
,
707 sal_uInt16 FieldCount
,
708 sal_uInt16 methodCount
,
709 sal_uInt16 referenceCount
);
713 void setSuperType(sal_uInt16 index
, OString
const & name
);
715 void createBlop(); // throws std::bad_alloc
718 TypeWriter::TypeWriter(typereg_Version version
,
719 rtl::OString
const & documentation
,
720 rtl::OString
const & fileName
,
721 RTTypeClass RTTypeClass
,
723 const OString
& typeName
,
724 sal_uInt16 superTypeCount
,
725 sal_uInt16 fieldCount
,
726 sal_uInt16 methodCount
,
727 sal_uInt16 referenceCount
)
731 static_cast< enum RTTypeClass
>(
732 RTTypeClass
| (published
? RT_TYPE_PUBLISHED
: 0)))
733 , m_typeName(typeName
)
734 , m_nSuperTypes(superTypeCount
)
736 , m_doku(documentation
)
737 , m_fileName(fileName
)
738 , m_fieldCount(fieldCount
)
739 , m_methodCount(methodCount
)
740 , m_referenceCount(referenceCount
)
744 if (m_nSuperTypes
> 0)
746 m_superTypeNames
= new OString
[m_nSuperTypes
];
749 m_superTypeNames
= NULL
;
753 m_fields
= new FieldEntry
[fieldCount
];
756 m_methods
= new MethodEntry
[methodCount
];
758 if (m_referenceCount
)
759 m_references
= new ReferenceEntry
[referenceCount
];
762 TypeWriter::~TypeWriter()
764 if (m_superTypeNames
)
765 delete[] m_superTypeNames
;
776 if (m_referenceCount
)
777 delete[] m_references
;
783 void TypeWriter::setSuperType(sal_uInt16 index
, OString
const & name
)
785 m_superTypeNames
[index
] = name
;
788 void TypeWriter::createBlop()
790 //TODO: Fix memory leaks that occur when std::bad_alloc is thrown
792 sal_uInt8
* pBlopFields
= NULL
;
793 sal_uInt8
* pBlopMethods
= NULL
;
794 sal_uInt8
* pBlopReferences
= NULL
;
795 sal_uInt8
* pBuffer
= NULL
;
796 sal_uInt32 blopFieldsSize
= 0;
797 sal_uInt32 blopMethodsSize
= 0;
798 sal_uInt32 blopReferenceSize
= 0;
800 CPInfo
root(CP_TAG_INVALID
, NULL
);
801 sal_uInt16 cpIndexThisName
= 0;
802 sal_uInt16
* cpIndexSuperNames
= NULL
;
803 sal_uInt16 cpIndexUik
= 0;
804 sal_uInt16 cpIndexDoku
= 0;
805 sal_uInt16 cpIndexFileName
= 0;
806 CPInfo
* pInfo
= NULL
;
808 sal_uInt16 entrySize
= sizeof(sal_uInt16
);
809 sal_uInt32 blopHeaderEntrySize
= BLOP_OFFSET_N_ENTRIES
+ entrySize
+ (BLOP_HEADER_N_ENTRIES
* entrySize
);
810 sal_uInt32 blopFieldEntrySize
= BLOP_FIELD_N_ENTRIES
* entrySize
;
811 sal_uInt32 blopMethodEntrySize
= BLOP_METHOD_N_ENTRIES
* entrySize
;
812 sal_uInt32 blopParamEntrySize
= BLOP_PARAM_N_ENTRIES
* entrySize
;
813 sal_uInt32 blopReferenceEntrySize
= BLOP_REFERENCE_N_ENTRIES
* entrySize
;
815 sal_uInt32 blopSize
= blopHeaderEntrySize
;
817 // create CP entry for this name
818 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, &root
);
819 pInfo
->m_value
.aUtf8
= m_typeName
.getStr();
820 cpIndexThisName
= pInfo
->m_index
;
823 blopSize
+= entrySize
;
825 // create CP entry for super names
828 blopSize
+= m_nSuperTypes
* entrySize
;
830 cpIndexSuperNames
= new sal_uInt16
[m_nSuperTypes
];
832 for (sal_uInt32 i
=0; i
< m_nSuperTypes
; i
++)
834 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
835 pInfo
->m_value
.aUtf8
= m_superTypeNames
[i
].getStr();
836 cpIndexSuperNames
[i
] = pInfo
->m_index
;
840 // create CP entry for uik
843 pInfo
= new CPInfo(CP_TAG_UIK
, pInfo
);
844 pInfo
->m_value
.aUik
= m_pUik
;
845 cpIndexUik
= pInfo
->m_index
;
848 // create CP entry for doku
849 if (m_doku
.getLength())
851 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
852 pInfo
->m_value
.aUtf8
= m_doku
.getStr();
853 cpIndexDoku
= pInfo
->m_index
;
856 // create CP entry for idl source filename
857 if (m_fileName
.getLength())
859 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
860 pInfo
->m_value
.aUtf8
= m_fileName
.getStr();
861 cpIndexFileName
= pInfo
->m_index
;
865 blopSize
+= sizeof(sal_uInt16
); // fieldCount + nFieldEntries
869 sal_uInt16 cpIndexName
= 0;
870 sal_uInt16 cpIndexTypeName
= 0;
871 sal_uInt16 cpIndexValue
= 0;
872 sal_uInt16 cpIndexDoku2
= 0;
873 sal_uInt16 cpIndexFileName2
= 0;
875 // nFieldEntries + n fields
876 blopFieldsSize
= sizeof(sal_uInt16
) + (m_fieldCount
* blopFieldEntrySize
);
878 blopSize
+= blopFieldsSize
;
880 pBlopFields
= new sal_uInt8
[blopFieldsSize
];
881 pBuffer
= pBlopFields
;
883 pBuffer
+= writeUINT16(pBuffer
, BLOP_FIELD_N_ENTRIES
);
885 for (sal_uInt16 i
= 0; i
< m_fieldCount
; i
++)
891 cpIndexFileName2
= 0;
893 pBuffer
+= writeUINT16(pBuffer
, m_fields
[i
].m_access
);
895 if (m_fields
[i
].m_name
.getLength())
897 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
898 pInfo
->m_value
.aUtf8
= m_fields
[i
].m_name
.getStr();
899 cpIndexName
= pInfo
->m_index
;
901 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
903 if (m_fields
[i
].m_typeName
.getLength())
905 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
906 pInfo
->m_value
.aUtf8
= m_fields
[i
].m_typeName
.getStr();
907 cpIndexTypeName
= pInfo
->m_index
;
909 pBuffer
+= writeUINT16(pBuffer
, cpIndexTypeName
);
911 if (m_fields
[i
].m_constValueType
!= RT_TYPE_NONE
)
913 pInfo
= new CPInfo((CPInfoTag
)m_fields
[i
].m_constValueType
, pInfo
);
914 pInfo
->m_value
.aConst
= m_fields
[i
].m_constValue
;
915 cpIndexValue
= pInfo
->m_index
;
917 pBuffer
+= writeUINT16(pBuffer
, cpIndexValue
);
919 if (m_fields
[i
].m_doku
.getLength())
921 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
922 pInfo
->m_value
.aUtf8
= m_fields
[i
].m_doku
.getStr();
923 cpIndexDoku2
= pInfo
->m_index
;
925 pBuffer
+= writeUINT16(pBuffer
, cpIndexDoku2
);
927 if (m_fields
[i
].m_fileName
.getLength())
929 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
930 pInfo
->m_value
.aUtf8
= m_fields
[i
].m_fileName
.getStr();
931 cpIndexFileName2
= pInfo
->m_index
;
933 pBuffer
+= writeUINT16(pBuffer
, cpIndexFileName2
);
938 blopSize
+= sizeof(sal_uInt16
); // methodCount
942 sal_uInt16
* pMethodEntrySize
= new sal_uInt16
[m_methodCount
];
943 sal_uInt16 cpIndexName
= 0;
944 sal_uInt16 cpIndexReturn
= 0;
945 sal_uInt16 cpIndexDoku2
= 0;
947 // nMethodEntries + nParamEntries
948 blopMethodsSize
= (2 * sizeof(sal_uInt16
));
950 for (sal_uInt16 i
= 0; i
< m_methodCount
; i
++)
952 pMethodEntrySize
[i
] = (sal_uInt16
)
953 ( blopMethodEntrySize
+ // header
954 sizeof(sal_uInt16
) + // parameterCount
955 (m_methods
[i
].m_paramCount
* blopParamEntrySize
) + // exceptions
956 sizeof(sal_uInt16
) + // exceptionCount
957 (m_methods
[i
].m_excCount
* sizeof(sal_uInt16
)) ); // exceptions
959 blopMethodsSize
+= pMethodEntrySize
[i
];
962 pBlopMethods
= new sal_uInt8
[blopMethodsSize
];
964 blopSize
+= blopMethodsSize
;
966 pBuffer
= pBlopMethods
;
968 pBuffer
+= writeUINT16(pBuffer
, BLOP_METHOD_N_ENTRIES
);
969 pBuffer
+= writeUINT16(pBuffer
, BLOP_PARAM_N_ENTRIES
);
971 for (sal_uInt16 i
= 0; i
< m_methodCount
; i
++)
976 pBuffer
+= writeUINT16(pBuffer
, pMethodEntrySize
[i
]);
977 pBuffer
+= writeUINT16(
979 sal::static_int_cast
< sal_uInt16
>(m_methods
[i
].m_mode
));
981 if (m_methods
[i
].m_name
.getLength())
983 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
984 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_name
.getStr();
985 cpIndexName
= pInfo
->m_index
;
987 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
990 if (m_methods
[i
].m_returnTypeName
.getLength())
992 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
993 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_returnTypeName
.getStr();
994 cpIndexReturn
= pInfo
->m_index
;
996 pBuffer
+= writeUINT16(pBuffer
, cpIndexReturn
);
998 if (m_methods
[i
].m_doku
.getLength())
1000 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1001 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_doku
.getStr();
1002 cpIndexDoku2
= pInfo
->m_index
;
1004 pBuffer
+= writeUINT16(pBuffer
, cpIndexDoku2
);
1008 pBuffer
+= writeUINT16(pBuffer
, m_methods
[i
].m_paramCount
);
1010 for (j
= 0; j
< m_methods
[i
].m_paramCount
; j
++)
1012 if (m_methods
[i
].m_params
[j
].m_typeName
.getLength())
1014 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1015 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_params
[j
].m_typeName
.getStr();
1016 cpIndexName
= pInfo
->m_index
;
1018 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
1021 pBuffer
+= writeUINT16(
1023 sal::static_int_cast
< sal_uInt16
>(
1024 m_methods
[i
].m_params
[j
].m_mode
));
1026 if (m_methods
[i
].m_params
[j
].m_name
.getLength())
1028 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1029 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_params
[j
].m_name
.getStr();
1030 cpIndexName
= pInfo
->m_index
;
1032 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
1036 pBuffer
+= writeUINT16(pBuffer
, m_methods
[i
].m_excCount
);
1038 for (j
= 0; j
< m_methods
[i
].m_excCount
; j
++)
1040 if (m_methods
[i
].m_excNames
[j
].getLength())
1042 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1043 pInfo
->m_value
.aUtf8
= m_methods
[i
].m_excNames
[j
].getStr();
1044 cpIndexName
= pInfo
->m_index
;
1046 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
1051 delete[] pMethodEntrySize
;
1055 blopSize
+= entrySize
; // referenceCount
1057 if (m_referenceCount
)
1059 sal_uInt16 cpIndexName
= 0;
1060 sal_uInt16 cpIndexDoku2
= 0;
1062 // nReferenceEntries + n references
1063 blopReferenceSize
= entrySize
+ (m_referenceCount
* blopReferenceEntrySize
);
1065 blopSize
+= blopReferenceSize
;
1067 pBlopReferences
= new sal_uInt8
[blopReferenceSize
];
1068 pBuffer
= pBlopReferences
;
1070 pBuffer
+= writeUINT16(pBuffer
, BLOP_REFERENCE_N_ENTRIES
);
1072 for (sal_uInt16 i
= 0; i
< m_referenceCount
; i
++)
1074 pBuffer
+= writeUINT16(
1076 sal::static_int_cast
< sal_uInt16
>(m_references
[i
].m_type
));
1081 if (m_references
[i
].m_name
.getLength())
1083 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1084 pInfo
->m_value
.aUtf8
= m_references
[i
].m_name
.getStr();
1085 cpIndexName
= pInfo
->m_index
;
1087 pBuffer
+= writeUINT16(pBuffer
, cpIndexName
);
1089 if (m_references
[i
].m_doku
.getLength())
1091 pInfo
= new CPInfo(CP_TAG_UTF8_NAME
, pInfo
);
1092 pInfo
->m_value
.aUtf8
= m_references
[i
].m_doku
.getStr();
1093 cpIndexDoku2
= pInfo
->m_index
;
1095 pBuffer
+= writeUINT16(pBuffer
, cpIndexDoku2
);
1097 pBuffer
+= writeUINT16(pBuffer
, m_references
[i
].m_access
);
1102 // get CP infos blop-length
1103 pInfo
= root
.m_next
;
1104 sal_uInt32 cpBlopSize
= 0;
1105 sal_uInt16 cpCount
= 0;
1109 cpBlopSize
+= pInfo
->getBlopSize();
1111 pInfo
= pInfo
->m_next
;
1114 blopSize
+= cpBlopSize
;
1115 blopSize
+= sizeof(sal_uInt16
); // constantPoolCount
1117 // write all in flat buffer
1119 sal_uInt8
* blop
= new sal_uInt8
[blopSize
];
1123 // Assumes two's complement arithmetic with modulo-semantics:
1124 pBuffer
+= writeUINT32(pBuffer
, magic
+ m_version
);
1125 pBuffer
+= writeUINT32(pBuffer
, blopSize
);
1126 pBuffer
+= writeUINT16(pBuffer
, minorVersion
);
1127 pBuffer
+= writeUINT16(pBuffer
, majorVersion
);
1128 pBuffer
+= writeUINT16(pBuffer
, BLOP_HEADER_N_ENTRIES
);
1130 pBuffer
+= writeUINT16(pBuffer
, (sal_uInt16
)RT_UNO_IDL
);
1131 pBuffer
+= writeUINT16(pBuffer
, (sal_uInt16
)m_typeClass
);
1132 pBuffer
+= writeUINT16(pBuffer
, cpIndexThisName
);
1133 pBuffer
+= writeUINT16(pBuffer
, cpIndexUik
);
1134 pBuffer
+= writeUINT16(pBuffer
, cpIndexDoku
);
1135 pBuffer
+= writeUINT16(pBuffer
, cpIndexFileName
);
1138 pBuffer
+= writeUINT16(pBuffer
, m_nSuperTypes
);
1141 for (sal_uInt32 i
=0; i
< m_nSuperTypes
; i
++)
1143 pBuffer
+= writeUINT16(pBuffer
, cpIndexSuperNames
[i
]);
1145 delete[] cpIndexSuperNames
;
1148 pBuffer
+= writeUINT16(pBuffer
, cpCount
);
1150 // write and delete CP infos
1151 pInfo
= root
.m_next
;
1155 CPInfo
* pNextInfo
= pInfo
->m_next
;
1157 pBuffer
+= pInfo
->toBlop(pBuffer
);
1164 pBuffer
+= writeUINT16(pBuffer
, m_fieldCount
);
1167 memcpy(pBuffer
, pBlopFields
, blopFieldsSize
);
1168 pBuffer
+= blopFieldsSize
;
1172 pBuffer
+= writeUINT16(pBuffer
, m_methodCount
);
1173 if (blopMethodsSize
)
1175 memcpy(pBuffer
, pBlopMethods
, blopMethodsSize
);
1176 pBuffer
+= blopMethodsSize
;
1180 pBuffer
+= writeUINT16(pBuffer
, m_referenceCount
);
1181 if (blopReferenceSize
)
1183 memcpy(pBuffer
, pBlopReferences
, blopReferenceSize
);
1184 pBuffer
+= blopReferenceSize
;
1187 delete[] pBlopFields
;
1188 delete[] pBlopMethods
;
1189 delete[] pBlopReferences
;
1193 m_blopSize
= blopSize
;
1197 /**************************************************************************
1201 **************************************************************************/
1205 static void TYPEREG_CALLTYPE
acquire(TypeWriterImpl hEntry
)
1207 TypeWriter
* pEntry
= (TypeWriter
*) hEntry
;
1210 pEntry
->m_refCount
++;
1213 static void TYPEREG_CALLTYPE
release(TypeWriterImpl hEntry
)
1215 TypeWriter
* pEntry
= (TypeWriter
*) hEntry
;
1219 if (--pEntry
->m_refCount
== 0)
1224 static void TYPEREG_CALLTYPE
setUik(TypeWriterImpl hEntry
, const RTUik
* uik
)
1226 TypeWriter
* pEntry
= (TypeWriter
*) hEntry
;
1232 pEntry
->m_pUik
->m_Data1
= uik
->m_Data1
;
1233 pEntry
->m_pUik
->m_Data2
= uik
->m_Data2
;
1234 pEntry
->m_pUik
->m_Data3
= uik
->m_Data3
;
1235 pEntry
->m_pUik
->m_Data4
= uik
->m_Data4
;
1236 pEntry
->m_pUik
->m_Data5
= uik
->m_Data5
;
1239 pEntry
->m_pUik
= new RTUik(*uik
);
1243 static void TYPEREG_CALLTYPE
setDoku(TypeWriterImpl hEntry
, rtl_uString
* doku
)
1245 static_cast< TypeWriter
* >(hEntry
)->m_doku
= toByteString(doku
);
1248 static void TYPEREG_CALLTYPE
setFileName(TypeWriterImpl hEntry
, rtl_uString
* fileName
)
1250 static_cast< TypeWriter
* >(hEntry
)->m_fileName
= toByteString(fileName
);
1253 sal_Bool
typereg_writer_setFieldData(
1254 void * handle
, sal_uInt16 index
, rtl_uString
const * documentation
,
1255 rtl_uString
const * fileName
, RTFieldAccess flags
, rtl_uString
const * name
,
1256 rtl_uString
const * typeName
, RTValueType valueType
,
1257 RTConstValueUnion valueValue
)
1258 SAL_THROW_EXTERN_C()
1261 static_cast< TypeWriter
* >(handle
)->m_fields
[index
].setData(
1262 toByteString(name
), toByteString(typeName
),
1263 toByteString(documentation
), toByteString(fileName
), flags
,
1264 valueType
, valueValue
);
1265 } catch (std::bad_alloc
&) {
1271 static void TYPEREG_CALLTYPE
setFieldData(TypeWriterImpl hEntry
,
1274 rtl_uString
* typeName
,
1276 rtl_uString
* fileName
,
1277 RTFieldAccess access
,
1278 RTValueType valueType
,
1279 RTConstValueUnion constValue
)
1281 typereg_writer_setFieldData(
1282 hEntry
, index
, doku
, fileName
, access
, name
, typeName
, valueType
,
1286 sal_Bool
typereg_writer_setMethodData(
1287 void * handle
, sal_uInt16 index
, rtl_uString
const * documentation
,
1288 RTMethodMode flags
, rtl_uString
const * name
,
1289 rtl_uString
const * returnTypeName
, sal_uInt16 parameterCount
,
1290 sal_uInt16 exceptionCount
)
1291 SAL_THROW_EXTERN_C()
1294 static_cast< TypeWriter
* >(handle
)->m_methods
[index
].setData(
1295 toByteString(name
), toByteString(returnTypeName
), flags
,
1296 parameterCount
, exceptionCount
, toByteString(documentation
));
1297 } catch (std::bad_alloc
&) {
1303 static void TYPEREG_CALLTYPE
setMethodData(TypeWriterImpl hEntry
,
1306 rtl_uString
* returnTypeName
,
1308 sal_uInt16 paramCount
,
1309 sal_uInt16 excCount
,
1312 typereg_writer_setMethodData(
1313 hEntry
, index
, doku
, mode
, name
, returnTypeName
, paramCount
, excCount
);
1316 sal_Bool
typereg_writer_setMethodParameterData(
1317 void * handle
, sal_uInt16 methodIndex
, sal_uInt16 parameterIndex
,
1318 RTParamMode flags
, rtl_uString
const * name
, rtl_uString
const * typeName
)
1319 SAL_THROW_EXTERN_C()
1322 static_cast< TypeWriter
* >(handle
)->
1323 m_methods
[methodIndex
].m_params
[parameterIndex
].setData(
1324 toByteString(typeName
), toByteString(name
), flags
);
1325 } catch (std::bad_alloc
&) {
1331 static void TYPEREG_CALLTYPE
setParamData(TypeWriterImpl hEntry
,
1333 sal_uInt16 paramIndex
,
1338 typereg_writer_setMethodParameterData(
1339 hEntry
, index
, paramIndex
, mode
, name
, type
);
1342 sal_Bool
typereg_writer_setMethodExceptionTypeName(
1343 void * handle
, sal_uInt16 methodIndex
, sal_uInt16 exceptionIndex
,
1344 rtl_uString
const * typeName
)
1345 SAL_THROW_EXTERN_C()
1348 static_cast< TypeWriter
* >(handle
)->m_methods
[methodIndex
].setExcName(
1349 exceptionIndex
, toByteString(typeName
));
1350 } catch (std::bad_alloc
&) {
1356 static void TYPEREG_CALLTYPE
setExcData(TypeWriterImpl hEntry
,
1358 sal_uInt16 excIndex
,
1361 typereg_writer_setMethodExceptionTypeName(hEntry
, index
, excIndex
, type
);
1364 void const * typereg_writer_getBlob(void * handle
, sal_uInt32
* size
)
1365 SAL_THROW_EXTERN_C()
1367 TypeWriter
* writer
= static_cast< TypeWriter
* >(handle
);
1368 if (writer
->m_blop
== 0) {
1370 writer
->createBlop();
1371 } catch (std::bad_alloc
&) {
1375 *size
= writer
->m_blopSize
;
1376 return writer
->m_blop
;
1379 static const sal_uInt8
* TYPEREG_CALLTYPE
getBlop(TypeWriterImpl hEntry
)
1382 return static_cast< sal_uInt8
const * >(
1383 typereg_writer_getBlob(hEntry
, &size
));
1386 static sal_uInt32 TYPEREG_CALLTYPE
getBlopSize(TypeWriterImpl hEntry
)
1389 typereg_writer_getBlob(hEntry
, &size
);
1393 sal_Bool
typereg_writer_setReferenceData(
1394 void * handle
, sal_uInt16 index
, rtl_uString
const * documentation
,
1395 RTReferenceType sort
, RTFieldAccess flags
, rtl_uString
const * typeName
)
1396 SAL_THROW_EXTERN_C()
1399 static_cast< TypeWriter
* >(handle
)->m_references
[index
].setData(
1400 toByteString(typeName
), sort
, toByteString(documentation
), flags
);
1401 } catch (std::bad_alloc
&) {
1407 static void TYPEREG_CALLTYPE
setReferenceData(TypeWriterImpl hEntry
,
1410 RTReferenceType refType
,
1412 RTFieldAccess access
)
1414 typereg_writer_setReferenceData(hEntry
, index
, doku
, refType
, access
, name
);
1417 void * typereg_writer_create(
1418 typereg_Version version
, rtl_uString
const * documentation
,
1419 rtl_uString
const * fileName
, RTTypeClass typeClass
, sal_Bool published
,
1420 rtl_uString
const * typeName
, sal_uInt16 superTypeCount
,
1421 sal_uInt16 fieldCount
, sal_uInt16 methodCount
, sal_uInt16 referenceCount
)
1422 SAL_THROW_EXTERN_C()
1425 return new TypeWriter(
1426 version
, toByteString(documentation
), toByteString(fileName
),
1427 typeClass
, published
, toByteString(typeName
), superTypeCount
,
1428 fieldCount
, methodCount
, referenceCount
);
1429 } catch (std::bad_alloc
&) {
1434 void typereg_writer_destroy(void * handle
) SAL_THROW_EXTERN_C() {
1435 delete static_cast< TypeWriter
* >(handle
);
1438 sal_Bool
typereg_writer_setSuperTypeName(
1439 void * handle
, sal_uInt16 index
, rtl_uString
const * typeName
)
1440 SAL_THROW_EXTERN_C()
1443 static_cast< TypeWriter
* >(handle
)->setSuperType(
1444 index
, toByteString(typeName
));
1445 } catch (std::bad_alloc
&) {
1451 static TypeWriterImpl TYPEREG_CALLTYPE
createEntry(
1452 RTTypeClass typeClass
, rtl_uString
* typeName
, rtl_uString
* superTypeName
,
1453 sal_uInt16 fieldCount
, sal_uInt16 methodCount
, sal_uInt16 referenceCount
)
1455 rtl::OUString empty
;
1456 sal_uInt16 superTypeCount
= rtl_uString_getLength(superTypeName
) == 0
1458 TypeWriterImpl t
= typereg_writer_create(
1459 TYPEREG_VERSION_0
, empty
.pData
, empty
.pData
, typeClass
, false, typeName
,
1460 superTypeCount
, fieldCount
, methodCount
, referenceCount
);
1461 if (superTypeCount
> 0) {
1462 typereg_writer_setSuperTypeName(t
, 0, superTypeName
);
1467 RegistryTypeWriter_Api
* TYPEREG_CALLTYPE
initRegistryTypeWriter_Api(void)
1469 static RegistryTypeWriter_Api aApi
= {0,0,0,0,0,0,0,0,0,0,0,0,0};
1472 aApi
.createEntry
= &createEntry
;
1473 aApi
.acquire
= &acquire
;
1474 aApi
.release
= &release
;
1475 aApi
.setUik
= &setUik
;
1476 aApi
.setDoku
= &setDoku
;
1477 aApi
.setFileName
= &setFileName
;
1478 aApi
.setFieldData
= &setFieldData
;
1479 aApi
.setMethodData
= &setMethodData
;
1480 aApi
.setParamData
= &setParamData
;
1481 aApi
.setExcData
= &setExcData
;
1482 aApi
.getBlop
= &getBlop
;
1483 aApi
.getBlopSize
= &getBlopSize
;
1484 aApi
.setReferenceData
= &setReferenceData
;