LibreOffice
LibreOffice 24.2 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 
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 
31 #include "com/sun/star/uno/XInterface.hpp"
33 
34 
35 namespace com
36 {
37 namespace sun
38 {
39 namespace star
40 {
41 namespace uno
42 {
43 
44 class OWeakRefListener;
45 class XWeak;
46 
57 {
58 public:
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
84 
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
117 
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 
154 protected:
156  OWeakRefListener * m_pImpl;
158 };
159 
171 template< class interface_type >
173 {
174 public:
179  {}
180 
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
202 
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: */
static SAL_WARN_UNUSED_RESULT Reference< interface_type > query(const BaseReference &rRef)
Queries given interface reference for type interface_type.
Definition: Reference.hxx:373
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:664
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:587
Definition: types.h:359
Template reference class for interface type derived from BaseReference.
Definition: unotype.hxx:43
WeakReference(const Reference< interface_type > &rRef)
Copy ctor.
Definition: weakref.hxx:185
WeakReferenceHelper & operator=(const WeakReferenceHelper &rWeakRef)
Releases this reference and takes over rWeakRef.
css::uno::Reference< css::uno::XInterface > get() const
Gets a hard reference to the object.
The WeakReference<> holds a weak reference to an object.
Definition: weakref.hxx:172
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:32
WeakReference()
Default ctor.
Definition: weakref.hxx:177
The WeakReferenceHelper holds a weak reference to an object.
Definition: weakref.hxx:56
WeakReferenceHelper()
Default ctor.
Definition: weakref.hxx:61