1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_TOOLS_WEAKBASE_HXX
21 #define INCLUDED_TOOLS_WEAKBASE_HXX
23 #include <tools/weakbase.h>
25 /// see weakbase.h for documentation
30 template< class reference_type
>
31 inline WeakReference
< reference_type
>::WeakReference()
33 mpWeakConnection
= new WeakConnection
<reference_type
>( 0 );
36 template< class reference_type
>
37 inline WeakReference
< reference_type
>::WeakReference( reference_type
* pReference
)
40 mpWeakConnection
= pReference
->getWeakConnection();
42 mpWeakConnection
= new WeakConnection
<reference_type
>( 0 );
45 template< class reference_type
>
46 inline WeakReference
< reference_type
>::WeakReference( const WeakReference
< reference_type
>& rWeakRef
)
48 mpWeakConnection
= rWeakRef
.mpWeakConnection
;
51 template< class reference_type
>
52 inline WeakReference
< reference_type
>::WeakReference( WeakReference
< reference_type
>&& rWeakRef
)
54 mpWeakConnection
= std::move(rWeakRef
.mpWeakConnection
);
57 template< class reference_type
>
58 inline bool WeakReference
< reference_type
>::is() const
60 return mpWeakConnection
->mpReference
!= 0;
63 template< class reference_type
>
64 inline reference_type
* WeakReference
< reference_type
>::get() const
66 return mpWeakConnection
->mpReference
;
69 template< class reference_type
>
70 inline void WeakReference
< reference_type
>::reset( reference_type
* pReference
)
73 mpWeakConnection
= pReference
->getWeakConnection();
75 mpWeakConnection
= new WeakConnection
<reference_type
>( 0 );
78 template< class reference_type
>
79 inline reference_type
* WeakReference
< reference_type
>::operator->() const
81 OSL_PRECOND(mpWeakConnection
.is(), "tools::WeakReference::operator->() : null body");
82 return mpWeakConnection
->mpReference
;
85 template< class reference_type
>
86 inline bool WeakReference
< reference_type
>::operator==(const reference_type
* pReferenceObject
) const
88 return mpWeakConnection
->mpReference
== pReferenceObject
;
91 template< class reference_type
>
92 inline bool WeakReference
< reference_type
>::operator==(const WeakReference
<reference_type
> & handle
) const
94 return mpWeakConnection
== handle
.mpWeakConnection
;
97 template< class reference_type
>
98 inline bool WeakReference
< reference_type
>::operator!=(const WeakReference
<reference_type
> & handle
) const
100 return mpWeakConnection
!= handle
.mpWeakConnection
;
103 template< class reference_type
>
104 inline bool WeakReference
< reference_type
>::operator<(const WeakReference
<reference_type
> & handle
) const
106 return mpWeakConnection
->mpReference
< handle
.mpWeakConnection
->mpReference
;
109 template< class reference_type
>
110 inline bool WeakReference
< reference_type
>::operator>(const WeakReference
<reference_type
> & handle
) const
112 return mpWeakConnection
->mpReference
> handle
.mpWeakConnection
->mpReference
;
115 template< class reference_type
>
116 inline WeakReference
<reference_type
>& WeakReference
<reference_type
>::operator= (
117 const WeakReference
<reference_type
>& rReference
)
119 if (&rReference
!= this)
121 mpWeakConnection
= rReference
.mpWeakConnection
;
126 template< class reference_type
>
127 inline WeakReference
<reference_type
>& WeakReference
<reference_type
>::operator= (
128 WeakReference
<reference_type
>&& rReference
)
130 mpWeakConnection
= std::move(rReference
.mpWeakConnection
);
134 template< class reference_type
>
135 inline WeakBase
< reference_type
>::WeakBase()
139 template< class reference_type
>
140 inline WeakBase
< reference_type
>::~WeakBase()
142 if( mpWeakConnection
.is() )
144 mpWeakConnection
->mpReference
= 0;
148 template< class reference_type
>
149 inline void WeakBase
< reference_type
>::clearWeak()
151 if( mpWeakConnection
.is() )
152 mpWeakConnection
->mpReference
= 0;
155 template< class reference_type
>
156 inline WeakConnection
< reference_type
>* WeakBase
< reference_type
>::getWeakConnection()
158 if( !mpWeakConnection
.is() )
160 mpWeakConnection
= new WeakConnection
< reference_type
>( static_cast< reference_type
* >( this ) );
162 return mpWeakConnection
.get();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */