LibreOffice LibreOffice 4.1 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Any.hxx
Go to the documentation of this file.
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 inline Any::Any() SAL_THROW(())
40 {
41 ::uno_any_construct( this, 0, 0, (uno_AcquireFunc)cpp_acquire );
42 }
43
44 //______________________________________________________________________________
45 template <typename T>
46 inline Any::Any( T const & value )
47 {
48 ::uno_type_any_construct(
49 this, const_cast<T *>(&value),
50 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
51 (uno_AcquireFunc) cpp_acquire );
52 }
53 //______________________________________________________________________________
54 inline Any::Any( bool value )
55 {
56 sal_Bool b = value;
57 ::uno_type_any_construct(
58 this, &b, ::getCppuBooleanType().getTypeLibType(),
59 (uno_AcquireFunc) cpp_acquire );
60 }
61
62 //__________________________________________________________________________________________________
63 inline Any::Any( const Any & rAny ) SAL_THROW(())
64 {
65 ::uno_type_any_construct( this, rAny.pData, rAny.pType, (uno_AcquireFunc)cpp_acquire );
66 }
67 //__________________________________________________________________________________________________
68 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 (uno_AcquireFunc)cpp_acquire );
73 }
74 //__________________________________________________________________________________________________
75 inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) SAL_THROW(())
76 {
77 ::uno_any_construct(
78 this, const_cast< void * >( pData_ ), pTypeDescr, (uno_AcquireFunc)cpp_acquire );
79 }
80 //__________________________________________________________________________________________________
81 inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) SAL_THROW(())
82 {
83 ::uno_type_any_construct(
84 this, const_cast< void * >( pData_ ), pType_, (uno_AcquireFunc)cpp_acquire );
85 }
86 //__________________________________________________________________________________________________
87 inline Any::~Any() SAL_THROW(())
88 {
89 ::uno_any_destruct(
90 this, (uno_ReleaseFunc)cpp_release );
91 }
92 //__________________________________________________________________________________________________
93 inline Any & Any::operator = ( const Any & rAny ) SAL_THROW(())
94 {
95 if (this != &rAny)
96 {
97 ::uno_type_any_assign(
98 this, rAny.pData, rAny.pType,
99 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
100 }
101 return *this;
102 }
103 //__________________________________________________________________________________________________
104 inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW(())
105 {
106 return ::rtl::OUString( pType->pTypeName );
107 }
108 //__________________________________________________________________________________________________
109 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 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
114 }
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 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 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
128 }
129 //__________________________________________________________________________________________________
130 inline void Any::clear() SAL_THROW(())
131 {
132 ::uno_any_clear(
133 this, (uno_ReleaseFunc)cpp_release );
134 }
135 //__________________________________________________________________________________________________
136 inline sal_Bool Any::isExtractableTo( const Type & rType ) const SAL_THROW(())
137 {
138 return ::uno_type_isAssignableFromData(
139 rType.getTypeLibType(), pData, pType,
140 (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
141 }
142
143 //______________________________________________________________________________
144 template <typename T>
145 inline bool Any::has() const
146 {
147 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 (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 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 (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
165 }
166 //__________________________________________________________________________________________________
167 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 (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ));
172 }
173
174 //__________________________________________________________________________________________________
175 template< class C >
176 inline Any SAL_CALL makeAny( const C & value ) SAL_THROW(())
177 {
178 return Any( &value, ::cppu::getTypeFavourUnsigned(&value) );
179 }
180
181 // additionally specialized for C++ bool
182 //______________________________________________________________________________
183 template<>
184 inline Any SAL_CALL makeAny( bool const & value ) SAL_THROW(())
185 {
186 const sal_Bool b = value;
187 return Any( &b, ::getCppuBooleanType() );
188 }
189
190 //__________________________________________________________________________________________________
191 #ifdef RTL_FAST_STRING
192 template< class C1, class C2 >
193 inline Any SAL_CALL makeAny( const rtl::OUStringConcat< C1, C2 >& value ) SAL_THROW(())
194 {
195 const rtl::OUString str( value );
196 return Any( &str, ::cppu::getTypeFavourUnsigned(&str) );
197 }
198 #endif
199 //__________________________________________________________________________________________________
200 template< class C >
201 inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW(())
202 {
203 const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
204 ::uno_type_any_assign(
205 &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
206 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
207 }
208
209 // additionally for C++ bool:
210 //______________________________________________________________________________
211 inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
212 SAL_THROW(())
213 {
214 sal_Bool b = value;
215 ::uno_type_any_assign(
216 &rAny, &b, ::getCppuBooleanType().getTypeLibType(),
217 (uno_AcquireFunc) cpp_acquire, (uno_ReleaseFunc) cpp_release );
218 }
219
220 //______________________________________________________________________________
221 #ifdef RTL_FAST_STRING
222 template< class C1, class C2 >
223 inline void SAL_CALL operator <<= ( Any & rAny, const rtl::OUStringConcat< C1, C2 >& value )
224 SAL_THROW(())
225 {
226 const rtl::OUString str( value );
227 const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
228 ::uno_type_any_assign(
229 &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
230 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
231 }
232 #endif
233 //__________________________________________________________________________________________________
234 template< class C >
235 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW(())
236 {
237 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 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
243 }
244
245 // bool
246 //__________________________________________________________________________________________________
247 inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW(())
248 {
249 if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
250 {
251 value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False);
252 return sal_True;
253 }
254 return sal_False;
255 }
256 //__________________________________________________________________________________________________
257 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 (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False));
261 }
262
263 //______________________________________________________________________________
264 template<>
265 inline sal_Bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
266 SAL_THROW(())
267 {
268 if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
269 {
270 value = *reinterpret_cast< sal_Bool const * >(
271 rAny.pData ) != sal_False;
272 return true;
273 }
274 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 inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW(())
291 {
292 if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
293 {
294 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
295 return sal_True;
296 }
297 return sal_False;
298 }
299 // short
300 //__________________________________________________________________________________________________
301 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW(())
302 {
303 switch (rAny.pType->eTypeClass)
304 {
305 case typelib_TypeClass_BYTE:
306 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
307 return sal_True;
308 case typelib_TypeClass_SHORT:
309 case typelib_TypeClass_UNSIGNED_SHORT:
310 value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
311 return sal_True;
312 default:
313 return sal_False;
314 }
315 }
316 //__________________________________________________________________________________________________
317 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW(())
318 {
319 switch (rAny.pType->eTypeClass)
320 {
321 case typelib_TypeClass_BYTE:
322 value = (sal_uInt16)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
323 return sal_True;
324 case typelib_TypeClass_SHORT:
325 case typelib_TypeClass_UNSIGNED_SHORT:
326 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
327 return sal_True;
328 default:
329 return sal_False;
330 }
331 }
332 // long
333 //__________________________________________________________________________________________________
334 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW(())
335 {
336 switch (rAny.pType->eTypeClass)
337 {
338 case typelib_TypeClass_BYTE:
339 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
340 return sal_True;
341 case typelib_TypeClass_SHORT:
342 value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
343 return sal_True;
344 case typelib_TypeClass_UNSIGNED_SHORT:
345 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
346 return sal_True;
347 case typelib_TypeClass_LONG:
348 case typelib_TypeClass_UNSIGNED_LONG:
349 value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
350 return sal_True;
351 default:
352 return sal_False;
353 }
354 }
355 //__________________________________________________________________________________________________
356 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW(())
357 {
358 switch (rAny.pType->eTypeClass)
359 {
360 case typelib_TypeClass_BYTE:
361 value = (sal_uInt32)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
362 return sal_True;
363 case typelib_TypeClass_SHORT:
364 value = (sal_uInt32)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
365 return sal_True;
366 case typelib_TypeClass_UNSIGNED_SHORT:
367 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
368 return sal_True;
369 case typelib_TypeClass_LONG:
370 case typelib_TypeClass_UNSIGNED_LONG:
371 value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
372 return sal_True;
373 default:
374 return sal_False;
375 }
376 }
377 // hyper
378 //__________________________________________________________________________________________________
379 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW(())
380 {
381 switch (rAny.pType->eTypeClass)
382 {
383 case typelib_TypeClass_BYTE:
384 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
385 return sal_True;
386 case typelib_TypeClass_SHORT:
387 value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
388 return sal_True;
389 case typelib_TypeClass_UNSIGNED_SHORT:
390 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
391 return sal_True;
392 case typelib_TypeClass_LONG:
393 value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
394 return sal_True;
395 case typelib_TypeClass_UNSIGNED_LONG:
396 value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
397 return sal_True;
398 case typelib_TypeClass_HYPER:
399 case typelib_TypeClass_UNSIGNED_HYPER:
400 value = * reinterpret_cast< const sal_Int64 * >( rAny.pData );
401 return sal_True;
402 default:
403 return sal_False;
404 }
405 }
406 //__________________________________________________________________________________________________
407 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW(())
408 {
409 switch (rAny.pType->eTypeClass)
410 {
411 case typelib_TypeClass_BYTE:
412 value = (sal_uInt64)( * reinterpret_cast< const sal_Int8 * >( rAny.pData ) );
413 return sal_True;
414 case typelib_TypeClass_SHORT:
415 value = (sal_uInt64)( * reinterpret_cast< const sal_Int16 * >( rAny.pData ) );
416 return sal_True;
417 case typelib_TypeClass_UNSIGNED_SHORT:
418 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
419 return sal_True;
420 case typelib_TypeClass_LONG:
421 value = (sal_uInt64)( * reinterpret_cast< const sal_Int32 * >( rAny.pData ) );
422 return sal_True;
423 case typelib_TypeClass_UNSIGNED_LONG:
424 value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
425 return sal_True;
426 case typelib_TypeClass_HYPER:
427 case typelib_TypeClass_UNSIGNED_HYPER:
428 value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData );
429 return sal_True;
430 default:
431 return sal_False;
432 }
433 }
434 // float
435 //__________________________________________________________________________________________________
436 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW(())
437 {
438 switch (rAny.pType->eTypeClass)
439 {
440 case typelib_TypeClass_BYTE:
441 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
442 return sal_True;
443 case typelib_TypeClass_SHORT:
444 value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
445 return sal_True;
446 case typelib_TypeClass_UNSIGNED_SHORT:
447 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
448 return sal_True;
449 case typelib_TypeClass_FLOAT:
450 value = * reinterpret_cast< const float * >( rAny.pData );
451 return sal_True;
452 default:
453 return sal_False;
454 }
455 }
456 // double
457 //__________________________________________________________________________________________________
458 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW(())
459 {
460 switch (rAny.pType->eTypeClass)
461 {
462 case typelib_TypeClass_BYTE:
463 value = * reinterpret_cast< const sal_Int8 * >( rAny.pData );
464 return sal_True;
465 case typelib_TypeClass_SHORT:
466 value = * reinterpret_cast< const sal_Int16 * >( rAny.pData );
467 return sal_True;
468 case typelib_TypeClass_UNSIGNED_SHORT:
469 value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData );
470 return sal_True;
471 case typelib_TypeClass_LONG:
472 value = * reinterpret_cast< const sal_Int32 * >( rAny.pData );
473 return sal_True;
474 case typelib_TypeClass_UNSIGNED_LONG:
475 value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData );
476 return sal_True;
477 case typelib_TypeClass_FLOAT:
478 value = * reinterpret_cast< const float * >( rAny.pData );
479 return sal_True;
480 case typelib_TypeClass_DOUBLE:
481 value = * reinterpret_cast< const double * >( rAny.pData );
482 return sal_True;
483 default:
484 return sal_False;
485 }
486 }
487 // string
488 //__________________________________________________________________________________________________
489 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW(())
490 {
491 if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
492 {
493 value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData );
494 return sal_True;
495 }
496 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 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW(())
507 {
508 if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
509 {
510 value = * reinterpret_cast< const Type * >( rAny.pData );
511 return sal_True;
512 }
513 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 inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW(())
524 {
525 if (&rAny != &value)
526 {
527 ::uno_type_any_assign(
528 &value, rAny.pData, rAny.pType,
529 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
530 }
531 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 inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW(())
548 {
549 const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
550 return ::uno_type_equalData(
551 rAny.pData, rAny.pType,
552 const_cast< C * >( &value ), rType.getTypeLibType(),
553 (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 inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW(())
559 {
560 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 T Any::get() const
571 {
572 T value = T();
573 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 Reference<XInterface>() );
581 }
582 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: */
data.h
com::sun::star::uno::Any::operator!=
sal_Bool operator!=(const Any &rAny) const
Unequality operator: compares two anys.
Definition: Any.hxx:167
com::sun::star::uno::BaseReference
This base class serves as a base class for all template reference classes and has been introduced due...
Definition: Reference.h:54
_typelib_TypeDescription
Full type description of a type.
Definition: typedescription.h:71
uno_ReleaseFunc
void(* uno_ReleaseFunc)(void *pInterface)
Generic function pointer declaration to release an interface.
Definition: data.h:52
typelib_TypeClass_STRING
type class of string
Definition: typeclass.h:53
com::sun::star::uno::Any::clear
void clear()
Clears this any.
Definition: Any.hxx:130
_typelib_TypeDescriptionReference::pTypeName
rtl_uString * pTypeName
fully qualified name of type
Definition: typedescription.h:55
com::sun::star::uno::Any::getValueTypeName
inline::rtl::OUString getValueTypeName() const
Gets the type name of the set value.
Definition: Any.hxx:104
typelib_TypeClass_SHORT
type class of short
Definition: typeclass.h:37
com::sun::star::uno::operator>>=
sal_Bool operator>>=(const Any &rAny, C &value)
Template binary &gt;&gt;= operator to assign a value from an any.
Definition: Any.hxx:235
com::sun::star::uno::Any::~Any
~Any()
Destructor: Destructs any content and frees memory.
Definition: Any.hxx:87
sal_Int8
signed char sal_Int8
Definition: types.h:42
getCppuBooleanType
const ::com::sun::star::uno::Type & getCppuBooleanType()
Gets the meta type of IDL type boolean.
Definition: Type.hxx:111
com::sun::star::uno::Any::operator==
sal_Bool operator==(const Any &rAny) const
Equality operator: compares two anys.
Definition: Any.hxx:160
uno_any_assign
CPPU_DLLPUBLIC void uno_any_assign(uno_Any *pDest, void *pSource, struct _typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Assign an any with a given value.
com::sun::star::uno::Any::isExtractableTo
sal_Bool isExtractableTo(const Type &rType) const
Tests whether this any is extractable to a value of given type.
Definition: Any.hxx:136
_uno_Any::pData
void * pData
pointer to value; this may point to pReserved and thus the uno_Any is not anytime mem-copyable! You m...
Definition: any2.h:49
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:32
typelib_TypeClass_DOUBLE
type class of double
Definition: typeclass.h:51
typelib_TypeClass_UNSIGNED_LONG
type class of unsigned long
Definition: typeclass.h:43
Any.h
typelib_TypeClass_LONG
type class of long
Definition: typeclass.h:41
SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:374
com::sun::star::uno::Any::has
bool has() const
Tests whether this any can provide a value of specified type.
Definition: Any.hxx:145
uno_any_clear
CPPU_DLLPUBLIC void uno_any_clear(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Sets value to void.
typelib_TypeClass_BOOLEAN
type class of boolean
Definition: typeclass.h:33
genfunc.hxx
com::sun::star::uno::cppu_Any_extraction_failure_msg
rtl_uString * cppu_Any_extraction_failure_msg(uno_Any const *pAny, typelib_TypeDescriptionReference *pType) SAL_THROW_EXTERN_C()
com::sun::star::uno::operator==
sal_Bool operator==(const Any &rAny, const C &value)
Template equality operator: compares set value of left side any to right side value.
Definition: Any.hxx:547
uno_QueryInterfaceFunc
void *(* uno_QueryInterfaceFunc)(void *pInterface, struct _typelib_TypeDescriptionReference *pType)
Generic function pointer declaration to query for an interface.
Definition: data.h:40
uno_type_equalData
CPPU_DLLPUBLIC sal_Bool uno_type_equalData(void *pVal1, struct _typelib_TypeDescriptionReference *pVal1Type, void *pVal2, struct _typelib_TypeDescriptionReference *pVal2Type, uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Tests if two values are equal.
com::sun::star::uno::Any::get
T get() const
Provides a value of specified type, so you can easily write e.g.
Definition: Any.hxx:570
typelib_TypeClass_TYPE
type class of type
Definition: typeclass.h:55
uno_type_assignData
CPPU_DLLPUBLIC sal_Bool uno_type_assignData(void *pDest, struct _typelib_TypeDescriptionReference *pDestType, void *pSource, struct _typelib_TypeDescriptionReference *pSourceType, uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Assigns a destination value with a source value.
typelib_TypeClass_HYPER
type class of hyper
Definition: typeclass.h:45
com::sun::star::uno::cpp_queryInterface
void * cpp_queryInterface(void *pCppI, typelib_TypeDescriptionReference *pType)
Function to query for a C++ interface.
Definition: genfunc.hxx:48
typelib_TypeClass_INTERFACE
type class of interface
Definition: typeclass.h:73
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
uno_type_isAssignableFromData
CPPU_DLLPUBLIC sal_Bool uno_type_isAssignableFromData(struct _typelib_TypeDescriptionReference *pAssignable, void *pFrom, struct _typelib_TypeDescriptionReference *pFromType, uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Tests whether a value of given type is assignable from given value.
sal_False
#define sal_False
Definition: types.h:38
com::sun::star::uno::makeAny
Any makeAny(const C &value)
Template function to generically construct an any from a C++ value.
Definition: Any.hxx:176
typelib_TypeClass_FLOAT
type class of float
Definition: typeclass.h:49
_uno_Any
This is the binary specification of an UNO any.
Definition: any2.h:40
_uno_Any::pType
struct _typelib_TypeDescriptionReference * pType
type of value
Definition: any2.h:44
com::sun::star::uno::cpp_acquire
void cpp_acquire(void *pCppI)
Function to acquire a C++ interface.
Definition: genfunc.hxx:36
uno_any_construct
CPPU_DLLPUBLIC void uno_any_construct(uno_Any *pDest, void *pSource, struct _typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
Constructs an any with a given value.
com::sun::star::uno::Any::operator=
Any & operator=(const Any &rAny)
Assignment operator: Sets the value of the given any.
Definition: Any.hxx:93
unotype.hxx
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:87
com::sun::star::uno::Any::Any
Any()
Default constructor: Any holds no value; its type is void.
Definition: Any.hxx:39
com::sun::star::uno::operator<<=
void operator<<=(Any &rAny, const C &value)
Template binary &lt;&lt;= operator to set the value of an any.
Definition: Any.hxx:201
_typelib_TypeDescriptionReference::pType
struct _typelib_TypeDescription * pType
pointer to full typedescription; this value is only valid if the type is never swapped out ...
Definition: typedescription.h:58
com::sun::star::uno::Any::setValue
void setValue(const void *pData_, const Type &rType)
Sets a value.
Definition: Any.hxx:109
com::sun::star::uno::cpp_release
void cpp_release(void *pCppI)
Function to release a C++ interface.
Definition: genfunc.hxx:42
com::sun::star::uno::Type::getTypeLibType
typelib_TypeDescriptionReference * getTypeLibType() const
Gets the C typelib type description reference pointer.
Definition: Type.h:155
typelib_TypeClass_UNSIGNED_SHORT
type class of unsigned short
Definition: typeclass.h:39
Type.hxx
uno_any_destruct
CPPU_DLLPUBLIC void uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Destructs an any.
SAL_THROW_EXTERN_C
CPPU_DLLPUBLIC void SAL_THROW_EXTERN_C()
This method is called to wait for a reply of a previously sent request.
com::sun::star::uno::operator!=
sal_Bool operator!=(const Any &rAny, const C &value)
Template unequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:558
typelib_TypeClass_BYTE
type class of byte
Definition: typeclass.h:35
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition: Any.h:46
uno_type_any_construct
CPPU_DLLPUBLIC void uno_type_any_construct(uno_Any *pDest, void *pSource, struct _typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
Constructs an any with a given value.
_typelib_TypeDescriptionReference
Holds a weak reference to a type description.
Definition: typedescription.h:40
cppu::getTypeFavourUnsigned
::com::sun::star::uno::Type const & getTypeFavourUnsigned(SAL_UNUSED_PARAMETER T const *)
A working replacement for getCppuType (see there).
Definition: unotype.hxx:287
SAL_THROW
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition: Type.h:55
uno_type_any_assign
CPPU_DLLPUBLIC void uno_type_any_assign(uno_Any *pDest, void *pSource, struct _typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
Assign an any with a given value.
sal_True
#define sal_True
Definition: types.h:39
uno_AcquireFunc
void(* uno_AcquireFunc)(void *pInterface)
Generic function pointer declaration to acquire an interface.
Definition: data.h:46
typelib_TypeClass_UNSIGNED_HYPER
type class of unsigned hyper
Definition: typeclass.h:47