update emoji autocorrect entries from po-files
[LibreOffice.git] / include / rtl / ref.hxx
blob097584b1a276533164af9429c0edbdfbebe19cd7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <cassert>
27 #include <sal/types.h>
29 namespace rtl
32 /** Template reference class for reference type.
34 template <class reference_type>
35 class Reference
37 /** The <b>reference_type</b> body pointer.
39 reference_type * m_pBody;
42 public:
43 /** Constructor...
45 inline Reference()
46 : m_pBody (0)
50 /** Constructor...
52 inline Reference (reference_type * pBody, __sal_NoAcquire)
53 : m_pBody (pBody)
57 /** Constructor...
59 inline Reference (reference_type * pBody)
60 : m_pBody (pBody)
62 if (m_pBody)
63 m_pBody->acquire();
66 /** Copy constructor...
68 inline Reference (const Reference<reference_type> & handle)
69 : m_pBody (handle.m_pBody)
71 if (m_pBody)
72 m_pBody->acquire();
76 /** Destructor...
78 inline ~Reference()
80 if (m_pBody)
81 m_pBody->release();
84 /** Set...
85 Similar to assignment.
87 inline Reference<reference_type> &
88 SAL_CALL set (reference_type * pBody)
90 if (pBody)
91 pBody->acquire();
92 reference_type * const pOld = m_pBody;
93 m_pBody = pBody;
94 if (pOld)
95 pOld->release();
96 return *this;
99 /** Assignment.
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 );
109 /** Assignment...
111 inline Reference<reference_type> &
112 SAL_CALL operator= (reference_type * pBody)
114 return set( 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()
126 if (m_pBody)
128 reference_type * const pOld = m_pBody;
129 m_pBody = 0;
130 pOld->release();
132 return *this;
136 /** Get the body. Can be used instead of operator->().
137 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
138 are the same.
140 inline reference_type * SAL_CALL get() const
142 return m_pBody;
146 /** Probably most common used: handle->someBodyOp().
148 inline reference_type * SAL_CALL operator->() const
150 assert(m_pBody != 0);
151 return m_pBody;
155 /** Allows (*handle).someBodyOp().
157 inline reference_type & SAL_CALL operator*() const
159 assert(m_pBody != 0);
160 return *m_pBody;
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.
182 inline bool
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.
191 inline bool
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.
200 inline bool
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.
209 inline bool
210 SAL_CALL operator> (const Reference<reference_type> & handle) const
212 return (m_pBody > handle.m_pBody);
216 /// @cond INTERNAL
217 /** Enables boost::mem_fn and boost::bind to recognize Reference.
219 template <typename T>
220 inline T * get_pointer( Reference<T> const& r )
222 return r.get();
224 /// @endcond
226 } // namespace rtl
228 #endif /* ! INCLUDED_RTL_REF_HXX */
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */