LibreOffice: cppuhelper/weakref.hxx Source File

LibreOffice LibreOffice 7.3 SDK C/C++ API Reference

Loading...
Searching...
No Matches
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
20/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_CPPUHELPER_WEAKREF_HXX
24#define INCLUDED_CPPUHELPER_WEAKREF_HXX
25
26#include "sal/config.h"
27
28#include <cstddef>
29
30#include "com/sun/star/uno/Reference.hxx"
31#include "com/sun/star/uno/XInterface.hpp"
32#include "cppuhelper/cppuhelperdllapi.h"
33
34
35namespace com
36{
37namespace sun
38{
39namespace star
40{
41namespace uno
42{
43
44class OWeakRefListener;
45
55 class CPPUHELPER_DLLPUBLIC WeakReferenceHelper
56{
57public:
60 WeakReferenceHelper()
61 : m_pImpl( NULL )
62 {}
63
68 WeakReferenceHelper( const WeakReferenceHelper & rWeakRef );
69
70#if defined LIBO_INTERNAL_ONLY
71 WeakReferenceHelper(WeakReferenceHelper && other) noexcept : m_pImpl(other.m_pImpl)
72 { other.m_pImpl = nullptr; }
73#endif
74
80 WeakReferenceHelper( const css::uno::Reference< css::uno::XInterface > & xInt );
81
84 ~WeakReferenceHelper();
85
90 WeakReferenceHelper & SAL_CALL operator = ( const WeakReferenceHelper & rWeakRef );
91
92#if defined LIBO_INTERNAL_ONLY
93 WeakReferenceHelper & SAL_CALL operator =(WeakReferenceHelper && other);
94#endif
95
102 WeakReferenceHelper & SAL_CALL operator = (
103 const css::uno::Reference< css::uno::XInterface > & xInt );
104
110 bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const
111 { return (get() == rObj.get()); }
112
117 css::uno::Reference< css::uno::XInterface > SAL_CALL get() const;
118
123 SAL_CALL operator Reference< XInterface > () const
124 { return get(); }
125
130 void SAL_CALL clear();
131
132protected:
134 OWeakRefListener * m_pImpl;
136};
137
149template< class interface_type >
150 class SAL_WARN_UNUSED WeakReference : public WeakReferenceHelper
151{
152public:
155 WeakReference()
156 : WeakReferenceHelper()
157 {}
158
163 WeakReference( const Reference< interface_type > & rRef )
164 : WeakReferenceHelper( rRef )
165 {}
166
175 WeakReference & SAL_CALL operator = (
176 const css::uno::Reference< interface_type > & xInt )
177 { WeakReferenceHelper::operator=(xInt); return *this; }
178
179#if defined LIBO_INTERNAL_ONLY
180 WeakReference & SAL_CALL operator = (
181 css::uno::Reference< interface_type > && xInt )
182 { WeakReferenceHelper::operator=(std::move(xInt)); return *this; }
183#endif
184
189 SAL_CALL operator Reference< interface_type > () const
190 { return Reference< interface_type >::query( get() ); }
191};
192
193}
194}
195}
196}
197
198#endif
199
200/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
config.h
cppuhelperdllapi.h
CPPUHELPER_DLLPUBLIC
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:32
Reference.hxx
com
Definition: types.h:359
com::sun::star::uno::Reference
Template reference class for interface type derived from BaseReference.
Definition: Reference.h:184
com::sun::star::uno::WeakReferenceHelper
The WeakReferenceHelper holds a weak reference to an object.
Definition: weakref.hxx:56
com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper
WeakReferenceHelper(const css::uno::Reference< css::uno::XInterface > &xInt)
Initialize this reference with the hard interface reference xInt.
com::sun::star::uno::WeakReferenceHelper::get
css::uno::Reference< css::uno::XInterface > get() const
Gets a hard reference to the object.
com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper
WeakReferenceHelper(const WeakReferenceHelper &rWeakRef)
Copy ctor.
com::sun::star::uno::WeakReferenceHelper::~WeakReferenceHelper
~WeakReferenceHelper()
Releases this reference.
com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper
WeakReferenceHelper()
Default ctor.
Definition: weakref.hxx:60
com::sun::star::uno::WeakReferenceHelper::clear
void clear()
Releases this reference.
com::sun::star::uno::WeakReference
The WeakReference<> holds a weak reference to an object.
Definition: weakref.hxx:151
com::sun::star::uno::WeakReference::WeakReference
WeakReference()
Default ctor.
Definition: weakref.hxx:155
com::sun::star::uno::WeakReference::WeakReference
WeakReference(const Reference< interface_type > &rRef)
Copy ctor.
Definition: weakref.hxx:163