From 02836cba55eedbf9424ecc89ea3ea834d3a99488 Mon Sep 17 00:00:00 2001 From: Daniel Boelzle Date: Fri, 16 Mar 2001 15:34:33 +0000 Subject: optimized inline implementation of UNO base types --- cppu/inc/com/sun/star/uno/Reference.h | 264 +++++++++++++++------------------- 1 file changed, 116 insertions(+), 148 deletions(-) (limited to 'cppu/inc/com/sun/star/uno/Reference.h') 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.
*/ enum __UnoReference_NoAcquire @@ -94,78 +95,19 @@ enum __UnoReference_NoAcquire UNO_REF_NO_ACQUIRE }; -/** Base reference class holding/ acquiring an interface.
- 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 ==, =!.
*/ class BaseReference { - /** the interface pointer
- */ - XInterface * _pInterface; - protected: - /** Default Constructor: - Sets null reference. + /** the interface pointer
*/ - inline BaseReference() SAL_THROW( () ); - /** Constructor: - Sets given interface pointer. -
- @param pInterface an interface pointer - */ - inline BaseReference( XInterface * pInterface ) SAL_THROW( () ); - /** Constructor: - Sets reference to given interface pointer without acquiring it. -
- @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. -
- @param rRef another reference - */ - inline BaseReference( const BaseReference & rRef ) SAL_THROW( () ); - /** Destructor: - Releases interface reference. -
- */ - inline ~BaseReference() SAL_THROW( () ); - - /** Sets interface pointer. An interface already set will be released. -
- @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. -
- @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. -
- */ - inline void SAL_CALL clear() SAL_THROW( () ); /** Gets interface pointer. This call does not acquire the interface.
@@ -173,12 +115,29 @@ public: */ inline XInterface * SAL_CALL get() const SAL_THROW( () ) { return _pInterface; } + /** Checks if reference is null.
@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
+ Checks if both references are null or refer to the same object. +
+ @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
+ Checks if both references are null or refer to the same object. +
+ @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
Checks if both references are null or refer to the same object.
@@ -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. +
+ */ + inline ~Reference() SAL_THROW( () ); + /** Default Constructor: Sets null reference.
*/ - inline Reference() SAL_THROW( () ) - : BaseReference() - {} + inline Reference() SAL_THROW( () ); + /** Copy constructor: Copies interface reference.
@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.
@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.
@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.
@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 (interface_type). @@ -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 (interface_type).
@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 (interface_type) - 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. +
+ */ + inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW( () ) + { return * reinterpret_cast< const Reference< XInterface > * >( this ); } + + /** Dereference operator: + Used to call interface methods. +
+ @return unacquired interface pointer + */ + inline interface_type * SAL_CALL operator -> () const SAL_THROW( () ) + { return static_cast< interface_type * >( _pInterface ); } + + /** Gets interface pointer. + This call does not acquire the interface. +
+ @return unacquired 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. +
+ */ + inline void SAL_CALL clear() SAL_THROW( () ); + + /** Sets the given interface. + An interface already set will be released. +
+ @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. +
+ @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.
@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 (interface_type) - 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.
- @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 (interface_type) + and sets it. An interface already set will be released.
- @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 (interface_type) + and sets it. An interface already set will be released.
- @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 interface_type. -
- @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 interface_type.
@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. -
- */ - inline SAL_CALL operator const Reference< XInterface > & () const SAL_THROW( () ) - { return * reinterpret_cast< const Reference< XInterface > * >( this ); } - - /** Dereference operator: - Used to call interface methods. -
- @return unacquired interface pointer - */ - inline interface_type * SAL_CALL operator -> () const SAL_THROW( () ) - { return static_cast< interface_type * >( BaseReference::get() ); } - - /** Gets interface pointer. - This call does not acquire the interface. + inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ) SAL_THROW( (RuntimeException) ); + /** Queries given interface for type interface_type.
- @return unacquired 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) ); }; } -- cgit v1.2.3