merged tag ooo/DEV300_m102
[LibreOffice.git] / cppu / source / uno / constr.hxx
blob8e6d35e9db64fda1e5a6bd4c96b54e6b4025d30e
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 ************************************************************************/
27 #ifndef CONSTR_HXX
28 #define CONSTR_HXX
30 #include "prim.hxx"
33 namespace cppu
36 //##################################################################################################
37 //#### construction ################################################################################
38 //##################################################################################################
40 //--------------------------------------------------------------------------------------------------
41 inline void _defaultConstructUnion(
42 void * pMem,
43 typelib_TypeDescription * pTypeDescr )
44 SAL_THROW( () )
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(
53 void * pMem,
54 typelib_CompoundTypeDescription * pCompType )
55 SAL_THROW( () );
56 //--------------------------------------------------------------------------------------------------
57 inline void _defaultConstructStruct(
58 void * pMem,
59 typelib_CompoundTypeDescription * pTypeDescr )
60 SAL_THROW( () )
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;
71 while (nDescr--)
73 ::uno_type_constructData( (char *)pMem + pMemberOffsets[nDescr], ppTypeRefs[nDescr] );
77 //--------------------------------------------------------------------------------------------------
78 inline void _defaultConstructArray(
79 void * pMem,
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;
86 sal_Int32 i;
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);
102 break;
104 case typelib_TypeClass_STRING:
105 for (i=0; i < nTotalElements; i++)
107 rtl_uString** ppElement = (rtl_uString **)pMem + i;
108 *ppElement = 0;
109 rtl_uString_new( ppElement);
111 break;
112 case typelib_TypeClass_TYPE:
113 for (i=0; i < nTotalElements; i++)
115 typelib_TypeDescriptionReference** ppElement = (typelib_TypeDescriptionReference **)pMem + i;
116 *ppElement = _getVoidType();
118 break;
119 case typelib_TypeClass_ANY:
120 for (i=0; i < nTotalElements; i++)
122 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem + i );
124 break;
125 case typelib_TypeClass_ENUM:
126 for (i=0; i < nTotalElements; i++)
128 *((sal_Int32 *)pMem + i) = ((typelib_EnumTypeDescription *)pElementType)->nDefaultEnumValue;
130 break;
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 );
137 break;
138 case typelib_TypeClass_UNION:
139 for (i=0; i < nTotalElements; i++)
141 _defaultConstructUnion( (sal_Char*)pMem + i * nElementSize, pElementType );
143 break;
144 case typelib_TypeClass_SEQUENCE:
145 for (i=0; i < nTotalElements; i++)
147 uno_Sequence** ppElement = (uno_Sequence **)pMem + i;
148 *ppElement = createEmptySequence();
150 break;
151 default:
152 OSL_ASSERT(false);
153 break;
155 TYPELIB_DANGER_RELEASE( pElementType );
158 //--------------------------------------------------------------------------------------------------
159 inline void _defaultConstructData(
160 void * pMem,
161 typelib_TypeDescriptionReference * pType,
162 typelib_TypeDescription * pTypeDescr )
163 SAL_THROW( () )
165 switch (pType->eTypeClass)
167 case typelib_TypeClass_CHAR:
168 *(sal_Unicode *)pMem = '\0';
169 break;
170 case typelib_TypeClass_BOOLEAN:
171 *(sal_Bool *)pMem = sal_False;
172 break;
173 case typelib_TypeClass_BYTE:
174 *(sal_Int8 *)pMem = 0;
175 break;
176 case typelib_TypeClass_SHORT:
177 case typelib_TypeClass_UNSIGNED_SHORT:
178 *(sal_Int16 *)pMem = 0;
179 break;
180 case typelib_TypeClass_LONG:
181 case typelib_TypeClass_UNSIGNED_LONG:
182 *(sal_Int32 *)pMem = 0;
183 break;
184 case typelib_TypeClass_HYPER:
185 case typelib_TypeClass_UNSIGNED_HYPER:
186 *(sal_Int64 *)pMem = 0;
187 break;
188 case typelib_TypeClass_FLOAT:
189 *(float *)pMem = 0.0;
190 break;
191 case typelib_TypeClass_DOUBLE:
192 *(double *)pMem = 0.0;
193 break;
194 case typelib_TypeClass_STRING:
195 *(rtl_uString **)pMem = 0;
196 ::rtl_uString_new( (rtl_uString **)pMem );
197 break;
198 case typelib_TypeClass_TYPE:
199 *(typelib_TypeDescriptionReference **)pMem = _getVoidType();
200 break;
201 case typelib_TypeClass_ANY:
202 CONSTRUCT_EMPTY_ANY( (uno_Any *)pMem );
203 break;
204 case typelib_TypeClass_ENUM:
205 if (pTypeDescr)
207 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
209 else
211 TYPELIB_DANGER_GET( &pTypeDescr, pType );
212 *(sal_Int32 *)pMem = ((typelib_EnumTypeDescription *)pTypeDescr)->nDefaultEnumValue;
213 TYPELIB_DANGER_RELEASE( pTypeDescr );
215 break;
216 case typelib_TypeClass_STRUCT:
217 case typelib_TypeClass_EXCEPTION:
218 if (pTypeDescr)
220 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
222 else
224 TYPELIB_DANGER_GET( &pTypeDescr, pType );
225 _defaultConstructStruct( pMem, (typelib_CompoundTypeDescription *)pTypeDescr );
226 TYPELIB_DANGER_RELEASE( pTypeDescr );
228 break;
229 case typelib_TypeClass_ARRAY:
230 if (pTypeDescr)
232 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
234 else
236 TYPELIB_DANGER_GET( &pTypeDescr, pType );
237 _defaultConstructArray( pMem, (typelib_ArrayTypeDescription *)pTypeDescr );
238 TYPELIB_DANGER_RELEASE( pTypeDescr );
240 break;
241 case typelib_TypeClass_UNION:
242 if (pTypeDescr)
244 _defaultConstructUnion( pMem, pTypeDescr );
246 else
248 TYPELIB_DANGER_GET( &pTypeDescr, pType );
249 _defaultConstructUnion( pMem, pTypeDescr );
250 TYPELIB_DANGER_RELEASE( pTypeDescr );
252 break;
253 case typelib_TypeClass_SEQUENCE:
254 *(uno_Sequence **)pMem = createEmptySequence();
255 break;
256 case typelib_TypeClass_INTERFACE:
257 *(void **)pMem = 0; // either cpp or c-uno interface
258 break;
259 default:
260 OSL_ASSERT(false);
261 break;
267 #endif