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