1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _CPPUHELPER_WEAKAGG_HXX_
24 #define _CPPUHELPER_WEAKAGG_HXX_
25 
26 #include <cppuhelper/weak.hxx>
27 #include "cppuhelper/cppuhelperdllapi.h"
28 #include <com/sun/star/uno/XAggregation.hpp>
29 
30 
31 namespace cppu
32 {
33 
34 /** Base class to implement an UNO object supporting weak references, i.e. the object can be held
35     weakly (by a ::com::sun::star::uno::WeakReference) and aggregation, i.e. the object can be
36     aggregated by another (delegator).
37     This implementation copes with reference counting.  Upon last release(), the virtual dtor
38     is called.
39 
40     @derive
41     Inherit from this class and delegate acquire()/ release() calls.  Re-implement
42     XAggregation::queryInterface().
43 */
44 class CPPUHELPER_DLLPUBLIC OWeakAggObject
45 	: public ::cppu::OWeakObject
46 	, public ::com::sun::star::uno::XAggregation
47 {
48 public:
49 	/** Constructor.  No delegator set.
50     */
51 	inline OWeakAggObject() SAL_THROW( () )
52 		{}
53 
54 	/** If a delegator is set, then the delegators gets acquired.  Otherwise call is delegated to
55         base class ::cppu::OWeakObject.
56     */
57 	virtual void SAL_CALL acquire() throw();
58 	/** If a delegator is set, then the delegators gets released.  Otherwise call is delegated to
59         base class ::cppu::OWeakObject.
60     */
61 	virtual void SAL_CALL release() throw();
62 	/** If a delegator is set, then the delegator is queried for the demanded interface.  If the
63         delegator cannot provide the demanded interface, it calls queryAggregation() on its
64         aggregated objects.
65 
66         @param rType demanded interface type
67         @return demanded type or empty any
68         @see queryAggregation.
69     */
70 	virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType )
71 		throw(::com::sun::star::uno::RuntimeException);
72 
73 	/** Set the delegator.  The delegator member reference is a weak reference.
74 
75         @param Delegator the object that delegate its queryInterface to this aggregate.
76     */
77 	virtual void SAL_CALL setDelegator( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & Delegator )
78 		throw(::com::sun::star::uno::RuntimeException);
79 	/** Called by the delegator or queryInterface. Re-implement this method instead of
80         queryInterface.
81 
82         @see queryInterface
83     */
84 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType )
85 		throw(::com::sun::star::uno::RuntimeException);
86 
87 protected:
88 	/** Virtual dtor. Called when reference count is 0.
89 
90         @attention
91         Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
92         exception upon destruction!
93 	*/
94     virtual ~OWeakAggObject() SAL_THROW( (::com::sun::star::uno::RuntimeException) );
95 
96 	/** weak reference to delegator.
97 	*/
98 	::com::sun::star::uno::WeakReferenceHelper xDelegator;
99 private:
100     /** @internal */
101 	OWeakAggObject( const OWeakAggObject & rObj ) SAL_THROW( () );
102     /** @internal */
103     OWeakAggObject & operator = ( const OWeakAggObject & rObj ) SAL_THROW( () );
104 };
105 
106 }
107 
108 #endif
109