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 .
22 #include "typelib/typedescription.h"
23 #include "typelib/typeclass.h"
24 #include "uno/sequence2.h"
27 #include "uno/mapping.h"
28 #include "uno/dispatcher.h"
30 #include "osl/interlck.h"
31 #include "osl/diagnose.h"
32 #include "rtl/ustring.hxx"
33 #include "rtl/alloc.h"
35 #if OSL_DEBUG_LEVEL > 1
36 #include "rtl/ustrbuf.hxx"
37 #include "rtl/string.hxx"
44 extern uno_Sequence g_emptySeq
;
45 extern typelib_TypeDescriptionReference
* g_pVoidType
;
47 //--------------------------------------------------------------------------------------------------
50 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
51 uno_Mapping
* mapping
)
59 (*mapping
->mapInterface
)(
60 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
64 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
65 (*mapping
->mapInterface
)(
66 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
67 TYPELIB_DANGER_RELEASE( pTypeDescr
);
72 //--------------------------------------------------------------------------------------------------
73 inline void _acquire( void * p
, uno_AcquireFunc acquire
) SAL_THROW(())
83 (*((uno_Interface
*)p
)->acquire
)( (uno_Interface
*)p
);
87 //--------------------------------------------------------------------------------------------------
88 inline void _release( void * p
, uno_ReleaseFunc release
) SAL_THROW(())
98 (*((uno_Interface
*)p
)->release
)( (uno_Interface
*)p
);
103 //------------------------------------------------------------------------------
104 inline sal_uInt32
calcSeqMemSize(
105 sal_Int32 nElementSize
, sal_Int32 nElements
)
108 (sal_uInt64
) SAL_SEQUENCE_HEADER_SIZE
+
109 ((sal_uInt64
) nElementSize
* (sal_uInt64
) nElements
);
110 if (nSize
> 0xffffffffU
)
113 return (sal_uInt32
) nSize
;
116 //--------------------------------------------------------------------------------------------------
117 inline uno_Sequence
* createEmptySequence() SAL_THROW(())
119 osl_atomic_increment( &g_emptySeq
.nRefCount
);
122 //--------------------------------------------------------------------------------------------------
123 inline typelib_TypeDescriptionReference
* _getVoidType()
128 g_pVoidType
= * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID
);
130 ::typelib_typedescriptionreference_acquire( g_pVoidType
);
134 //--------------------------------------------------------------------------------------------------
135 #if OSL_DEBUG_LEVEL > 0
136 #define CONSTRUCT_EMPTY_ANY( pAny ) \
137 (pAny)->pType = _getVoidType(); \
138 (pAny)->pData = (void *)0xdeadbeef;
140 #define CONSTRUCT_EMPTY_ANY( pAny ) \
141 (pAny)->pType = _getVoidType(); \
142 (pAny)->pData = (pAny);
145 //--------------------------------------------------------------------------------------------------
146 #define TYPE_ACQUIRE( pType ) \
147 osl_atomic_increment( &(pType)->nRefCount );
149 //--------------------------------------------------------------------------------------------------
150 extern "C" void * binuno_queryInterface(
151 void * pUnoI
, typelib_TypeDescriptionReference
* pDestType
);
153 //--------------------------------------------------------------------------------------------------
154 inline typelib_TypeDescriptionReference
* _unionGetSetType(
155 void * pUnion
, typelib_TypeDescription
* pTD
)
158 typelib_TypeDescriptionReference
* pRet
= 0;
161 sal_Int64
* pDiscr
= ((typelib_UnionTypeDescription
*)pTD
)->pDiscriminants
;
162 sal_Int64 nDiscr
= *(sal_Int64
*)pUnion
;
163 for ( nPos
= ((typelib_UnionTypeDescription
*)pTD
)->nMembers
; nPos
--; )
165 if (pDiscr
[nPos
] == nDiscr
)
167 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->ppTypeRefs
[nPos
];
174 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->pDefaultTypeRef
;
176 typelib_typedescriptionreference_acquire( pRet
);
179 //--------------------------------------------------------------------------------------------------
180 inline sal_Bool
_type_equals(
181 typelib_TypeDescriptionReference
* pType1
, typelib_TypeDescriptionReference
* pType2
)
184 return (pType1
== pType2
||
185 (pType1
->eTypeClass
== pType2
->eTypeClass
&&
186 pType1
->pTypeName
->length
== pType2
->pTypeName
->length
&&
187 ::rtl_ustr_compare( pType1
->pTypeName
->buffer
, pType2
->pTypeName
->buffer
) == 0));
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */