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