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 8358695 : inline Any::Any() SAL_THROW(())
40 : {
41 8358695 : ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire );
42 8358695 : }
43 :
44 : //______________________________________________________________________________
45 : template <typename T>
46 31412 : inline Any::Any( T const & value )
47 : {
48 31412 : ::uno_type_any_construct(
49 : this, const_cast<T *>(&value),
50 : ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
51 : (uno_AcquireFunc) cpp_acquire );
52 31412 : }
53 : //______________________________________________________________________________
54 742 : inline Any::Any( bool value )
55 : {
56 742 : sal_Bool b = value;
57 : ::uno_type_any_construct(
58 742 : this, &b, ::getCppuBooleanType().getTypeLibType(),
59 742 : (uno_AcquireFunc) cpp_acquire );
60 742 : }
61 :
62 : //__________________________________________________________________________________________________
63 7350022 : inline Any::Any( const Any & rAny ) SAL_THROW(())
64 : {
65 7350022 : ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire );
66 7350022 : }
67 : //__________________________________________________________________________________________________
68 4968558 : 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 4968558 : (uno_AcquireFunc)cpp_acquire );
73 4968558 : }
74 : //__________________________________________________________________________________________________
75 44 : inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
76 : {
77 : ::uno_any_construct(
78 44 : this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire );
79 44 : }
80 : //__________________________________________________________________________________________________
81 2611027 : inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
82 : {
83 : ::uno_type_any_construct(
84 2611027 : this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire );
85 2611027 : }
86 : //__________________________________________________________________________________________________
87 23127810 : inline Any::~Any() SAL_THROW(())
88 : {
89 : ::uno_any_destruct(
90 23127810 : this, (uno_ReleaseFunc)cpp_release );
91 23127810 : }
92 : //__________________________________________________________________________________________________
93 7498491 : inline Any & Any::operator = ( const Any & rAny ) SAL_THROW(())
94 : {
95 7498491 : if (this != &rAny)
96 : {
97 : ::uno_type_any_assign(
98 : this, rAny.pData, rAny.pType,
99 7498367 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
100 : }
101 7498491 : return *this;
102 : }
103 : //__________________________________________________________________________________________________
104 36 : inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW(())
105 : {
106 36 : return ::rtl::OUString( pType->pTypeName );
107 : }
108 : //__________________________________________________________________________________________________
109 31122 : 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 31122 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
114 31122 : }
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 760 : 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 760 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
128 760 : }
129 : //__________________________________________________________________________________________________
130 1772 : inline void Any::clear() SAL_THROW(())
131 : {
132 : ::uno_any_clear(
133 1772 : this, (uno_ReleaseFunc)cpp_release );
134 1772 : }
135 : //__________________________________________________________________________________________________
136 11201 : inline sal_Bool Any::isExtractableTo( const Type & rType ) const SAL_THROW(())
137 : {
138 : return ::uno_type_isAssignableFromData(
139 : rType.getTypeLibType(), pData, pType,
140 11201 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
141 : }
142 :
143 : //______________________________________________________________________________
144 : template <typename T>
145 244 : inline bool Any::has() const
146 : {
147 244 : 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 244 : (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 157657 : 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 157657 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
165 : }
166 : //__________________________________________________________________________________________________
167 337 : 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 337 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ));
172 : }
173 :
174 : //__________________________________________________________________________________________________
175 : template< class C >
176 2984215 : inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(())
177 : {
178 2984215 : return Any( &value, ::cppu::getTypeFavourUnsigned(&value) );
179 : }
180 :
181 : // additionally specialized for C++ bool
182 : //______________________________________________________________________________
183 : template<>
184 199489 : inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(())
185 : {
186 199489 : const sal_Bool b = value;
187 199489 : return Any( &b, ::getCppuBooleanType() );
188 : }
189 :
190 : //__________________________________________________________________________________________________
191 : #ifdef RTL_FAST_STRING
192 : template< class C1, class C2 >
193 4869 : inline Any SAL_CALL makeAny( const rtl::OUStringConcat< C1, C2 >& value ) SAL_THROW(())
194 : {
195 4869 : const rtl::OUString str( value );
196 4869 : return Any( &str, ::cppu::getTypeFavourUnsigned(&str) );
197 : }
198 : #endif
199 : //__________________________________________________________________________________________________
200 : template< class C >
201 1068481 : inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(())
202 : {
203 1068481 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
204 1068481 : ::uno_type_any_assign(
205 : &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
206 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
207 1068481 : }
208 :
209 : // additionally for C++ bool:
210 : //______________________________________________________________________________
211 7168 : inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
212 : SAL_THROW(())
213 : {
214 7168 : sal_Bool b = value;
215 : ::uno_type_any_assign(
216 7168 : &rAny, &b, ::getCppuBooleanType().getTypeLibType(),
217 7168 : (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release );
218 7168 : }
219 :
220 : //______________________________________________________________________________
221 : #ifdef RTL_FAST_STRING
222 : template< class C1, class C2 >
223 192 : inline void SAL_CALL operator <<= ( Any & rAny, const rtl::OUStringConcat< C1, C2 >& value )
224 : SAL_THROW(())
225 : {
226 192 : const rtl::OUString str( value );
227 192 : const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
228 : ::uno_type_any_assign(
229 : &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
230 192 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
231 192 : }
232 : #endif
233 : //__________________________________________________________________________________________________
234 : template< class C >
235 959612 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(())
236 : {
237 959612 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
238 : return ::uno_type_assignData(
239 : &value, rType.getTypeLibType(),
240 : rAny.pData, rAny.pType,
241 : (uno_QueryInterfaceFunc)cpp_queryInterface,
242 959612 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
243 : }
244 :
245 : // bool
246 : //__________________________________________________________________________________________________
247 376492 : inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW(())
248 : {
249 376492 : if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
250 : {
251 366851 : value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False);
252 366851 : return sal_True;
253 : }
254 9641 : return sal_False;
255 : }
256 : //__________________________________________________________________________________________________
257 0 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW(())
258 : {
259 : return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
260 0 : (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False));
261 : }
262 :
263 : //______________________________________________________________________________
264 : template<>
265 17564 : inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
266 : SAL_THROW(())
267 : {
268 17564 : if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
269 : {
270 : value = *reinterpret_cast< sal_Bool const * >(
271 16627 : rAny.pData ) != sal_False;
272 16627 : return true;
273 : }
274 937 : return false;
275 : }
276 :
277 : //______________________________________________________________________________
278 : template<>
279 : inline sal_Bool SAL_CALL operator == ( Any const & rAny, bool const & value )
280 : SAL_THROW(())
281 : {
282 : return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
283 : (value ==
284 : (*reinterpret_cast< sal_Bool const * >( rAny.pData )
285 : != sal_False)));
286 : }
287 :
288 : // byte
289 : //__________________________________________________________________________________________________
290 1469 : inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW(())
291 : {
292 1469 : if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
293 : {
294 1356 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
295 1356 : return sal_True;
296 : }
297 113 : return sal_False;
298 : }
299 : // short
300 : //__________________________________________________________________________________________________
301 105257 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(())
302 : {
303 105257 : switch (rAny.pType->eTypeClass)
304 : {
305 : case typelib_TypeClass_BYTE:
306 65 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
307 65 : return sal_True;
308 : case typelib_TypeClass_SHORT:
309 : case typelib_TypeClass_UNSIGNED_SHORT:
310 82097 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
311 82097 : return sal_True;
312 : default:
313 23095 : return sal_False;
314 : }
315 : }
316 : //__________________________________________________________________________________________________
317 1738 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(())
318 : {
319 1738 : switch (rAny.pType->eTypeClass)
320 : {
321 : case typelib_TypeClass_BYTE:
322 4 : value = (sal_uInt16)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
323 4 : return sal_True;
324 : case typelib_TypeClass_SHORT:
325 : case typelib_TypeClass_UNSIGNED_SHORT:
326 1666 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
327 1666 : return sal_True;
328 : default:
329 68 : return sal_False;
330 : }
331 : }
332 : // long
333 : //__________________________________________________________________________________________________
334 168497 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(())
335 : {
336 168497 : switch (rAny.pType->eTypeClass)
337 : {
338 : case typelib_TypeClass_BYTE:
339 50 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
340 50 : return sal_True;
341 : case typelib_TypeClass_SHORT:
342 46731 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
343 46731 : return sal_True;
344 : case typelib_TypeClass_UNSIGNED_SHORT:
345 10 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
346 10 : return sal_True;
347 : case typelib_TypeClass_LONG:
348 : case typelib_TypeClass_UNSIGNED_LONG:
349 118139 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
350 118139 : return sal_True;
351 : default:
352 3567 : return sal_False;
353 : }
354 : }
355 : //__________________________________________________________________________________________________
356 3928 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(())
357 : {
358 3928 : switch (rAny.pType->eTypeClass)
359 : {
360 : case typelib_TypeClass_BYTE:
361 2 : value = (sal_uInt32)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
362 2 : return sal_True;
363 : case typelib_TypeClass_SHORT:
364 2 : value = (sal_uInt32)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
365 2 : return sal_True;
366 : case typelib_TypeClass_UNSIGNED_SHORT:
367 122 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
368 122 : return sal_True;
369 : case typelib_TypeClass_LONG:
370 : case typelib_TypeClass_UNSIGNED_LONG:
371 2220 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
372 2220 : return sal_True;
373 : default:
374 1582 : return sal_False;
375 : }
376 : }
377 : // hyper
378 : //__________________________________________________________________________________________________
379 1846 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(())
380 : {
381 1846 : switch (rAny.pType->eTypeClass)
382 : {
383 : case typelib_TypeClass_BYTE:
384 2 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
385 2 : return sal_True;
386 : case typelib_TypeClass_SHORT:
387 2 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
388 2 : return sal_True;
389 : case typelib_TypeClass_UNSIGNED_SHORT:
390 2 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
391 2 : return sal_True;
392 : case typelib_TypeClass_LONG:
393 70 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
394 70 : return sal_True;
395 : case typelib_TypeClass_UNSIGNED_LONG:
396 2 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
397 2 : return sal_True;
398 : case typelib_TypeClass_HYPER:
399 : case typelib_TypeClass_UNSIGNED_HYPER:
400 1266 : value = * reinterpret_cast< const sal_Int64 * >( rAny.pData );
401 1266 : return sal_True;
402 : default:
403 502 : return sal_False;
404 : }
405 : }
406 : //__________________________________________________________________________________________________
407 44 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(())
408 : {
409 44 : switch (rAny.pType->eTypeClass)
410 : {
411 : case typelib_TypeClass_BYTE:
412 2 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
413 2 : return sal_True;
414 : case typelib_TypeClass_SHORT:
415 2 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
416 2 : return sal_True;
417 : case typelib_TypeClass_UNSIGNED_SHORT:
418 2 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
419 2 : return sal_True;
420 : case typelib_TypeClass_LONG:
421 2 : value = (sal_uInt64)( * reinterpret_cast< const sal_Int32 * >( rAny.pData ) );
422 2 : return sal_True;
423 : case typelib_TypeClass_UNSIGNED_LONG:
424 2 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
425 2 : return sal_True;
426 : case typelib_TypeClass_HYPER:
427 : case typelib_TypeClass_UNSIGNED_HYPER:
428 8 : value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData );
429 8 : return sal_True;
430 : default:
431 26 : return sal_False;
432 : }
433 : }
434 : // float
435 : //__________________________________________________________________________________________________
436 974 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(())
437 : {
438 974 : switch (rAny.pType->eTypeClass)
439 : {
440 : case typelib_TypeClass_BYTE:
441 2 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
442 2 : return sal_True;
443 : case typelib_TypeClass_SHORT:
444 22 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
445 22 : return sal_True;
446 : case typelib_TypeClass_UNSIGNED_SHORT:
447 2 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
448 2 : return sal_True;
449 : case typelib_TypeClass_FLOAT:
450 916 : value = * reinterpret_cast< const float * >( rAny.pData );
451 916 : return sal_True;
452 : default:
453 32 : return sal_False;
454 : }
455 : }
456 : // double
457 : //__________________________________________________________________________________________________
458 25676 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(())
459 : {
460 25676 : switch (rAny.pType->eTypeClass)
461 : {
462 : case typelib_TypeClass_BYTE:
463 6 : value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
464 6 : return sal_True;
465 : case typelib_TypeClass_SHORT:
466 2 : value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
467 2 : return sal_True;
468 : case typelib_TypeClass_UNSIGNED_SHORT:
469 2 : value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
470 2 : return sal_True;
471 : case typelib_TypeClass_LONG:
472 32 : value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
473 32 : return sal_True;
474 : case typelib_TypeClass_UNSIGNED_LONG:
475 2 : value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
476 2 : return sal_True;
477 : case typelib_TypeClass_FLOAT:
478 15761 : value = * reinterpret_cast< const float * >( rAny.pData );
479 15761 : return sal_True;
480 : case typelib_TypeClass_DOUBLE:
481 5081 : value = * reinterpret_cast< const double * >( rAny.pData );
482 5081 : return sal_True;
483 : default:
484 4790 : return sal_False;
485 : }
486 : }
487 : // string
488 : //__________________________________________________________________________________________________
489 1191275 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(())
490 : {
491 1191275 : if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
492 : {
493 1144293 : value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData );
494 1144293 : return sal_True;
495 : }
496 46982 : return sal_False;
497 : }
498 : //__________________________________________________________________________________________________
499 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW(())
500 : {
501 : return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
502 : value.equals( * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ) ));
503 : }
504 : // type
505 : //__________________________________________________________________________________________________
506 500 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(())
507 : {
508 500 : if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
509 : {
510 462 : value = * reinterpret_cast< const Type * >( rAny.pData );
511 462 : return sal_True;
512 : }
513 38 : return sal_False;
514 : }
515 : //__________________________________________________________________________________________________
516 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW(())
517 : {
518 : return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
519 : value.equals( * reinterpret_cast< const Type * >( rAny.pData ) ));
520 : }
521 : // any
522 : //__________________________________________________________________________________________________
523 5923 : inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(())
524 : {
525 5923 : if (&rAny != &value)
526 : {
527 : ::uno_type_any_assign(
528 : &value, rAny.pData, rAny.pType,
529 5923 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
530 : }
531 5923 : return sal_True;
532 : }
533 : // interface
534 : //__________________________________________________________________________________________________
535 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW(())
536 : {
537 : if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
538 : {
539 : return reinterpret_cast< const BaseReference * >( rAny.pData )->operator == ( value );
540 : }
541 : return sal_False;
542 : }
543 :
544 : // operator to compare to an any.
545 : //__________________________________________________________________________________________________
546 : template< class C >
547 6 : inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(())
548 : {
549 6 : const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
550 : return ::uno_type_equalData(
551 : rAny.pData, rAny.pType,
552 : const_cast< C * >( &value ), rType.getTypeLibType(),
553 6 : (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
554 : }
555 : // operator to compare to an any. may use specialized operators ==.
556 : //__________________________________________________________________________________________________
557 : template< class C >
558 2 : inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(())
559 : {
560 2 : return (! operator == ( rAny, value ));
561 : }
562 :
563 : #if ! defined(EXCEPTIONS_OFF)
564 : extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
565 : uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
566 : SAL_THROW_EXTERN_C();
567 :
568 : //______________________________________________________________________________
569 : template <typename T>
570 18109 : T Any::get() const
571 : {
572 18109 : T value = T();
573 18109 : if (! (*this >>= value)) {
574 : throw RuntimeException(
575 : ::rtl::OUString(
576 : cppu_Any_extraction_failure_msg(
577 : this,
578 : ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
579 : SAL_NO_ACQUIRE ),
580 0 : Reference<XInterface>() );
581 : }
582 18109 : return value;
583 : }
584 : // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
585 : template <>
586 : sal_uInt16 Any::get<sal_uInt16>() const;
587 : #endif // ! defined(EXCEPTIONS_OFF)
588 :
589 : }
590 : }
591 : }
592 : }
593 :
594 : #endif
595 :
596 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|