LibreOffice: rtl/ref.hxx Source File

LibreOffice LibreOffice 5.3 SDK C/C++ API Reference

ref.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #ifndef INCLUDED_RTL_REF_HXX
21 #define INCLUDED_RTL_REF_HXX
22
23 #include <sal/config.h>
24
25 #include <cassert>
26
27 #include <sal/types.h>
28
29 namespace rtl
30 {
31
34 template <class reference_type>
35 class Reference
36 {
39 reference_type * m_pBody;
40
41
42 public:
45 inline Reference()
46 : m_pBody (NULL)
47 {}
48
49
52 inline Reference (reference_type * pBody, __sal_NoAcquire)
53 : m_pBody (pBody)
54 {
55 }
56
59 inline Reference (reference_type * pBody)
60 : m_pBody (pBody)
61 {
62 if (m_pBody)
63 m_pBody->acquire();
64 }
65
68 inline Reference (const Reference<reference_type> & handle)
69 : m_pBody (handle.m_pBody)
70 {
71 if (m_pBody)
72 m_pBody->acquire();
73 }
74
75 #ifdef LIBO_INTERNAL_ONLY
76
78 inline Reference (Reference<reference_type> && handle)
79 : m_pBody (handle.m_pBody)
80 {
81 handle.m_pBody = nullptr;
82 }
83 #endif
84
87 inline ~Reference()
88 {
89 if (m_pBody)
90 m_pBody->release();
91 }
92
96 inline Reference<reference_type> &
97 SAL_CALL set (reference_type * pBody)
98 {
99 if (pBody)
100 pBody->acquire();
101 reference_type * const pOld = m_pBody;
102 m_pBody = pBody;
103 if (pOld)
104 pOld->release();
105 return *this;
106 }
107
112 inline Reference<reference_type> &
113 SAL_CALL operator= (const Reference<reference_type> & handle)
114 {
115 return set( handle.m_pBody );
116 }
117
118 #ifdef LIBO_INTERNAL_ONLY
119
124 inline Reference<reference_type> &
125 operator= (Reference<reference_type> && handle)
126 {
127 // self-movement guts ourself
128 if (m_pBody)
129 m_pBody->release();
130 m_pBody = handle.m_pBody;
131 handle.m_pBody = nullptr;
132 return *this;
133 }
134 #endif
135
138 inline Reference<reference_type> &
139 SAL_CALL operator= (reference_type * pBody)
140 {
141 return set( pBody );
142 }
143
151 inline Reference<reference_type> & SAL_CALL clear()
152 {
153 if (m_pBody)
154 {
155 reference_type * const pOld = m_pBody;
156 m_pBody = NULL;
157 pOld->release();
158 }
159 return *this;
160 }
161
162
167 inline reference_type * SAL_CALL get() const
168 {
169 return m_pBody;
170 }
171
172
175 inline reference_type * SAL_CALL operator->() const
176 {
177 assert(m_pBody != NULL);
178 return m_pBody;
179 }
180
181
184 inline reference_type & SAL_CALL operator*() const
185 {
186 assert(m_pBody != NULL);
187 return *m_pBody;
188 }
189
190
193 inline bool SAL_CALL is() const
194 {
195 return (m_pBody != NULL);
196 }
197
198
201 inline bool SAL_CALL operator== (const reference_type * pBody) const
202 {
203 return (m_pBody == pBody);
204 }
205
206
209 inline bool
210 SAL_CALL operator== (const Reference<reference_type> & handle) const
211 {
212 return (m_pBody == handle.m_pBody);
213 }
214
215
218 inline bool
219 SAL_CALL operator!= (const Reference<reference_type> & handle) const
220 {
221 return (m_pBody != handle.m_pBody);
222 }
223
224
227 inline bool
228 SAL_CALL operator< (const Reference<reference_type> & handle) const
229 {
230 return (m_pBody < handle.m_pBody);
231 }
232
233
236 inline bool
237 SAL_CALL operator> (const Reference<reference_type> & handle) const
238 {
239 return (m_pBody > handle.m_pBody);
240 }
241 };
242
243 } // namespace rtl
244
245 #endif /* ! INCLUDED_RTL_REF_HXX */
246
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference::operator*
reference_type & operator*() const
Allows (*handle).someBodyOp().
Definition: ref.hxx:184
rtl::Reference::Reference
Reference(const Reference< reference_type > &handle)
Copy constructor...
Definition: ref.hxx:68
rtl::Reference::Reference
Reference(reference_type *pBody)
Constructor...
Definition: ref.hxx:59
rtl::Reference::~Reference
~Reference()
Destructor...
Definition: ref.hxx:87
rtl::Reference::is
bool is() const
Returns True if the handle does point to a valid body.
Definition: ref.hxx:193
rtl::Reference::Reference
Reference(reference_type *pBody, __sal_NoAcquire)
Constructor...
Definition: ref.hxx:52
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:384
rtl::Reference::Reference
Reference()
Constructor...
Definition: ref.hxx:45
rtl::Reference::operator=
Reference< reference_type > & operator=(const Reference< reference_type > &handle)
Assignment.
Definition: ref.hxx:113
types.h
config.h
rtl::Reference::operator!=
bool operator!=(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:219
rtl::Reference::operator==
bool operator==(const reference_type *pBody) const
Returns True if this points to pBody.
Definition: ref.hxx:201
rtl::Reference::operator->
reference_type * operator->() const
Probably most common used: handle->someBodyOp().
Definition: ref.hxx:175
rtl::Reference::operator>
bool operator>(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:237
rtl::Reference
Template reference class for reference type.
Definition: ref.hxx:35
rtl::Reference::clear
Reference< reference_type > & clear()
Unbind the body from this handle.
Definition: ref.hxx:151
rtl
Definition: bootstrap.hxx:29