1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _CPPUHELPER_WEAKAGG_HXX_
28 #define _CPPUHELPER_WEAKAGG_HXX_
29 
30 #include <cppuhelper/weak.hxx>
31 #include <com/sun/star/uno/XAggregation.hpp>
32 
33 
34 namespace cppu
35 {
36 
37 /** Base class to implement an UNO object supporting weak references, i.e. the object can be held
38     weakly (by a ::com::sun::star::uno::WeakReference) and aggregation, i.e. the object can be
39     aggregated by another (delegator).
40     This implementation copes with reference counting.  Upon last release(), the virtual dtor
41     is called.
42 
43     @derive
44     Inherit from this class and delegate acquire()/ release() calls.  Re-implement
45     XAggregation::queryInterface().
46 */
47 class OWeakAggObject
48 	: public ::cppu::OWeakObject
49 	, public ::com::sun::star::uno::XAggregation
50 {
51 public:
52 	/** Constructor.  No delegator set.
53     */
54 	inline OWeakAggObject() SAL_THROW( () )
55 		{}
56 
57 	/** If a delegator is set, then the delegators gets acquired.  Otherwise call is delegated to
58         base class ::cppu::OWeakObject.
59     */
60 	virtual void SAL_CALL acquire() throw();
61 	/** If a delegator is set, then the delegators gets released.  Otherwise call is delegated to
62         base class ::cppu::OWeakObject.
63     */
64 	virtual void SAL_CALL release() throw();
65 	/** If a delegator is set, then the delegator is queried for the demanded interface.  If the
66         delegator cannot provide the demanded interface, it calls queryAggregation() on its
67         aggregated objects.
68 
69         @param rType demanded interface type
70         @return demanded type or empty any
71         @see queryAggregation.
72     */
73 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType )
74 		throw(::com::sun::star::uno::RuntimeException);
75 
76 	/** Set the delegator.  The delegator member reference is a weak reference.
77 
78         @param Delegator the object that delegate its queryInterface to this aggregate.
79     */
80 	virtual void SAL_CALL setDelegator( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & Delegator )
81 		throw(::com::sun::star::uno::RuntimeException);
82 	/** Called by the delegator or queryInterface. Re-implement this method instead of
83         queryInterface.
84 
85         @see queryInterface
86     */
87 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType )
88 		throw(::com::sun::star::uno::RuntimeException);
89 
90 protected:
91 	/** Virtual dtor. Called when reference count is 0.
92 
93         @attention
94         Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
95         exception upon destruction!
96 	*/
97     virtual ~OWeakAggObject() SAL_THROW( (::com::sun::star::uno::RuntimeException) );
98 
99 	/** weak reference to delegator.
100 	*/
101 	::com::sun::star::uno::WeakReferenceHelper xDelegator;
102 private:
103     /** @internal */
104 	OWeakAggObject( const OWeakAggObject & rObj ) SAL_THROW( () );
105     /** @internal */
106     OWeakAggObject & operator = ( const OWeakAggObject & rObj ) SAL_THROW( () );
107 };
108 
109 }
110 
111 #endif
112