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