From 230d11f43273266e9ff30ec4f5314d431de78e8b Mon Sep 17 00:00:00 2001 From: Daniel Boelzle Date: Mon, 19 Aug 2002 06:18:50 +0000 Subject: #102391# introducing some base type extensions --- cppu/inc/com/sun/star/uno/Any.h | 12 ++- cppu/inc/com/sun/star/uno/Any.hxx | 11 ++- cppu/inc/com/sun/star/uno/Reference.h | 116 +++++++++++++++++++++-- cppu/inc/com/sun/star/uno/Reference.hxx | 161 +++++++++++++++++++++++--------- cppu/inc/com/sun/star/uno/Type.h | 15 ++- cppu/inc/uno/data.h | 38 ++++++-- cppu/prj/build.lst | 3 +- cppu/source/cppu/cppu_opt.cxx | 80 ++++++++++++++++ cppu/source/cppu/makefile.mk | 82 ++++++++++++++++ cppu/source/uno/data.cxx | 62 +++++++++++- cppu/test/test_di.cxx | 15 ++- cppu/test/testcppu.cxx | 15 ++- cppu/util/cppu.map | 3 + cppu/util/makefile.mk | 7 +- 14 files changed, 539 insertions(+), 81 deletions(-) create mode 100644 cppu/source/cppu/cppu_opt.cxx create mode 100644 cppu/source/cppu/makefile.mk diff --git a/cppu/inc/com/sun/star/uno/Any.h b/cppu/inc/com/sun/star/uno/Any.h index 9d157ced647b..b2a934ad6eed 100644 --- a/cppu/inc/com/sun/star/uno/Any.h +++ b/cppu/inc/com/sun/star/uno/Any.h @@ -2,9 +2,9 @@ * * $RCSfile: Any.h,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: dbo $ $Date: 2001-11-09 09:14:30 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -227,6 +227,14 @@ public: */ inline void SAL_CALL clear() SAL_THROW( () ); + /** Tests whether this any is extractable to a value of given type. + Widening conversion without data loss is taken into account. + + @param rType destination type + @return true if this any is extractable to value of given type (e.g. using >>= operator) + */ + inline sal_Bool SAL_CALL isExtractableTo( const Type & rType ) const SAL_THROW( () ); + /** Equality operator: compares two anys. The values need not be of equal type, e.g. a short integer is compared to a long integer. diff --git a/cppu/inc/com/sun/star/uno/Any.hxx b/cppu/inc/com/sun/star/uno/Any.hxx index 13981ff54820..f66331350934 100644 --- a/cppu/inc/com/sun/star/uno/Any.hxx +++ b/cppu/inc/com/sun/star/uno/Any.hxx @@ -2,9 +2,9 @@ * * $RCSfile: Any.hxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: dbo $ $Date: 2001-12-17 12:49:34 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -166,6 +166,13 @@ inline void Any::clear() SAL_THROW( () ) this, (uno_ReleaseFunc)cpp_release ); } //__________________________________________________________________________________________________ +inline sal_Bool Any::isExtractableTo( const Type & rType ) const SAL_THROW( () ) +{ + return ::uno_type_isAssignableFromData( + rType.getTypeLibType(), pData, pType, + (uno_QueryInterfaceFunc)cpp_queryInterface, (uno_ReleaseFunc)cpp_release ); +} +//__________________________________________________________________________________________________ inline sal_Bool Any::operator == ( const Any & rAny ) const SAL_THROW( () ) { return ::uno_type_equalData( diff --git a/cppu/inc/com/sun/star/uno/Reference.h b/cppu/inc/com/sun/star/uno/Reference.h index abaeed812514..88422a175f44 100644 --- a/cppu/inc/com/sun/star/uno/Reference.h +++ b/cppu/inc/com/sun/star/uno/Reference.h @@ -2,9 +2,9 @@ * * $RCSfile: Reference.h,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: dbo $ $Date: 2001-11-09 09:14:30 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -77,6 +77,7 @@ namespace uno class RuntimeException; class XInterface; +class Type; class Any; /** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. @@ -101,6 +102,26 @@ protected: */ XInterface * _pInterface; + /** Queries given interface for type rType. + + @param pInterface interface pointer + @param rType interface type + @return interface of demanded type (may be null) + */ + inline static XInterface * SAL_CALL __query( XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Queries given interface for type rType. + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface interface pointer + @param rType interface type + @return interface of demanded type + */ + inline static XInterface * SAL_CALL __query_throw( XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ); +#endif + public: /** Gets interface pointer. This call does not acquire the interface. @@ -114,7 +135,7 @@ public: @return true if reference acquires an interface, i.e. true if it is not null */ inline sal_Bool SAL_CALL is() const SAL_THROW( () ) - { return (_pInterface != 0); } + { return (0 != _pInterface); } /** Equality operator: compares two interfaces Checks if both references are null or refer to the same object. @@ -146,22 +167,38 @@ public: */ inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const SAL_THROW( () ); - // needed for some stl container operations, though this makes no sense on pointers + /** needed for some stl container operations, though this makes no sense on pointers + @internal + */ inline sal_Bool SAL_CALL operator < ( const BaseReference & rRef ) const SAL_THROW( () ) { return (_pInterface < rRef._pInterface); } }; -/** Enum defining UNO_QUERY and UNO_REF_QUERY for query interface constructor of reference template. +/** Enum defining UNO_QUERY and UNO_REF_QUERY for implicit interface query. */ enum __UnoReference_Query { - /** This enum value can be used for querying interface constructor of reference template. + /** This enum value can be used for implicit interface query. */ UNO_QUERY, - /** This enum value can be used for querying interface constructor of reference template. + /** This enum value can be used for implicit interface query. */ UNO_REF_QUERY }; +#ifndef EXCEPTIONS_OFF +/** Enum defining UNO_QUERY_THROW and UNO_REF_QUERY_THROW for implicit interface query. + If the demanded interface is unavailable, then a RuntimeException is thrown. +*/ +enum __UnoReference_QueryThrow +{ + /** This enum value can be used for implicit interface query. + */ + UNO_QUERY_THROW, + /** This enum value can be used for implicit interface query. + */ + UNO_REF_QUERY_THROW +}; +#endif /** Template reference class for interface type derived from BaseReference. A special constructor given the UNO_QUERY or UNO_REF_QUERY identifier queries interfaces @@ -170,12 +207,23 @@ enum __UnoReference_Query template< class interface_type > class Reference : public BaseReference { - /** Queries given interface reference for type interface_type. + /** Queries given interface for type interface_type. @param pInterface interface pointer @return interface of demanded type (may be null) */ - inline static interface_type * SAL_CALL __query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ); + inline static interface_type * SAL_CALL __query( XInterface * pInterface ) + SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Queries given interface for type interface_type. + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface interface pointer + @return interface of demanded type + */ + inline static interface_type * SAL_CALL __query_throw( XInterface * pInterface ) + SAL_THROW( (RuntimeException) ); +#endif public: // these are here to force memory de/allocation to sal lib. @@ -244,6 +292,32 @@ public: @param dummy UNO_QUERY to force obvious distinction to other constructors */ inline Reference( const Any & rAny, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Constructor: Queries given interface for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param rRef another reference + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( const BaseReference & rRef, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given interface for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param pInterface an interface pointer + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( XInterface * pInterface, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Constructor: Queries given any for reference interface type (interface_type). + Throws a RuntimeException if the demanded interface cannot be queried. + + @param rAny an any + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to other constructors + */ + inline Reference( const Any & rAny, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); +#endif /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and any interface must be derived from com.sun.star.uno.XInterface. @@ -286,6 +360,7 @@ public: /** Sets interface pointer without acquiring it. An interface already set will be released. @param pInterface an interface pointer + @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods @return true, if non-null interface was set */ inline sal_Bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ); @@ -294,6 +369,7 @@ public: @deprecated @param pInterface an interface pointer + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods @return true, if non-null interface was set */ inline sal_Bool SAL_CALL set( interface_type * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ); @@ -302,6 +378,7 @@ public: An interface already set will be released. @param pInterface an interface pointer + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to set methods @return true, if non-null interface was set */ inline sal_Bool SAL_CALL set( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); @@ -309,9 +386,30 @@ public: An interface already set will be released. @param rRef another reference + @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to set methods @return true, if non-null interface was set */ inline sal_Bool SAL_CALL set( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); +#ifndef EXCEPTIONS_OFF + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + Throws a RuntimeException if the demanded interface cannot be set. + + @param pInterface an interface pointer + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to set methods + */ + inline void SAL_CALL set( XInterface * pInterface, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for reference interface type (interface_type) and sets it. + An interface already set will be released. + Throws a RuntimeException if the demanded interface cannot be set. + + @param rRef another reference + @param dummy UNO_QUERY_THROW or UNO_REF_QUERY_THROW to force obvious distinction + to set methods + */ + inline void SAL_CALL set( const BaseReference & rRef, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ); +#endif /** Assignment operator: Acquires given interface pointer and sets reference. An interface already set will be released. diff --git a/cppu/inc/com/sun/star/uno/Reference.hxx b/cppu/inc/com/sun/star/uno/Reference.hxx index 45907f36fbbc..3ec7ff2b0948 100644 --- a/cppu/inc/com/sun/star/uno/Reference.hxx +++ b/cppu/inc/com/sun/star/uno/Reference.hxx @@ -2,9 +2,9 @@ * * $RCSfile: Reference.hxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: dbo $ $Date: 2002-03-13 09:45:34 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:44 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -81,62 +81,57 @@ namespace uno { //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW( () ) +inline XInterface * BaseReference::__query( + XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ) { - if (_pInterface == pInterface) - return sal_True; -#ifndef EXCEPTIONS_OFF - try - { -#endif - // only the query to XInterface must return the same pointer if they belong to same objects - Reference< XInterface > x1( _pInterface, UNO_QUERY ); - Reference< XInterface > x2( pInterface, UNO_QUERY ); - return (x1._pInterface == x2._pInterface); -#ifndef EXCEPTIONS_OFF - } - catch (RuntimeException &) + if (pInterface) { - return sal_False; + Any aRet( pInterface->queryInterface( rType ) ); + if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) + { + XInterface * pRet = reinterpret_cast< XInterface * >( aRet.pReserved ); + aRet.pReserved = 0; + return pRet; + } } -#endif -} -//__________________________________________________________________________________________________ -inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW( () ) -{ - return (! operator == ( pInterface )); + return 0; } //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW( () ) +template< class interface_type > +inline interface_type * Reference< interface_type >::__query( + XInterface * pInterface ) SAL_THROW( (RuntimeException) ) { - return operator == ( rRef._pInterface ); + return static_cast< interface_type * >( + BaseReference::__query( + pInterface, ::getCppuType( (const Reference< interface_type > *)0 ) ) ); } +#ifndef EXCEPTIONS_OFF +extern "C" rtl_uString * SAL_CALL __cppu_unsatisfied_query_msg( + typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C(); //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW( () ) +inline XInterface * BaseReference::__query_throw( + XInterface * pInterface, const Type & rType ) + SAL_THROW( (RuntimeException) ) { - return (! operator == ( rRef._pInterface )); + XInterface * pQueried = __query( pInterface, rType ); + if (pQueried) + return pQueried; + throw RuntimeException( + ::rtl::OUString( __cppu_unsatisfied_query_msg( rType.getTypeLibType() ), SAL_NO_ACQUIRE ), + Reference< XInterface >( pInterface ) ); } - -//################################################################################################## - //__________________________________________________________________________________________________ template< class interface_type > -inline interface_type * Reference< interface_type >::__query( +inline interface_type * Reference< interface_type >::__query_throw( XInterface * pInterface ) SAL_THROW( (RuntimeException) ) { - if (pInterface) - { - const Type & rType = ::getCppuType( (const Reference< interface_type > *)0 ); - Any aRet( pInterface->queryInterface( rType ) ); - if (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass) - { - interface_type * pRet = reinterpret_cast< interface_type * >( aRet.pReserved ); - aRet.pReserved = 0; - return pRet; - } - } - return 0; + return static_cast< interface_type * >( + BaseReference::__query_throw( + pInterface, ::getCppuType( (const Reference< interface_type > *)0 ) ) ); } +#endif //__________________________________________________________________________________________________ template< class interface_type > @@ -198,6 +193,27 @@ inline Reference< interface_type >::Reference( const Any & rAny, __UnoReference_ _pInterface = (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass ? __query( reinterpret_cast< XInterface * >( rAny.pReserved ) ) : 0); } +#ifndef EXCEPTIONS_OFF +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const BaseReference & rRef, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = __query_throw( rRef.get() ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( XInterface * pInterface, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = __query_throw( pInterface ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const Any & rAny, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = __query_throw( typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass + ? reinterpret_cast< XInterface * >( rAny.pReserved ) : 0 ); +} +#endif //__________________________________________________________________________________________________ template< class interface_type > @@ -219,7 +235,7 @@ inline sal_Bool Reference< interface_type >::set( if (_pInterface) _pInterface->release(); _pInterface = pInterface; - return (pInterface != 0); + return (0 != pInterface); } //__________________________________________________________________________________________________ template< class interface_type > @@ -229,7 +245,7 @@ inline sal_Bool Reference< interface_type >::set( if (_pInterface) _pInterface->release(); _pInterface = pInterface; - return (pInterface != 0); + return (0 != pInterface); } //__________________________________________________________________________________________________ template< class interface_type > @@ -260,6 +276,22 @@ inline sal_Bool Reference< interface_type >::set( { return set( __query( rRef.get() ), SAL_NO_ACQUIRE ); } +#ifndef EXCEPTIONS_OFF +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + XInterface * pInterface, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + set( __query_throw( pInterface ), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::set( + const BaseReference & rRef, __UnoReference_QueryThrow ) SAL_THROW( (RuntimeException) ) +{ + set( __query_throw( rRef.get() ), SAL_NO_ACQUIRE ); +} +#endif //__________________________________________________________________________________________________ template< class interface_type > @@ -293,6 +325,45 @@ inline Reference< interface_type > Reference< interface_type >::query( return Reference< interface_type >( __query( pInterface ), SAL_NO_ACQUIRE ); } +//################################################################################################## + +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW( () ) +{ + if (_pInterface == pInterface) + return sal_True; +#ifndef EXCEPTIONS_OFF + try + { +#endif + // only the query to XInterface must return the same pointer if they belong to same objects + Reference< XInterface > x1( _pInterface, UNO_QUERY ); + Reference< XInterface > x2( pInterface, UNO_QUERY ); + return (x1._pInterface == x2._pInterface); +#ifndef EXCEPTIONS_OFF + } + catch (RuntimeException &) + { + return sal_False; + } +#endif +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator != ( XInterface * pInterface ) const SAL_THROW( () ) +{ + return (! operator == ( pInterface )); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW( () ) +{ + return operator == ( rRef._pInterface ); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW( () ) +{ + return (! operator == ( rRef._pInterface )); +} + } } } diff --git a/cppu/inc/com/sun/star/uno/Type.h b/cppu/inc/com/sun/star/uno/Type.h index 16fa64734a68..649bdd378de8 100644 --- a/cppu/inc/com/sun/star/uno/Type.h +++ b/cppu/inc/com/sun/star/uno/Type.h @@ -2,9 +2,9 @@ * * $RCSfile: Type.h,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: dbo $ $Date: 2002-06-20 11:04:52 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -211,6 +211,17 @@ public: inline typelib_TypeDescriptionReference * SAL_CALL getTypeLibType() const SAL_THROW( () ) { return _pType; } + /** Tests if values of this reflected type can be assigned by values of given type. + This includes widening conversion (e.g., long assignable from short), as long as there + is no data loss. + + @param rType another type + @return true if values of this type can be assigned from values of given type, + false otherwise + */ + inline sal_Bool SAL_CALL isAssignableFrom( const Type & rType ) const SAL_THROW( () ) + { return ::typelib_typedescriptionreference_isAssignableFrom( _pType, rType._pType ); } + /** Compares two types. @param rType another type diff --git a/cppu/inc/uno/data.h b/cppu/inc/uno/data.h index 2883c1ccda38..d0511ec08768 100644 --- a/cppu/inc/uno/data.h +++ b/cppu/inc/uno/data.h @@ -2,9 +2,9 @@ * * $RCSfile: data.h,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: dbo $ $Date: 2001-08-21 09:17:07 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:46 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -219,9 +219,10 @@ void SAL_CALL uno_type_constructData( void * pMem, struct _typelib_TypeDescriptionReference * pType ) SAL_THROW_EXTERN_C(); -/** Assigns a destination value with a source value. Widening conversion WITHOUT data loss is - allowed (e.g., assigning a long with a short). Assignment from any value to a value of type - Any and vice versa is allowed. +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. @param pDest pointer to destination value @param pDestTypeDescr type description of destination value @@ -241,9 +242,10 @@ sal_Bool SAL_CALL uno_assignData( void * pSource, struct _typelib_TypeDescription * pSourceTypeDescr, uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) SAL_THROW_EXTERN_C(); -/** Assigns a destination value with a source value. Widening conversion WITHOUT data loss is - allowed (e.g., assigning a long with a short). Assignment from any value to a value of type - Any and vice versa is allowed. +/** Assigns a destination value with a source value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. @param pDest pointer to destination value @param pDestType type of destination value @@ -264,6 +266,26 @@ sal_Bool SAL_CALL uno_type_assignData( uno_QueryInterfaceFunc queryInterface, uno_AcquireFunc acquire, uno_ReleaseFunc release ) SAL_THROW_EXTERN_C(); +/** Tests whether a value of given type is assignable from given value. + Widening conversion WITHOUT data loss is allowed (e.g., assigning a long with a short). + Querying for demanded interface type is allowed. + Assignment from any value to a value of type Any and vice versa is allowed. + + @param pAssignable type + @param pFrom pointer to value + @param pFromType type of value + @param queryInterface function called each time an interface needs to be queried; + defaults (0) to uno + @param release function called each time an interface needs to be released; + defaults (0) to uno + @return true if value is destination has been successfully assigned +*/ +sal_Bool SAL_CALL uno_type_isAssignableFromData( + struct _typelib_TypeDescriptionReference * pAssignable, + void * pFrom, struct _typelib_TypeDescriptionReference * pFromType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C(); + #ifdef __cplusplus } #endif diff --git a/cppu/prj/build.lst b/cppu/prj/build.lst index ec256164a16a..74b9f1cfeb94 100644 --- a/cppu/prj/build.lst +++ b/cppu/prj/build.lst @@ -4,4 +4,5 @@ cu cppu\source nmake - all cu_source NULL cu cppu\source\uno nmake - all cu_uno cu_source NULL cu cppu\source\threadpool nmake - all cu_thpool cu_source NULL cu cppu\source\typelib nmake - all cu_typelib NULL -cu cppu\util nmake - all cu_util cu_thpool cu_typelib cu_uno NULL +cu cppu\source\cppu nmake - all cu_cppu NULL +cu cppu\util nmake - all cu_util cu_thpool cu_typelib cu_cppu cu_uno NULL diff --git a/cppu/source/cppu/cppu_opt.cxx b/cppu/source/cppu/cppu_opt.cxx new file mode 100644 index 000000000000..18af1d7893b1 --- /dev/null +++ b/cppu/source/cppu/cppu_opt.cxx @@ -0,0 +1,80 @@ +/************************************************************************* + * + * $RCSfile: cppu_opt.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:47 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include +#include + + +using namespace ::rtl; + +//################################################################################################## +extern "C" rtl_uString * SAL_CALL __cppu_unsatisfied_query_msg( + typelib_TypeDescriptionReference * pType ) + SAL_THROW_EXTERN_C() +{ + OUStringBuffer buf( 64 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("unsatisfied query for interface of type ") ); + buf.append( * reinterpret_cast< OUString const * >( &pType->pTypeName ) ); + buf.append( (sal_Unicode)'!' ); + OUString ret( buf.makeStringAndClear() ); + rtl_uString_acquire( ret.pData ); + return ret.pData; +} diff --git a/cppu/source/cppu/makefile.mk b/cppu/source/cppu/makefile.mk new file mode 100644 index 000000000000..43f60bfee13f --- /dev/null +++ b/cppu/source/cppu/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.3 $ +# +# last change: $Author: dbo $ $Date: 2002-08-19 07:18:47 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=cppu +TARGET=cppu_cppu + +# --- Settings ----------------------------------------------------- + +.INCLUDE : ..$/..$/util$/makefile.pmk +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/cppu_opt.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : ..$/..$/util$/target.pmk +.INCLUDE : target.mk diff --git a/cppu/source/uno/data.cxx b/cppu/source/uno/data.cxx index e8e3ed198afe..23691abde96e 100644 --- a/cppu/source/uno/data.cxx +++ b/cppu/source/uno/data.cxx @@ -2,9 +2,9 @@ * * $RCSfile: data.cxx,v $ * - * $Revision: 1.16 $ + * $Revision: 1.17 $ * - * last change: $Author: dbo $ $Date: 2001-10-19 13:25:14 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -277,6 +277,64 @@ sal_Bool SAL_CALL uno_assignData( pSource, pSourceTD->pWeakRef, pSourceTD, queryInterface, acquire, release ); } +//################################################################################################## +sal_Bool SAL_CALL uno_type_isAssignableFromData( + typelib_TypeDescriptionReference * pAssignable, + void * pFrom, typelib_TypeDescriptionReference * pFromType, + uno_QueryInterfaceFunc queryInterface, uno_ReleaseFunc release ) + SAL_THROW_EXTERN_C() +{ + if (::typelib_typedescriptionreference_isAssignableFrom( pAssignable, pFromType )) + return sal_True; + if (typelib_TypeClass_INTERFACE != pFromType->eTypeClass || + typelib_TypeClass_INTERFACE != pAssignable->eTypeClass) + { + return sal_False; + } + + // query + if (!pFrom) + return sal_False; + void * pInterface = *(void **)pFrom; + if (! pInterface) + return sal_False; + + if (queryInterface) + { + void * p = (*queryInterface)( pInterface, pAssignable ); + if (p) + { + (*release)( p ); + } + return (0 != p); + } + else /* bin UNO */ + { + uno_Any aRet, aExc; + uno_Any * pExc = &aExc; + + void * aArgs[1]; + aArgs[0] = &pAssignable; + + typelib_TypeDescription * pMTqueryInterface = __getQueryInterfaceTypeDescr(); + (*((uno_Interface *)pInterface)->pDispatcher)( + (uno_Interface *)pInterface, pMTqueryInterface, &aRet, aArgs, &pExc ); + ::typelib_typedescription_release( pMTqueryInterface ); + + OSL_ENSURE( !pExc, "### Exception occured during queryInterface()!" ); + if (pExc) + { + __destructAny( pExc, 0 ); + return sal_False; + } + else + { + sal_Bool ret = (typelib_TypeClass_INTERFACE == aRet.pType->eTypeClass); + __destructAny( &aRet, 0 ); + return ret; + } + } +} } diff --git a/cppu/test/test_di.cxx b/cppu/test/test_di.cxx index bbc7bf765c9f..961d6d3448ff 100644 --- a/cppu/test/test_di.cxx +++ b/cppu/test/test_di.cxx @@ -2,9 +2,9 @@ * * $RCSfile: test_di.cxx,v $ * - * $Revision: 1.14 $ + * $Revision: 1.15 $ * - * last change: $Author: dbo $ $Date: 2002-04-24 13:43:27 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -79,6 +79,7 @@ #include +#include #include @@ -653,6 +654,16 @@ static void checkInvalidInterfaceQuery( catch (RuntimeException &) { } + try + { + Reference< lang::XComponent > xComp( xObj, UNO_QUERY_THROW ); + OSL_ASSERT( 0 ); + } + catch (RuntimeException & exc) + { +// OString str( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); +// OSL_TRACE( str.getStr() ); + } } //================================================================================================== diff --git a/cppu/test/testcppu.cxx b/cppu/test/testcppu.cxx index 10ba472387dc..1ebc678e4c48 100644 --- a/cppu/test/testcppu.cxx +++ b/cppu/test/testcppu.cxx @@ -2,9 +2,9 @@ * * $RCSfile: testcppu.cxx,v $ * - * $Revision: 1.24 $ + * $Revision: 1.25 $ * - * last change: $Author: dbo $ $Date: 2001-10-17 13:02:12 $ + * last change: $Author: dbo $ $Date: 2002-08-19 07:18:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -324,6 +324,8 @@ nPos = (sal_Int32)&((Test3 *)0)->aAny; a3.td.dDouble = 2; a3.bBool = sal_True; a3.aAny = makeAny( (sal_Int32)2 ); + OSL_ASSERT( a3.aAny.isExtractableTo( ::getCppuType( (sal_Int64 const *)0 ) ) ); + OSL_ASSERT( ::getCppuType( (sal_Int64 const *)0 ).isAssignableFrom( a3.aAny.getValueType() ) ); bAssignable = uno_type_assignData( &sz3, getCppuType( (Test3*)0).getTypeLibType(), &a3, getCppuType( (Test3*)0).getTypeLibType(), @@ -1129,10 +1131,13 @@ int SAL_CALL main(int argc, char **argv) test_interface(); test_inheritance(); - // shutdown #ifdef SAL_W32 - Reference< XComponent > xComp( xContext, UNO_QUERY ); - OSL_ENSURE( xComp.is(), "### root component context implement XComponent!" ); + // shutdown + Reference< XComponent > xComp( xContext, UNO_QUERY_THROW ); + xComp.set( xContext, UNO_QUERY_THROW ); + Reference< XInterface > x( + xContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theTypeDescriptionManager") ) ), UNO_QUERY_THROW ); xComp->dispose(); #endif } diff --git a/cppu/util/cppu.map b/cppu/util/cppu.map index 5e20ab3a4164..c146ac03597c 100755 --- a/cppu/util/cppu.map +++ b/cppu/util/cppu.map @@ -47,6 +47,7 @@ UDK_3_0_0 { uno_type_copyAndConvertData; uno_assignData; uno_type_assignData; + uno_type_isAssignableFromData; uno_any_assign; uno_type_any_assign; @@ -91,6 +92,8 @@ UDK_3_0_0 { uno_threadpool_dispose; uno_threadpool_attach; uno_threadpool_detach; + + __cppu_unsatisfied_query_msg; local: *; }; diff --git a/cppu/util/makefile.mk b/cppu/util/makefile.mk index e3cc6be229f8..78c179ad5140 100644 --- a/cppu/util/makefile.mk +++ b/cppu/util/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.4 $ +# $Revision: 1.5 $ # -# last change: $Author: svesik $ $Date: 2002-03-11 21:15:38 $ +# last change: $Author: dbo $ $Date: 2002-08-19 07:18:50 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -78,7 +78,8 @@ UNIXVERSIONNAMES=UDK SHL1LIBS= \ $(SLB)$/cppu_typelib.lib \ $(SLB)$/cppu_uno.lib \ - $(SLB)$/cppu_threadpool.lib + $(SLB)$/cppu_threadpool.lib \ + $(SLB)$/cppu_cppu.lib SHL1TARGET=$(TARGET) -- cgit v1.2.3