1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_CPPUHELPER_WEAKAGG_HXX
20 #define INCLUDED_CPPUHELPER_WEAKAGG_HXX
22 #include <cppuhelper/weak.hxx>
23 #include <cppuhelper/weakref.hxx>
24 #include <com/sun/star/uno/XAggregation.hpp>
25 #include <cppuhelper/cppuhelperdllapi.h>
31 /** Base class to implement an UNO object supporting weak references, i.e. the object can be held
32 weakly (by a ::com::sun::star::uno::WeakReference) and aggregation, i.e. the object can be
33 aggregated by another (delegator).
34 This implementation copes with reference counting. Upon last release(), the virtual dtor
38 Inherit from this class and delegate acquire()/ release() calls. Re-implement
39 XAggregation::queryInterface().
41 class CPPUHELPER_DLLPUBLIC OWeakAggObject
42 : public ::cppu::OWeakObject
43 , public ::com::sun::star::uno::XAggregation
46 /** Constructor. No delegator set.
48 inline OWeakAggObject()
51 /** If a delegator is set, then the delegators gets acquired. Otherwise call is delegated to
52 base class ::cppu::OWeakObject.
54 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
55 /** If a delegator is set, then the delegators gets released. Otherwise call is delegated to
56 base class ::cppu::OWeakObject.
58 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
59 /** If a delegator is set, then the delegator is queried for the demanded interface. If the
60 delegator cannot provide the demanded interface, it calls queryAggregation() on its
63 @param rType demanded interface type
64 @return demanded type or empty any
65 @see queryAggregation.
67 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
)
68 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
70 /** Set the delegator. The delegator member reference is a weak reference.
72 @param Delegator the object that delegate its queryInterface to this aggregate.
74 virtual void SAL_CALL
setDelegator( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> & Delegator
)
75 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
76 /** Called by the delegator or queryInterface. Re-implement this method instead of
81 virtual ::com::sun::star::uno::Any SAL_CALL
queryAggregation( const ::com::sun::star::uno::Type
& rType
)
82 throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
85 /** Virtual dtor. Called when reference count is 0.
88 Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
89 exception upon destruction!
91 virtual ~OWeakAggObject();
93 /** weak reference to delegator.
95 ::com::sun::star::uno::WeakReferenceHelper xDelegator
;
97 OWeakAggObject( const OWeakAggObject
& rObj
) SAL_DELETED_FUNCTION
;
98 OWeakAggObject
& operator = ( const OWeakAggObject
& rObj
)
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */