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 a UNO object supporting weak references, i.e. the object can be held
32 weakly (by a css::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 css::uno::XAggregation
46 /** Constructor. No delegator set.
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 css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) SAL_OVERRIDE
;
69 /** Set the delegator. The delegator member reference is a weak reference.
71 @param Delegator the object that delegate its queryInterface to this aggregate.
73 virtual void SAL_CALL
setDelegator( const css::uno::Reference
< css::uno::XInterface
> & Delegator
) SAL_OVERRIDE
;
74 /** Called by the delegator or queryInterface. Re-implement this method instead of
79 virtual css::uno::Any SAL_CALL
queryAggregation( const css::uno::Type
& rType
) SAL_OVERRIDE
;
82 /** Virtual dtor. Called when reference count is 0.
85 Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
86 exception upon destruction!
88 virtual ~OWeakAggObject() SAL_OVERRIDE
;
90 /** weak reference to delegator.
92 css::uno::WeakReferenceHelper xDelegator
;
94 OWeakAggObject( const OWeakAggObject
& rObj
) SAL_DELETED_FUNCTION
;
95 OWeakAggObject
& operator = ( const OWeakAggObject
& rObj
)
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */