Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : : #ifndef PRIM_HXX
20 : : #define PRIM_HXX
21 : :
22 : : #include "typelib/typedescription.h"
23 : : #include "typelib/typeclass.h"
24 : : #include "uno/sequence2.h"
25 : : #include "uno/any2.h"
26 : : #include "uno/data.h"
27 : : #include "uno/mapping.h"
28 : : #include "uno/dispatcher.h"
29 : :
30 : : #include "osl/interlck.h"
31 : : #include "osl/diagnose.h"
32 : : #include "rtl/ustring.hxx"
33 : : #include "rtl/alloc.h"
34 : :
35 : : #if OSL_DEBUG_LEVEL > 1
36 : : #include "rtl/ustrbuf.hxx"
37 : : #include "rtl/string.hxx"
38 : : #endif
39 : :
40 : :
41 : : namespace cppu
42 : : {
43 : :
44 : : extern uno_Sequence g_emptySeq;
45 : : extern typelib_TypeDescriptionReference * g_pVoidType;
46 : :
47 : : //--------------------------------------------------------------------------------------------------
48 : 228018 : inline void * _map(
49 : : void * p,
50 : : typelib_TypeDescriptionReference * pType, typelib_TypeDescription * pTypeDescr,
51 : : uno_Mapping * mapping )
52 : : SAL_THROW(())
53 : : {
54 : 228018 : void * pRet = 0;
55 [ + + ]: 228018 : if (p)
56 : : {
57 [ + + ]: 212865 : if (pTypeDescr)
58 : : {
59 : : (*mapping->mapInterface)(
60 [ + - ]: 101138 : mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
61 : : }
62 : : else
63 : : {
64 [ + - ][ - + ]: 111727 : TYPELIB_DANGER_GET( &pTypeDescr, pType );
[ + - ][ + + ]
[ + - ]
65 : : (*mapping->mapInterface)(
66 [ + - ]: 111727 : mapping, &pRet, p, (typelib_InterfaceTypeDescription *)pTypeDescr );
67 [ + - ][ - + ]: 111727 : TYPELIB_DANGER_RELEASE( pTypeDescr );
68 : : }
69 : : }
70 : 228018 : return pRet;
71 : : }
72 : : //--------------------------------------------------------------------------------------------------
73 : 38586668 : inline void _acquire( void * p, uno_AcquireFunc acquire ) SAL_THROW(())
74 : : {
75 [ + + ]: 38586668 : if (p)
76 : : {
77 [ + + ]: 37558551 : if (acquire)
78 : : {
79 : 36758454 : (*acquire)( p );
80 : : }
81 : : else
82 : : {
83 : 800097 : (*((uno_Interface *)p)->acquire)( (uno_Interface *)p );
84 : : }
85 : : }
86 : 38586664 : }
87 : : //--------------------------------------------------------------------------------------------------
88 : 39520396 : inline void _release( void * p, uno_ReleaseFunc release ) SAL_THROW(())
89 : : {
90 [ + + ]: 39520396 : if (p)
91 : : {
92 [ + + ]: 17276564 : if (release)
93 : : {
94 : 16336995 : (*release)( p );
95 : : }
96 : : else
97 : : {
98 : 939569 : (*((uno_Interface *)p)->release)( (uno_Interface *)p );
99 : : }
100 : : }
101 : 39520393 : }
102 : :
103 : : //------------------------------------------------------------------------------
104 : 13622954 : inline sal_uInt32 calcSeqMemSize(
105 : : sal_Int32 nElementSize, sal_Int32 nElements )
106 : : {
107 : : sal_uInt64 nSize =
108 : : (sal_uInt64) SAL_SEQUENCE_HEADER_SIZE +
109 : 13622954 : ((sal_uInt64) nElementSize * (sal_uInt64) nElements);
110 [ - + ]: 13622954 : if (nSize > 0xffffffffU)
111 : 0 : return 0;
112 : : else
113 : 13622954 : return (sal_uInt32) nSize;
114 : : }
115 : :
116 : : //--------------------------------------------------------------------------------------------------
117 : 13584361 : inline uno_Sequence * createEmptySequence() SAL_THROW(())
118 : : {
119 : 13584361 : ::osl_incrementInterlockedCount( &g_emptySeq.nRefCount );
120 : 13584381 : return &g_emptySeq;
121 : : }
122 : : //--------------------------------------------------------------------------------------------------
123 : 60072032 : inline typelib_TypeDescriptionReference * _getVoidType()
124 : : SAL_THROW(())
125 : : {
126 [ + + ]: 60072032 : if (! g_pVoidType)
127 : : {
128 : 752 : g_pVoidType = * ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID );
129 : : }
130 : 60072032 : ::typelib_typedescriptionreference_acquire( g_pVoidType );
131 : 60072206 : return g_pVoidType;
132 : : }
133 : :
134 : : //--------------------------------------------------------------------------------------------------
135 : : #if OSL_DEBUG_LEVEL > 0
136 : : #define CONSTRUCT_EMPTY_ANY( pAny ) \
137 : : (pAny)->pType = _getVoidType(); \
138 : : (pAny)->pData = (void *)0xdeadbeef;
139 : : #else
140 : : #define CONSTRUCT_EMPTY_ANY( pAny ) \
141 : : (pAny)->pType = _getVoidType(); \
142 : : (pAny)->pData = (pAny);
143 : : #endif
144 : :
145 : : //--------------------------------------------------------------------------------------------------
146 : : #define TYPE_ACQUIRE( pType ) \
147 : : ::osl_incrementInterlockedCount( &(pType)->nRefCount );
148 : :
149 : : //--------------------------------------------------------------------------------------------------
150 : : extern "C" void * binuno_queryInterface(
151 : : void * pUnoI, typelib_TypeDescriptionReference * pDestType );
152 : :
153 : : //--------------------------------------------------------------------------------------------------
154 : 0 : inline typelib_TypeDescriptionReference * _unionGetSetType(
155 : : void * pUnion, typelib_TypeDescription * pTD )
156 : : SAL_THROW(())
157 : : {
158 : 0 : typelib_TypeDescriptionReference * pRet = 0;
159 : : sal_Int32 nPos;
160 : :
161 : 0 : sal_Int64 * pDiscr = ((typelib_UnionTypeDescription *)pTD)->pDiscriminants;
162 : 0 : sal_Int64 nDiscr = *(sal_Int64 *)pUnion;
163 [ # # ]: 0 : for ( nPos = ((typelib_UnionTypeDescription *)pTD)->nMembers; nPos--; )
164 : : {
165 [ # # ]: 0 : if (pDiscr[nPos] == nDiscr)
166 : : {
167 : 0 : pRet = ((typelib_UnionTypeDescription *)pTD)->ppTypeRefs[nPos];
168 : 0 : break;
169 : : }
170 : : }
171 [ # # ]: 0 : if (nPos >= 0)
172 : : {
173 : : // default
174 : 0 : pRet = ((typelib_UnionTypeDescription *)pTD)->pDefaultTypeRef;
175 : : }
176 : 0 : typelib_typedescriptionreference_acquire( pRet );
177 : 0 : return pRet;
178 : : }
179 : : //--------------------------------------------------------------------------------------------------
180 : 6619911 : inline sal_Bool _type_equals(
181 : : typelib_TypeDescriptionReference * pType1, typelib_TypeDescriptionReference * pType2 )
182 : : SAL_THROW(())
183 : : {
184 : : return (pType1 == pType2 ||
185 : : (pType1->eTypeClass == pType2->eTypeClass &&
186 : : pType1->pTypeName->length == pType2->pTypeName->length &&
187 [ + + ][ + + ]: 6619911 : ::rtl_ustr_compare( pType1->pTypeName->buffer, pType2->pTypeName->buffer ) == 0));
[ + + ][ - + ]
188 : : }
189 : :
190 : : }
191 : :
192 : : #endif
193 : :
194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|