summaryrefslogtreecommitdiff
path: root/unotools/inc/unotools/sharedunocomponent.hxx
diff options
context:
space:
mode:
authorRĂ¼diger Timm <rt@openoffice.org>2008-12-09 07:25:38 +0000
committerRĂ¼diger Timm <rt@openoffice.org>2008-12-09 07:25:38 +0000
commit28bbe98abeef2ca37413405d3d94321353084390 (patch)
tree9926d153000e25cc00370e6a71481be9aae58d65 /unotools/inc/unotools/sharedunocomponent.hxx
parent05b8a81ec36166f1fedad8194d0bad07444a1495 (diff)
CWS-TOOLING: integrate CWS dba31d
2008-12-08 16:22:07 +0100 rt r265005 : Remove DOS lineends 2008-12-05 13:56:24 +0100 fs r264906 : #i10000# removed unreachable statement 2008-11-20 11:41:26 +0100 fs r264037 : merged in the fix for #i95865# (it was wrongly committed to CWS dba32a, should have been here) 2008-11-20 11:34:24 +0100 fs r264036 : line ends 2008-11-14 08:44:50 +0100 lla r263665 : #i10000# comparsion between int and uint fixed 2008-11-13 13:31:12 +0100 lla r263641 : #i10000# build problem fixed 2008-11-13 11:20:01 +0100 lla r263625 : #i96130# hard code name of extension 2008-11-12 11:13:41 +0100 fs r263582 : #i96096# when opening a SRB-report fails due to the missing SRB extension, log this as warning only, and proceed with the migration 2008-11-12 11:11:35 +0100 fs r263581 : #i96096# ContentType handling. Now all contents deliver proper results in XContent::getContentType 2008-11-12 11:10:11 +0100 fs r263580 : #i96096# new ctors taking UNO_QUERY_THROW 2008-11-11 10:10:13 +0100 lla r263546 : CWS-TOOLING: rebase CWS dba31d to trunk@263288 (milestone: DEV300:m35) 2008-11-06 15:55:39 +0100 oj r263393 : #i93452# get field from model fallbackis the name 2008-11-06 15:31:47 +0100 oj r263392 : #i93465# remeber location of floating windows 2008-11-06 13:36:24 +0100 oj r263381 : #i93450# check typemap for null 2008-11-06 13:28:49 +0100 oj r263379 : #i93020# empty column list boxes when new relation should be created 2008-11-06 12:33:53 +0100 oj r263377 : #i93012# set border to default : flat 2008-11-06 12:26:54 +0100 oj r263375 : #i74927# do some less calls for odbc 2008-11-06 09:34:01 +0100 oj r263362 : #i93383# grabFocus in suspend to get allmodified cells 2008-11-03 21:01:39 +0100 oj r263308 : #i86739# check if slash can be valid for tables 2008-11-03 14:40:21 +0100 oj r263287 : #i86739# check if slash can be valid for tables 2008-11-03 14:32:17 +0100 oj r263286 : #i95227# column width 2008-11-03 14:27:26 +0100 oj r263285 : link fwe 2008-11-03 14:24:54 +0100 oj r263284 : #i95235# changed to hold no ref only weak 2008-10-31 11:21:48 +0100 oj r262859 : #i93459# set images add menu entry 2008-10-31 09:06:37 +0100 oj r262851 : #i88629# correct fileopen filter for database odb files 2008-10-30 15:01:04 +0100 oj r262828 : #i95229# set filter at the composer 2008-10-29 15:57:41 +0100 oj r262817 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:19 +0100 oj r262816 : #i95235# changed to hold no ref only weak 2008-10-29 15:57:03 +0100 oj r262815 : #i95235# changed to hold no ref only weak 2008-10-29 15:56:15 +0100 oj r262814 : #i95235# filtermanger changed to hold no ref only weak 2008-10-29 10:32:39 +0100 oj r262773 : #i93474# use correct table name 2008-10-28 13:49:33 +0100 lla r262744 : #i95524# make an Invalidate and refresh on Tables 2008-10-28 10:45:02 +0100 fs r262707 : line ends 2008-10-28 10:34:42 +0100 fs r262706 : #i95522# don't expect the component to live in a TopWindow 2008-10-28 08:30:40 +0100 lla r262696 : #i93176# set preview mode on view 2008-10-28 07:56:57 +0100 oj r262694 : merge cvs svn 2008-10-27 14:13:51 +0100 oj r262673 : #i94129# use dummy data 2008-10-27 12:38:45 +0100 fs r262669 : #i94125# rework ScrollColumns 2008-10-23 15:53:57 +0200 oj r262624 : #i94568# do not load the embeddedobj just copy the storage 2008-10-23 14:39:14 +0200 oj r262622 : #i94129# handle chart correctly 2008-10-22 10:51:19 +0200 lla r262582 : #i94115# problem with left walk chart shape fixed 2008-10-22 07:47:48 +0200 oj r262576 : #i94455# rename now do not use remove insert 2008-10-22 07:47:27 +0200 oj r262575 : #i94455# rename now do not use remove insert 2008-10-21 12:46:26 +0200 lla r262567 : #i93845# extra check if default schema doesn't exists, fix assertion
Diffstat (limited to 'unotools/inc/unotools/sharedunocomponent.hxx')
-rw-r--r--unotools/inc/unotools/sharedunocomponent.hxx731
1 files changed, 373 insertions, 358 deletions
diff --git a/unotools/inc/unotools/sharedunocomponent.hxx b/unotools/inc/unotools/sharedunocomponent.hxx
index cdb4687e1e50..0ca5f6fcf77f 100644
--- a/unotools/inc/unotools/sharedunocomponent.hxx
+++ b/unotools/inc/unotools/sharedunocomponent.hxx
@@ -1,358 +1,373 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: sharedunocomponent.hxx,v $
- * $Revision: 1.7 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org 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 version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
-#define UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
-
-#include "unotoolsdllapi.h"
-
-#include <boost/shared_ptr.hpp>
-#include <com/sun/star/uno/Reference.hxx>
-#include <rtl/ref.hxx>
-
-namespace com { namespace sun { namespace star {
- namespace lang {
- class XComponent;
- }
-} } }
-//............................................................................
-namespace utl
-{
-//............................................................................
-
- //========================================================================
- //= DisposableComponent
- //========================================================================
- /** is a class which controls lifetime of an UNO component via ->XComponent::dispose
-
- You'll usually never use this class directly, but only as parameter for a
- ->SharedUNOComponent class.
- */
- class UNOTOOLS_DLLPUBLIC DisposableComponent
- {
- ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
- m_xComponent;
-
- public:
- /** constructs a ->DisposableComponent instance
-
- @param _rxComponent
- the component whose life time should be controlled by the instance. Must not be <NULL/>.
- */
- DisposableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent );
-
- /** disposes the component represented by the instance
-
- The component is queried for ->XComponent(which <em>must</em> be supported),
- and ->XComponent::dispose is invoked. A failure of this invocation (e.g. a thrown
- exception) is silenced in release builds, and reported in debug builds.
- */
- ~DisposableComponent();
-
- private:
- DisposableComponent(); // never implemented
- DisposableComponent( const DisposableComponent& ); // never implemented
- DisposableComponent& operator=( const DisposableComponent& ); // never implemented
- };
-
- //========================================================================
- //= CloseableComponent
- //========================================================================
- class CloseableComponentImpl;
- /** is a class which controls lifetime of an UNO component via ->XCloseable::close
-
- You'll usually never use this class directly, but only as parameter for a
- ->SharedUNOComponent class.
- */
- class UNOTOOLS_DLLPUBLIC CloseableComponent
- {
- private:
- /** Our IMPL class.
- */
- ::rtl::Reference< CloseableComponentImpl > m_pImpl;
-
- public:
- /** constructs a ->CloseableComponent instance
-
- @param _rxComponent
- the component whose life time should be controlled by the instance. Must not be <NULL/>.
- */
- CloseableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent );
-
- /** destroys resources associated with this instance, and disposes the component
-
- The component is queried for ->XCloseable (which <em>must</em> be supported),
- and ->XCloseable::close is invoked, with delivering the ownership.
- If the invocation fails with a ->CloseVetoException, this is ignored, since in
- this case the vetoing instance took the ownership.
-
- Any other failure will be reported in a debug version via assertion mechanisms,
- and silenced in release builds.
- */
- ~CloseableComponent();
-
- private:
- CloseableComponent(); // never implemented
- CloseableComponent( const CloseableComponent& ); // never implemented
- CloseableComponent& operator=( const CloseableComponent& ); // never implemented
- };
-
- //========================================================================
- //= SharedUNOComponent
- //========================================================================
- /** is a helper class for sharing ownership of a UNO component
-
- If you need to share an UNO component, which normally needs a dedicated owner,
- and is lifetime controlled by an explicit disposal action (not necessarily ->XComponent::dispose,
- but <em>any</em> explicit method call, after which the object is considered
- to be disposed), between different classes, ->SharedUNOComponent is what you need.
-
- Instead of passing around a <code>Reference&lt; XFoo &gt;</code>, and bothering
- with ownership and disposal, you just use a <code>SharedUNOComponent&lt; XFoo &gt;</code>.
- This instance can be passed around, including copying, and in nearly all respects behaves
- like the original <code>Reference&lt; XFoo &gt;</code>. However, when the last
- ->SharedUNOComponent referencing a certain <code>Reference&lt; XFoo &gt;</code> dies, it
- will automatically get rid of the object held by this reference.
-
- @param INTERFACE
- the UNO interface type as which the component should be held
-
- @param COMPONENT_HOLDER
- a class which can be used to represent and dispose a UNO component.
- The class must support (maybe explicit only) construction from a
- <code>Reference&lt; INTERFACE &gt;</code>, and destruction. Upon destruction,
- the class must dispose (by any suitable means) the component instance it was
- constructed with.
- */
- template < class INTERFACE, class COMPONENT = DisposableComponent >
- class SharedUNOComponent
- {
- private:
- typedef COMPONENT Component;
- typedef ::boost::shared_ptr< Component > ComponentPointer;
-
- private:
- ComponentPointer m_pComponent;
- ::com::sun::star::uno::Reference< INTERFACE > m_xTypedComponent;
-
- public:
- enum AssignmentMode
- {
- TakeOwnership,
- NoTakeOwnership
- };
-
- public:
- inline SharedUNOComponent()
- {
- }
-
- explicit inline SharedUNOComponent( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode eMode = TakeOwnership )
- {
- reset( _rxComponent, eMode );
- }
-
-#ifndef EXCEPTIONS_OFF
- inline SharedUNOComponent( const SharedUNOComponent& _rxComponent, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
- {
- set( _rxComponent, _setThrow );
- }
-#endif
-
-// SharedUNOComponent& operator=( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent );
- // this operator is not implemented by intention. There is no canonic ownership after this operatoer
- // would hvae been applied: Should the SharedUNOComponent have the ownership of the component,
- // or shouldn't it? Hard to guess, and probably wrong in 50 percent of all cases, anyway. So,
- // instead of tempting clients of this class to use such a dangerous operator, we do
- // not offer it at all. If you need to assign a Reference< INTERFACE > to your SharedUNOComponent,
- // use the ->reset method.
-
- /** assigns a new component, and releases the old one
- */
- void reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode = TakeOwnership );
-
- inline bool set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query );
- inline bool set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query );
- inline bool set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query );
-
-#ifndef EXCEPTIONS_OFF
- inline void set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
- inline void set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
- inline void set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
-
- inline void set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
- inline void set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
- inline void set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
-#endif
-
- INTERFACE* SAL_CALL operator->() const;
-
- inline operator const ::com::sun::star::uno::Reference< INTERFACE >&() const
- {
- return m_xTypedComponent;
- }
-
- inline const ::com::sun::star::uno::Reference< INTERFACE >& getTyped() const
- {
- return m_xTypedComponent;
- }
-
- inline bool is() const
- {
- return m_xTypedComponent.is();
- }
-
- inline void clear()
- {
- m_pComponent.reset();
- m_xTypedComponent.clear();
- }
- };
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- INTERFACE* SAL_CALL SharedUNOComponent< INTERFACE, COMPONENT >::operator->() const
- {
- return m_xTypedComponent.operator->();
- }
-
- //-------------------------------------------------------------------------
- // assignments
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode )
- {
- m_pComponent.reset( _eMode == TakeOwnership ? new COMPONENT( _rxComponent ) : NULL );
- m_xTypedComponent = _rxComponent;
- }
-
- //-------------------------------------------------------------------------
- // comparison operators
- template < class INTERFACE, class COMPONENT >
- bool operator==( const ::com::sun::star::uno::Reference< INTERFACE >& _rLHS, const SharedUNOComponent< INTERFACE, COMPONENT >& _rRHS )
- {
- return _rLHS == _rRHS.getTyped();
- }
-
- template < class INTERFACE, class COMPONENT >
- bool operator==( const SharedUNOComponent< INTERFACE, COMPONENT >& _rLHS, const ::com::sun::star::uno::Reference< INTERFACE >& _rRHS )
- {
- return _rLHS.getTyped() == _rRHS;
- }
-
- //-------------------------------------------------------------------------
- // conversion to Any
- template < class INTERFACE, class COMPONENT >
- inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () )
- {
- rAny <<= value.getTyped();
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- inline ::com::sun::star::uno::Any SAL_CALL makeAny( const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () )
- {
- return makeAny( value.getTyped() );
- }
-
-#ifndef EXCEPTIONS_OFF
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _queryThrow ), TakeOwnership );
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _queryThrow ), TakeOwnership );
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _queryThrow ), TakeOwnership );
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _setThrow ), TakeOwnership );
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _setThrow ), TakeOwnership );
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- void SharedUNOComponent< INTERFACE, COMPONENT >::set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
- {
- *this = _rComp;
- // provoke an exception in case the component is NULL
- m_xTypedComponent.set( m_xTypedComponent, _setThrow );
- }
-#endif
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- bool SharedUNOComponent< INTERFACE, COMPONENT >::set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _query ) );
- return is();
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _query ) );
- return is();
- }
-
- //-------------------------------------------------------------------------
- template < class INTERFACE, class COMPONENT >
- bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query )
- {
- reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _query ) );
- return is();
- }
-
-//............................................................................
-} // namespace utl
-//............................................................................
-
-#endif // UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: sharedunocomponent.hxx,v $
+ * $Revision: 1.7 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
+#define UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX
+
+#include "unotoolsdllapi.h"
+
+#include <boost/shared_ptr.hpp>
+#include <com/sun/star/uno/Reference.hxx>
+#include <rtl/ref.hxx>
+
+namespace com { namespace sun { namespace star {
+ namespace lang {
+ class XComponent;
+ }
+} } }
+//............................................................................
+namespace utl
+{
+//............................................................................
+
+ //========================================================================
+ //= DisposableComponent
+ //========================================================================
+ /** is a class which controls lifetime of an UNO component via ->XComponent::dispose
+
+ You'll usually never use this class directly, but only as parameter for a
+ ->SharedUNOComponent class.
+ */
+ class UNOTOOLS_DLLPUBLIC DisposableComponent
+ {
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
+ m_xComponent;
+
+ public:
+ /** constructs a ->DisposableComponent instance
+
+ @param _rxComponent
+ the component whose life time should be controlled by the instance. Must not be <NULL/>.
+ */
+ DisposableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent );
+
+ /** disposes the component represented by the instance
+
+ The component is queried for ->XComponent(which <em>must</em> be supported),
+ and ->XComponent::dispose is invoked. A failure of this invocation (e.g. a thrown
+ exception) is silenced in release builds, and reported in debug builds.
+ */
+ ~DisposableComponent();
+
+ private:
+ DisposableComponent(); // never implemented
+ DisposableComponent( const DisposableComponent& ); // never implemented
+ DisposableComponent& operator=( const DisposableComponent& ); // never implemented
+ };
+
+ //========================================================================
+ //= CloseableComponent
+ //========================================================================
+ class CloseableComponentImpl;
+ /** is a class which controls lifetime of an UNO component via ->XCloseable::close
+
+ You'll usually never use this class directly, but only as parameter for a
+ ->SharedUNOComponent class.
+ */
+ class UNOTOOLS_DLLPUBLIC CloseableComponent
+ {
+ private:
+ /** Our IMPL class.
+ */
+ ::rtl::Reference< CloseableComponentImpl > m_pImpl;
+
+ public:
+ /** constructs a ->CloseableComponent instance
+
+ @param _rxComponent
+ the component whose life time should be controlled by the instance. Must not be <NULL/>.
+ */
+ CloseableComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent );
+
+ /** destroys resources associated with this instance, and disposes the component
+
+ The component is queried for ->XCloseable (which <em>must</em> be supported),
+ and ->XCloseable::close is invoked, with delivering the ownership.
+ If the invocation fails with a ->CloseVetoException, this is ignored, since in
+ this case the vetoing instance took the ownership.
+
+ Any other failure will be reported in a debug version via assertion mechanisms,
+ and silenced in release builds.
+ */
+ ~CloseableComponent();
+
+ private:
+ CloseableComponent(); // never implemented
+ CloseableComponent( const CloseableComponent& ); // never implemented
+ CloseableComponent& operator=( const CloseableComponent& ); // never implemented
+ };
+
+ //========================================================================
+ //= SharedUNOComponent
+ //========================================================================
+ /** is a helper class for sharing ownership of a UNO component
+
+ If you need to share an UNO component, which normally needs a dedicated owner,
+ and is lifetime controlled by an explicit disposal action (not necessarily ->XComponent::dispose,
+ but <em>any</em> explicit method call, after which the object is considered
+ to be disposed), between different classes, ->SharedUNOComponent is what you need.
+
+ Instead of passing around a <code>Reference&lt; XFoo &gt;</code>, and bothering
+ with ownership and disposal, you just use a <code>SharedUNOComponent&lt; XFoo &gt;</code>.
+ This instance can be passed around, including copying, and in nearly all respects behaves
+ like the original <code>Reference&lt; XFoo &gt;</code>. However, when the last
+ ->SharedUNOComponent referencing a certain <code>Reference&lt; XFoo &gt;</code> dies, it
+ will automatically get rid of the object held by this reference.
+
+ @param INTERFACE
+ the UNO interface type as which the component should be held
+
+ @param COMPONENT_HOLDER
+ a class which can be used to represent and dispose a UNO component.
+ The class must support (maybe explicit only) construction from a
+ <code>Reference&lt; INTERFACE &gt;</code>, and destruction. Upon destruction,
+ the class must dispose (by any suitable means) the component instance it was
+ constructed with.
+ */
+ template < class INTERFACE, class COMPONENT = DisposableComponent >
+ class SharedUNOComponent
+ {
+ private:
+ typedef COMPONENT Component;
+ typedef ::boost::shared_ptr< Component > ComponentPointer;
+
+ private:
+ ComponentPointer m_pComponent;
+ ::com::sun::star::uno::Reference< INTERFACE > m_xTypedComponent;
+
+ public:
+ enum AssignmentMode
+ {
+ TakeOwnership,
+ NoTakeOwnership
+ };
+
+ public:
+ inline SharedUNOComponent()
+ {
+ }
+
+ explicit inline SharedUNOComponent( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode eMode = TakeOwnership )
+ {
+ reset( _rxComponent, eMode );
+ }
+
+#ifndef EXCEPTIONS_OFF
+ inline SharedUNOComponent( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ set( _pInterface, _queryThrow );
+ }
+
+ inline SharedUNOComponent( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ set( _rRef, _queryThrow );
+ }
+
+ inline SharedUNOComponent( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ set( _rAny, _queryThrow );
+ }
+
+ inline SharedUNOComponent( const SharedUNOComponent& _rxComponent, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
+ {
+ set( _rxComponent, _setThrow );
+ }
+#endif
+
+// SharedUNOComponent& operator=( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent );
+ // this operator is not implemented by intention. There is no canonic ownership after this operatoer
+ // would hvae been applied: Should the SharedUNOComponent have the ownership of the component,
+ // or shouldn't it? Hard to guess, and probably wrong in 50 percent of all cases, anyway. So,
+ // instead of tempting clients of this class to use such a dangerous operator, we do
+ // not offer it at all. If you need to assign a Reference< INTERFACE > to your SharedUNOComponent,
+ // use the ->reset method.
+
+ /** assigns a new component, and releases the old one
+ */
+ void reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode = TakeOwnership );
+
+ inline bool set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query );
+ inline bool set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query );
+ inline bool set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query );
+
+#ifndef EXCEPTIONS_OFF
+ inline void set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
+ inline void set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
+ inline void set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow );
+
+ inline void set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
+ inline void set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
+ inline void set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow );
+#endif
+
+ INTERFACE* SAL_CALL operator->() const;
+
+ inline operator const ::com::sun::star::uno::Reference< INTERFACE >&() const
+ {
+ return m_xTypedComponent;
+ }
+
+ inline const ::com::sun::star::uno::Reference< INTERFACE >& getTyped() const
+ {
+ return m_xTypedComponent;
+ }
+
+ inline bool is() const
+ {
+ return m_xTypedComponent.is();
+ }
+
+ inline void clear()
+ {
+ m_pComponent.reset();
+ m_xTypedComponent.clear();
+ }
+ };
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ INTERFACE* SAL_CALL SharedUNOComponent< INTERFACE, COMPONENT >::operator->() const
+ {
+ return m_xTypedComponent.operator->();
+ }
+
+ //-------------------------------------------------------------------------
+ // assignments
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::reset( const ::com::sun::star::uno::Reference< INTERFACE >& _rxComponent, AssignmentMode _eMode )
+ {
+ m_pComponent.reset( _eMode == TakeOwnership ? new COMPONENT( _rxComponent ) : NULL );
+ m_xTypedComponent = _rxComponent;
+ }
+
+ //-------------------------------------------------------------------------
+ // comparison operators
+ template < class INTERFACE, class COMPONENT >
+ bool operator==( const ::com::sun::star::uno::Reference< INTERFACE >& _rLHS, const SharedUNOComponent< INTERFACE, COMPONENT >& _rRHS )
+ {
+ return _rLHS == _rRHS.getTyped();
+ }
+
+ template < class INTERFACE, class COMPONENT >
+ bool operator==( const SharedUNOComponent< INTERFACE, COMPONENT >& _rLHS, const ::com::sun::star::uno::Reference< INTERFACE >& _rRHS )
+ {
+ return _rLHS.getTyped() == _rRHS;
+ }
+
+ //-------------------------------------------------------------------------
+ // conversion to Any
+ template < class INTERFACE, class COMPONENT >
+ inline void SAL_CALL operator <<= ( ::com::sun::star::uno::Any & rAny, const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () )
+ {
+ rAny <<= value.getTyped();
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ inline ::com::sun::star::uno::Any SAL_CALL makeAny( const SharedUNOComponent< INTERFACE, COMPONENT >& value ) SAL_THROW( () )
+ {
+ return makeAny( value.getTyped() );
+ }
+
+#ifndef EXCEPTIONS_OFF
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _queryThrow ), TakeOwnership );
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference & _rRef, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _queryThrow ), TakeOwnership );
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_QueryThrow _queryThrow )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _queryThrow ), TakeOwnership );
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const INTERFACE* _pInterface, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _setThrow ), TakeOwnership );
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Reference< INTERFACE >& _rRef, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _setThrow ), TakeOwnership );
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ void SharedUNOComponent< INTERFACE, COMPONENT >::set( const SharedUNOComponent& _rComp, ::com::sun::star::uno::UnoReference_SetThrow _setThrow )
+ {
+ *this = _rComp;
+ // provoke an exception in case the component is NULL
+ m_xTypedComponent.set( m_xTypedComponent, _setThrow );
+ }
+#endif
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ bool SharedUNOComponent< INTERFACE, COMPONENT >::set( ::com::sun::star::uno::XInterface* _pInterface, ::com::sun::star::uno::UnoReference_Query _query )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _pInterface, _query ) );
+ return is();
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::BaseReference& _rRef, ::com::sun::star::uno::UnoReference_Query _query )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _rRef, _query ) );
+ return is();
+ }
+
+ //-------------------------------------------------------------------------
+ template < class INTERFACE, class COMPONENT >
+ bool SharedUNOComponent< INTERFACE, COMPONENT >::set( const ::com::sun::star::uno::Any& _rAny, ::com::sun::star::uno::UnoReference_Query _query )
+ {
+ reset( ::com::sun::star::uno::Reference< INTERFACE >( _rAny, _query ) );
+ return is();
+ }
+
+//............................................................................
+} // namespace utl
+//............................................................................
+
+#endif // UNOTOOLS_INC_SHAREDUNOCOMPONENT_HXX