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 );
34 mpWeakConnection
->acquire();
37 template< class reference_type
>
38 inline WeakReference
< reference_type
>::WeakReference( reference_type
* pReference
)
41 mpWeakConnection
= pReference
->getWeakConnection();
43 mpWeakConnection
= new WeakConnection
<reference_type
>( 0 );
45 mpWeakConnection
->acquire();
48 template< class reference_type
>
49 inline WeakReference
< reference_type
>::WeakReference( const WeakReference
< reference_type
>& rWeakRef
)
51 mpWeakConnection
= rWeakRef
.mpWeakConnection
;
52 mpWeakConnection
->acquire();
55 template< class reference_type
>
56 inline WeakReference
< reference_type
>::~WeakReference()
58 mpWeakConnection
->release();
61 template< class reference_type
>
62 inline bool WeakReference
< reference_type
>::is() const
64 return mpWeakConnection
->mpReference
!= 0;
67 template< class reference_type
>
68 inline reference_type
* WeakReference
< reference_type
>::get() const
70 return mpWeakConnection
->mpReference
;
73 template< class reference_type
>
74 inline void WeakReference
< reference_type
>::reset( reference_type
* pReference
)
76 mpWeakConnection
->release();
79 mpWeakConnection
= pReference
->getWeakConnection();
81 mpWeakConnection
= new WeakConnection
<reference_type
>( 0 );
83 mpWeakConnection
->acquire();
86 template< class reference_type
>
87 inline reference_type
* WeakReference
< reference_type
>::operator->() const
89 OSL_PRECOND(mpWeakConnection
, "tools::WeakReference::operator->() : null body");
90 return mpWeakConnection
->mpReference
;
93 template< class reference_type
>
94 inline bool WeakReference
< reference_type
>::operator==(const reference_type
* pReferenceObject
) const
96 return mpWeakConnection
->mpReference
== pReferenceObject
;
99 template< class reference_type
>
100 inline bool WeakReference
< reference_type
>::operator==(const WeakReference
<reference_type
> & handle
) const
102 return mpWeakConnection
== handle
.mpWeakConnection
;
105 template< class reference_type
>
106 inline bool WeakReference
< reference_type
>::operator!=(const WeakReference
<reference_type
> & handle
) const
108 return mpWeakConnection
!= handle
.mpWeakConnection
;
111 template< class reference_type
>
112 inline bool WeakReference
< reference_type
>::operator<(const WeakReference
<reference_type
> & handle
) const
114 return mpWeakConnection
->mpReference
< handle
.mpWeakConnection
->mpReference
;
117 template< class reference_type
>
118 inline bool WeakReference
< reference_type
>::operator>(const WeakReference
<reference_type
> & handle
) const
120 return mpWeakConnection
->mpReference
> handle
.mpWeakConnection
->mpReference
;
123 template< class reference_type
>
124 inline WeakReference
<reference_type
>& WeakReference
<reference_type
>::operator= (
125 const WeakReference
<reference_type
>& rReference
)
127 if (&rReference
!= this)
129 mpWeakConnection
->release();
131 mpWeakConnection
= rReference
.mpWeakConnection
;
132 mpWeakConnection
->acquire();
137 template< class reference_type
>
138 inline WeakBase
< reference_type
>::WeakBase()
140 mpWeakConnection
= 0;
143 template< class reference_type
>
144 inline WeakBase
< reference_type
>::~WeakBase()
146 if( mpWeakConnection
)
148 mpWeakConnection
->mpReference
= 0;
149 mpWeakConnection
->release();
150 mpWeakConnection
= 0;
154 template< class reference_type
>
155 inline void WeakBase
< reference_type
>::clearWeak()
157 if( mpWeakConnection
)
158 mpWeakConnection
->mpReference
= 0;
161 template< class reference_type
>
162 inline WeakConnection
< reference_type
>* WeakBase
< reference_type
>::getWeakConnection()
164 if( !mpWeakConnection
)
166 mpWeakConnection
= new WeakConnection
< reference_type
>( static_cast< reference_type
* >( this ) );
167 mpWeakConnection
->acquire();
169 return mpWeakConnection
;
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */