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 .
19 #ifndef INCLUDED_CPPU_SOURCE_UNO_DESTR_HXX
20 #define INCLUDED_CPPU_SOURCE_UNO_DESTR_HXX
22 #include <sal/config.h>
33 //#### destruction #################################################################################
39 typelib_CompoundTypeDescription
* pTypeDescr
,
40 uno_ReleaseFunc release
);
42 inline void _destructStruct(
44 typelib_CompoundTypeDescription
* pTypeDescr
,
45 uno_ReleaseFunc release
)
47 if (pTypeDescr
->pBaseTypeDescription
)
49 destructStruct( pValue
, pTypeDescr
->pBaseTypeDescription
, release
);
52 typelib_TypeDescriptionReference
** ppTypeRefs
= pTypeDescr
->ppTypeRefs
;
53 sal_Int32
* pMemberOffsets
= pTypeDescr
->pMemberOffsets
;
54 sal_Int32 nDescr
= pTypeDescr
->nMembers
;
57 ::uno_type_destructData(
58 static_cast<char *>(pValue
) + pMemberOffsets
[nDescr
],
59 ppTypeRefs
[nDescr
], release
);
64 void destructSequence(
65 uno_Sequence
* pSequence
,
66 typelib_TypeDescriptionReference
* pType
,
67 typelib_TypeDescription
* pTypeDescr
,
68 uno_ReleaseFunc release
);
71 inline void _destructAny(
73 uno_ReleaseFunc release
)
75 typelib_TypeDescriptionReference
* pType
= pAny
->pType
;
77 switch (pType
->eTypeClass
)
79 case typelib_TypeClass_HYPER
:
80 case typelib_TypeClass_UNSIGNED_HYPER
:
81 if (sizeof(void *) < sizeof(sal_Int64
))
83 ::rtl_freeMemory( pAny
->pData
);
86 case typelib_TypeClass_FLOAT
:
87 if (sizeof(void *) < sizeof(float))
89 ::rtl_freeMemory( pAny
->pData
);
92 case typelib_TypeClass_DOUBLE
:
93 if (sizeof(void *) < sizeof(double))
95 ::rtl_freeMemory( pAny
->pData
);
98 case typelib_TypeClass_STRING
:
99 ::rtl_uString_release( static_cast<rtl_uString
*>(pAny
->pReserved
) );
101 case typelib_TypeClass_TYPE
:
102 ::typelib_typedescriptionreference_release(
103 static_cast<typelib_TypeDescriptionReference
*>(pAny
->pReserved
) );
105 case typelib_TypeClass_ANY
:
106 OSL_FAIL( "### unexpected nested any!" );
107 ::uno_any_destruct( static_cast<uno_Any
*>(pAny
->pData
), release
);
108 ::rtl_freeMemory( pAny
->pData
);
110 case typelib_TypeClass_TYPEDEF
:
111 OSL_FAIL( "### unexpected typedef!" );
113 case typelib_TypeClass_STRUCT
:
114 case typelib_TypeClass_EXCEPTION
:
116 typelib_TypeDescription
* pTypeDescr
= 0;
117 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
118 _destructStruct( pAny
->pData
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
119 TYPELIB_DANGER_RELEASE( pTypeDescr
);
120 ::rtl_freeMemory( pAny
->pData
);
123 case typelib_TypeClass_SEQUENCE
:
126 static_cast<uno_Sequence
*>(pAny
->pReserved
), pType
, 0, release
);
129 case typelib_TypeClass_INTERFACE
:
130 _release( pAny
->pReserved
, release
);
135 #if OSL_DEBUG_LEVEL > 0
136 pAny
->pData
= reinterpret_cast<void *>(0xdeadbeef);
139 ::typelib_typedescriptionreference_release( pType
);
142 inline sal_Int32
idestructElements(
143 void * pElements
, typelib_TypeDescriptionReference
* pElementType
,
144 sal_Int32 nStartIndex
, sal_Int32 nStopIndex
,
145 uno_ReleaseFunc release
)
147 switch (pElementType
->eTypeClass
)
149 case typelib_TypeClass_CHAR
:
150 return (sal_Int32
)(sizeof(sal_Unicode
));
151 case typelib_TypeClass_BOOLEAN
:
152 return (sal_Int32
)(sizeof(sal_Bool
));
153 case typelib_TypeClass_BYTE
:
154 return (sal_Int32
)(sizeof(sal_Int8
));
155 case typelib_TypeClass_SHORT
:
156 case typelib_TypeClass_UNSIGNED_SHORT
:
157 return (sal_Int32
)(sizeof(sal_Int16
));
158 case typelib_TypeClass_LONG
:
159 case typelib_TypeClass_UNSIGNED_LONG
:
160 return (sal_Int32
)(sizeof(sal_Int32
));
161 case typelib_TypeClass_HYPER
:
162 case typelib_TypeClass_UNSIGNED_HYPER
:
163 return (sal_Int32
)(sizeof(sal_Int64
));
164 case typelib_TypeClass_FLOAT
:
165 return (sal_Int32
)(sizeof(float));
166 case typelib_TypeClass_DOUBLE
:
167 return (sal_Int32
)(sizeof(double));
169 case typelib_TypeClass_STRING
:
171 rtl_uString
** pDest
= static_cast<rtl_uString
**>(pElements
);
172 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
174 ::rtl_uString_release( pDest
[nPos
] );
176 return (sal_Int32
)(sizeof(rtl_uString
*));
178 case typelib_TypeClass_TYPE
:
180 typelib_TypeDescriptionReference
** pDest
= static_cast<typelib_TypeDescriptionReference
**>(pElements
);
181 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
183 ::typelib_typedescriptionreference_release( pDest
[nPos
] );
185 return (sal_Int32
)(sizeof(typelib_TypeDescriptionReference
*));
187 case typelib_TypeClass_ANY
:
189 uno_Any
* pDest
= static_cast<uno_Any
*>(pElements
);
190 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
192 _destructAny( &pDest
[nPos
], release
);
194 return (sal_Int32
)(sizeof(uno_Any
));
196 case typelib_TypeClass_ENUM
:
197 return (sal_Int32
)(sizeof(sal_Int32
));
198 case typelib_TypeClass_STRUCT
:
199 case typelib_TypeClass_EXCEPTION
:
201 typelib_TypeDescription
* pElementTypeDescr
= 0;
202 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
203 sal_Int32 nElementSize
= pElementTypeDescr
->nSize
;
204 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
207 static_cast<char *>(pElements
) + (nElementSize
* nPos
),
208 reinterpret_cast<typelib_CompoundTypeDescription
*>(pElementTypeDescr
),
211 sal_Int32 nSize
= pElementTypeDescr
->nSize
;
212 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
215 case typelib_TypeClass_SEQUENCE
:
217 typelib_TypeDescription
* pElementTypeDescr
= 0;
218 TYPELIB_DANGER_GET( &pElementTypeDescr
, pElementType
);
219 uno_Sequence
** pDest
= static_cast<uno_Sequence
**>(pElements
);
220 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
224 pElementTypeDescr
->pWeakRef
, pElementTypeDescr
,
227 TYPELIB_DANGER_RELEASE( pElementTypeDescr
);
228 return (sal_Int32
)(sizeof(uno_Sequence
*));
230 case typelib_TypeClass_INTERFACE
:
234 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
236 void * p
= static_cast<void **>(pElements
)[nPos
];
245 for ( sal_Int32 nPos
= nStartIndex
; nPos
< nStopIndex
; ++nPos
)
247 uno_Interface
* p
= static_cast<uno_Interface
**>(pElements
)[nPos
];
254 return (sal_Int32
)(sizeof(void *));
262 inline void idestroySequence(
264 typelib_TypeDescriptionReference
* pType
,
265 typelib_TypeDescription
* pTypeDescr
,
266 uno_ReleaseFunc release
)
268 assert(pSeq
!= nullptr);
269 assert(pSeq
->nRefCount
== 0);
270 if (pSeq
->nElements
> 0)
276 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
, 0,
277 pSeq
->nElements
, release
);
281 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
284 reinterpret_cast<typelib_IndirectTypeDescription
*>(pTypeDescr
)->pType
, 0,
285 pSeq
->nElements
, release
);
286 TYPELIB_DANGER_RELEASE( pTypeDescr
);
289 ::rtl_freeMemory( pSeq
);
292 inline void idestructSequence(
294 typelib_TypeDescriptionReference
* pType
,
295 typelib_TypeDescription
* pTypeDescr
,
296 uno_ReleaseFunc release
)
298 if (osl_atomic_decrement( &pSeq
->nRefCount
) == 0)
300 idestroySequence(pSeq
, pType
, pTypeDescr
, release
);
304 inline void _destructData(
306 typelib_TypeDescriptionReference
* pType
,
307 typelib_TypeDescription
* pTypeDescr
,
308 uno_ReleaseFunc release
)
310 switch (pType
->eTypeClass
)
312 case typelib_TypeClass_STRING
:
313 ::rtl_uString_release( *static_cast<rtl_uString
**>(pValue
) );
315 case typelib_TypeClass_TYPE
:
316 ::typelib_typedescriptionreference_release( *static_cast<typelib_TypeDescriptionReference
**>(pValue
) );
318 case typelib_TypeClass_ANY
:
319 _destructAny( static_cast<uno_Any
*>(pValue
), release
);
321 case typelib_TypeClass_TYPEDEF
:
322 OSL_FAIL( "### unexpected typedef!" );
324 case typelib_TypeClass_STRUCT
:
325 case typelib_TypeClass_EXCEPTION
:
328 _destructStruct( pValue
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
332 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
333 _destructStruct( pValue
, reinterpret_cast<typelib_CompoundTypeDescription
*>(pTypeDescr
), release
);
334 TYPELIB_DANGER_RELEASE( pTypeDescr
);
337 case typelib_TypeClass_SEQUENCE
:
340 *static_cast<uno_Sequence
**>(pValue
), pType
, pTypeDescr
, release
);
343 case typelib_TypeClass_INTERFACE
:
344 _release( *static_cast<void **>(pValue
), release
);
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */