added set() methods, refined query

This commit is contained in:
Daniel Boelzle
2001-02-16 15:38:07 +00:00
parent 9b1c37bec3
commit bc95803588
2 changed files with 42 additions and 20 deletions

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: Reference.h,v $ * $RCSfile: Reference.h,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: dbo $ $Date: 2001-02-05 11:54:21 $ * last change: $Author: dbo $ $Date: 2001-02-16 16:38:07 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -137,6 +137,19 @@ protected:
*/ */
inline ~BaseReference() throw (); inline ~BaseReference() 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 ) 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, __UnoReference_NoAcquire ) throw ();
public: public:
// these are here to force memory de/allocation to sal lib. // these are here to force memory de/allocation to sal lib.
inline static void * SAL_CALL operator new( size_t nSize ) throw () inline static void * SAL_CALL operator new( size_t nSize ) throw ()
@@ -148,17 +161,6 @@ public:
inline static void SAL_CALL operator delete( void *, void * ) throw () inline static void SAL_CALL operator delete( void *, void * ) throw ()
{} {}
/** Sets interface pointer. An interface already set will be released.
<br>
@param pInterface an interface pointer
*/
inline void SAL_CALL set( XInterface * pInterface ) 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, __UnoReference_NoAcquire ) throw ();
/** Clears reference, i.e. releases interface. /** Clears reference, i.e. releases interface.
Reference is null after clear() call. Reference is null after clear() call.
<br> <br>
@@ -222,6 +224,11 @@ enum __UnoReference_Query
template< class interface_type > template< class interface_type >
class Reference : public BaseReference class Reference : public BaseReference
{ {
/** Queries given interface reference for type <b>interface_type</b>.
<br>
@param pInterface interface pointer
@return interface of demanded type (may be null)
*/
inline static XInterface * SAL_CALL __query( XInterface * pInterface ) throw (RuntimeException); inline static XInterface * SAL_CALL __query( XInterface * pInterface ) throw (RuntimeException);
public: public:
// these are here to force memory de/allocation to sal lib. // these are here to force memory de/allocation to sal lib.
@@ -292,6 +299,7 @@ public:
An interface already set will be released. An interface already set will be released.
<br> <br>
@param pInterface an interface pointer @param pInterface an interface pointer
@return true, if non-null interface was set
*/ */
inline sal_Bool SAL_CALL set( XInterface * pInterface, __UnoReference_Query ) throw (RuntimeException) inline sal_Bool SAL_CALL set( XInterface * pInterface, __UnoReference_Query ) throw (RuntimeException)
{ return BaseReference::set( __query( pInterface ), UNO_REF_NO_ACQUIRE ); } { return BaseReference::set( __query( pInterface ), UNO_REF_NO_ACQUIRE ); }
@@ -300,6 +308,7 @@ public:
An interface already set will be released. An interface already set will be released.
<br> <br>
@param rRef another reference @param rRef another reference
@return true, if non-null interface was set
*/ */
inline sal_Bool SAL_CALL set( const BaseReference & rRef, __UnoReference_Query ) throw (RuntimeException) inline sal_Bool SAL_CALL set( const BaseReference & rRef, __UnoReference_Query ) throw (RuntimeException)
{ return BaseReference::set( __query( rRef.get() ), UNO_REF_NO_ACQUIRE ); } { return BaseReference::set( __query( rRef.get() ), UNO_REF_NO_ACQUIRE ); }
@@ -308,16 +317,18 @@ public:
An interface already set will be released. An interface already set will be released.
<br> <br>
@param rRef another reference @param rRef another reference
@return true, if non-null interface was set
*/ */
inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) throw () inline sal_Bool SAL_CALL set( const Reference< interface_type > & rRef ) throw ()
{ BaseReference::set( rRef.get() ); return is(); } { return BaseReference::set( rRef.get() ); }
/** Sets the given interface. /** Sets the given interface.
An interface already set will be released. An interface already set will be released.
<br> <br>
@param pInterface another interface @param pInterface another interface
@return true, if non-null interface was set
*/ */
inline sal_Bool SAL_CALL set( interface_type * pInterface ) throw () inline sal_Bool SAL_CALL set( interface_type * pInterface ) throw ()
{ BaseReference::set( pInterface ); return is(); } { return BaseReference::set( pInterface ); }
/** Assignment operator: /** Assignment operator:
Acquires given interface pointer and sets reference. Acquires given interface pointer and sets reference.

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: Reference.hxx,v $ * $RCSfile: Reference.hxx,v $
* *
* $Revision: 1.4 $ * $Revision: 1.5 $
* *
* last change: $Author: dbo $ $Date: 2001-02-05 11:54:21 $ * last change: $Author: dbo $ $Date: 2001-02-16 16:38:07 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -125,7 +125,7 @@ inline sal_Bool BaseReference::operator == ( const BaseReference & rRef ) const
return (x1.get() == x2.get()); return (x1.get() == x2.get());
} }
//__________________________________________________________________________________________________ //__________________________________________________________________________________________________
inline void BaseReference::set( XInterface * pInterface ) throw () inline sal_Bool BaseReference::set( XInterface * pInterface ) throw ()
{ {
if (pInterface != _pInterface) if (pInterface != _pInterface)
{ {
@@ -135,6 +135,7 @@ inline void BaseReference::set( XInterface * pInterface ) throw ()
_pInterface->release(); _pInterface->release();
_pInterface = pInterface; _pInterface = pInterface;
} }
return (pInterface != 0);
} }
//__________________________________________________________________________________________________ //__________________________________________________________________________________________________
inline sal_Bool BaseReference::set( XInterface * pInterface, __UnoReference_NoAcquire ) throw () inline sal_Bool BaseReference::set( XInterface * pInterface, __UnoReference_NoAcquire ) throw ()
@@ -167,8 +168,18 @@ template< class interface_type >
inline XInterface * Reference< interface_type >::__query( inline XInterface * Reference< interface_type >::__query(
XInterface * pInterface ) throw (RuntimeException) XInterface * pInterface ) throw (RuntimeException)
{ {
const Type & rType = ::getCppuType( (const Reference< interface_type > *)0 ); if (pInterface)
return reinterpret_cast< XInterface * >( cpp_queryInterface( pInterface, rType.getTypeLibType() ) ); {
const Type & rType = ::getCppuType( (const Reference< interface_type > *)0 );
Any aRet( pInterface->queryInterface( rType ) );
if (aRet.hasValue())
{
XInterface * pRet = * reinterpret_cast< XInterface * const * >( aRet.getValue() );
pRet->acquire();
return pRet;
}
}
return 0;
} }
} }