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