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_RTL_REF_HXX
21 #define INCLUDED_RTL_REF_HXX
23 #include <sal/config.h>
27 #include <sal/types.h>
32 /** Template reference class for reference type.
34 template <class reference_type
>
37 /** The <b>reference_type</b> body pointer.
39 reference_type
* m_pBody
;
52 inline Reference (reference_type
* pBody
, __sal_NoAcquire
)
59 inline Reference (reference_type
* pBody
)
66 /** Copy constructor...
68 inline Reference (const Reference
<reference_type
> & handle
)
69 : m_pBody (handle
.m_pBody
)
75 #ifdef LIBO_INTERNAL_ONLY
76 /** Move constructor...
78 inline Reference (Reference
<reference_type
> && handle
)
79 : m_pBody (handle
.m_pBody
)
81 handle
.m_pBody
= nullptr;
94 Similar to assignment.
96 inline Reference
<reference_type
> &
97 SAL_CALL
set (reference_type
* pBody
)
101 reference_type
* const pOld
= m_pBody
;
109 Unbinds this instance from its body (if bound) and
110 bind it to the body represented by the handle.
112 inline Reference
<reference_type
> &
113 SAL_CALL
operator= (const Reference
<reference_type
> & handle
)
115 return set( handle
.m_pBody
);
118 #ifdef LIBO_INTERNAL_ONLY
120 * Unbinds this instance from its body (if bound),
121 * bind it to the body represented by the handle, and
122 * set the body represented by the handle to nullptr.
124 inline Reference
<reference_type
> &
125 operator= (Reference
<reference_type
> && handle
)
127 // self-movement guts ourself
130 m_pBody
= handle
.m_pBody
;
131 handle
.m_pBody
= nullptr;
138 inline Reference
<reference_type
> &
139 SAL_CALL
operator= (reference_type
* pBody
)
144 /** Unbind the body from this handle.
145 Note that for a handle representing a large body,
146 "handle.clear().set(new body());" _might_
147 perform a little bit better than "handle.set(new body());",
148 since in the second case two large objects exist in memory
149 (the old body and the new body).
151 inline Reference
<reference_type
> & SAL_CALL
clear()
155 reference_type
* const pOld
= m_pBody
;
163 /** Get the body. Can be used instead of operator->().
164 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
167 inline reference_type
* SAL_CALL
get() const
173 /** Probably most common used: handle->someBodyOp().
175 inline reference_type
* SAL_CALL
operator->() const
177 assert(m_pBody
!= NULL
);
182 /** Allows (*handle).someBodyOp().
184 inline reference_type
& SAL_CALL
operator*() const
186 assert(m_pBody
!= NULL
);
191 /** Returns True if the handle does point to a valid body.
193 inline bool SAL_CALL
is() const
195 return (m_pBody
!= NULL
);
199 /** Returns True if this points to pBody.
201 inline bool SAL_CALL
operator== (const reference_type
* pBody
) const
203 return (m_pBody
== pBody
);
207 /** Returns True if handle points to the same body.
210 SAL_CALL
operator== (const Reference
<reference_type
> & handle
) const
212 return (m_pBody
== handle
.m_pBody
);
216 /** Needed to place References into STL collection.
219 SAL_CALL
operator!= (const Reference
<reference_type
> & handle
) const
221 return (m_pBody
!= handle
.m_pBody
);
225 /** Needed to place References into STL collection.
228 SAL_CALL
operator< (const Reference
<reference_type
> & handle
) const
230 return (m_pBody
< handle
.m_pBody
);
234 /** Needed to place References into STL collection.
237 SAL_CALL
operator> (const Reference
<reference_type
> & handle
) const
239 return (m_pBody
> handle
.m_pBody
);
245 #endif /* ! INCLUDED_RTL_REF_HXX */
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */