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 .
28 //##################################################################################################
29 //#### construction ################################################################################
30 //##################################################################################################
32 //--------------------------------------------------------------------------------------------------
33 inline void _defaultConstructUnion(
35 typelib_TypeDescription
* pTypeDescr
)
38 ::uno_type_constructData(
39 (char *)pMem
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
40 ((typelib_UnionTypeDescription
*)pTypeDescr
)->pDefaultTypeRef
);
41 *(sal_Int64
*)pMem
= ((typelib_UnionTypeDescription
*)pTypeDescr
)->nDefaultDiscriminant
;
43 //==================================================================================================
44 void defaultConstructStruct(
46 typelib_CompoundTypeDescription
* pCompType
)
48 //--------------------------------------------------------------------------------------------------
49 inline void _defaultConstructStruct(
51 typelib_CompoundTypeDescription
* pTypeDescr
)
54 if (pTypeDescr
->pBaseTypeDescription
)
56 defaultConstructStruct( pMem
, pTypeDescr
->pBaseTypeDescription
);
59 typelib_TypeDescriptionReference
** ppTypeRefs
= (pTypeDescr
)->ppTypeRefs
;
60 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
61 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
65 ::uno_type_constructData( (char *)pMem
+ pMemberOffsets
[nDescr
], ppTypeRefs
[nDescr
] );
69 //--------------------------------------------------------------------------------------------------
70 inline void _defaultConstructArray(
72 typelib_ArrayTypeDescription
* pTypeDescr
)
74 typelib_TypeDescription
* pElementType
= NULL
;
75 TYPELIB_DANGER_GET( &pElementType
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
76 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
77 sal_Int32 nElementSize
= pElementType
->nSize
;
79 switch ( pElementType
->eTypeClass
)
81 case typelib_TypeClass_CHAR
:
82 case typelib_TypeClass_BOOLEAN
:
83 case typelib_TypeClass_BYTE
:
84 case typelib_TypeClass_SHORT
:
85 case typelib_TypeClass_UNSIGNED_SHORT
:
86 case typelib_TypeClass_LONG
:
87 case typelib_TypeClass_UNSIGNED_LONG
:
88 case typelib_TypeClass_HYPER
:
89 case typelib_TypeClass_UNSIGNED_HYPER
:
90 case typelib_TypeClass_FLOAT
:
91 case typelib_TypeClass_DOUBLE
:
92 case typelib_TypeClass_INTERFACE
:
93 memset(pMem
, 0, nElementSize
* nTotalElements
);
96 case typelib_TypeClass_STRING
:
97 for (i
=0; i
< nTotalElements
; i
++)
99 rtl_uString
** ppElement
= (rtl_uString
**)pMem
+ i
;
101 rtl_uString_new( ppElement
);
104 case typelib_TypeClass_TYPE
:
105 for (i
=0; i
< nTotalElements
; i
++)
107 typelib_TypeDescriptionReference
** ppElement
= (typelib_TypeDescriptionReference
**)pMem
+ i
;
108 *ppElement
= _getVoidType();
111 case typelib_TypeClass_ANY
:
112 for (i
=0; i
< nTotalElements
; i
++)
114 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
+ i
);
117 case typelib_TypeClass_ENUM
:
118 for (i
=0; i
< nTotalElements
; i
++)
120 *((sal_Int32
*)pMem
+ i
) = ((typelib_EnumTypeDescription
*)pElementType
)->nDefaultEnumValue
;
123 case typelib_TypeClass_STRUCT
:
124 case typelib_TypeClass_EXCEPTION
:
125 for (i
=0; i
< nTotalElements
; i
++)
127 _defaultConstructStruct( (sal_Char
*)pMem
+ i
* nElementSize
, (typelib_CompoundTypeDescription
*)pElementType
);
130 case typelib_TypeClass_UNION
:
131 for (i
=0; i
< nTotalElements
; i
++)
133 _defaultConstructUnion( (sal_Char
*)pMem
+ i
* nElementSize
, pElementType
);
136 case typelib_TypeClass_SEQUENCE
:
137 for (i
=0; i
< nTotalElements
; i
++)
139 uno_Sequence
** ppElement
= (uno_Sequence
**)pMem
+ i
;
140 *ppElement
= createEmptySequence();
147 TYPELIB_DANGER_RELEASE( pElementType
);
150 //--------------------------------------------------------------------------------------------------
151 inline void _defaultConstructData(
153 typelib_TypeDescriptionReference
* pType
,
154 typelib_TypeDescription
* pTypeDescr
)
157 switch (pType
->eTypeClass
)
159 case typelib_TypeClass_CHAR
:
160 *(sal_Unicode
*)pMem
= '\0';
162 case typelib_TypeClass_BOOLEAN
:
163 *(sal_Bool
*)pMem
= sal_False
;
165 case typelib_TypeClass_BYTE
:
166 *(sal_Int8
*)pMem
= 0;
168 case typelib_TypeClass_SHORT
:
169 case typelib_TypeClass_UNSIGNED_SHORT
:
170 *(sal_Int16
*)pMem
= 0;
172 case typelib_TypeClass_LONG
:
173 case typelib_TypeClass_UNSIGNED_LONG
:
174 *(sal_Int32
*)pMem
= 0;
176 case typelib_TypeClass_HYPER
:
177 case typelib_TypeClass_UNSIGNED_HYPER
:
178 *(sal_Int64
*)pMem
= 0;
180 case typelib_TypeClass_FLOAT
:
181 *(float *)pMem
= 0.0;
183 case typelib_TypeClass_DOUBLE
:
184 *(double *)pMem
= 0.0;
186 case typelib_TypeClass_STRING
:
187 *(rtl_uString
**)pMem
= 0;
188 ::rtl_uString_new( (rtl_uString
**)pMem
);
190 case typelib_TypeClass_TYPE
:
191 *(typelib_TypeDescriptionReference
**)pMem
= _getVoidType();
193 case typelib_TypeClass_ANY
:
194 CONSTRUCT_EMPTY_ANY( (uno_Any
*)pMem
);
196 case typelib_TypeClass_ENUM
:
199 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
203 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
204 *(sal_Int32
*)pMem
= ((typelib_EnumTypeDescription
*)pTypeDescr
)->nDefaultEnumValue
;
205 TYPELIB_DANGER_RELEASE( pTypeDescr
);
208 case typelib_TypeClass_STRUCT
:
209 case typelib_TypeClass_EXCEPTION
:
212 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
216 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
217 _defaultConstructStruct( pMem
, (typelib_CompoundTypeDescription
*)pTypeDescr
);
218 TYPELIB_DANGER_RELEASE( pTypeDescr
);
221 case typelib_TypeClass_ARRAY
:
224 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
228 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
229 _defaultConstructArray( pMem
, (typelib_ArrayTypeDescription
*)pTypeDescr
);
230 TYPELIB_DANGER_RELEASE( pTypeDescr
);
233 case typelib_TypeClass_UNION
:
236 _defaultConstructUnion( pMem
, pTypeDescr
);
240 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
241 _defaultConstructUnion( pMem
, pTypeDescr
);
242 TYPELIB_DANGER_RELEASE( pTypeDescr
);
245 case typelib_TypeClass_SEQUENCE
:
246 *(uno_Sequence
**)pMem
= createEmptySequence();
248 case typelib_TypeClass_INTERFACE
:
249 *(void **)pMem
= 0; // either cpp or c-uno interface
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */