1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
36 //##################################################################################################
37 //#### construction ################################################################################
38 //##################################################################################################
40 //--------------------------------------------------------------------------------------------------
41 inline void _defaultConstructUnion(
43 typelib_TypeDescription
* pTypeDescr
)
46 ::uno_type_constructData(
47 (char *)pMem
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
48 ((typelib_UnionTypeDescription
*)pTypeDescr
)->pDefaultTypeRef
);
49 *(sal_Int64
*)pMem
= ((typelib_UnionTypeDescription
*)pTypeDescr
)->nDefaultDiscriminant
;
51 //==================================================================================================
52 void defaultConstructStruct(
54 typelib_CompoundTypeDescription
* pCompType
)
56 //--------------------------------------------------------------------------------------------------
57 inline void _defaultConstructStruct(
59 typelib_CompoundTypeDescription
* pTypeDescr
)
62 if (pTypeDescr
->pBaseTypeDescription
)
64 defaultConstructStruct( pMem
, pTypeDescr
->pBaseTypeDescription
);
67 typelib_TypeDescriptionReference
** ppTypeRefs
= (pTypeDescr
)->ppTypeRefs
;
68 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
69 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
73 ::uno_type_constructData( (char *)pMem
+ pMemberOffsets
[nDescr
], ppTypeRefs
[nDescr
] );
77 //--------------------------------------------------------------------------------------------------
78 inline void _defaultConstructArray(
80 typelib_ArrayTypeDescription
* pTypeDescr
)
82 typelib_TypeDescription
* pElementType
= NULL
;
83 TYPELIB_DANGER_GET( &pElementType
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
84 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
85 sal_Int32 nElementSize
= pElementType
->nSize
;
87 switch ( pElementType
->eTypeClass
)
89 case typelib_TypeClass_CHAR
:
90 case typelib_TypeClass_BOOLEAN
:
91 case typelib_TypeClass_BYTE
:
92 case typelib_TypeClass_SHORT
:
93 case typelib_TypeClass_UNSIGNED_SHORT
:
94 case typelib_TypeClass_LONG
:
95 case typelib_TypeClass_UNSIGNED_LONG
:
96 case typelib_TypeClass_HYPER
:
97 case typelib_TypeClass_UNSIGNED_HYPER
:
98 case typelib_TypeClass_FLOAT
:
99 case typelib_TypeClass_DOUBLE
:
100 case typelib_TypeClass_INTERFACE
:
101 ::rtl_zeroMemory(pMem
, nElementSize
* nTotalElements
);
104 case typelib_TypeClass_STRING
:
105 for (i
=0; i
< nTotalElements
; i
++)
107 rtl_uString
** ppElement
= (rtl_uString
**)pMem
+ i
;
109 rtl_uString_new( ppElement
);
112 case typelib_TypeClass_TYPE
:
113 for (i
=0; i
< nTotalElements
; i
++)
115 typelib_TypeDescriptionReference
** ppElement
= (typelib_TypeDescriptionReference
**)pMem
+ i
;
116 *ppElement
= _getVoidType();
119 case typelib_TypeClass_ANY
:
120 for (i
=0; i
< nTotalElements
; i
++)
122 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
+ i
);
125 case typelib_TypeClass_ENUM
:
126 for (i
=0; i
< nTotalElements
; i
++)
128 *((sal_Int32
*)pMem
+ i
) = ((typelib_EnumTypeDescription
*)pElementType
)->nDefaultEnumValue
;
131 case typelib_TypeClass_STRUCT
:
132 case typelib_TypeClass_EXCEPTION
:
133 for (i
=0; i
< nTotalElements
; i
++)
135 _defaultConstructStruct( (sal_Char
*)pMem
+ i
* nElementSize
, (typelib_CompoundTypeDescription
*)pElementType
);
138 case typelib_TypeClass_UNION
:
139 for (i
=0; i
< nTotalElements
; i
++)
141 _defaultConstructUnion( (sal_Char
*)pMem
+ i
* nElementSize
, pElementType
);
144 case typelib_TypeClass_SEQUENCE
:
145 for (i
=0; i
< nTotalElements
; i
++)
147 uno_Sequence
** ppElement
= (uno_Sequence
**)pMem
+ i
;
148 *ppElement
= createEmptySequence();
155 TYPELIB_DANGER_RELEASE( pElementType
);
158 //--------------------------------------------------------------------------------------------------
159 inline void _defaultConstructData(
161 typelib_TypeDescriptionReference
* pType
,
162 typelib_TypeDescription
* pTypeDescr
)
165 switch (pType
->eTypeClass
)
167 case typelib_TypeClass_CHAR
:
168 *(sal_Unicode
*)pMem
= '\0';
170 case typelib_TypeClass_BOOLEAN
:
171 *(sal_Bool
*)pMem
= sal_False
;
173 case typelib_TypeClass_BYTE
:
174 *(sal_Int8
*)pMem
= 0;
176 case typelib_TypeClass_SHORT
:
177 case typelib_TypeClass_UNSIGNED_SHORT
:
178 *(sal_Int16
*)pMem
= 0;
180 case typelib_TypeClass_LONG
:
181 case typelib_TypeClass_UNSIGNED_LONG
:
182 *(sal_Int32
*)pMem
= 0;
184 case typelib_TypeClass_HYPER
:
185 case typelib_TypeClass_UNSIGNED_HYPER
:
186 *(sal_Int64
*)pMem
= 0;
188 case typelib_TypeClass_FLOAT
:
189 *(float *)pMem
= 0.0;
191 case typelib_TypeClass_DOUBLE
:
192 *(double *)pMem
= 0.0;
194 case typelib_TypeClass_STRING
:
195 *(rtl_uString
**)pMem
= 0;
196 ::rtl_uString_new( (rtl_uString
**)pMem
);
198 case typelib_TypeClass_TYPE
:
199 *(typelib_TypeDescriptionReference
**)pMem
= _getVoidType();
201 case typelib_TypeClass_ANY
:
202 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
);
204 case typelib_TypeClass_ENUM
:
207 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
211 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
212 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
213 TYPELIB_DANGER_RELEASE( pTypeDescr
);
216 case typelib_TypeClass_STRUCT
:
217 case typelib_TypeClass_EXCEPTION
:
220 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
224 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
225 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
226 TYPELIB_DANGER_RELEASE( pTypeDescr
);
229 case typelib_TypeClass_ARRAY
:
232 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
236 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
237 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
238 TYPELIB_DANGER_RELEASE( pTypeDescr
);
241 case typelib_TypeClass_UNION
:
244 _defaultConstructUnion( pMem
, pTypeDescr
);
248 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
249 _defaultConstructUnion( pMem
, pTypeDescr
);
250 TYPELIB_DANGER_RELEASE( pTypeDescr
);
253 case typelib_TypeClass_SEQUENCE
:
254 *(uno_Sequence
**)pMem
= createEmptySequence();
256 case typelib_TypeClass_INTERFACE
:
257 *(void **)pMem
= 0; // either cpp or c-uno interface