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
)
85 Similar to assignment.
87 inline Reference
<reference_type
> &
88 SAL_CALL
set (reference_type
* pBody
)
92 reference_type
* const pOld
= m_pBody
;
100 Unbinds this instance from its body (if bound) and
101 bind it to the body represented by the handle.
103 inline Reference
<reference_type
> &
104 SAL_CALL
operator= (const Reference
<reference_type
> & handle
)
106 return set( handle
.m_pBody
);
111 inline Reference
<reference_type
> &
112 SAL_CALL
operator= (reference_type
* pBody
)
117 /** Unbind the body from this handle.
118 Note that for a handle representing a large body,
119 "handle.clear().set(new body());" _might_
120 perform a little bit better than "handle.set(new body());",
121 since in the second case two large objects exist in memory
122 (the old body and the new body).
124 inline Reference
<reference_type
> & SAL_CALL
clear()
128 reference_type
* const pOld
= m_pBody
;
136 /** Get the body. Can be used instead of operator->().
137 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
140 inline reference_type
* SAL_CALL
get() const
146 /** Probably most common used: handle->someBodyOp().
148 inline reference_type
* SAL_CALL
operator->() const
150 assert(m_pBody
!= 0);
155 /** Allows (*handle).someBodyOp().
157 inline reference_type
& SAL_CALL
operator*() const
159 assert(m_pBody
!= 0);
164 /** Returns True if the handle does point to a valid body.
166 inline bool SAL_CALL
is() const
168 return (m_pBody
!= 0);
172 /** Returns True if this points to pBody.
174 inline bool SAL_CALL
operator== (const reference_type
* pBody
) const
176 return (m_pBody
== pBody
);
180 /** Returns True if handle points to the same body.
183 SAL_CALL
operator== (const Reference
<reference_type
> & handle
) const
185 return (m_pBody
== handle
.m_pBody
);
189 /** Needed to place References into STL collection.
192 SAL_CALL
operator!= (const Reference
<reference_type
> & handle
) const
194 return (m_pBody
!= handle
.m_pBody
);
198 /** Needed to place References into STL collection.
201 SAL_CALL
operator< (const Reference
<reference_type
> & handle
) const
203 return (m_pBody
< handle
.m_pBody
);
207 /** Needed to place References into STL collection.
210 SAL_CALL
operator> (const Reference
<reference_type
> & handle
) const
212 return (m_pBody
> handle
.m_pBody
);
217 /** Enables boost::mem_fn and boost::bind to recognize Reference.
219 template <typename T
>
220 inline T
* get_pointer( Reference
<T
> const& r
)
228 #endif /* ! INCLUDED_RTL_REF_HXX */
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */