LibreOffice
LibreOffice 7.1 SDK C/C++ API Reference
weakref.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_CPPUHELPER_WEAKREF_HXX
20#define INCLUDED_CPPUHELPER_WEAKREF_HXX
21
22#include "sal/config.h"
23
24#include <cstddef>
25
27#include "com/sun/star/uno/XInterface.hpp"
29
30
31namespace com
32{
33namespace sun
34{
35namespace star
36{
37namespace uno
38{
39
40class OWeakRefListener;
41
52{
53public:
57 : m_pImpl( NULL )
58 {}
59
65
66#if defined LIBO_INTERNAL_ONLY
67 WeakReferenceHelper(WeakReferenceHelper && other) noexcept : m_pImpl(other.m_pImpl)
68 { other.m_pImpl = nullptr; }
69#endif
70
76 WeakReferenceHelper( const css::uno::Reference< css::uno::XInterface > & xInt );
77
81
86 WeakReferenceHelper & SAL_CALL operator = ( const WeakReferenceHelper & rWeakRef );
87
88#if defined LIBO_INTERNAL_ONLY
89 WeakReferenceHelper & SAL_CALL operator =(WeakReferenceHelper && other);
90#endif
91
98 WeakReferenceHelper & SAL_CALL operator = (
99 const css::uno::Reference< css::uno::XInterface > & xInt );
100
106 bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const
107 { return (get() == rObj.get()); }
108
113 css::uno::Reference< css::uno::XInterface > SAL_CALL get() const;
114
119 SAL_CALL operator Reference< XInterface > () const
120 { return get(); }
121
126 void SAL_CALL clear();
127
128protected:
130 OWeakRefListener * m_pImpl;
132};
133
145template< class interface_type >
147{
148public:
153 {}
154
160 : WeakReferenceHelper( rRef )
161 {}
162
171 WeakReference & SAL_CALL operator = (
172 const css::uno::Reference< interface_type > & xInt )
173 { WeakReferenceHelper::operator=(xInt); return *this; }
174
175#if defined LIBO_INTERNAL_ONLY
176 WeakReference & SAL_CALL operator = (
177 css::uno::Reference< interface_type > && xInt )
178 { WeakReferenceHelper::operator=(std::move(xInt)); return *this; }
179#endif
180
185 SAL_CALL operator Reference< interface_type > () const
186 { return Reference< interface_type >::query( get() ); }
187};
188
189}
190}
191}
192}
193
194#endif
195
196/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:558
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
Definition: types.h:355
bool operator==(const Any &rAny, const C &value)
Template equality operator: compares set value of left side any to right side value.
Definition: Any.hxx:653
Template reference class for interface type derived from BaseReference.
Definition: Reference.h:180
static SAL_WARN_UNUSED_RESULT Reference< interface_type > query(const BaseReference &rRef)
Queries given interface reference for type interface_type.
Definition: Reference.hxx:369
The WeakReferenceHelper holds a weak reference to an object.
Definition: weakref.hxx:52
WeakReferenceHelper(const css::uno::Reference< css::uno::XInterface > &xInt)
Initialize this reference with the hard interface reference xInt.
css::uno::Reference< css::uno::XInterface > get() const
Gets a hard reference to the object.
WeakReferenceHelper(const WeakReferenceHelper &rWeakRef)
Copy ctor.
~WeakReferenceHelper()
Releases this reference.
WeakReferenceHelper & operator=(const WeakReferenceHelper &rWeakRef)
Releases this reference and takes over rWeakRef.
WeakReferenceHelper()
Default ctor.
Definition: weakref.hxx:56
void clear()
Releases this reference.
The WeakReference<> holds a weak reference to an object.
Definition: weakref.hxx:147
WeakReference()
Default ctor.
Definition: weakref.hxx:151
WeakReference(const Reference< interface_type > &rRef)
Copy ctor.
Definition: weakref.hxx:159