xref: /aoo41x/main/cppu/inc/com/sun/star/uno/Any.hxx (revision a997bb20)
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
10c6ed87c9SAndrew Rist  *
11c6ed87c9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c6ed87c9SAndrew Rist  *
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.
19c6ed87c9SAndrew Rist  *
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 //__________________________________________________________________________________________________
Any()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>
Any(T const & value)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 //______________________________________________________________________________
Any(bool value)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 //__________________________________________________________________________________________________
Any(const Any & rAny)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 //__________________________________________________________________________________________________
Any(const void * pData_,const Type & rType)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 //__________________________________________________________________________________________________
Any(const void * pData_,typelib_TypeDescription * pTypeDescr)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 //__________________________________________________________________________________________________
Any(const void * pData_,typelib_TypeDescriptionReference * pType_)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 //__________________________________________________________________________________________________
~Any()91cdf0e10cSrcweir inline Any::~Any() SAL_THROW( () )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	::uno_any_destruct(
94cdf0e10cSrcweir 		this, (uno_ReleaseFunc)cpp_release );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir //__________________________________________________________________________________________________
operator =(const Any & rAny)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 //__________________________________________________________________________________________________
getValueTypeName() const108cdf0e10cSrcweir inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW( () )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	return ::rtl::OUString( pType->pTypeName );
111cdf0e10cSrcweir }
112cdf0e10cSrcweir //__________________________________________________________________________________________________
setValue(const void * pData_,const Type & rType)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 //__________________________________________________________________________________________________
setValue(const void * pData_,typelib_TypeDescriptionReference * pType_)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 //__________________________________________________________________________________________________
setValue(const void * pData_,typelib_TypeDescription * pTypeDescr)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 //__________________________________________________________________________________________________
clear()134cdf0e10cSrcweir inline void Any::clear() SAL_THROW( () )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	::uno_any_clear(
137cdf0e10cSrcweir 		this, (uno_ReleaseFunc)cpp_release );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir //__________________________________________________________________________________________________
isExtractableTo(const Type & rType) const140cdf0e10cSrcweir 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>
has() const149cdf0e10cSrcweir 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 //__________________________________________________________________________________________________
operator ==(const Any & rAny) const164cdf0e10cSrcweir 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 //__________________________________________________________________________________________________
operator !=(const Any & rAny) const171cdf0e10cSrcweir 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 >
makeAny(const C & value)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<>
makeAny(bool const & value)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 >
operator <<=(Any & rAny,const C & value)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 //______________________________________________________________________________
operator <<=(Any & rAny,bool const & value)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 >
operator >>=(const Any & rAny,C & value)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 //__________________________________________________________________________________________________
operator >>=(const::com::sun::star::uno::Any & rAny,sal_Bool & value)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 	{
233cdf0e10cSrcweir 		value = (* reinterpret_cast< const sal_Bool * >( &rAny.pReserved ) != sal_False);
234cdf0e10cSrcweir 		return sal_True;
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir 	return sal_False;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir //__________________________________________________________________________________________________
operator ==(const Any & rAny,const sal_Bool & value)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 &&
242cdf0e10cSrcweir 			(value != sal_False) == (* reinterpret_cast< const sal_Bool * >( &rAny.pReserved ) != sal_False));
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir //______________________________________________________________________________
246cdf0e10cSrcweir template<>
operator >>=(Any const & rAny,bool & value)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*a997bb20SJim Jagielski 			&rAny.pReserved ) != sal_False;
2544082994dSJim Jagielski 		return sal_True;
255cdf0e10cSrcweir 	}
2564082994dSJim Jagielski 	return sal_False;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //______________________________________________________________________________
260cdf0e10cSrcweir template<>
operator ==(Any const & rAny,bool const & value)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 ==
266cdf0e10cSrcweir              (*reinterpret_cast< sal_Bool const * >( &rAny.pReserved )
267cdf0e10cSrcweir               != sal_False)));
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir // byte
271cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const::com::sun::star::uno::Any & rAny,sal_Int8 & value)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 	{
276cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
277cdf0e10cSrcweir 		return sal_True;
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir 	return sal_False;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir // short
282cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_Int16 & value)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:
288cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
289cdf0e10cSrcweir 		return sal_True;
290cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
291cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
292cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
293cdf0e10cSrcweir 		return sal_True;
294cdf0e10cSrcweir 	default:
295cdf0e10cSrcweir 		return sal_False;
296cdf0e10cSrcweir 	}
297cdf0e10cSrcweir }
298cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_uInt16 & value)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:
304cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
305cdf0e10cSrcweir 		return sal_True;
306cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
307cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
308cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
309cdf0e10cSrcweir 		return sal_True;
310cdf0e10cSrcweir 	default:
311cdf0e10cSrcweir 		return sal_False;
312cdf0e10cSrcweir 	}
313cdf0e10cSrcweir }
314cdf0e10cSrcweir // long
315cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_Int32 & value)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:
321cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
322cdf0e10cSrcweir 		return sal_True;
323cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
324cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
325cdf0e10cSrcweir 		return sal_True;
326cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
327cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
328cdf0e10cSrcweir 		return sal_True;
329cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
330cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
331cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int32 * >( &rAny.pReserved );
332cdf0e10cSrcweir 		return sal_True;
333cdf0e10cSrcweir 	default:
334cdf0e10cSrcweir 		return sal_False;
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir }
337cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_uInt32 & value)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:
343cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
344cdf0e10cSrcweir 		return sal_True;
345cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
346cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
347cdf0e10cSrcweir 		return sal_True;
348cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
349cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
350cdf0e10cSrcweir 		return sal_True;
351cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
352cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
353cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt32 * >( &rAny.pReserved );
354cdf0e10cSrcweir 		return sal_True;
355cdf0e10cSrcweir 	default:
356cdf0e10cSrcweir 		return sal_False;
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir }
359cdf0e10cSrcweir // hyper
360cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_Int64 & value)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:
366cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
367cdf0e10cSrcweir 		return sal_True;
368cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
369cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
370cdf0e10cSrcweir 		return sal_True;
371cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
372cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
373cdf0e10cSrcweir 		return sal_True;
374cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
375cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int32 * >( &rAny.pReserved );
376cdf0e10cSrcweir 		return sal_True;
377cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
378cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt32 * >( &rAny.pReserved );
379cdf0e10cSrcweir 		return sal_True;
380cdf0e10cSrcweir 	case typelib_TypeClass_HYPER:
381cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_HYPER:
382cdf0e10cSrcweir         value = * reinterpret_cast< const sal_Int64 * >(
383cdf0e10cSrcweir             (sizeof(void *) >= sizeof(sal_Int64)) ? (void *)&rAny.pReserved : rAny.pData );
384cdf0e10cSrcweir 		return sal_True;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	default:
387cdf0e10cSrcweir 		return sal_False;
388cdf0e10cSrcweir 	}
389cdf0e10cSrcweir }
390cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,sal_uInt64 & value)391cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW( () )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir 	switch (rAny.pType->eTypeClass)
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
396cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
397cdf0e10cSrcweir 		return sal_True;
398cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
399cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
400cdf0e10cSrcweir 		return sal_True;
401cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
402cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
403cdf0e10cSrcweir 		return sal_True;
404cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
405cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int32 * >( &rAny.pReserved );
406cdf0e10cSrcweir 		return sal_True;
407cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
408cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt32 * >( &rAny.pReserved );
409cdf0e10cSrcweir 		return sal_True;
410cdf0e10cSrcweir 	case typelib_TypeClass_HYPER:
411cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_HYPER:
412cdf0e10cSrcweir         value = * reinterpret_cast< const sal_uInt64 * >(
413cdf0e10cSrcweir             (sizeof(void *) >= sizeof(sal_uInt64)) ? (void *)&rAny.pReserved : rAny.pData );
414cdf0e10cSrcweir 		return sal_True;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 	default:
417cdf0e10cSrcweir 		return sal_False;
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir }
420cdf0e10cSrcweir // float
421cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,float & value)422cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW( () )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir 	switch (rAny.pType->eTypeClass)
425cdf0e10cSrcweir 	{
426cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
427cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
428cdf0e10cSrcweir 		return sal_True;
429cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
430cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
431cdf0e10cSrcweir 		return sal_True;
432cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
433cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
434cdf0e10cSrcweir 		return sal_True;
435cdf0e10cSrcweir 	case typelib_TypeClass_FLOAT:
436cdf0e10cSrcweir         value = * reinterpret_cast< const float * >(
437cdf0e10cSrcweir             (sizeof(void *) >= sizeof(float)) ? (void *)&rAny.pReserved : rAny.pData );
438cdf0e10cSrcweir 		return sal_True;
439cdf0e10cSrcweir 
440cdf0e10cSrcweir 	default:
441cdf0e10cSrcweir 		return sal_False;
442cdf0e10cSrcweir 	}
443cdf0e10cSrcweir }
444cdf0e10cSrcweir // double
445cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,double & value)446cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW( () )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir 	switch (rAny.pType->eTypeClass)
449cdf0e10cSrcweir 	{
450cdf0e10cSrcweir 	case typelib_TypeClass_BYTE:
451cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int8 * >( &rAny.pReserved );
452cdf0e10cSrcweir 		return sal_True;
453cdf0e10cSrcweir 	case typelib_TypeClass_SHORT:
454cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int16 * >( &rAny.pReserved );
455cdf0e10cSrcweir 		return sal_True;
456cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_SHORT:
457cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt16 * >( &rAny.pReserved );
458cdf0e10cSrcweir 		return sal_True;
459cdf0e10cSrcweir 	case typelib_TypeClass_LONG:
460cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_Int32 * >( &rAny.pReserved );
461cdf0e10cSrcweir 		return sal_True;
462cdf0e10cSrcweir 	case typelib_TypeClass_UNSIGNED_LONG:
463cdf0e10cSrcweir 		value = * reinterpret_cast< const sal_uInt32 * >( &rAny.pReserved );
464cdf0e10cSrcweir 		return sal_True;
465cdf0e10cSrcweir 	case typelib_TypeClass_FLOAT:
466cdf0e10cSrcweir         value = * reinterpret_cast< const float * >(
467cdf0e10cSrcweir             (sizeof(void *) >= sizeof(float)) ? (void *)&rAny.pReserved : rAny.pData );
468cdf0e10cSrcweir 		return sal_True;
469cdf0e10cSrcweir 	case typelib_TypeClass_DOUBLE:
470cdf0e10cSrcweir         value = * reinterpret_cast< const double * >(
471cdf0e10cSrcweir             (sizeof(void *) >= sizeof(double)) ? (void *)&rAny.pReserved : rAny.pData );
472cdf0e10cSrcweir 		return sal_True;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	default:
475cdf0e10cSrcweir 		return sal_False;
476cdf0e10cSrcweir 	}
477cdf0e10cSrcweir }
478cdf0e10cSrcweir // string
479cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,::rtl::OUString & value)480cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW( () )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
483cdf0e10cSrcweir 	{
484cdf0e10cSrcweir 		value = * reinterpret_cast< const ::rtl::OUString * >( &rAny.pReserved );
485cdf0e10cSrcweir 		return sal_True;
486cdf0e10cSrcweir 	}
487cdf0e10cSrcweir 	return sal_False;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir //__________________________________________________________________________________________________
operator ==(const Any & rAny,const::rtl::OUString & value)490cdf0e10cSrcweir inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW( () )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir 	return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
493cdf0e10cSrcweir 			value.equals( * reinterpret_cast< const ::rtl::OUString * >( &rAny.pReserved ) ));
494cdf0e10cSrcweir }
495cdf0e10cSrcweir // type
496cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,Type & value)497cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW( () )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir 	if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
500cdf0e10cSrcweir 	{
501cdf0e10cSrcweir 		value = * reinterpret_cast< const Type * >( &rAny.pReserved );
502cdf0e10cSrcweir 		return sal_True;
503cdf0e10cSrcweir 	}
504cdf0e10cSrcweir 	return sal_False;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir //__________________________________________________________________________________________________
operator ==(const Any & rAny,const Type & value)507cdf0e10cSrcweir inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW( () )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir 	return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
510cdf0e10cSrcweir 			value.equals( * reinterpret_cast< const Type * >( &rAny.pReserved ) ));
511cdf0e10cSrcweir }
512cdf0e10cSrcweir // any
513cdf0e10cSrcweir //__________________________________________________________________________________________________
operator >>=(const Any & rAny,Any & value)514cdf0e10cSrcweir inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW( () )
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	if (&rAny != &value)
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir 		::uno_type_any_assign(
519cdf0e10cSrcweir 			&value, rAny.pData, rAny.pType,
520cdf0e10cSrcweir             (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
521cdf0e10cSrcweir 	}
522cdf0e10cSrcweir 	return sal_True;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir // interface
525cdf0e10cSrcweir //__________________________________________________________________________________________________
operator ==(const Any & rAny,const BaseReference & value)526cdf0e10cSrcweir inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW( () )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir 	if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
529cdf0e10cSrcweir 	{
530cdf0e10cSrcweir 		return reinterpret_cast< const BaseReference * >( &rAny.pReserved )->operator == ( value );
531cdf0e10cSrcweir 	}
532cdf0e10cSrcweir 	return sal_False;
533cdf0e10cSrcweir }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir // operator to compare to an any.
536cdf0e10cSrcweir //__________________________________________________________________________________________________
537cdf0e10cSrcweir template< class C >
operator ==(const Any & rAny,const C & value)538cdf0e10cSrcweir inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW( () )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir 	const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
541cdf0e10cSrcweir 	return ::uno_type_equalData(
542cdf0e10cSrcweir 		rAny.pData, rAny.pType,
543cdf0e10cSrcweir 		const_cast< C * >( &value ), rType.getTypeLibType(),
544cdf0e10cSrcweir 		(uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release );
545cdf0e10cSrcweir }
546cdf0e10cSrcweir // operator to compare to an any.  may use specialized operators ==.
547cdf0e10cSrcweir //__________________________________________________________________________________________________
548cdf0e10cSrcweir template< class C >
operator !=(const Any & rAny,const C & value)549cdf0e10cSrcweir inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW( () )
550cdf0e10cSrcweir {
551cdf0e10cSrcweir 	return (! operator == ( rAny, value ));
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir #if ! defined(EXCEPTIONS_OFF)
555cdf0e10cSrcweir extern "C" rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
556cdf0e10cSrcweir     uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
557cdf0e10cSrcweir     SAL_THROW_EXTERN_C();
558cdf0e10cSrcweir 
559cdf0e10cSrcweir //______________________________________________________________________________
560cdf0e10cSrcweir template <typename T>
get() const561cdf0e10cSrcweir T Any::get() const
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     T value = T();
564cdf0e10cSrcweir     if (! (*this >>= value)) {
565cdf0e10cSrcweir         throw RuntimeException(
566cdf0e10cSrcweir             ::rtl::OUString(
567cdf0e10cSrcweir                 cppu_Any_extraction_failure_msg(
568cdf0e10cSrcweir                     this,
569cdf0e10cSrcweir                     ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
570cdf0e10cSrcweir                 SAL_NO_ACQUIRE ),
571cdf0e10cSrcweir             Reference<XInterface>() );
572cdf0e10cSrcweir     }
573cdf0e10cSrcweir     return value;
574cdf0e10cSrcweir }
575cdf0e10cSrcweir // not impl: forbid use with ambiguous type (sal_Unicode, sal_uInt16)
576cdf0e10cSrcweir template <>
577cdf0e10cSrcweir sal_uInt16 Any::get<sal_uInt16>() const;
578cdf0e10cSrcweir #endif // ! defined(EXCEPTIONS_OFF)
579cdf0e10cSrcweir 
580cdf0e10cSrcweir }
581cdf0e10cSrcweir }
582cdf0e10cSrcweir }
583cdf0e10cSrcweir }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir #endif
586