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
;
36 template< class reference_type
>
37 inline WeakReference
< reference_type
>::WeakReference( reference_type
* pReference
)
42 template< class reference_type
>
43 inline WeakReference
< reference_type
>::WeakReference( const WeakReference
< reference_type
>& rWeakRef
)
45 mpWeakConnection
= rWeakRef
.mpWeakConnection
;
48 template< class reference_type
>
49 inline WeakReference
< reference_type
>::WeakReference( WeakReference
< reference_type
>&& rWeakRef
)
51 mpWeakConnection
= std::move(rWeakRef
.mpWeakConnection
);
55 template< class reference_type
>
56 inline bool WeakReference
< reference_type
>::is() const
58 return mpWeakConnection
->mpReference
!= nullptr;
61 template< class reference_type
>
62 inline reference_type
* WeakReference
< reference_type
>::get() const
64 auto pWeakBase
= mpWeakConnection
->mpReference
;
67 assert(dynamic_cast<reference_type
*>(pWeakBase
));
68 return static_cast<reference_type
*>(pWeakBase
);
71 template< class reference_type
>
72 inline void WeakReference
< reference_type
>::reset( reference_type
* pReference
)
75 mpWeakConnection
= pReference
->getWeakConnection();
80 template< class reference_type
>
81 inline void WeakReference
< reference_type
>::reset()
83 mpWeakConnection
= new WeakConnection
;
86 template< class reference_type
>
87 inline reference_type
* WeakReference
< reference_type
>::operator->() const
92 template< class reference_type
>
93 inline bool WeakReference
< reference_type
>::operator==(const reference_type
* pReferenceObject
) const
95 return mpWeakConnection
->mpReference
== pReferenceObject
;
98 template< class reference_type
>
99 inline bool WeakReference
< reference_type
>::operator==(const WeakReference
<reference_type
> & handle
) const
101 return mpWeakConnection
== handle
.mpWeakConnection
;
104 template< class reference_type
>
105 inline bool WeakReference
< reference_type
>::operator!=(const WeakReference
<reference_type
> & handle
) const
107 return mpWeakConnection
!= handle
.mpWeakConnection
;
110 template< class reference_type
>
111 inline bool WeakReference
< reference_type
>::operator<(const WeakReference
<reference_type
> & handle
) const
113 return mpWeakConnection
->mpReference
< handle
.mpWeakConnection
->mpReference
;
116 template< class reference_type
>
117 inline bool WeakReference
< reference_type
>::operator>(const WeakReference
<reference_type
> & handle
) const
119 return mpWeakConnection
->mpReference
> handle
.mpWeakConnection
->mpReference
;
122 template< class reference_type
>
123 inline WeakReference
<reference_type
>& WeakReference
<reference_type
>::operator= (
124 const WeakReference
<reference_type
>& rReference
)
126 if (&rReference
!= this)
127 mpWeakConnection
= rReference
.mpWeakConnection
;
131 template< class reference_type
>
132 inline WeakReference
<reference_type
>& WeakReference
<reference_type
>::operator= (
133 WeakReference
<reference_type
>&& rReference
)
135 mpWeakConnection
= std::move(rReference
.mpWeakConnection
);
139 inline void WeakBase::clearWeak()
141 if( mpWeakConnection
.is() )
142 mpWeakConnection
->mpReference
= nullptr;
145 inline WeakConnection
* WeakBase::getWeakConnection()
147 if( !mpWeakConnection
.is() )
148 mpWeakConnection
= new WeakConnection( this );
149 return mpWeakConnection
.get();
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */