tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / cppu / source / uno / destr.hxx
blob13e4ca044c3ab9e4dd80cf0ef12f0ce0a7f9e92c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
21 #include <sal/config.h>
22 #include <osl/diagnose.h>
24 #include <cassert>
25 #include <cstdlib>
27 #include "prim.hxx"
29 namespace cppu
33 //#### destruction #################################################################################
36 void destructStruct(
37 void * pValue,
38 typelib_CompoundTypeDescription * pTypeDescr,
39 uno_ReleaseFunc release );
41 inline void _destructStruct(
42 void * pValue,
43 typelib_CompoundTypeDescription * pTypeDescr,
44 uno_ReleaseFunc release )
46 if (pTypeDescr->pBaseTypeDescription)
48 destructStruct( pValue, pTypeDescr->pBaseTypeDescription, release );
51 typelib_TypeDescriptionReference ** ppTypeRefs = pTypeDescr->ppTypeRefs;
52 sal_Int32 * pMemberOffsets = pTypeDescr->pMemberOffsets;
53 sal_Int32 nDescr = pTypeDescr->nMembers;
54 while (nDescr--)
56 ::uno_type_destructData(
57 static_cast<char *>(pValue) + pMemberOffsets[nDescr],
58 ppTypeRefs[nDescr], release );
63 void destructSequence(
64 uno_Sequence * pSequence,
65 typelib_TypeDescriptionReference * pType,
66 typelib_TypeDescription * pTypeDescr,
67 uno_ReleaseFunc release );
70 inline void _destructAny(
71 uno_Any * pAny,
72 uno_ReleaseFunc release )
74 typelib_TypeDescriptionReference * pType = pAny->pType;
76 switch (pType->eTypeClass)
78 case typelib_TypeClass_HYPER:
79 case typelib_TypeClass_UNSIGNED_HYPER:
80 if (sizeof(void *) < sizeof(sal_Int64))
82 std::free( pAny->pData );
84 break;
85 case typelib_TypeClass_FLOAT:
86 if (sizeof(void *) < sizeof(float))
88 std::free( pAny->pData );
90 break;
91 case typelib_TypeClass_DOUBLE:
92 if (sizeof(void *) < sizeof(double))
94 std::free( pAny->pData );
96 break;
97 case typelib_TypeClass_STRING:
98 ::rtl_uString_release( static_cast<rtl_uString *>(pAny->pReserved) );
99 break;
100 case typelib_TypeClass_TYPE:
101 ::typelib_typedescriptionreference_release(
102 static_cast<typelib_TypeDescriptionReference *>(pAny->pReserved) );
103 break;
104 case typelib_TypeClass_ANY:
105 OSL_FAIL( "### unexpected nested any!" );
106 ::uno_any_destruct( static_cast<uno_Any *>(pAny->pData), release );
107 std::free( pAny->pData );
108 break;
109 case typelib_TypeClass_TYPEDEF:
110 OSL_FAIL( "### unexpected typedef!" );
111 break;
112 case typelib_TypeClass_STRUCT:
113 case typelib_TypeClass_EXCEPTION:
115 typelib_TypeDescription * pTypeDescr = nullptr;
116 TYPELIB_DANGER_GET( &pTypeDescr, pType );
117 _destructStruct( pAny->pData, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
118 TYPELIB_DANGER_RELEASE( pTypeDescr );
119 std::free( pAny->pData );
120 break;
122 case typelib_TypeClass_SEQUENCE:
124 destructSequence(
125 static_cast<uno_Sequence *>(pAny->pReserved), pType, nullptr, release );
126 break;
128 case typelib_TypeClass_INTERFACE:
129 _release( pAny->pReserved, release );
130 break;
131 default:
132 break;
134 #if OSL_DEBUG_LEVEL > 0
135 pAny->pData = reinterpret_cast<void *>(uintptr_t(0xdeadbeef));
136 #endif
138 ::typelib_typedescriptionreference_release( pType );
141 inline sal_Int32 idestructElements(
142 void * pElements, typelib_TypeDescriptionReference * pElementType,
143 sal_Int32 nStartIndex, sal_Int32 nStopIndex,
144 uno_ReleaseFunc release )
146 switch (pElementType->eTypeClass)
148 case typelib_TypeClass_CHAR:
149 return sal_Int32(sizeof(sal_Unicode));
150 case typelib_TypeClass_BOOLEAN:
151 return sal_Int32(sizeof(sal_Bool));
152 case typelib_TypeClass_BYTE:
153 return sal_Int32(sizeof(sal_Int8));
154 case typelib_TypeClass_SHORT:
155 case typelib_TypeClass_UNSIGNED_SHORT:
156 return sal_Int32(sizeof(sal_Int16));
157 case typelib_TypeClass_LONG:
158 case typelib_TypeClass_UNSIGNED_LONG:
159 return sal_Int32(sizeof(sal_Int32));
160 case typelib_TypeClass_HYPER:
161 case typelib_TypeClass_UNSIGNED_HYPER:
162 return sal_Int32(sizeof(sal_Int64));
163 case typelib_TypeClass_FLOAT:
164 return sal_Int32(sizeof(float));
165 case typelib_TypeClass_DOUBLE:
166 return sal_Int32(sizeof(double));
168 case typelib_TypeClass_STRING:
170 rtl_uString ** pDest = static_cast<rtl_uString **>(pElements);
171 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
173 ::rtl_uString_release( pDest[nPos] );
175 return sal_Int32(sizeof(rtl_uString *));
177 case typelib_TypeClass_TYPE:
179 typelib_TypeDescriptionReference ** pDest = static_cast<typelib_TypeDescriptionReference **>(pElements);
180 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
182 ::typelib_typedescriptionreference_release( pDest[nPos] );
184 return sal_Int32(sizeof(typelib_TypeDescriptionReference *));
186 case typelib_TypeClass_ANY:
188 uno_Any * pDest = static_cast<uno_Any *>(pElements);
189 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
191 _destructAny( &pDest[nPos], release );
193 return sal_Int32(sizeof(uno_Any));
195 case typelib_TypeClass_ENUM:
196 return sal_Int32(sizeof(sal_Int32));
197 case typelib_TypeClass_STRUCT:
198 case typelib_TypeClass_EXCEPTION:
200 typelib_TypeDescription * pElementTypeDescr = nullptr;
201 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
202 sal_Int32 nElementSize = pElementTypeDescr->nSize;
203 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
205 _destructStruct(
206 static_cast<char *>(pElements) + (nElementSize * nPos),
207 reinterpret_cast<typelib_CompoundTypeDescription *>(pElementTypeDescr),
208 release );
210 sal_Int32 nSize = pElementTypeDescr->nSize;
211 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
212 return nSize;
214 case typelib_TypeClass_SEQUENCE:
216 typelib_TypeDescription * pElementTypeDescr = nullptr;
217 TYPELIB_DANGER_GET( &pElementTypeDescr, pElementType );
218 uno_Sequence ** pDest = static_cast<uno_Sequence **>(pElements);
219 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
221 destructSequence(
222 pDest[nPos],
223 pElementTypeDescr->pWeakRef, pElementTypeDescr,
224 release );
226 TYPELIB_DANGER_RELEASE( pElementTypeDescr );
227 return sal_Int32(sizeof(uno_Sequence *));
229 case typelib_TypeClass_INTERFACE:
231 if (release)
233 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
235 void * p = static_cast<void **>(pElements)[nPos];
236 if (p)
238 (*release)( p );
242 else
244 for ( sal_Int32 nPos = nStartIndex; nPos < nStopIndex; ++nPos )
246 uno_Interface * p = static_cast<uno_Interface **>(pElements)[nPos];
247 if (p)
249 (*p->release)( p );
253 return sal_Int32(sizeof(void *));
255 default:
256 OSL_ASSERT(false);
257 return 0;
261 inline void idestroySequence(
262 uno_Sequence * pSeq,
263 typelib_TypeDescriptionReference * pType,
264 typelib_TypeDescription * pTypeDescr,
265 uno_ReleaseFunc release )
267 assert(pSeq != nullptr);
268 assert(pSeq->nRefCount == 0);
269 if (pSeq->nElements > 0)
271 if (pTypeDescr)
273 idestructElements(
274 pSeq->elements,
275 reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType, 0,
276 pSeq->nElements, release );
278 else
280 TYPELIB_DANGER_GET( &pTypeDescr, pType );
281 idestructElements(
282 pSeq->elements,
283 reinterpret_cast<typelib_IndirectTypeDescription *>(pTypeDescr)->pType, 0,
284 pSeq->nElements, release );
285 TYPELIB_DANGER_RELEASE( pTypeDescr );
288 std::free( pSeq );
291 inline void idestructSequence(
292 uno_Sequence * pSeq,
293 typelib_TypeDescriptionReference * pType,
294 typelib_TypeDescription * pTypeDescr,
295 uno_ReleaseFunc release )
297 if (osl_atomic_decrement( &pSeq->nRefCount ) == 0)
299 idestroySequence(pSeq, pType, pTypeDescr, release);
303 inline void _destructData(
304 void * pValue,
305 typelib_TypeDescriptionReference * pType,
306 typelib_TypeDescription * pTypeDescr,
307 uno_ReleaseFunc release )
309 switch (pType->eTypeClass)
311 case typelib_TypeClass_STRING:
312 ::rtl_uString_release( *static_cast<rtl_uString **>(pValue) );
313 break;
314 case typelib_TypeClass_TYPE:
315 ::typelib_typedescriptionreference_release( *static_cast<typelib_TypeDescriptionReference **>(pValue) );
316 break;
317 case typelib_TypeClass_ANY:
318 _destructAny( static_cast<uno_Any *>(pValue), release );
319 break;
320 case typelib_TypeClass_TYPEDEF:
321 OSL_FAIL( "### unexpected typedef!" );
322 break;
323 case typelib_TypeClass_STRUCT:
324 case typelib_TypeClass_EXCEPTION:
325 if (pTypeDescr)
327 _destructStruct( pValue, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
329 else
331 TYPELIB_DANGER_GET( &pTypeDescr, pType );
332 _destructStruct( pValue, reinterpret_cast<typelib_CompoundTypeDescription *>(pTypeDescr), release );
333 TYPELIB_DANGER_RELEASE( pTypeDescr );
335 break;
336 case typelib_TypeClass_SEQUENCE:
338 idestructSequence(
339 *static_cast<uno_Sequence **>(pValue), pType, pTypeDescr, release );
340 break;
342 case typelib_TypeClass_INTERFACE:
343 _release( *static_cast<void **>(pValue), release );
344 break;
345 default:
346 break;
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */