diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2001-03-16 15:34:33 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2001-03-16 15:34:33 +0000 |
commit | 02836cba55eedbf9424ecc89ea3ea834d3a99488 (patch) | |
tree | 63932b63b7c8eecd1fdf2a01453742a418133861 /cppu/inc | |
parent | 57728cd1ebbba73a2fda0eb619493d2af9ab0792 (diff) |
optimized inline implementation of UNO base types
Diffstat (limited to 'cppu/inc')
-rw-r--r-- | cppu/inc/com/sun/star/uno/Any.h | 37 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Any.hxx | 257 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Reference.h | 264 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Reference.hxx | 184 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Sequence.h | 22 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Sequence.hxx | 33 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Type.h | 19 | ||||
-rw-r--r-- | cppu/inc/com/sun/star/uno/Type.hxx | 9 |
8 files changed, 455 insertions, 370 deletions
diff --git a/cppu/inc/com/sun/star/uno/Any.h b/cppu/inc/com/sun/star/uno/Any.h index 623769cceb44..5fbd11c57195 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.3 $ + * $Revision: 1.4 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,10 +61,6 @@ #ifndef _COM_SUN_STAR_UNO_ANY_H_ #define _COM_SUN_STAR_UNO_ANY_H_ -#ifndef _CPPU_MACROS_HXX_ -#include <cppu/macros.hxx> -#endif - #ifndef _UNO_ANY2_H_ #include <uno/any2.h> #endif @@ -109,13 +105,13 @@ class Any : public uno_Any { public: // these are here to force memory de/allocation to sal lib. - inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) { return ::rtl_allocateMemory( nSize ); } - inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) { ::rtl_freeMemory( pMem ); } - inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) { return pMem; } - inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) {} /** Default constructor: @@ -189,7 +185,7 @@ public: @param a pointer to type description pointer */ inline void SAL_CALL getValueTypeDescription( typelib_TypeDescription ** ppTypeDescr ) const SAL_THROW( () ) - { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, getValueTypeRef() ); } + { ::typelib_typedescriptionreference_getDescription( ppTypeDescr, pType ); } /** Gets the type class of the set value. <br> @@ -202,15 +198,14 @@ public: <br> @return the type name of the set value */ - inline ::rtl::OUString SAL_CALL getValueTypeName() const SAL_THROW( () ) - { return ::rtl::OUString( pType->pTypeName ); } + inline ::rtl::OUString SAL_CALL getValueTypeName() const SAL_THROW( () ); /** Tests if any contains a value. <br> @return true if any has a value, false otherwise */ inline sal_Bool SAL_CALL hasValue() const SAL_THROW( () ) - { return (TypeClass_VOID != getValueTypeClass()); } + { return (typelib_TypeClass_VOID != pType->eTypeClass); } /** Gets a pointer to the set value. <br> @@ -262,8 +257,7 @@ public: @param rAny another any (right side) @return true if both any contains unequal values */ - inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const SAL_THROW( () ) - { return (! operator == ( rAny )); } + inline sal_Bool SAL_CALL operator != ( const Any & rAny ) const SAL_THROW( () ); }; /** Template function to generically construct an any from a C++ value. @@ -283,7 +277,7 @@ class Type; @param value source value (right side) */ template< class C > -inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const C & value ) SAL_THROW( () ); +inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW( () ); /** Template binary >>= operator to assign a value from an any.<br> If the any does not contain a value that can be assigned <b>without</b> data loss, this operation will fail returning false. @@ -293,7 +287,7 @@ inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const C & @return true if assignment was possible without data loss */ template< class C > -inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, C & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( () ); /** Template equality operator: compares set value of left side any to right side value.<br> The values need not be of equal type, e.g. a short integer is compared to @@ -306,7 +300,7 @@ inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, @return true if values are equal, false otherwise */ template< class C > -inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, const C & value ) SAL_THROW( () ); +inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_THROW( () ); /** Template unequality operator: compares set value of left side any to right side value.<br> The values need not be of equal type, e.g. a short integer is compared to a long integer.<br> @@ -318,10 +312,7 @@ inline sal_Bool SAL_CALL operator == ( const ::com::sun::star::uno::Any & rAny, @return true if values are unequal, false otherwise */ template< class C > -inline sal_Bool SAL_CALL operator != ( const ::com::sun::star::uno::Any & rAny, const C & value ) SAL_THROW( () ) -{ - return (! operator == ( rAny, value )); -} +inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW( () ); // additional specialized >>= and == operators // bool diff --git a/cppu/inc/com/sun/star/uno/Any.hxx b/cppu/inc/com/sun/star/uno/Any.hxx index bc5cab368b07..a7dcdd455f22 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.3 $ + * $Revision: 1.4 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -67,9 +67,6 @@ #ifndef _UNO_DATA_H_ #include <uno/data.h> #endif -#ifndef _UNO_ANY2_H_ -#include <uno/any2.h> -#endif #ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ #include <com/sun/star/uno/Type.hxx> #endif @@ -102,7 +99,7 @@ inline Any::Any() SAL_THROW( () ) //__________________________________________________________________________________________________ inline Any::Any( const Any & rAny ) SAL_THROW( () ) { - ::uno_type_any_construct( this, rAny.pData, rAny.getValueTypeRef(), cpp_acquire ); + ::uno_type_any_construct( this, rAny.pData, rAny.pType, cpp_acquire ); } //__________________________________________________________________________________________________ inline Any::Any( const void * pData, const Type & rType ) SAL_THROW( () ) @@ -132,10 +129,18 @@ inline Any::~Any() SAL_THROW( () ) inline Any & Any::operator = ( const Any & rAny ) SAL_THROW( () ) { if (this != &rAny) - setValue( rAny.getValue(), rAny.getValueTypeRef() ); + { + ::uno_type_any_assign( + this, rAny.pData, rAny.pType, cpp_acquire, cpp_release ); + } return *this; } //__________________________________________________________________________________________________ +inline ::rtl::OUString Any::getValueTypeName() const SAL_THROW( () ) +{ + return ::rtl::OUString( pType->pTypeName ); +} +//__________________________________________________________________________________________________ inline void Any::setValue( const void * pData, const Type & rType ) SAL_THROW( () ) { ::uno_type_any_assign( @@ -162,11 +167,14 @@ inline void Any::clear() SAL_THROW( () ) //__________________________________________________________________________________________________ inline sal_Bool Any::operator == ( const Any & rAny ) const SAL_THROW( () ) { - const Type & rType = ::getCppuType( this ); return ::uno_type_equalData( - const_cast< void * >( getValue() ), getValueTypeRef(), - const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), - cpp_queryInterface, cpp_release ); + pData, pType, rAny.pData, rAny.pType, cpp_queryInterface, cpp_release ); +} +//__________________________________________________________________________________________________ +inline sal_Bool Any::operator != ( const Any & rAny ) const SAL_THROW( () ) +{ + return (! ::uno_type_equalData( + pData, pType, rAny.pData, rAny.pType, cpp_queryInterface, cpp_release )); } //__________________________________________________________________________________________________ @@ -180,9 +188,10 @@ inline Any SAL_CALL makeAny( const C & value ) SAL_THROW( () ) template< class C > inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) SAL_THROW( () ) { - rAny.setValue( &value, ::getCppuType( &value ) ); + const Type & rType = ::getCppuType( &value ); + ::uno_type_any_assign( + &rAny, const_cast< C * >( &value ), rType.getTypeLibType(), cpp_acquire, cpp_release ); } - //__________________________________________________________________________________________________ template< class C > inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( () ) @@ -190,7 +199,7 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( const Type & rType = ::getCppuType( &value ); return ::uno_type_assignData( &value, rType.getTypeLibType(), - const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), + rAny.pData, rAny.pType, cpp_queryInterface, cpp_acquire, cpp_release ); } @@ -198,9 +207,9 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, C & value ) SAL_THROW( //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) SAL_THROW( () ) { - if (TypeClass_BOOLEAN == rAny.getValueTypeClass()) + if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass) { - value = (* reinterpret_cast< const sal_Bool * >( rAny.getValue() ) != sal_False); + value = (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False); return sal_True; } return sal_False; @@ -208,16 +217,16 @@ inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) SAL_THROW( () ) { - return (TypeClass_BOOLEAN == rAny.getValueTypeClass() && - (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.getValue() ) != sal_False)); + return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass && + (value != sal_False) == (* reinterpret_cast< const sal_Bool * >( rAny.pData ) != sal_False)); } // byte //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) SAL_THROW( () ) { - if (TypeClass_BYTE == rAny.getValueTypeClass()) + if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass) { - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; } return sal_False; @@ -226,14 +235,14 @@ inline sal_Bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; } return sal_False; @@ -241,14 +250,14 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) SA //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; } return sal_False; @@ -257,20 +266,20 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) S //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_LONG: - case TypeClass_UNSIGNED_LONG: - value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); return sal_True; } return sal_False; @@ -278,20 +287,20 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) SA //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_LONG: - case TypeClass_UNSIGNED_LONG: - value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + case typelib_TypeClass_LONG: + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); return sal_True; } return sal_False; @@ -300,26 +309,26 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) S //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_LONG: - value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_LONG: - value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); return sal_True; - case TypeClass_HYPER: - case TypeClass_UNSIGNED_HYPER: - value = * reinterpret_cast< const sal_Int64 * >( rAny.getValue() ); + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_Int64 * >( rAny.pData ); return sal_True; } return sal_False; @@ -327,26 +336,26 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) SA //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_LONG: - value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_LONG: - value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); return sal_True; - case TypeClass_HYPER: - case TypeClass_UNSIGNED_HYPER: - value = * reinterpret_cast< const sal_uInt64 * >( rAny.getValue() ); + case typelib_TypeClass_HYPER: + case typelib_TypeClass_UNSIGNED_HYPER: + value = * reinterpret_cast< const sal_uInt64 * >( rAny.pData ); return sal_True; } return sal_False; @@ -355,19 +364,19 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) S //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_FLOAT: - value = * reinterpret_cast< const float * >( rAny.getValue() ); + case typelib_TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.pData ); return sal_True; } return sal_False; @@ -376,28 +385,28 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, float & value ) SAL_TH //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_THROW( () ) { - switch (rAny.getValueTypeClass()) + switch (rAny.pType->eTypeClass) { - case TypeClass_BYTE: - value = * reinterpret_cast< const sal_Int8 * >( rAny.getValue() ); + case typelib_TypeClass_BYTE: + value = * reinterpret_cast< const sal_Int8 * >( rAny.pData ); return sal_True; - case TypeClass_SHORT: - value = * reinterpret_cast< const sal_Int16 * >( rAny.getValue() ); + case typelib_TypeClass_SHORT: + value = * reinterpret_cast< const sal_Int16 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_SHORT: - value = * reinterpret_cast< const sal_uInt16 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_SHORT: + value = * reinterpret_cast< const sal_uInt16 * >( rAny.pData ); return sal_True; - case TypeClass_LONG: - value = * reinterpret_cast< const sal_Int32 * >( rAny.getValue() ); + case typelib_TypeClass_LONG: + value = * reinterpret_cast< const sal_Int32 * >( rAny.pData ); return sal_True; - case TypeClass_UNSIGNED_LONG: - value = * reinterpret_cast< const sal_uInt32 * >( rAny.getValue() ); + case typelib_TypeClass_UNSIGNED_LONG: + value = * reinterpret_cast< const sal_uInt32 * >( rAny.pData ); return sal_True; - case TypeClass_FLOAT: - value = * reinterpret_cast< const float * >( rAny.getValue() ); + case typelib_TypeClass_FLOAT: + value = * reinterpret_cast< const float * >( rAny.pData ); return sal_True; - case TypeClass_DOUBLE: - value = * reinterpret_cast< const double * >( rAny.getValue() ); + case typelib_TypeClass_DOUBLE: + value = * reinterpret_cast< const double * >( rAny.pData ); return sal_True; } return sal_False; @@ -406,9 +415,9 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, double & value ) SAL_T //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) SAL_THROW( () ) { - if (TypeClass_STRING == rAny.getValueTypeClass()) + if (typelib_TypeClass_STRING == rAny.pType->eTypeClass) { - value = * reinterpret_cast< const ::rtl::OUString * >( rAny.getValue() ); + value = * reinterpret_cast< const ::rtl::OUString * >( rAny.pData ); return sal_True; } return sal_False; @@ -416,16 +425,16 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & valu //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) SAL_THROW( () ) { - return (TypeClass_STRING == rAny.getValueTypeClass() && - value == * reinterpret_cast< const ::rtl::OUString * >( rAny.getValue() )); + return (typelib_TypeClass_STRING == rAny.pType->eTypeClass && + value == * reinterpret_cast< const ::rtl::OUString * >( rAny.pData )); } // type //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THROW( () ) { - if (TypeClass_TYPE == rAny.getValueTypeClass()) + if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass) { - value = * reinterpret_cast< const Type * >( rAny.getValue() ); + value = * reinterpret_cast< const Type * >( rAny.pData ); return sal_True; } return sal_False; @@ -433,28 +442,27 @@ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) SAL_THR //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator == ( const Any & rAny, const Type & value ) SAL_THROW( () ) { - return (TypeClass_TYPE == rAny.getValueTypeClass() && - value == * reinterpret_cast< const Type * >( rAny.getValue() )); + return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass && + value == * reinterpret_cast< const Type * >( rAny.pData )); } // any //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) SAL_THROW( () ) { - value = rAny; + if (&rAny != &value) + { + ::uno_type_any_assign( + &value, rAny.pData, rAny.pType, cpp_acquire, cpp_release ); + } return sal_True; } // interface //__________________________________________________________________________________________________ inline sal_Bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) SAL_THROW( () ) { - if (TypeClass_INTERFACE == rAny.getValueTypeClass()) + if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass) { - XInterface * p1 = * reinterpret_cast< XInterface * const * >( rAny.getValue() ); - if (p1 && p1 == value.get()) - return sal_True; - Reference< XInterface > xI1( p1, UNO_QUERY ); - Reference< XInterface > xI2( value.get(), UNO_QUERY ); - return (xI1.is() && xI1.get() == xI2.get()); + return reinterpret_cast< BaseReference const * >( rAny.pData )->operator == ( value ); } return sal_False; } @@ -466,10 +474,17 @@ inline sal_Bool SAL_CALL operator == ( const Any & rAny, const C & value ) SAL_T { const Type & rType = ::getCppuType( &value ); return ::uno_type_equalData( - const_cast< void * >( rAny.getValue() ), rAny.getValueTypeRef(), + rAny.pData, rAny.pType, const_cast< C * >( &value ), rType.getTypeLibType(), cpp_queryInterface, cpp_release ); } +// operator to compare to an any. may use specialized operators ==. +//__________________________________________________________________________________________________ +template< class C > +inline sal_Bool SAL_CALL operator != ( const Any & rAny, const C & value ) SAL_THROW( () ) +{ + return (! operator == ( rAny, value )); +} } } diff --git a/cppu/inc/com/sun/star/uno/Reference.h b/cppu/inc/com/sun/star/uno/Reference.h index c7775f07e4f3..f71ca3b30f49 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.6 $ + * $Revision: 1.7 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -82,7 +82,8 @@ namespace uno class RuntimeException; class XInterface; -/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. +/** DEPRECATED: use SAL_NO_ACQUIRE + Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. <br> */ enum __UnoReference_NoAcquire @@ -94,78 +95,19 @@ enum __UnoReference_NoAcquire UNO_REF_NO_ACQUIRE }; -/** Base reference class holding/ acquiring an interface.<br> - Constructors acquire an interface while the destructor releases it. - This class serves as a base class for all template reference classes and +/** This base class serves as a base class for all template reference classes and has been introduced due to compiler problems with templated operators ==, =!. <br> */ class BaseReference { - /** the interface pointer<br> - */ - XInterface * _pInterface; - protected: - /** Default Constructor: - Sets null reference. + /** the interface pointer <br> */ - inline BaseReference() SAL_THROW( () ); - /** Constructor: - Sets given interface pointer. - <br> - @param pInterface an interface pointer - */ - inline BaseReference( XInterface * pInterface ) SAL_THROW( () ); - /** Constructor: - Sets reference to given interface pointer without acquiring it. - <br> - @param pInterface interface pointer - @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors - */ - inline BaseReference( XInterface * pInterface, __sal_NoAcquire ) SAL_THROW( () ); - /** Copy constructor: - Copies interface reference. - <br> - @param rRef another reference - */ - inline BaseReference( const BaseReference & rRef ) SAL_THROW( () ); - /** Destructor: - Releases interface reference. - <br> - */ - inline ~BaseReference() SAL_THROW( () ); - - /** Sets interface pointer. An interface already set will be released. - <br> - @param pInterface an interface pointer - @return true, if non-null interface was set - */ - inline sal_Bool SAL_CALL set( XInterface * pInterface ) SAL_THROW( () ); - /** Sets interface pointer without acquiring it. - An interface already set will be released. - <br> - @param pInterface an interface pointer - */ - inline sal_Bool SAL_CALL set( XInterface * pInterface, __sal_NoAcquire ) SAL_THROW( () ); + XInterface * _pInterface; public: - // these are here to force memory de/allocation to sal lib. - inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) - { return ::rtl_allocateMemory( nSize ); } - inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) - { ::rtl_freeMemory( pMem ); } - inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) - { return pMem; } - inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) - {} - - /** Clears reference, i.e. releases interface. - Reference is null after clear() call. - <br> - */ - inline void SAL_CALL clear() SAL_THROW( () ); /** Gets interface pointer. This call does <b>not</b> acquire the interface. <br> @@ -173,12 +115,29 @@ public: */ inline XInterface * SAL_CALL get() const SAL_THROW( () ) { return _pInterface; } + /** Checks if reference is null. <br> @return true if reference acquires an interface, i.e. is not null */ inline sal_Bool SAL_CALL is() const SAL_THROW( () ) { return (_pInterface != 0); } + + /** Equality operator: compares two interfaces<br> + Checks if both references are null or refer to the same object. + <br> + @param rRef another interface + @return true if both references are null or refer to the same object, false otherwise + */ + inline sal_Bool SAL_CALL operator == ( XInterface * pInterface ) const SAL_THROW( () ); + /** Unequality operator: compares two interfaces<br> + Checks if both references are null or refer to the same object. + <br> + @param rRef another interface + @return false if both references are null or refer to the same object, true otherwise + */ + inline sal_Bool SAL_CALL operator != ( XInterface * pInterface ) const SAL_THROW( () ); + /** Equality operator: compares two interfaces<br> Checks if both references are null or refer to the same object. <br> @@ -192,10 +151,9 @@ public: @param rRef another reference @return false if both references are null or refer to the same object, true otherwise */ - inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const SAL_THROW( () ) - { return (! operator == ( rRef )); } + inline sal_Bool SAL_CALL operator != ( const BaseReference & rRef ) const SAL_THROW( () ); - // needed for stl container operations, though this makes no sense on pointers + // needed for some stl container operations, though this makes no sense on pointers inline sal_Bool SAL_CALL operator < ( const BaseReference & rRef ) const SAL_THROW( () ) { return (_pInterface < rRef._pInterface); } }; @@ -229,60 +187,59 @@ class Reference : public BaseReference @param pInterface interface pointer @return interface of demanded type (may be null) */ - inline static XInterface * SAL_CALL __query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ); + inline static interface_type * SAL_CALL __query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ); + public: // these are here to force memory de/allocation to sal lib. - static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) + static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) { return ::rtl_allocateMemory( nSize ); } - static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) + static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) { ::rtl_freeMemory( pMem ); } - static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) + static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) { return pMem; } - static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) + static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) {} + /** Destructor: + Releases interface if set. + <br> + */ + inline ~Reference() SAL_THROW( () ); + /** Default Constructor: Sets null reference. <br> */ - inline Reference() SAL_THROW( () ) - : BaseReference() - {} + inline Reference() SAL_THROW( () ); + /** Copy constructor: Copies interface reference. <br> @param rRef another reference */ - inline Reference( const Reference< interface_type > & rRef ) SAL_THROW( () ) - : BaseReference( rRef ) - {} + inline Reference( const Reference< interface_type > & rRef ) SAL_THROW( () ); /** Constructor: Sets given interface pointer. <br> @param pInterface an interface pointer */ - inline Reference( interface_type * pInterface ) SAL_THROW( () ) - : BaseReference( pInterface ) - {} + inline Reference( interface_type * pInterface ) SAL_THROW( () ); /** Constructor: Sets given interface pointer without acquiring it. <br> @param pInterface another reference - @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors + @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors */ - inline Reference( XInterface * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ) - : BaseReference( pInterface, SAL_NO_ACQUIRE ) - {} - /** Constructor: + inline Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ); + /** DEPRECATED: use SAL_NO_ACQUIRE version + Constructor: Sets given interface pointer without acquiring it. <br> @param pInterface another reference - @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors + @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors */ - inline Reference( XInterface * pInterface, __sal_NoAcquire ) SAL_THROW( () ) - : BaseReference( pInterface, SAL_NO_ACQUIRE ) - {} + inline Reference( interface_type * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ); /** Constructor: Queries given interface for reference interface type (<b>interface_type</b>). @@ -290,54 +247,93 @@ public: @param rRef another reference @param dummy UNO_QUERY or UNO_REF_QUERY to force obvious distinction to other constructors */ - inline Reference( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) - : BaseReference( __query( rRef.get() ), SAL_NO_ACQUIRE ) - {} + inline Reference( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); /** Constructor: Queries given interface for reference interface type (<b>interface_type</b>). <br> @param pInterface an interface pointer @param dummy UNO_QUERY to force obvious distinction to other constructors */ - inline Reference( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) - : BaseReference( __query( pInterface ), SAL_NO_ACQUIRE ) - {} + inline Reference( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); - /** Queries given interface for reference interface type (<b>interface_type</b>) - and sets it. + /** Cast operator to Reference< XInterface >: + Reference objects are binary compatible and any interface must be derived + from com.sun.star.uno.XInterface. + This a useful direct cast possibility. + <br> + */ + inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW( () ) + { return * reinterpret_cast< const Reference< XInterface > * >( this ); } + + /** Dereference operator: + Used to call interface methods. + <br> + @return <b>un</b>acquired interface pointer + */ + inline interface_type * SAL_CALL operator -> () const SAL_THROW( () ) + { return static_cast< interface_type * >( _pInterface ); } + + /** Gets interface pointer. + This call does <b>not</b> acquire the interface. + <br> + @return <b>un</b>acquired interface pointer + */ + inline interface_type * SAL_CALL get() const SAL_THROW( () ) + { return static_cast< interface_type * >( _pInterface ); } + + /** Clears reference, i.e. releases interface. + Reference is null after clear() call. + <br> + */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Sets the given interface. + An interface already set will be released. + <br> + @param rRef another reference + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) SAL_THROW( () ); + /** Sets the given interface. + An interface already set will be released. + <br> + @param pInterface another interface + @return true, if non-null interface was set + */ + inline sal_Bool SAL_CALL set( interface_type * pInterface ) SAL_THROW( () ); + + /** Sets interface pointer without acquiring it. An interface already set will be released. <br> @param pInterface an interface pointer @return true, if non-null interface was set */ - inline sal_Bool SAL_CALL set( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) - { return BaseReference::set( __query( pInterface ), SAL_NO_ACQUIRE ); } - /** Queries given interface for reference interface type (<b>interface_type</b>) - and sets it. + inline sal_Bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ); + /** DEPRECATED: use SAL_NO_ACQUIRE version + Sets interface pointer without acquiring it. An interface already set will be released. <br> - @param rRef another reference + @param pInterface an interface pointer @return true, if non-null interface was set */ - inline sal_Bool SAL_CALL set( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) - { return BaseReference::set( __query( rRef.get() ), SAL_NO_ACQUIRE ); } + inline sal_Bool SAL_CALL set( interface_type * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ); - /** Sets the given interface. + /** Queries given interface for reference interface type (<b>interface_type</b>) + and sets it. An interface already set will be released. <br> - @param rRef another reference + @param pInterface an interface pointer @return true, if non-null interface was set */ - inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) SAL_THROW( () ) - { return BaseReference::set( rRef.get() ); } - /** Sets the given interface. + inline sal_Bool SAL_CALL set( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for reference interface type (<b>interface_type</b>) + and sets it. An interface already set will be released. <br> - @param pInterface another interface + @param rRef another reference @return true, if non-null interface was set */ - inline sal_Bool SAL_CALL set( interface_type * pInterface ) SAL_THROW( () ) - { return BaseReference::set( pInterface ); } + inline sal_Bool SAL_CALL set( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ); /** Assignment operator: Acquires given interface pointer and sets reference. @@ -354,48 +350,20 @@ public: @param rRef an interface reference @return this reference */ - inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ) SAL_THROW( () ) - { return operator = ( rRef.get() ); } + inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ) SAL_THROW( () ); - /** Queries given interface for type <b>interface_type</b>. - <br> - @param pInterface interface pointer - @return interface reference of demanded type (may be null) - */ - inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ) - { return Reference< interface_type >( __query( pInterface ), SAL_NO_ACQUIRE ); } /** Queries given interface reference for type <b>interface_type</b>. <br> @param rRef interface reference @return interface reference of demanded type (may be null) */ - inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) SAL_THROW( (RuntimeException) ) - { return Reference< interface_type >( __query( rRef.get() ), SAL_NO_ACQUIRE ); } - - /** Cast operatory to Reference< XInterface >: - Reference objects are binary compatible and any interface must be derived - from com.sun.star.uno.XInterface. - This a useful direct cast possibility. - <br> - */ - inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW( () ) - { return * reinterpret_cast< const Reference< XInterface > * >( this ); } - - /** Dereference operator: - Used to call interface methods. - <br> - @return <b>un</b>acquired interface pointer - */ - inline interface_type * SAL_CALL operator -> () const SAL_THROW( () ) - { return static_cast< interface_type * >( BaseReference::get() ); } - - /** Gets interface pointer. - This call does <b>not</b> acquire the interface. + inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for type <b>interface_type</b>. <br> - @return <b>un</b>acquired interface pointer + @param pInterface interface pointer + @return interface reference of demanded type (may be null) */ - inline interface_type * SAL_CALL get() const SAL_THROW( () ) - { return static_cast< interface_type * >( BaseReference::get() ); } + inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ) SAL_THROW( (RuntimeException) ); }; } diff --git a/cppu/inc/com/sun/star/uno/Reference.hxx b/cppu/inc/com/sun/star/uno/Reference.hxx index cdd9e6dc2fbb..0cfa7644a80b 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.7 $ + * $Revision: 1.8 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -85,47 +85,120 @@ namespace uno { //__________________________________________________________________________________________________ -inline BaseReference::BaseReference() SAL_THROW( () ) - : _pInterface( 0 ) +inline sal_Bool BaseReference::operator == ( XInterface * pInterface ) const SAL_THROW( () ) { + if (_pInterface == pInterface) + return sal_True; + // 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.get() == x2.get()); } //__________________________________________________________________________________________________ -inline BaseReference::BaseReference( XInterface * pInterface ) SAL_THROW( () ) - : _pInterface( pInterface ) +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.get() ); +} +//__________________________________________________________________________________________________ +inline sal_Bool BaseReference::operator != ( const BaseReference & rRef ) const SAL_THROW( () ) +{ + return (! operator == ( rRef.get() )); +} + +//################################################################################################## + +//__________________________________________________________________________________________________ +template< class interface_type > +inline interface_type * Reference< interface_type >::__query( + 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.pData ); + * reinterpret_cast< interface_type ** >( aRet.pData ) = 0; + return pRet; + } + } + return 0; +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::~Reference() SAL_THROW( () ) { if (_pInterface) - _pInterface->acquire(); + _pInterface->release(); } //__________________________________________________________________________________________________ -inline BaseReference::BaseReference( XInterface * pInterface, __sal_NoAcquire ) SAL_THROW( () ) - : _pInterface( pInterface ) +template< class interface_type > +inline Reference< interface_type >::Reference() SAL_THROW( () ) { + _pInterface = 0; } //__________________________________________________________________________________________________ -inline BaseReference::BaseReference( const BaseReference & rRef ) SAL_THROW( () ) - : _pInterface( rRef._pInterface ) +template< class interface_type > +inline Reference< interface_type >::Reference( const Reference< interface_type > & rRef ) SAL_THROW( () ) { + _pInterface = rRef.get(); if (_pInterface) _pInterface->acquire(); } //__________________________________________________________________________________________________ -inline BaseReference::~BaseReference() SAL_THROW( () ) +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface ) SAL_THROW( () ) { + _pInterface = pInterface; if (_pInterface) - _pInterface->release(); + _pInterface->acquire(); } //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const SAL_THROW( () ) +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ) { - if (_pInterface == rRef._pInterface) - return sal_True; - // 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( rRef.get(), UNO_QUERY ); - return (x1.get() == x2.get()); + _pInterface = pInterface; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( interface_type * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ) +{ + _pInterface = pInterface; +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type >::Reference( const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = __query( rRef.get() ); } //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::set( XInterface * pInterface ) SAL_THROW( () ) +template< class interface_type > +inline Reference< interface_type >::Reference( XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + _pInterface = __query( pInterface ); +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline void Reference< interface_type >::clear() SAL_THROW( () ) +{ + if (_pInterface) + { + _pInterface->release(); + _pInterface = 0; + } +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface ) SAL_THROW( () ) { if (pInterface != _pInterface) { @@ -138,7 +211,9 @@ inline sal_Bool BaseReference::set( XInterface * pInterface ) SAL_THROW( () ) return (pInterface != 0); } //__________________________________________________________________________________________________ -inline sal_Bool BaseReference::set( XInterface * pInterface, __sal_NoAcquire ) SAL_THROW( () ) +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface, __sal_NoAcquire ) SAL_THROW( () ) { if (_pInterface) _pInterface->release(); @@ -146,13 +221,33 @@ inline sal_Bool BaseReference::set( XInterface * pInterface, __sal_NoAcquire ) S return (pInterface != 0); } //__________________________________________________________________________________________________ -inline void BaseReference::clear() SAL_THROW( () ) +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + interface_type * pInterface, __UnoReference_NoAcquire ) SAL_THROW( () ) { - if (_pInterface) - { - _pInterface->release(); - _pInterface = 0; - } + return set( pInterface, SAL_NO_ACQUIRE ); +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + const Reference< interface_type > & rRef ) SAL_THROW( () ) +{ + return set( rRef.get() ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + XInterface * pInterface, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + return set( __query( pInterface ), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline sal_Bool Reference< interface_type >::set( + const BaseReference & rRef, __UnoReference_Query ) SAL_THROW( (RuntimeException) ) +{ + return set( __query( rRef.get() ), SAL_NO_ACQUIRE ); } //__________________________________________________________________________________________________ @@ -160,26 +255,31 @@ template< class interface_type > inline Reference< interface_type > & Reference< interface_type >::operator = ( interface_type * pInterface ) SAL_THROW( () ) { - BaseReference::set( pInterface ); + set( pInterface ); return *this; } //__________________________________________________________________________________________________ template< class interface_type > -inline XInterface * Reference< interface_type >::__query( +inline Reference< interface_type > & Reference< interface_type >::operator = ( + const Reference< interface_type > & rRef ) SAL_THROW( () ) +{ + set( rRef.get() ); + return *this; +} + +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > Reference< interface_type >::query( + const BaseReference & rRef ) SAL_THROW( (RuntimeException) ) +{ + return Reference< interface_type >( __query( rRef.get() ), SAL_NO_ACQUIRE ); +} +//__________________________________________________________________________________________________ +template< class interface_type > +inline Reference< interface_type > Reference< interface_type >::query( 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) - { - XInterface * pRet = * reinterpret_cast< XInterface ** >( aRet.pData ); - * reinterpret_cast< XInterface ** >( aRet.pData ) = 0; - return pRet; - } - } - return 0; + return Reference< interface_type >( __query( pInterface ), SAL_NO_ACQUIRE ); } } diff --git a/cppu/inc/com/sun/star/uno/Sequence.h b/cppu/inc/com/sun/star/uno/Sequence.h index c326ad444dde..18125e7c04b1 100644 --- a/cppu/inc/com/sun/star/uno/Sequence.h +++ b/cppu/inc/com/sun/star/uno/Sequence.h @@ -2,9 +2,9 @@ * * $RCSfile: Sequence.h,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,10 +61,6 @@ #ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ #define _COM_SUN_STAR_UNO_SEQUENCE_H_ -#ifndef _CPPU_MACROS_HXX_ -#include <cppu/macros.hxx> -#endif - #ifndef _TYPELIB_TYPEDESCRIPTION_H_ #include <typelib/typedescription.h> #endif @@ -115,13 +111,13 @@ class Sequence public: // these are here to force memory de/allocation to sal lib. - inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) { return ::rtl_allocateMemory( nSize ); } - inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) { ::rtl_freeMemory( pMem ); } - inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) { return pMem; } - inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) {} // static pointer to typelib type @@ -181,8 +177,7 @@ public: <br> @return type of element */ - inline const Type & getElementType() const SAL_THROW( () ) - { return ::getCppuType( (const ElementType *)0 ); } + inline const Type & getElementType() const SAL_THROW( () ); /** Gets length of sequence. <br> @@ -247,8 +242,7 @@ public: @param rSeq another sequence of same type (right side) @return false if both sequences are equal, true otherwise */ - inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const SAL_THROW( () ) - { return (! operator == ( rSeq )); } + inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const SAL_THROW( () ); /** Reallocates sequence to new length. If the new length is smaller than the former, then upper elements diff --git a/cppu/inc/com/sun/star/uno/Sequence.hxx b/cppu/inc/com/sun/star/uno/Sequence.hxx index fe0b37c7fff8..e737e3836b23 100644 --- a/cppu/inc/com/sun/star/uno/Sequence.hxx +++ b/cppu/inc/com/sun/star/uno/Sequence.hxx @@ -2,9 +2,9 @@ * * $RCSfile: Sequence.hxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,10 +61,6 @@ #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ #define _COM_SUN_STAR_UNO_SEQUENCE_HXX_ -#ifndef _CPPU_MACROS_HXX_ -#include <cppu/macros.hxx> -#endif - #ifndef _OSL_DIAGNOSE_H_ #include <osl/diagnose.h> #endif @@ -134,14 +130,22 @@ template< class E > inline Sequence< E >::Sequence( sal_Int32 len ) SAL_THROW( () ) { const Type & rType = ::getCppuType( this ); - ::uno_type_sequence_construct( &_pSequence, rType.getTypeLibType(), 0, len, cpp_acquire ); + ::uno_type_sequence_construct( + &_pSequence, rType.getTypeLibType(), 0, len, cpp_acquire ); } //__________________________________________________________________________________________________ template< class E > inline Sequence< E >::~Sequence() SAL_THROW( () ) { const Type & rType = ::getCppuType( this ); - ::uno_type_destructData( this, rType.getTypeLibType(), cpp_release ); + ::uno_type_destructData( + this, rType.getTypeLibType(), cpp_release ); +} +//__________________________________________________________________________________________________ +template< class E > +inline const Type & Sequence< E >::getElementType() const SAL_THROW( () ) +{ + return ::getCppuType( (const ElementType *)0 ); } //__________________________________________________________________________________________________ template< class E > @@ -166,6 +170,12 @@ inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const } //__________________________________________________________________________________________________ template< class E > +inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const SAL_THROW( () ) +{ + return (! operator == ( rSeq )); +} +//__________________________________________________________________________________________________ +template< class E > inline E * Sequence< E >::getArray() SAL_THROW( () ) { const Type & rType = ::getCppuType( this ); @@ -178,14 +188,17 @@ template< class E > inline E & Sequence< E >::operator [] ( sal_Int32 nIndex ) SAL_THROW( () ) { OSL_ENSURE( nIndex >= 0 && nIndex < getLength(), "### illegal index of sequence!" ); - return getArray()[ nIndex ]; + const Type & rType = ::getCppuType( this ); + ::uno_type_sequence_reference2One( + &_pSequence, rType.getTypeLibType(), cpp_acquire, cpp_release ); + return reinterpret_cast< E * >( _pSequence->elements )[ nIndex ]; } //__________________________________________________________________________________________________ template< class E > inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const SAL_THROW( () ) { OSL_ENSURE( nIndex >= 0 && nIndex < getLength(), "### illegal index of sequence!" ); - return getConstArray()[ nIndex ]; + return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ]; } //__________________________________________________________________________________________________ template< class E > diff --git a/cppu/inc/com/sun/star/uno/Type.h b/cppu/inc/com/sun/star/uno/Type.h index 711472937b10..ce5df50cb365 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.3 $ + * $Revision: 1.4 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -119,13 +119,13 @@ class Type public: // these are here to force memory de/allocation to sal lib. - inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) { return ::rtl_allocateMemory( nSize ); } - inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) { ::rtl_freeMemory( pMem ); } - inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW( () ) + inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) { return pMem; } - inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW( () ) + inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) {} /** Default Constructor: @@ -205,8 +205,7 @@ public: <br> @return name of the set type */ - inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW( () ) - { return ::rtl::OUString( _pType->pTypeName ); } + inline ::rtl::OUString SAL_CALL getTypeName() const SAL_THROW( () ); /** Obtains a full type description of set type. <br> @@ -237,7 +236,7 @@ public: @return true if both types refer the same type, false otherwise */ inline sal_Bool SAL_CALL operator == ( const Type & rType ) const SAL_THROW( () ) - { return equals( rType ); } + { return ::typelib_typedescriptionreference_equals( _pType, rType._pType ); } /** Unequality operator: Compares two types. <br> @@ -245,7 +244,7 @@ public: @return false if both types refer the same type, true otherwise */ inline sal_Bool SAL_CALL operator != ( const Type & rType ) const SAL_THROW( () ) - { return (! equals( rType )); } + { return (! ::typelib_typedescriptionreference_equals( _pType, rType._pType )); } }; } diff --git a/cppu/inc/com/sun/star/uno/Type.hxx b/cppu/inc/com/sun/star/uno/Type.hxx index 30ac5da53bec..1d1eed9f86ec 100644 --- a/cppu/inc/com/sun/star/uno/Type.hxx +++ b/cppu/inc/com/sun/star/uno/Type.hxx @@ -2,9 +2,9 @@ * * $RCSfile: Type.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:55 $ + * last change: $Author: dbo $ $Date: 2001-03-16 16:34:33 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -125,6 +125,11 @@ inline Type::Type( const Type & rType ) SAL_THROW( () ) ::typelib_typedescriptionreference_acquire( _pType ); } //__________________________________________________________________________________________________ +inline ::rtl::OUString Type::getTypeName() const SAL_THROW( () ) +{ + return ::rtl::OUString( _pType->pTypeName ); +} +//__________________________________________________________________________________________________ inline Type & Type::operator = ( const Type & rType ) SAL_THROW( () ) { ::typelib_typedescriptionreference_assign( &_pType, rType._pType ); |