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 _COM_SUN_STAR_UNO_ANY_HXX_
20 : : #define _COM_SUN_STAR_UNO_ANY_HXX_
21 : :
22 : : #include <com/sun/star/uno/Any.h>
23 : : #include <uno/data.h>
24 : : #include <com/sun/star/uno/Type.hxx>
25 : : #include <com/sun/star/uno/XInterface.hpp>
26 : : #include <com/sun/star/uno/genfunc.hxx>
27 : : #include "cppu/unotype.hxx"
28 : :
29 : : namespace com
30 : : {
31 : : namespace sun
32 : : {
33 : : namespace star
34 : : {
35 : : namespace uno
36 : : {
37 : :
38 : : //__________________________________________________________________________________________________
39 : 33178414 : inline Any::Any() SAL_THROW(())
40 : : {
41 : 33178418 : ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire );
42 : 33178423 : }
43 : :
44 : : //______________________________________________________________________________
45 : : template <typename T>
46 : 50695 : inline Any::Any( T const & value )
47 : : {
48 : 50695 : ::uno_type_any_construct(
49 : : this, const_cast<T *>(&value),
50 : : ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
51 : : (uno_AcquireFunc) cpp_acquire );
52 : 50695 : }
53 : : //______________________________________________________________________________
54 : 863 : inline Any::Any( bool value )
55 : : {
56 : 863 : sal_Bool b = value;
57 : : ::uno_type_any_construct(
58 [ + - ]: 863 : this, &b, ::getCppuBooleanType().getTypeLibType(),
59 : 863 : (uno_AcquireFunc) cpp_acquire );
60 : 863 : }
61 : :
62 : : //__________________________________________________________________________________________________
63 : 31605076 : inline Any::Any( const Any & rAny ) SAL_THROW(())
64 : : {
65 : 31605076 : ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire );
66 : 31605076 : }
67 : : //__________________________________________________________________________________________________
68 : 19701435 : inline Any::Any( const void * pData_, const Type & rType ) SAL_THROW(())
69 : : {
70 : : ::uno_type_any_construct(
71 : : this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
72 : 19701438 : (uno_AcquireFunc)cpp_acquire );
73 : 19701438 : }
74 : : //__________________________________________________________________________________________________
75 : 4154 : inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
76 : : {
77 : : ::uno_any_construct(
78 : 4154 : this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire );
79 : 4154 : }
80 : : //__________________________________________________________________________________________________
81 : 10309825 : inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
82 : : {
83 : : ::uno_type_any_construct(
84 : 10309833 : this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire );
85 : 10309834 : }
86 : : //__________________________________________________________________________________________________
87 : 92713511 : inline Any::~Any() SAL_THROW(())
88 : : {
89 : : ::uno_any_destruct(
90 : 92713511 : this, (uno_ReleaseFunc)cpp_release );
91 : 92713521 : }
92 : : //__________________________________________________________________________________________________
93 : 27803407 : inline Any & Any::operator = ( const Any & rAny ) SAL_THROW(())
94 : : {
95 [ + - ]: 27803407 : if (this != &rAny)
96 : : {
97 : : ::uno_type_any_assign(
98 : : this, rAny.pData, rAny.pType,
99 : 27803407 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
100 : : }
101 : 27803407 : return *this;
102 : : }
103 : : //__________________________________________________________________________________________________
104 : 334 : inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW(())
105 : : {
106 : 334 : return ::rtl::OUString( pType->pTypeName );
107 : : }
108 : : //__________________________________________________________________________________________________
109 : 327045 : inline void Any::setValue( const void * pData_, const Type & rType ) SAL_THROW(())
110 : : {
111 : : ::uno_type_any_assign(
112 : : this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
113 : 327045 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
114 : 327045 : }
115 : : //__________________________________________________________________________________________________
116 : : inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
117 : : {
118 : : ::uno_type_any_assign(
119 : : this, const_cast< void * >( pData_ ), pType_,
120 : : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
121 : : }
122 : : //__________________________________________________________________________________________________
123 : 18153 : inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
124 : : {
125 : : ::uno_any_assign(
126 : : this, const_cast< void * >( pData_ ), pTypeDescr,
127 : 18153 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
128 : 18153 : }
129 : : //__________________________________________________________________________________________________
130 : 13057 : inline void Any::clear() SAL_THROW(())
131 : : {
132 : : ::uno_any_clear(
133 : 13057 : this, (uno_ReleaseFunc)cpp_release );
134 : 13057 : }
135 : : //__________________________________________________________________________________________________
136 : 77624 : inline sal_Bool Any::isExtractableTo( const Type & rType ) const SAL_THROW(())
137 : : {
138 : : return ::uno_type_isAssignableFromData(
139 : : rType.getTypeLibType(), pData, pType,
140 : 77624 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
141 : : }
142 : :
143 : : //______________________________________________________________________________
144 : : template <typename T>
145 : 1500 : inline bool Any::has() const
146 : : {
147 : 1500 : Type const & rType = ::cppu::getTypeFavourUnsigned(static_cast< T * >(0));
148 : : return ::uno_type_isAssignableFromData(
149 : : rType.getTypeLibType(), pData, pType,
150 : : (uno_QueryInterfaceFunc) cpp_queryInterface,
151 : 1500 : (uno_ReleaseFunc) cpp_release );
152 : : }
153 : : #if ! defined(__SUNPRO_CC)
154 : : // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
155 : : template <>
156 : : bool Any::has<sal_uInt16>() const;
157 : : #endif // ! defined(__SUNPRO_CC)
158 : :
159 : : //__________________________________________________________________________________________________
160 : 393409 : inline sal_Bool Any::operator == ( const Any & rAny ) const SAL_THROW(())
161 : : {
162 : : return ::uno_type_equalData(
163 : : pData, pType, rAny.pData, rAny.pType,
164 : 393409 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
165 : : }
166 : : //__________________________________________________________________________________________________
167 : 8676 : inline sal_Bool Any::operator != ( const Any & rAny ) const SAL_THROW(())
168 : : {
169 : : return (! ::uno_type_equalData(
170 : : pData, pType, rAny.pData, rAny.pType,
171 : 8676 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ));
172 : : }
173 : :
174 : : //__________________________________________________________________________________________________
175 : : template< class C >
176 : 10740623 : inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(())
177 : : {
178 : 10740623 : return Any( &value, ::cppu::getTypeFavourUnsigned(&value) );
179 : : }
180 : :
181 : : // additionally specialized for C++ bool
182 : : //______________________________________________________________________________
183 : : template<>
184 : 681071 : inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(())
185 : : {
186 : 681071 : const sal_Bool b = value;
187 [ + - ]: 681071 : return Any( &b, ::getCppuBooleanType() );
188 : : }
189 : :
190 : : //__________________________________________________________________________________________________
191 : : template< class C >
192 : 4471565 : inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(())
193 : : {
194 : 4471565 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
195 : 4471565 : ::uno_type_any_assign(
196 : : &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
197 : : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
198 : 4471565 : }
199 : :
200 : : // additionally for C++ bool:
201 : : //______________________________________________________________________________
202 : 328442 : inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
203 : : SAL_THROW(())
204 : : {
205 : 328442 : sal_Bool b = value;
206 : : ::uno_type_any_assign(
207 [ + - ]: 328442 : &rAny, &b, ::getCppuBooleanType().getTypeLibType(),
208 : 328442 : (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release );
209 : 328442 : }
210 : :
211 : : //__________________________________________________________________________________________________
212 : : template< class C >
213 : 5812911 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(())
214 : : {
215 : 5812911 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
216 : : return ::uno_type_assignData(
217 : : &value, rType.getTypeLibType(),
218 : : rAny.pData, rAny.pType,
219 : : (uno_QueryInterfaceFunc)cpp_queryInterface,
220 : 5812911 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
221 : : }
222 : :
223 : : // bool
224 : : //__________________________________________________________________________________________________
225 : 1891071 : inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW(())
226 : : {
227 [ + + ]: 1891071 : if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
228 : : {
229 : 1819100 : value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False);
230 : 1819100 : return sal_True;
231 : : }
232 : 1891071 : return sal_False;
233 : : }
234 : : //__________________________________________________________________________________________________
235 : 0 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW(())
236 : : {
237 : : return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
238 [ # # ][ # # ]: 0 : (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False));
239 : : }
240 : :
241 : : //______________________________________________________________________________
242 : : template<>
243 : 81878 : inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
244 : : SAL_THROW(())
245 : : {
246 [ + + ]: 81878 : if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
247 : : {
248 : : value = *reinterpret_cast< sal_Bool const * >(
249 : 71732 : rAny.pData ) != sal_False;
250 : 71732 : return true;
251 : : }
252 : 81878 : return false;
253 : : }
254 : :
255 : : //______________________________________________________________________________
256 : : template<>
257 : : inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value )
258 : : SAL_THROW(())
259 : : {
260 : : return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
261 : : (value ==
262 : : (*reinterpret_cast< sal_Bool const * >( rAny.pData )
263 : : != sal_False)));
264 : : }
265 : :
266 : : // byte
267 : : //__________________________________________________________________________________________________
268 : 3178 : inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW(())
269 : : {
270 [ + + ]: 3178 : if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
271 : : {
272 : 2964 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
273 : 2964 : return sal_True;
274 : : }
275 : 3178 : return sal_False;
276 : : }
277 : : // short
278 : : //__________________________________________________________________________________________________
279 : 1016412 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(())
280 : : {
281 [ + + + ]: 1016412 : switch (rAny.pType->eTypeClass)
282 : : {
283 : : case typelib_TypeClass_BYTE:
284 : 114 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
285 : 114 : return sal_True;
286 : : case typelib_TypeClass_SHORT:
287 : : case typelib_TypeClass_UNSIGNED_SHORT:
288 : 909551 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
289 : 909551 : return sal_True;
290 : : default:
291 : 1016412 : return sal_False;
292 : : }
293 : : }
294 : : //__________________________________________________________________________________________________
295 : 517458 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(())
296 : : {
297 [ + + + ]: 517458 : switch (rAny.pType->eTypeClass)
298 : : {
299 : : case typelib_TypeClass_BYTE:
300 : 10 : value = (sal_uInt16)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
301 : 10 : return sal_True;
302 : : case typelib_TypeClass_SHORT:
303 : : case typelib_TypeClass_UNSIGNED_SHORT:
304 : 517278 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
305 : 517278 : return sal_True;
306 : : default:
307 : 517458 : return sal_False;
308 : : }
309 : : }
310 : : // long
311 : : //__________________________________________________________________________________________________
312 : 979165 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(())
313 : : {
314 [ + + + + : 979165 : switch (rAny.pType->eTypeClass)
+ ]
315 : : {
316 : : case typelib_TypeClass_BYTE:
317 : 124 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
318 : 124 : return sal_True;
319 : : case typelib_TypeClass_SHORT:
320 : 303196 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
321 : 303196 : return sal_True;
322 : : case typelib_TypeClass_UNSIGNED_SHORT:
323 : 3627 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
324 : 3627 : return sal_True;
325 : : case typelib_TypeClass_LONG:
326 : : case typelib_TypeClass_UNSIGNED_LONG:
327 : 645566 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
328 : 645566 : return sal_True;
329 : : default:
330 : 979165 : return sal_False;
331 : : }
332 : : }
333 : : //__________________________________________________________________________________________________
334 : 89762 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(())
335 : : {
336 [ + + + + : 89762 : switch (rAny.pType->eTypeClass)
+ ]
337 : : {
338 : : case typelib_TypeClass_BYTE:
339 : 5 : value = (sal_uInt32)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
340 : 5 : return sal_True;
341 : : case typelib_TypeClass_SHORT:
342 : 5 : value = (sal_uInt32)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
343 : 5 : return sal_True;
344 : : case typelib_TypeClass_UNSIGNED_SHORT:
345 : 71795 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
346 : 71795 : return sal_True;
347 : : case typelib_TypeClass_LONG:
348 : : case typelib_TypeClass_UNSIGNED_LONG:
349 : 12756 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
350 : 12756 : return sal_True;
351 : : default:
352 : 89762 : return sal_False;
353 : : }
354 : : }
355 : : // hyper
356 : : //__________________________________________________________________________________________________
357 : 1924 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(())
358 : : {
359 [ + + + + : 1924 : switch (rAny.pType->eTypeClass)
+ + + ]
360 : : {
361 : : case typelib_TypeClass_BYTE:
362 : 5 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
363 : 5 : return sal_True;
364 : : case typelib_TypeClass_SHORT:
365 : 5 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
366 : 5 : return sal_True;
367 : : case typelib_TypeClass_UNSIGNED_SHORT:
368 : 5 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
369 : 5 : return sal_True;
370 : : case typelib_TypeClass_LONG:
371 : 245 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
372 : 245 : return sal_True;
373 : : case typelib_TypeClass_UNSIGNED_LONG:
374 : 5 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
375 : 5 : return sal_True;
376 : : case typelib_TypeClass_HYPER:
377 : : case typelib_TypeClass_UNSIGNED_HYPER:
378 : 1592 : value = * reinterpret_cast< const sal_Int64 * >( rAny.pData );
379 : 1592 : return sal_True;
380 : : default:
381 : 1924 : return sal_False;
382 : : }
383 : : }
384 : : //__________________________________________________________________________________________________
385 : 147 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(())
386 : : {
387 [ + + + + : 147 : switch (rAny.pType->eTypeClass)
+ + + ]
388 : : {
389 : : case typelib_TypeClass_BYTE:
390 : 5 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
391 : 5 : return sal_True;
392 : : case typelib_TypeClass_SHORT:
393 : 5 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
394 : 5 : return sal_True;
395 : : case typelib_TypeClass_UNSIGNED_SHORT:
396 : 5 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
397 : 5 : return sal_True;
398 : : case typelib_TypeClass_LONG:
399 : 5 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int32 * >( rAny.pData ) );
400 : 5 : return sal_True;
401 : : case typelib_TypeClass_UNSIGNED_LONG:
402 : 5 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
403 : 5 : return sal_True;
404 : : case typelib_TypeClass_HYPER:
405 : : case typelib_TypeClass_UNSIGNED_HYPER:
406 : 57 : value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData );
407 : 57 : return sal_True;
408 : : default:
409 : 147 : return sal_False;
410 : : }
411 : : }
412 : : // float
413 : : //__________________________________________________________________________________________________
414 : 15797 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(())
415 : : {
416 [ + + + + : 15797 : switch (rAny.pType->eTypeClass)
+ ]
417 : : {
418 : : case typelib_TypeClass_BYTE:
419 : 5 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
420 : 5 : return sal_True;
421 : : case typelib_TypeClass_SHORT:
422 : 34 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
423 : 34 : return sal_True;
424 : : case typelib_TypeClass_UNSIGNED_SHORT:
425 : 5 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
426 : 5 : return sal_True;
427 : : case typelib_TypeClass_FLOAT:
428 : 15673 : value = * reinterpret_cast< const float * >( rAny.pData );
429 : 15673 : return sal_True;
430 : : default:
431 : 15797 : return sal_False;
432 : : }
433 : : }
434 : : // double
435 : : //__________________________________________________________________________________________________
436 : 232280 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(())
437 : : {
438 [ + + + + : 232280 : switch (rAny.pType->eTypeClass)
+ + + + ]
439 : : {
440 : : case typelib_TypeClass_BYTE:
441 : 9 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
442 : 9 : return sal_True;
443 : : case typelib_TypeClass_SHORT:
444 : 5 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
445 : 5 : return sal_True;
446 : : case typelib_TypeClass_UNSIGNED_SHORT:
447 : 5 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
448 : 5 : return sal_True;
449 : : case typelib_TypeClass_LONG:
450 : 51 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
451 : 51 : return sal_True;
452 : : case typelib_TypeClass_UNSIGNED_LONG:
453 : 5 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
454 : 5 : return sal_True;
455 : : case typelib_TypeClass_FLOAT:
456 : 140626 : value = * reinterpret_cast< const float * >( rAny.pData );
457 : 140626 : return sal_True;
458 : : case typelib_TypeClass_DOUBLE:
459 : 37571 : value = * reinterpret_cast< const double * >( rAny.pData );
460 : 37571 : return sal_True;
461 : : default:
462 : 232280 : return sal_False;
463 : : }
464 : : }
465 : : // string
466 : : //__________________________________________________________________________________________________
467 : 5300519 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(())
468 : : {
469 [ + + ]: 5300519 : if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
470 : : {
471 : 5099841 : value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData );
472 : 5099841 : return sal_True;
473 : : }
474 : 5300519 : return sal_False;
475 : : }
476 : : //__________________________________________________________________________________________________
477 : : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW(())
478 : : {
479 : : return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
480 : : value.equals( * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ) ));
481 : : }
482 : : // type
483 : : //__________________________________________________________________________________________________
484 : 1996 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(())
485 : : {
486 [ + + ]: 1996 : if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
487 : : {
488 : 1901 : value = * reinterpret_cast< const Type * >( rAny.pData );
489 : 1901 : return sal_True;
490 : : }
491 : 1996 : return sal_False;
492 : : }
493 : : //__________________________________________________________________________________________________
494 : : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW(())
495 : : {
496 : : return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
497 : : value.equals( * reinterpret_cast< const Type * >( rAny.pData ) ));
498 : : }
499 : : // any
500 : : //__________________________________________________________________________________________________
501 : 56354 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(())
502 : : {
503 [ + - ]: 56354 : if (&rAny != &value)
504 : : {
505 : : ::uno_type_any_assign(
506 : : &value, rAny.pData, rAny.pType,
507 : 56354 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
508 : : }
509 : 56354 : return sal_True;
510 : : }
511 : : // interface
512 : : //__________________________________________________________________________________________________
513 : : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW(())
514 : : {
515 : : if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
516 : : {
517 : : return reinterpret_cast< const BaseReference * >( rAny.pData )->operator == ( value );
518 : : }
519 : : return sal_False;
520 : : }
521 : :
522 : : // operator to compare to an any.
523 : : //__________________________________________________________________________________________________
524 : : template< class C >
525 : 129 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(())
526 : : {
527 : 129 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
528 : : return ::uno_type_equalData(
529 : : rAny.pData, rAny.pType,
530 : : const_cast< C * >( &value ), rType.getTypeLibType(),
531 : 129 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
532 : : }
533 : : // operator to compare to an any. may use specialized operators ==.
534 : : //__________________________________________________________________________________________________
535 : : template< class C >
536 : 3 : inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(())
537 : : {
538 : 3 : return (! operator == ( rAny, value ));
539 : : }
540 : :
541 : : #if ! defined(EXCEPTIONS_OFF)
542 : : extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
543 : : uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
544 : : SAL_THROW_EXTERN_C();
545 : :
546 : : //______________________________________________________________________________
547 : : template <typename T>
548 : 73615 : T Any::get() const
549 : : {
550 : 69482 : T value = T();
551 [ # - + # : 73615 : if (! (*this >>= value)) {
- + - +
# ][ # - +
# - + # #
# ][ # # #
# # # # ]
[ # # # #
# - + ]
[ # # # # ]
[ # # ][ - + ]
[ # - + +
- + # # -
+ ]
552 : : throw RuntimeException(
553 : : ::rtl::OUString(
554 : : cppu_Any_extraction_failure_msg(
555 : : this,
556 : : ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
557 : : SAL_NO_ACQUIRE ),
558 [ # # # # ]: 0 : Reference<XInterface>() );
[ # # ][ # #
# # # ]
[ # # # ]
[ # # ][ # #
# # # ][ #
# # # #
# ][ # # ]
[ # # ][ # # ]
[ # # # #
# ][ # # ]
[ # # ][ # # ]
[ # # # ]
[ # # ]
[ # # # ]
[ # # ][ # # ]
[ # # ]
559 : : }
560 : 73615 : return value;
561 : : }
562 : : // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
563 : : template <>
564 : : sal_uInt16 Any::get<sal_uInt16>() const;
565 : : #endif // ! defined(EXCEPTIONS_OFF)
566 : :
567 : : }
568 : : }
569 : : }
570 : : }
571 : :
572 : : #endif
573 : :
574 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|