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: prim.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 ************************************************************************/
33 #include "typelib/typedescription.h"
34 #ifndef _typelib_TypeClass_H_
35 #include "typelib/typeclass.h"
37 #include "uno/sequence2.h"
40 #include "uno/mapping.h"
41 #include "uno/dispatcher.h"
43 #ifndef _OSL_INTERLCK_H
44 #include "osl/interlck.h"
46 #include "osl/diagnose.h"
47 #ifndef _RTL_USTRING_HXX
48 #include "rtl/ustring.hxx"
50 #include "rtl/alloc.h"
52 #if OSL_DEBUG_LEVEL > 1
53 #include "rtl/ustrbuf.hxx"
54 #include "rtl/string.hxx"
61 extern uno_Sequence g_emptySeq
;
62 extern typelib_TypeDescriptionReference
* g_pVoidType
;
64 //--------------------------------------------------------------------------------------------------
67 typelib_TypeDescriptionReference
* pType
, typelib_TypeDescription
* pTypeDescr
,
68 uno_Mapping
* mapping
)
76 (*mapping
->mapInterface
)(
77 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
81 TYPELIB_DANGER_GET( &pTypeDescr
, pType
);
82 (*mapping
->mapInterface
)(
83 mapping
, &pRet
, p
, (typelib_InterfaceTypeDescription
*)pTypeDescr
);
84 TYPELIB_DANGER_RELEASE( pTypeDescr
);
89 //--------------------------------------------------------------------------------------------------
90 inline void _acquire( void * p
, uno_AcquireFunc acquire
) SAL_THROW( () )
100 (*((uno_Interface
*)p
)->acquire
)( (uno_Interface
*)p
);
104 //--------------------------------------------------------------------------------------------------
105 inline void _release( void * p
, uno_ReleaseFunc release
) SAL_THROW( () )
115 (*((uno_Interface
*)p
)->release
)( (uno_Interface
*)p
);
120 //------------------------------------------------------------------------------
121 inline sal_uInt32
calcSeqMemSize(
122 sal_Int32 nElementSize
, sal_Int32 nElements
)
125 (sal_uInt64
) SAL_SEQUENCE_HEADER_SIZE
+
126 ((sal_uInt64
) nElementSize
* (sal_uInt64
) nElements
);
127 if (nSize
> 0xffffffffU
)
130 return (sal_uInt32
) nSize
;
133 //--------------------------------------------------------------------------------------------------
134 inline uno_Sequence
* createEmptySequence() SAL_THROW( () )
136 ::osl_incrementInterlockedCount( &g_emptySeq
.nRefCount
);
139 //--------------------------------------------------------------------------------------------------
140 inline typelib_TypeDescriptionReference
* _getVoidType()
145 g_pVoidType
= * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID
);
147 ::typelib_typedescriptionreference_acquire( g_pVoidType
);
151 //--------------------------------------------------------------------------------------------------
152 #if OSL_DEBUG_LEVEL > 0
153 #define CONSTRUCT_EMPTY_ANY( pAny ) \
154 (pAny)->pType = _getVoidType(); \
155 (pAny)->pData = (void *)0xdeadbeef;
157 #define CONSTRUCT_EMPTY_ANY( pAny ) \
158 (pAny)->pType = _getVoidType(); \
159 (pAny)->pData = (pAny);
162 //--------------------------------------------------------------------------------------------------
163 #define TYPE_ACQUIRE( pType ) \
164 ::osl_incrementInterlockedCount( &(pType)->nRefCount );
166 //--------------------------------------------------------------------------------------------------
167 extern "C" void * binuno_queryInterface(
168 void * pUnoI
, typelib_TypeDescriptionReference
* pDestType
);
170 //--------------------------------------------------------------------------------------------------
171 inline typelib_TypeDescriptionReference
* _unionGetSetType(
172 void * pUnion
, typelib_TypeDescription
* pTD
)
175 typelib_TypeDescriptionReference
* pRet
= 0;
178 sal_Int64
* pDiscr
= ((typelib_UnionTypeDescription
*)pTD
)->pDiscriminants
;
179 sal_Int64 nDiscr
= *(sal_Int64
*)pUnion
;
180 for ( nPos
= ((typelib_UnionTypeDescription
*)pTD
)->nMembers
; nPos
--; )
182 if (pDiscr
[nPos
] == nDiscr
)
184 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->ppTypeRefs
[nPos
];
191 pRet
= ((typelib_UnionTypeDescription
*)pTD
)->pDefaultTypeRef
;
193 typelib_typedescriptionreference_acquire( pRet
);
196 //--------------------------------------------------------------------------------------------------
197 inline sal_Bool
_type_equals(
198 typelib_TypeDescriptionReference
* pType1
, typelib_TypeDescriptionReference
* pType2
)
201 return (pType1
== pType2
||
202 (pType1
->eTypeClass
== pType2
->eTypeClass
&&
203 pType1
->pTypeName
->length
== pType2
->pTypeName
->length
&&
204 ::rtl_ustr_compare( pType1
->pTypeName
->buffer
, pType2
->pTypeName
->buffer
) == 0));