LibreOffice: cppuhelper/weakref.hxx Source File

LibreOffice LibreOffice 26.8 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;
45class XWeak;
46
56 class CPPUHELPER_DLLPUBLIC WeakReferenceHelper
57{
58public:
61 WeakReferenceHelper()
62 : m_pImpl( NULL )
63 {}
64
69 WeakReferenceHelper( const WeakReferenceHelper & rWeakRef );
70
71#if defined LIBO_INTERNAL_ONLY
72 WeakReferenceHelper(WeakReferenceHelper && other) noexcept : m_pImpl(other.m_pImpl)
73 { other.m_pImpl = nullptr; }
74#endif
75
81 WeakReferenceHelper( const css::uno::Reference< css::uno::XInterface > & xInt );
82
83#if defined LIBO_INTERNAL_ONLY
90 WeakReferenceHelper( const css::uno::Reference< css::uno::XWeak > & xWeak );
91#endif
92
95 ~WeakReferenceHelper();
96
101 WeakReferenceHelper & SAL_CALL operator = ( const WeakReferenceHelper & rWeakRef );
102
103#if defined LIBO_INTERNAL_ONLY
104 WeakReferenceHelper & operator =(WeakReferenceHelper && other);
105#endif
106
113 WeakReferenceHelper & SAL_CALL operator = (
114 const css::uno::Reference< css::uno::XInterface > & xInt );
115
116#if defined LIBO_INTERNAL_ONLY
123 WeakReferenceHelper & operator = (
124 const css::uno::Reference< css::uno::XWeak > & xWeak );
125#endif
126
132 bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const
133 { return (get() == rObj.get()); }
134
139 css::uno::Reference< css::uno::XInterface > SAL_CALL get() const;
140
145 SAL_CALL operator Reference< XInterface > () const
146 { return get(); }
147
152 void SAL_CALL clear();
153
154protected:
156 OWeakRefListener * m_pImpl;
158};
159
171template< class interface_type >
172 class SAL_WARN_UNUSED WeakReference : public WeakReferenceHelper
173{
174public:
177 WeakReference()
178 : WeakReferenceHelper()
179 {}
180
185 WeakReference( const Reference< interface_type > & rRef )
186 : WeakReferenceHelper( rRef )
187 {}
188
197 WeakReference & SAL_CALL operator = (
198 const css::uno::Reference< interface_type > & xInt )
199 { WeakReferenceHelper::operator=(xInt); return *this; }
200
201#if defined LIBO_INTERNAL_ONLY
208 WeakReference & operator = (
209 const css::uno::Reference< css::uno::XWeak > & xWeak )
210 { WeakReferenceHelper::operator=(xWeak); return *this; }
211#endif
212
217 SAL_CALL operator Reference< interface_type > () const
218 { return Reference< interface_type >::query( get() ); }
219};
220
221}
222}
223}
224}
225
226#endif
227
228/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
config.h
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition types.h:611
cppuhelperdllapi.h
CPPUHELPER_DLLPUBLIC
#define CPPUHELPER_DLLPUBLIC
Definition cppuhelperdllapi.h:32
Reference.hxx
com
Definition types.h:377
com::sun
Definition types.h:377
com::sun::star
Definition types.h:377
com::sun::star::uno
Definition typedescription.hxx:43
com::sun::star::uno::Reference< css::uno::XInterface >
com::sun::star::uno::Reference::query
static SAL_WARN_UNUSED_RESULT Reference< interface_type > query(const BaseReference &rRef)
Queries given interface reference for type interface_type.
Definition Reference.hxx:376
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::operator=
WeakReferenceHelper & operator=(const WeakReferenceHelper &rWeakRef)
Releases this reference and takes over rWeakRef.
com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper
WeakReferenceHelper()
Default ctor.
Definition weakref.hxx:61
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:173
com::sun::star::uno::WeakReference::WeakReference
WeakReference()
Default ctor.
Definition weakref.hxx:177
com::sun::star::uno::WeakReference::WeakReference
WeakReference(const Reference< interface_type > &rRef)
Copy ctor.
Definition weakref.hxx:185