Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/tools/weakbase.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
#ifndef INCLUDED_TOOLS_WEAKBASE_HXX
21
#define INCLUDED_TOOLS_WEAKBASE_HXX
22
23
#include <tools/weakbase.h>
24
25
/// see weakbase.h for documentation
26
27
namespace tools
28
{
29
30
template< class reference_type >
31
inline WeakReference< reference_type >::WeakReference()
32
{
33
    mpWeakConnection = new WeakConnection;
34
}
35
36
template< class reference_type >
37
inline WeakReference< reference_type >::WeakReference( reference_type* pReference )
38
0
{
39
0
    reset( pReference );
40
0
}
41
42
template< class reference_type >
43
inline WeakReference< reference_type >::WeakReference( const WeakReference< reference_type >& rWeakRef )
44
{
45
    mpWeakConnection = rWeakRef.mpWeakConnection;
46
}
47
48
template< class reference_type >
49
inline WeakReference< reference_type >::WeakReference( WeakReference< reference_type >&& rWeakRef )
50
{
51
    mpWeakConnection = std::move(rWeakRef.mpWeakConnection);
52
    rWeakRef.reset();
53
}
54
55
template< class reference_type >
56
inline bool WeakReference< reference_type >::is() const
57
{
58
    return mpWeakConnection->mpReference != nullptr;
59
}
60
61
template< class reference_type >
62
inline reference_type * WeakReference< reference_type >::get() const
63
0
{
64
0
    auto pWeakBase = mpWeakConnection->mpReference;
65
0
    if (!pWeakBase)
66
0
        return nullptr;
67
0
    assert(dynamic_cast<reference_type *>(pWeakBase));
68
0
    return static_cast<reference_type *>(pWeakBase);
69
0
}
70
71
template< class reference_type >
72
inline void WeakReference< reference_type >::reset( reference_type* pReference )
73
0
{
74
0
    if( pReference )
75
0
        mpWeakConnection = pReference->getWeakConnection();
76
0
    else
77
0
        reset();
78
0
}
79
80
template< class reference_type >
81
inline void WeakReference< reference_type >::reset()
82
0
{
83
0
    mpWeakConnection = new WeakConnection;
84
0
}
85
86
template< class reference_type >
87
inline reference_type * WeakReference< reference_type >::operator->() const
88
{
89
    return get();
90
}
91
92
template< class reference_type >
93
inline reference_type& WeakReference< reference_type >::operator*() const
94
{
95
    return *get();
96
}
97
98
template< class reference_type >
99
inline bool WeakReference< reference_type >::operator==(const reference_type * pReferenceObject) const
100
{
101
    return mpWeakConnection->mpReference == pReferenceObject;
102
}
103
104
template< class reference_type >
105
inline bool WeakReference< reference_type >::operator==(const WeakReference<reference_type> & handle) const
106
{
107
    return mpWeakConnection == handle.mpWeakConnection;
108
}
109
110
template< class reference_type >
111
inline bool WeakReference< reference_type >::operator!=(const WeakReference<reference_type> & handle) const
112
{
113
    return mpWeakConnection != handle.mpWeakConnection;
114
}
115
116
template< class reference_type >
117
inline bool WeakReference< reference_type >::operator<(const WeakReference<reference_type> & handle) const
118
{
119
    return mpWeakConnection->mpReference < handle.mpWeakConnection->mpReference;
120
}
121
122
template< class reference_type >
123
inline bool WeakReference< reference_type >::operator>(const WeakReference<reference_type> & handle) const
124
{
125
    return mpWeakConnection->mpReference > handle.mpWeakConnection->mpReference;
126
}
127
128
template< class reference_type >
129
inline WeakReference<reference_type>& WeakReference<reference_type>::operator= (
130
    const WeakReference<reference_type>& rReference)
131
{
132
    if (&rReference != this)
133
        mpWeakConnection = rReference.mpWeakConnection;
134
    return *this;
135
}
136
137
template< class reference_type >
138
inline WeakReference<reference_type>& WeakReference<reference_type>::operator= (
139
    WeakReference<reference_type>&& rReference)
140
{
141
    mpWeakConnection = std::move(rReference.mpWeakConnection);
142
    return *this;
143
}
144
145
inline void WeakBase::clearWeak()
146
0
{
147
0
    if( mpWeakConnection.is() )
148
0
        mpWeakConnection->mpReference = nullptr;
149
0
}
150
151
inline WeakConnection* WeakBase::getWeakConnection()
152
0
{
153
0
    if( !mpWeakConnection.is() )
154
0
        mpWeakConnection = new WeakConnection( this );
155
0
    return mpWeakConnection.get();
156
0
}
157
158
}
159
160
#endif
161
162
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */