update dev300-m58
[ooovba.git] / cppu / source / uno / prim.hxx
blobb617ced0846156e90a0741183d9ee64e789530b0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prim.hxx,v $
10 * $Revision: 1.18 $
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 ************************************************************************/
30 #ifndef PRIM_HXX
31 #define PRIM_HXX
33 #include "typelib/typedescription.h"
34 #ifndef _typelib_TypeClass_H_
35 #include "typelib/typeclass.h"
36 #endif
37 #include "uno/sequence2.h"
38 #include "uno/any2.h"
39 #include "uno/data.h"
40 #include "uno/mapping.h"
41 #include "uno/dispatcher.h"
43 #ifndef _OSL_INTERLCK_H
44 #include "osl/interlck.h"
45 #endif
46 #include "osl/diagnose.h"
47 #ifndef _RTL_USTRING_HXX
48 #include "rtl/ustring.hxx"
49 #endif
50 #include "rtl/alloc.h"
52 #if OSL_DEBUG_LEVEL > 1
53 #include "rtl/ustrbuf.hxx"
54 #include "rtl/string.hxx"
55 #endif
58 namespace cppu
61 extern uno_Sequence g_emptySeq;
62 extern typelib_TypeDescriptionReference * g_pVoidType;
64 //--------------------------------------------------------------------------------------------------
65 inline void * _map(
66 void * p,
67 typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
68 uno_Mapping * mapping )
69 SAL_THROW( () )
71 void * pRet = 0;
72 if (p)
74 if (pTypeDescr)
76 (*mapping->mapInterface)(
77 mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
79 else
81 TYPELIB_DANGER_GET( &pTypeDescr, pType );
82 (*mapping->mapInterface)(
83 mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
84 TYPELIB_DANGER_RELEASE( pTypeDescr );
87 return pRet;
89 //--------------------------------------------------------------------------------------------------
90 inline void _acquire( void * p, uno_AcquireFunc acquire ) SAL_THROW( () )
92 if (p)
94 if (acquire)
96 (*acquire)( p );
98 else
100 (*((uno_Interface *)p)->acquire)( (uno_Interface *)p );
104 //--------------------------------------------------------------------------------------------------
105 inline void _release( void * p, uno_ReleaseFunc release ) SAL_THROW( () )
107 if (p)
109 if (release)
111 (*release)( p );
113 else
115 (*((uno_Interface *)p)->release)( (uno_Interface *)p );
120 //------------------------------------------------------------------------------
121 inline sal_uInt32 calcSeqMemSize(
122 sal_Int32 nElementSize, sal_Int32 nElements )
124 sal_uInt64 nSize =
125 (sal_uInt64) SAL_SEQUENCE_HEADER_SIZE +
126 ((sal_uInt64) nElementSize * (sal_uInt64) nElements);
127 if (nSize > 0xffffffffU)
128 return 0;
129 else
130 return (sal_uInt32) nSize;
133 //--------------------------------------------------------------------------------------------------
134 inline uno_Sequence * createEmptySequence() SAL_THROW( () )
136 ::osl_incrementInterlockedCount( &g_emptySeq.nRefCount );
137 return &g_emptySeq;
139 //--------------------------------------------------------------------------------------------------
140 inline typelib_TypeDescriptionReference * _getVoidType()
141 SAL_THROW( () )
143 if (! g_pVoidType)
145 g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID );
147 ::typelib_typedescriptionreference_acquire( g_pVoidType );
148 return g_pVoidType;
151 //--------------------------------------------------------------------------------------------------
152 #if OSL_DEBUG_LEVEL > 0
153 #define CONSTRUCT_EMPTY_ANY( pAny ) \
154 (pAny)->pType = _getVoidType(); \
155 (pAny)->pData = (void *)0xdeadbeef;
156 #else
157 #define CONSTRUCT_EMPTY_ANY( pAny ) \
158 (pAny)->pType = _getVoidType(); \
159 (pAny)->pData = (pAny);
160 #endif
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 )
173 SAL_THROW( () )
175 typelib_TypeDescriptionReference * pRet = 0;
176 sal_Int32 nPos;
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];
185 break;
188 if (nPos >= 0)
190 // default
191 pRet = ((typelib_UnionTypeDescription *)pTD)->pDefaultTypeRef;
193 typelib_typedescriptionreference_acquire( pRet );
194 return pRet;
196 //--------------------------------------------------------------------------------------------------
197 inline sal_Bool _type_equals(
198 typelib_TypeDescriptionReference * pType1, typelib_TypeDescriptionReference * pType2 )
199 SAL_THROW( () )
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));
209 #endif