1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #ifndef _COM_SUN_STAR_UNO_TYPE_HXX_
24 #define _COM_SUN_STAR_UNO_TYPE_HXX_
25
26 #include <osl/mutex.hxx>
27 #include <com/sun/star/uno/Type.h>
28 #include "cppu/unotype.hxx"
29
30 namespace com
31 {
32 namespace sun
33 {
34 namespace star
35 {
36 namespace uno
37 {
38
39 //__________________________________________________________________________________________________
Type()40 inline Type::Type() SAL_THROW( () )
41 {
42 _pType = reinterpret_cast< const ::com::sun::star::uno::Type * >(
43 ::typelib_static_type_getByTypeClass( typelib_TypeClass_VOID ) )->getTypeLibType();
44 ::typelib_typedescriptionreference_acquire( _pType );
45 }
46 //__________________________________________________________________________________________________
Type(TypeClass eTypeClass,const::rtl::OUString & rTypeName)47 inline Type::Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ) SAL_THROW( () )
48 : _pType( 0 )
49 {
50 ::typelib_typedescriptionreference_new( &_pType, (typelib_TypeClass)eTypeClass, rTypeName.pData );
51 }
52 //__________________________________________________________________________________________________
Type(TypeClass eTypeClass,const sal_Char * pTypeName)53 inline Type::Type( TypeClass eTypeClass, const sal_Char * pTypeName ) SAL_THROW( () )
54 : _pType( 0 )
55 {
56 ::typelib_typedescriptionreference_newByAsciiName( &_pType, (typelib_TypeClass)eTypeClass, pTypeName );
57 }
58 //__________________________________________________________________________________________________
Type(typelib_TypeDescriptionReference * pType)59 inline Type::Type( typelib_TypeDescriptionReference * pType ) SAL_THROW( () )
60 : _pType( pType )
61 {
62 ::typelib_typedescriptionreference_acquire( _pType );
63 }
64 //__________________________________________________________________________________________________
Type(typelib_TypeDescriptionReference * pType,UnoType_NoAcquire)65 inline Type::Type( typelib_TypeDescriptionReference * pType, UnoType_NoAcquire ) SAL_THROW( () )
66 : _pType( pType )
67 {
68 }
69 //__________________________________________________________________________________________________
Type(typelib_TypeDescriptionReference * pType,__sal_NoAcquire)70 inline Type::Type( typelib_TypeDescriptionReference * pType, __sal_NoAcquire ) SAL_THROW( () )
71 : _pType( pType )
72 {
73 }
74 //__________________________________________________________________________________________________
Type(const Type & rType)75 inline Type::Type( const Type & rType ) SAL_THROW( () )
76 : _pType( rType._pType )
77 {
78 ::typelib_typedescriptionreference_acquire( _pType );
79 }
80 //__________________________________________________________________________________________________
getTypeName() const81 inline ::rtl::OUString Type::getTypeName() const SAL_THROW( () )
82 {
83 return ::rtl::OUString( _pType->pTypeName );
84 }
85 //__________________________________________________________________________________________________
operator =(const Type & rType)86 inline Type & Type::operator = ( const Type & rType ) SAL_THROW( () )
87 {
88 ::typelib_typedescriptionreference_assign( &_pType, rType._pType );
89 return *this;
90 }
91
92 //__________________________________________________________________________________________________
93 template< class T >
94 typelib_TypeDescriptionReference * Array< T >::s_pType = 0;
95
96 }
97 }
98 }
99 }
100
getCppuType(const::com::sun::star::uno::Type *)101 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::com::sun::star::uno::Type * ) SAL_THROW( () )
102 {
103 return ::cppu::UnoType< ::com::sun::star::uno::Type >::get();
104 }
105
getCppuVoidType()106 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuVoidType() SAL_THROW( () )
107 {
108 return ::cppu::UnoType< ::cppu::UnoVoidType >::get();
109 }
getVoidCppuType()110 inline const ::com::sun::star::uno::Type & SAL_CALL getVoidCppuType() SAL_THROW( () )
111 {
112 return ::cppu::UnoType< ::cppu::UnoVoidType >::get();
113 }
114
getCppuBooleanType()115 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuBooleanType() SAL_THROW( () )
116 {
117 return ::cppu::UnoType< bool >::get();
118 }
getBooleanCppuType()119 inline const ::com::sun::star::uno::Type & SAL_CALL getBooleanCppuType() SAL_THROW( () )
120 {
121 return ::cppu::UnoType< bool >::get();
122 }
getCppuType(const sal_Bool *)123 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Bool * ) SAL_THROW( () )
124 {
125 return ::cppu::UnoType< bool >::get();
126 }
127
getCppuType(bool const *)128 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType(
129 bool const * ) SAL_THROW( () )
130 {
131 return ::cppu::UnoType< bool >::get();
132 }
133
getCharCppuType()134 inline const ::com::sun::star::uno::Type & SAL_CALL getCharCppuType() SAL_THROW( () )
135 {
136 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
137 }
getCppuCharType()138 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuCharType() SAL_THROW( () )
139 {
140 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
141 }
142
getCppuType(const sal_Int8 *)143 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int8 * ) SAL_THROW( () )
144 {
145 return ::cppu::UnoType< ::sal_Int8 >::get();
146 }
147
getCppuType(const::rtl::OUString *)148 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const ::rtl::OUString * ) SAL_THROW( () )
149 {
150 return ::cppu::UnoType< ::rtl::OUString >::get();
151 }
152
getCppuType(const sal_Int16 *)153 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int16 * ) SAL_THROW( () )
154 {
155 return ::cppu::UnoType< ::sal_Int16 >::get();
156 }
157
getCppuType(const sal_uInt16 *)158 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt16 * ) SAL_THROW( () )
159 {
160 return ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get();
161 }
162
getCppuType(const sal_Int32 *)163 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int32 * ) SAL_THROW( () )
164 {
165 return ::cppu::UnoType< ::sal_Int32 >::get();
166 }
167
getCppuType(const sal_uInt32 *)168 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt32 * ) SAL_THROW( () )
169 {
170 return ::cppu::UnoType< ::sal_uInt32 >::get();
171 }
172
getCppuType(const sal_Int64 *)173 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_Int64 * ) SAL_THROW( () )
174 {
175 return ::cppu::UnoType< ::sal_Int64 >::get();
176 }
177
getCppuType(const sal_uInt64 *)178 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const sal_uInt64 * ) SAL_THROW( () )
179 {
180 return ::cppu::UnoType< ::sal_uInt64 >::get();
181 }
182
getCppuType(const float *)183 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const float * ) SAL_THROW( () )
184 {
185 return ::cppu::UnoType< float >::get();
186 }
187
getCppuType(const double *)188 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType( const double * ) SAL_THROW( () )
189 {
190 return ::cppu::UnoType< double >::get();
191 }
192
193 template< class T >
getCppuArrayType1(T * pT)194 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType1( T * pT ) SAL_THROW( () )
195 {
196 if (! ::com::sun::star::uno::Array< T >::s_pType)
197 {
198 const ::com::sun::star::uno::Type & rElementType =
199 ::cppu::getTypeFavourUnsigned( *pT );
200 sal_Int32 size = sizeof( **pT );
201 sal_Int32 dim1 = sizeof( *pT ) / size;
202 ::typelib_static_array_type_init(
203 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
204 1, dim1 );
205 }
206 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
207 & ::com::sun::star::uno::Array< T >::s_pType );
208 }
209
210 template< class T >
getCppuArrayType2(T * pT)211 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType2( T * pT ) SAL_THROW( () )
212 {
213 if (! ::com::sun::star::uno::Array< T >::s_pType)
214 {
215 const ::com::sun::star::uno::Type & rElementType =
216 ::cppu::getTypeFavourUnsigned( **pT );
217 sal_Int32 size = sizeof( ***pT );
218 sal_Int32 dim2 = sizeof( **pT ) / size;
219 sal_Int32 dim1 = sizeof( *pT ) / dim2 / size;
220 ::typelib_static_array_type_init(
221 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
222 2, dim1, dim2 );
223 }
224 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
225 & ::com::sun::star::uno::Array< T >::s_pType );
226 }
227
228 template< class T >
getCppuArrayType3(T * pT)229 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType3( T * pT ) SAL_THROW( () )
230 {
231 if (! ::com::sun::star::uno::Array< T >::s_pType)
232 {
233 const ::com::sun::star::uno::Type & rElementType =
234 ::cppu::getTypeFavourUnsigned( ***pT );
235 sal_Int32 size = sizeof( ****pT );
236 sal_Int32 dim3 = sizeof( ***pT ) / size;
237 sal_Int32 dim2 = sizeof( **pT ) / dim3 / size;
238 sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3)/ size;
239 ::typelib_static_array_type_init(
240 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
241 3, dim1, dim2, dim3 );
242 }
243 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
244 & ::com::sun::star::uno::Array< T >::s_pType );
245 }
246
247 template< class T >
getCppuArrayType4(T * pT)248 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType4( T * pT ) SAL_THROW( () )
249 {
250 if (! ::com::sun::star::uno::Array< T >::s_pType)
251 {
252 const ::com::sun::star::uno::Type & rElementType =
253 ::cppu::getTypeFavourUnsigned( ****pT );
254 sal_Int32 size = sizeof( *****pT );
255 sal_Int32 dim4 = sizeof( ****pT ) / size;
256 sal_Int32 dim3 = sizeof( ***pT ) / dim4 / size;
257 sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4) / size;
258 sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4) / size;
259 ::typelib_static_array_type_init(
260 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
261 4, dim1, dim2, dim3, dim4 );
262 }
263 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
264 & ::com::sun::star::uno::Array< T >::s_pType );
265 }
266
267 template< class T >
getCppuArrayType5(T * pT)268 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType5( T * pT ) SAL_THROW( () )
269 {
270 if (! ::com::sun::star::uno::Array< T >::s_pType)
271 {
272 const ::com::sun::star::uno::Type & rElementType =
273 ::cppu::getTypeFavourUnsigned( *****pT );
274 sal_Int32 size = sizeof( ******pT );
275 sal_Int32 dim5 = sizeof( *****pT ) / size;
276 sal_Int32 dim4 = sizeof( ****pT ) / dim5 / size;
277 sal_Int32 dim3 = sizeof( ***pT ) / (dim4 * dim5) / size;
278 sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4 * dim5) / size;
279 sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4 * dim5) / size;
280 ::typelib_static_array_type_init(
281 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
282 5, dim1, dim2, dim3, dim4, dim5 );
283 }
284 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
285 & ::com::sun::star::uno::Array< T >::s_pType );
286 }
287
288 template< class T >
getCppuArrayType6(T * pT)289 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuArrayType6( T * pT ) SAL_THROW( () )
290 {
291 if (! ::com::sun::star::uno::Array< T >::s_pType)
292 {
293 const ::com::sun::star::uno::Type & rElementType =
294 ::cppu::getTypeFavourUnsigned( ******pT );
295 sal_Int32 size = sizeof( *******pT );
296 sal_Int32 dim6 = sizeof( ******pT ) / size;
297 sal_Int32 dim5 = sizeof( *****pT ) / dim6 / size;
298 sal_Int32 dim4 = sizeof( ****pT ) / (dim5 * dim6) / size;
299 sal_Int32 dim3 = sizeof( ***pT ) / (dim4 * dim5 * dim6) / size;
300 sal_Int32 dim2 = sizeof( **pT ) / (dim3 * dim4 * dim5 * dim6) / size;
301 sal_Int32 dim1 = sizeof( *pT ) / (dim2 * dim3 * dim4 * dim5 * dim6) / size;
302 ::typelib_static_array_type_init(
303 & ::com::sun::star::uno::Array< T >::s_pType, rElementType.getTypeLibType(),
304 6, dim1, dim2, dim3, dim4, dim5, dim6 );
305 }
306 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
307 & ::com::sun::star::uno::Array< T >::s_pType );
308 }
309
310 template< typename T >
getCppuType()311 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType() SAL_THROW(())
312 {
313 return ::cppu::UnoType< T >::get();
314 }
315
316 template<>
getCppuType()317 inline const ::com::sun::star::uno::Type & SAL_CALL getCppuType< sal_Unicode >()
318 SAL_THROW(())
319 {
320 return ::cppu::UnoType< ::cppu::UnoCharType >::get();
321 }
322
323 #endif
324