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 ************************************************************************/
30 #include "typelib/typedescription.h"
31 #ifndef _typelib_TypeClass_H_
32 #include "typelib/typeclass.h"
34 #include "uno/sequence2.h"
37 #include "uno/mapping.h"
38 #include "uno/dispatcher.h"
40 #ifndef _OSL_INTERLCK_H
41 #include "osl/interlck.h"
43 #include "osl/diagnose.h"
44 #ifndef _RTL_USTRING_HXX
45 #include "rtl/ustring.hxx"
47 #include "rtl/alloc.h"
49 #if OSL_DEBUG_LEVEL > 1
50 #include "rtl/ustrbuf.hxx"
51 #include "rtl/string.hxx"
58 extern uno_Sequence g_emptySeq
;
59 extern typelib_TypeDescriptionReference
* g_pVoidType
;
61 //--------------------------------------------------------------------------------------------------
64 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
65 uno_Mapping
* mapping
)
73 (*mapping
->mapInterface
)(
74 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
78 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
79 (*mapping
->mapInterface
)(
80 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
81 TYPELIB_DANGER_RELEASE( pTypeDescr
);
86 //--------------------------------------------------------------------------------------------------
87 inline void _acquire( void * p
, uno_AcquireFunc acquire
) SAL_THROW( () )
97 (*((uno_Interface
*)p
)->acquire
)( (uno_Interface
*)p
);
101 //--------------------------------------------------------------------------------------------------
102 inline void _release( void * p
, uno_ReleaseFunc release
) SAL_THROW( () )
112 (*((uno_Interface
*)p
)->release
)( (uno_Interface
*)p
);
117 //------------------------------------------------------------------------------
118 inline sal_uInt32
calcSeqMemSize(
119 sal_Int32 nElementSize
, sal_Int32 nElements
)
122 (sal_uInt64
) SAL_SEQUENCE_HEADER_SIZE
+
123 ((sal_uInt64
) nElementSize
* (sal_uInt64
) nElements
);
124 if (nSize
> 0xffffffffU
)
127 return (sal_uInt32
) nSize
;
130 //--------------------------------------------------------------------------------------------------
131 inline uno_Sequence
* createEmptySequence() SAL_THROW( () )
133 ::osl_incrementInterlockedCount( &g_emptySeq
.nRefCount
);
136 //--------------------------------------------------------------------------------------------------
137 inline typelib_TypeDescriptionReference
* _getVoidType()
142 g_pVoidType
= * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID
);
144 ::typelib_typedescriptionreference_acquire( g_pVoidType
);
148 //--------------------------------------------------------------------------------------------------
149 #if OSL_DEBUG_LEVEL > 0
150 #define CONSTRUCT_EMPTY_ANY( pAny ) \
151 (pAny)->pType = _getVoidType(); \
152 (pAny)->pData = (void *)0xdeadbeef;
154 #define CONSTRUCT_EMPTY_ANY( pAny ) \
155 (pAny)->pType = _getVoidType(); \
156 (pAny)->pData = (pAny);
159 //--------------------------------------------------------------------------------------------------
160 #define TYPE_ACQUIRE( pType ) \
161 ::osl_incrementInterlockedCount( &(pType)->nRefCount );
163 //--------------------------------------------------------------------------------------------------
164 extern "C" void * binuno_queryInterface(
165 void * pUnoI
, typelib_TypeDescriptionReference
* pDestType
);
167 //--------------------------------------------------------------------------------------------------
168 inline typelib_TypeDescriptionReference
* _unionGetSetType(
169 void * pUnion
, typelib_TypeDescription
* pTD
)
172 typelib_TypeDescriptionReference
* pRet
= 0;
175 sal_Int64
* pDiscr
= ((typelib_UnionTypeDescription
*)pTD
)->pDiscriminants
;
176 sal_Int64 nDiscr
= *(sal_Int64
*)pUnion
;
177 for ( nPos
= ((typelib_UnionTypeDescription
*)pTD
)->nMembers
; nPos
--; )
179 if (pDiscr
[nPos
] == nDiscr
)
181 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->ppTypeRefs
[nPos
];
188 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->pDefaultTypeRef
;
190 typelib_typedescriptionreference_acquire( pRet
);
193 //--------------------------------------------------------------------------------------------------
194 inline sal_Bool
_type_equals(
195 typelib_TypeDescriptionReference
* pType1
, typelib_TypeDescriptionReference
* pType2
)
198 return (pType1
== pType2
||
199 (pType1
->eTypeClass
== pType2
->eTypeClass
&&
200 pType1
->pTypeName
->length
== pType2
->pTypeName
->length
&&
201 ::rtl_ustr_compare( pType1
->pTypeName
->buffer
, pType2
->pTypeName
->buffer
) == 0));