Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/cppuhelper/weakagg.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
/*
21
 * This file is part of LibreOffice published API.
22
 */
23
#ifndef INCLUDED_CPPUHELPER_WEAKAGG_HXX
24
#define INCLUDED_CPPUHELPER_WEAKAGG_HXX
25
26
#include "cppuhelper/weak.hxx"
27
#include "cppuhelper/weakref.hxx"
28
#include "com/sun/star/uno/XAggregation.hpp"
29
#include "cppuhelper/cppuhelperdllapi.h"
30
31
32
namespace cppu
33
{
34
35
/** Base class to implement a UNO object supporting weak references, i.e. the object can be held
36
    weakly (by a css::uno::WeakReference) and aggregation, i.e. the object can be
37
    aggregated by another (delegator).
38
    This implementation copes with reference counting.  Upon last release(), the virtual dtor
39
    is called.
40
41
    @derive
42
    Inherit from this class and delegate acquire()/ release() calls.  Re-implement
43
    XAggregation::queryInterface().
44
*/
45
class CPPUHELPER_DLLPUBLIC OWeakAggObject
46
    : public ::cppu::OWeakObject
47
    , public css::uno::XAggregation
48
{
49
public:
50
    /** Constructor.  No delegator set.
51
    */
52
    OWeakAggObject()
53
1.18M
        {}
54
55
    /** If a delegator is set, then the delegators gets acquired.  Otherwise call is delegated to
56
        base class ::cppu::OWeakObject.
57
    */
58
    virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE;
59
    /** If a delegator is set, then the delegators gets released.  Otherwise call is delegated to
60
        base class ::cppu::OWeakObject.
61
    */
62
    virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE;
63
    /** If a delegator is set, then the delegator is queried for the demanded interface.  If the
64
        delegator cannot provide the demanded interface, it calls queryAggregation() on its
65
        aggregated objects.
66
67
        @param rType demanded interface type
68
        @return demanded type or empty any
69
        @see queryAggregation.
70
    */
71
    virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) SAL_OVERRIDE;
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 css::uno::Reference< css::uno::XInterface > & Delegator ) SAL_OVERRIDE;
78
    /** Called by the delegator or queryInterface. Re-implement this method instead of
79
        queryInterface.
80
81
        @see queryInterface
82
    */
83
    virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type & rType ) SAL_OVERRIDE;
84
85
protected:
86
    /** Virtual dtor. Called when reference count is 0.
87
88
        @attention
89
        Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
90
        exception upon destruction!
91
    */
92
    virtual ~OWeakAggObject() SAL_OVERRIDE;
93
94
    /** weak reference to delegator.
95
    */
96
    css::uno::WeakReferenceHelper xDelegator;
97
private:
98
    OWeakAggObject( const OWeakAggObject & rObj ) SAL_DELETED_FUNCTION;
99
    OWeakAggObject & operator = ( const OWeakAggObject & rObj )
100
        SAL_DELETED_FUNCTION;
101
};
102
103
}
104
105
#endif
106
107
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */