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 <com/sun/star/uno/XAggregation.hpp> 28 29 30 namespace cppu 31 { 32 33 /** Base class to implement an UNO object supporting weak references, i.e. the object can be held 34 weakly (by a ::com::sun::star::uno::WeakReference) and aggregation, i.e. the object can be 35 aggregated by another (delegator). 36 This implementation copes with reference counting. Upon last release(), the virtual dtor 37 is called. 38 39 @derive 40 Inherit from this class and delegate acquire()/ release() calls. Re-implement 41 XAggregation::queryInterface(). 42 */ 43 class OWeakAggObject 44 : public ::cppu::OWeakObject 45 , public ::com::sun::star::uno::XAggregation 46 { 47 public: 48 /** Constructor. No delegator set. 49 */ 50 inline OWeakAggObject() SAL_THROW( () ) 51 {} 52 53 /** If a delegator is set, then the delegators gets acquired. Otherwise call is delegated to 54 base class ::cppu::OWeakObject. 55 */ 56 virtual void SAL_CALL acquire() throw(); 57 /** If a delegator is set, then the delegators gets released. Otherwise call is delegated to 58 base class ::cppu::OWeakObject. 59 */ 60 virtual void SAL_CALL release() throw(); 61 /** If a delegator is set, then the delegator is queried for the demanded interface. If the 62 delegator cannot provide the demanded interface, it calls queryAggregation() on its 63 aggregated objects. 64 65 @param rType demanded interface type 66 @return demanded type or empty any 67 @see queryAggregation. 68 */ 69 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) 70 throw(::com::sun::star::uno::RuntimeException); 71 72 /** Set the delegator. The delegator member reference is a weak reference. 73 74 @param Delegator the object that delegate its queryInterface to this aggregate. 75 */ 76 virtual void SAL_CALL setDelegator( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & Delegator ) 77 throw(::com::sun::star::uno::RuntimeException); 78 /** Called by the delegator or queryInterface. Re-implement this method instead of 79 queryInterface. 80 81 @see queryInterface 82 */ 83 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) 84 throw(::com::sun::star::uno::RuntimeException); 85 86 protected: 87 /** Virtual dtor. Called when reference count is 0. 88 89 @attention 90 Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any 91 exception upon destruction! 92 */ 93 virtual ~OWeakAggObject() SAL_THROW( (::com::sun::star::uno::RuntimeException) ); 94 95 /** weak reference to delegator. 96 */ 97 ::com::sun::star::uno::WeakReferenceHelper xDelegator; 98 private: 99 /** @internal */ 100 OWeakAggObject( const OWeakAggObject & rObj ) SAL_THROW( () ); 101 /** @internal */ 102 OWeakAggObject & operator = ( const OWeakAggObject & rObj ) SAL_THROW( () ); 103 }; 104 105 } 106 107 #endif 108