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/types.h>
24 #include <osl/diagnose.h>
25 #include <osl/interlck.h>
30 /** Interface for a reference type.
35 /** @see osl_incrementInterlockedCount.
37 virtual oslInterlockedCount SAL_CALL
acquire() = 0;
39 /** @see osl_decrementInterlockedCount.
41 virtual oslInterlockedCount SAL_CALL
release() = 0;
43 #if !defined _MSC_VER // public -> protected changes mangled names there
47 // avoid warnings about virtual members and non-virtual dtor
51 /** Template reference class for reference type derived from IReference.
53 template <class reference_type
>
56 /** The <b>reference_type</b> body pointer.
58 reference_type
* m_pBody
;
71 inline Reference (reference_type
* pBody
)
79 /** Copy constructor...
81 inline Reference (const Reference
<reference_type
> & handle
)
82 : m_pBody (handle
.m_pBody
)
98 Similar to assignment.
100 inline Reference
<reference_type
> &
101 SAL_CALL
set (reference_type
* pBody
)
105 reference_type
* const pOld
= m_pBody
;
113 Unbinds this instance from its body (if bound) and
114 bind it to the body represented by the handle.
116 inline Reference
<reference_type
> &
117 SAL_CALL
operator= (const Reference
<reference_type
> & handle
)
119 return set( handle
.m_pBody
);
124 inline Reference
<reference_type
> &
125 SAL_CALL
operator= (reference_type
* pBody
)
130 /** Unbind the body from this handle.
131 Note that for a handle representing a large body,
132 "handle.clear().set(new body());" _might_
133 perform a little bit better than "handle.set(new body());",
134 since in the second case two large objects exist in memory
135 (the old body and the new body).
137 inline Reference
<reference_type
> & SAL_CALL
clear()
141 reference_type
* const pOld
= m_pBody
;
149 /** Get the body. Can be used instead of operator->().
150 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
153 inline reference_type
* SAL_CALL
get() const
159 /** Probably most common used: handle->someBodyOp().
161 inline reference_type
* SAL_CALL
operator->() const
163 OSL_PRECOND(m_pBody
, "Reference::operator->() : null body");
168 /** Allows (*handle).someBodyOp().
170 inline reference_type
& SAL_CALL
operator*() const
172 OSL_PRECOND(m_pBody
, "Reference::operator*() : null body");
177 /** Returns True if the handle does point to a valid body.
179 inline sal_Bool SAL_CALL
is() const
181 return (m_pBody
!= 0);
185 /** Returns True if this points to pBody.
187 inline sal_Bool SAL_CALL
operator== (const reference_type
* pBody
) const
189 return (m_pBody
== pBody
);
193 /** Returns True if handle points to the same body.
196 SAL_CALL
operator== (const Reference
<reference_type
> & handle
) const
198 return (m_pBody
== handle
.m_pBody
);
202 /** Needed to place References into STL collection.
205 SAL_CALL
operator!= (const Reference
<reference_type
> & handle
) const
207 return (m_pBody
!= handle
.m_pBody
);
211 /** Needed to place References into STL collection.
214 SAL_CALL
operator< (const Reference
<reference_type
> & handle
) const
216 return (m_pBody
< handle
.m_pBody
);
220 /** Needed to place References into STL collection.
223 SAL_CALL
operator> (const Reference
<reference_type
> & handle
) const
225 return (m_pBody
> handle
.m_pBody
);
230 /** Enables boost::mem_fn and boost::bind to recognize Reference.
232 template <typename T
>
233 inline T
* get_pointer( Reference
<T
> const& r
)
241 #endif /* ! INCLUDED_RTL_REF_HXX */
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */