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: destr.hxx,v $
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 ************************************************************************/
39 //##################################################################################################
40 //#### destruction #################################################################################
41 //##################################################################################################
43 //--------------------------------------------------------------------------------------------------
44 inline void _destructUnion(
46 typelib_TypeDescription
* pTypeDescr
,
47 uno_ReleaseFunc release
)
50 typelib_TypeDescriptionReference
* pType
= _unionGetSetType( pValue
, pTypeDescr
);
51 ::uno_type_destructData(
52 (char *)pValue
+ ((typelib_UnionTypeDescription
*)pTypeDescr
)->nValueOffset
,
54 ::typelib_typedescriptionreference_release( pType
);
56 //==================================================================================================
59 typelib_CompoundTypeDescription
* pTypeDescr
,
60 uno_ReleaseFunc release
)
62 //--------------------------------------------------------------------------------------------------
63 inline void _destructStruct(
65 typelib_CompoundTypeDescription
* pTypeDescr
,
66 uno_ReleaseFunc release
)
69 if (pTypeDescr
->pBaseTypeDescription
)
71 destructStruct( pValue
, pTypeDescr
->pBaseTypeDescription
, release
);
74 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
75 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
76 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
79 ::uno_type_destructData(
80 (char *)pValue
+ pMemberOffsets
[nDescr
],
81 ppTypeRefs
[nDescr
], release
);
85 //--------------------------------------------------------------------------------------------------
86 inline void _destructArray(
88 typelib_ArrayTypeDescription
* pTypeDescr
,
89 uno_ReleaseFunc release
)
92 typelib_TypeDescription
* pElementType
= NULL
;
93 TYPELIB_DANGER_GET( &pElementType
, ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
94 sal_Int32 nElementSize
= pElementType
->nSize
;
95 TYPELIB_DANGER_RELEASE( pElementType
);
97 sal_Int32 nTotalElements
= pTypeDescr
->nTotalElements
;
98 for(sal_Int32 i
=0; i
< nTotalElements
; i
++)
100 ::uno_type_destructData(
101 (sal_Char
*)pValue
+ i
* nElementSize
,
102 ((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
, release
);
105 typelib_typedescriptionreference_release(((typelib_IndirectTypeDescription
*)pTypeDescr
)->pType
);
108 //==============================================================================
109 void destructSequence(
110 uno_Sequence
* pSequence
,
111 typelib_TypeDescriptionReference
* pType
,
112 typelib_TypeDescription
* pTypeDescr
,
113 uno_ReleaseFunc release
);
115 //--------------------------------------------------------------------------------------------------
116 inline void _destructAny(
118 uno_ReleaseFunc release
)
121 typelib_TypeDescriptionReference
* pType
= pAny
->pType
;
123 switch (pType
->eTypeClass
)
125 case typelib_TypeClass_HYPER
:
126 case typelib_TypeClass_UNSIGNED_HYPER
:
127 if (sizeof(void *) < sizeof(sal_Int64
))
129 ::rtl_freeMemory( pAny
->pData
);
132 case typelib_TypeClass_FLOAT
:
133 if (sizeof(void *) < sizeof(float))
135 ::rtl_freeMemory( pAny
->pData
);
138 case typelib_TypeClass_DOUBLE
:
139 if (sizeof(void *) < sizeof(double))
141 ::rtl_freeMemory( pAny
->pData
);
144 case typelib_TypeClass_STRING
:
145 ::rtl_uString_release( (rtl_uString
*)pAny
->pReserved
);
147 case typelib_TypeClass_TYPE
:
148 ::typelib_typedescriptionreference_release(
149 (typelib_TypeDescriptionReference
*)pAny
->pReserved
);
151 case typelib_TypeClass_ANY
:
152 OSL_ENSURE( sal_False
, "### unexpected nested any!" );
153 ::uno_any_destruct( (uno_Any
*)pAny
->pData
, release
);
154 ::rtl_freeMemory( pAny
->pData
);
156 case typelib_TypeClass_TYPEDEF
:
157 OSL_ENSURE( 0, "### unexpected typedef!" );
159 case typelib_TypeClass_STRUCT
:
160 case typelib_TypeClass_EXCEPTION
:
162 typelib_TypeDescription
* pTypeDescr
= 0;
163 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
164 _destructStruct( pAny
->pData
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
165 TYPELIB_DANGER_RELEASE( pTypeDescr
);
166 ::rtl_freeMemory( pAny
->pData
);
169 case typelib_TypeClass_UNION
:
171 typelib_TypeDescription
* pTypeDescr
= 0;
172 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
173 _destructUnion( pAny
->pData
, pTypeDescr
, release
);
174 TYPELIB_DANGER_RELEASE( pTypeDescr
);
175 ::rtl_freeMemory( pAny
->pData
);
178 case typelib_TypeClass_SEQUENCE
:
181 *(uno_Sequence
**) &pAny
->pReserved
, pType
, 0, release
);
184 case typelib_TypeClass_INTERFACE
:
185 _release( pAny
->pReserved
, release
);
190 #if OSL_DEBUG_LEVEL > 0
191 pAny
->pData
= (void *)0xdeadbeef;
194 ::typelib_typedescriptionreference_release( pType
);
196 //--------------------------------------------------------------------------------------------------
197 inline sal_Int32
idestructElements(
198 void * pElements
, typelib_TypeDescriptionReference
* pElementType
,
199 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
200 uno_ReleaseFunc release
)
203 switch (pElementType
->eTypeClass
)
205 case typelib_TypeClass_CHAR
:
206 return (sal_Int32
)(sizeof(sal_Unicode
));
207 case typelib_TypeClass_BOOLEAN
:
208 return (sal_Int32
)(sizeof(sal_Bool
));
209 case typelib_TypeClass_BYTE
:
210 return (sal_Int32
)(sizeof(sal_Int8
));
211 case typelib_TypeClass_SHORT
:
212 case typelib_TypeClass_UNSIGNED_SHORT
:
213 return (sal_Int32
)(sizeof(sal_Int16
));
214 case typelib_TypeClass_LONG
:
215 case typelib_TypeClass_UNSIGNED_LONG
:
216 return (sal_Int32
)(sizeof(sal_Int32
));
217 case typelib_TypeClass_HYPER
:
218 case typelib_TypeClass_UNSIGNED_HYPER
:
219 return (sal_Int32
)(sizeof(sal_Int64
));
220 case typelib_TypeClass_FLOAT
:
221 return (sal_Int32
)(sizeof(float));
222 case typelib_TypeClass_DOUBLE
:
223 return (sal_Int32
)(sizeof(double));
225 case typelib_TypeClass_STRING
:
227 rtl_uString
** pDest
= (rtl_uString
**)pElements
;
228 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
230 ::rtl_uString_release( pDest
[nPos
] );
232 return (sal_Int32
)(sizeof(rtl_uString
*));
234 case typelib_TypeClass_TYPE
:
236 typelib_TypeDescriptionReference
** pDest
= (typelib_TypeDescriptionReference
**)pElements
;
237 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
239 ::typelib_typedescriptionreference_release( pDest
[nPos
] );
241 return (sal_Int32
)(sizeof(typelib_TypeDescriptionReference
*));
243 case typelib_TypeClass_ANY
:
245 uno_Any
* pDest
= (uno_Any
*)pElements
;
246 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
248 _destructAny( &pDest
[nPos
], release
);
250 return (sal_Int32
)(sizeof(uno_Any
));
252 case typelib_TypeClass_ENUM
:
253 return (sal_Int32
)(sizeof(sal_Int32
));
254 case typelib_TypeClass_STRUCT
:
255 case typelib_TypeClass_EXCEPTION
:
257 typelib_TypeDescription
* pElementTypeDescr
= 0;
258 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
259 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
260 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
263 (char *)pElements
+ (nElementSize
* nPos
),
264 (typelib_CompoundTypeDescription
*)pElementTypeDescr
,
267 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
268 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
271 case typelib_TypeClass_UNION
:
273 typelib_TypeDescription
* pElementTypeDescr
= 0;
274 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
275 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
276 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
279 (char *)pElements
+ (nElementSize
* nPos
),
283 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
284 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
287 case typelib_TypeClass_SEQUENCE
:
289 typelib_TypeDescription
* pElementTypeDescr
= 0;
290 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
291 uno_Sequence
** pDest
= (uno_Sequence
**)pElements
;
292 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
296 pElementTypeDescr
->pWeakRef
, pElementTypeDescr
,
299 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
300 return (sal_Int32
)(sizeof(uno_Sequence
*));
302 case typelib_TypeClass_INTERFACE
:
306 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
308 void * p
= ((void **)pElements
)[nPos
];
317 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
319 uno_Interface
* p
= ((uno_Interface
**)pElements
)[nPos
];
326 return (sal_Int32
)(sizeof(void *));
334 //------------------------------------------------------------------------------
335 inline void idestructSequence(
337 typelib_TypeDescriptionReference
* pType
,
338 typelib_TypeDescription
* pTypeDescr
,
339 uno_ReleaseFunc release
)
341 if (::osl_decrementInterlockedCount( &pSeq
->nRefCount
) == 0)
343 if (pSeq
->nElements
> 0)
349 ((typelib_IndirectTypeDescription
*) pTypeDescr
)->pType
, 0,
350 pSeq
->nElements
, release
);
354 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
357 ((typelib_IndirectTypeDescription
*) pTypeDescr
)->pType
, 0,
358 pSeq
->nElements
, release
);
359 TYPELIB_DANGER_RELEASE( pTypeDescr
);
362 ::rtl_freeMemory( pSeq
);
366 //--------------------------------------------------------------------------------------------------
367 inline void _destructData(
369 typelib_TypeDescriptionReference
* pType
,
370 typelib_TypeDescription
* pTypeDescr
,
371 uno_ReleaseFunc release
)
374 switch (pType
->eTypeClass
)
376 case typelib_TypeClass_STRING
:
377 ::rtl_uString_release( *(rtl_uString
**)pValue
);
379 case typelib_TypeClass_TYPE
:
380 ::typelib_typedescriptionreference_release( *(typelib_TypeDescriptionReference
**)pValue
);
382 case typelib_TypeClass_ANY
:
383 _destructAny( (uno_Any
*)pValue
, release
);
385 case typelib_TypeClass_TYPEDEF
:
386 OSL_ENSURE( 0, "### unexpected typedef!" );
388 case typelib_TypeClass_STRUCT
:
389 case typelib_TypeClass_EXCEPTION
:
392 _destructStruct( pValue
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
396 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
397 _destructStruct( pValue
, (typelib_CompoundTypeDescription
*)pTypeDescr
, release
);
398 TYPELIB_DANGER_RELEASE( pTypeDescr
);
401 case typelib_TypeClass_ARRAY
:
404 _destructArray( pValue
, (typelib_ArrayTypeDescription
*)pTypeDescr
, release
);
408 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
409 _destructArray( pValue
, (typelib_ArrayTypeDescription
*)pTypeDescr
, release
);
410 TYPELIB_DANGER_RELEASE( pTypeDescr
);
413 case typelib_TypeClass_UNION
:
416 _destructUnion( pValue
, pTypeDescr
, release
);
420 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
421 _destructUnion( pValue
, pTypeDescr
, release
);
422 TYPELIB_DANGER_RELEASE( pTypeDescr
);
425 case typelib_TypeClass_SEQUENCE
:
428 *(uno_Sequence
**)pValue
, pType
, pTypeDescr
, release
);
431 case typelib_TypeClass_INTERFACE
:
432 _release( *(void **)pValue
, release
);