AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
4 #ifndef INCLUDED_RTL_REF_HXX
5 #define INCLUDED_RTL_REF_HXX
6 
7 #include "sal/config.h"
8 
9 #include <cassert>
10 #include <cstddef>
11 #include <functional>
12 #ifdef LIBO_INTERNAL_ONLY
13 #include <type_traits>
15 #endif
16 
17 #include "sal/types.h"
18 
19 namespace rtl
20 {
21 
24 template <class reference_type>
25 class Reference
26 {
29  reference_type * m_pBody;
30 
31 
32 public:
36  : m_pBody (NULL)
37  {}
38 
39 
42  Reference (reference_type * pBody, __sal_NoAcquire)
43  : m_pBody (pBody)
44  {
45  }
46 
49  Reference (reference_type * pBody)
50  : m_pBody (pBody)
51  {
52  if (m_pBody)
53  m_pBody->acquire();
54  }
55 
59  : m_pBody (handle.m_pBody)
60  {
61  if (m_pBody)
62  m_pBody->acquire();
63  }
64 
65 #ifdef LIBO_INTERNAL_ONLY
66 
68  Reference (Reference<reference_type> && handle) noexcept
69  : m_pBody (handle.m_pBody)
70  {
71  handle.m_pBody = nullptr;
72  }
73 #endif
74 
75 #if defined LIBO_INTERNAL_ONLY
76 
82  template< class derived_type >
83  inline Reference(
84  const Reference< derived_type > & rRef,
85  std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
86  : m_pBody (rRef.get())
87  {
88  if (m_pBody)
89  m_pBody->acquire();
90  }
91 
96  template< class super_type,
97  std::enable_if_t<std::is_base_of_v<super_type, reference_type>, int> = 0 >
98  inline operator css::uno::Reference<super_type>() const
99  {
100  return css::uno::Reference<super_type>(m_pBody);
101  }
102 #endif
103 
107  {
108  if (m_pBody)
109  m_pBody->release();
110  }
111 
116  SAL_CALL set (reference_type * pBody)
117  {
118  if (pBody)
119  pBody->acquire();
120  reference_type * const pOld = m_pBody;
121  m_pBody = pBody;
122  if (pOld)
123  pOld->release();
124  return *this;
125  }
126 
132  SAL_CALL operator= (const Reference<reference_type> & handle)
133  {
134  return set( handle.m_pBody );
135  }
136 
137 #ifdef LIBO_INTERNAL_ONLY
138 
145  {
146  // self-movement guts ourself
147  if (m_pBody)
148  m_pBody->release();
149  m_pBody = handle.m_pBody;
150  handle.m_pBody = nullptr;
151  return *this;
152  }
153 #endif
154 
157  Reference<reference_type> &
158  SAL_CALL operator= (reference_type * pBody)
159  {
160  return set( pBody );
161  }
162 
171  {
172  if (m_pBody)
173  {
174  reference_type * const pOld = m_pBody;
175  m_pBody = NULL;
176  pOld->release();
177  }
178  return *this;
179  }
180 
181 
186  reference_type * SAL_CALL get() const
187  {
188  return m_pBody;
189  }
190 
191 
194  reference_type * SAL_CALL operator->() const
195  {
196  assert(m_pBody != NULL);
197  return m_pBody;
198  }
199 
200 
203  reference_type & SAL_CALL operator*() const
204  {
205  assert(m_pBody != NULL);
206  return *m_pBody;
207  }
208 
209 
212  bool SAL_CALL is() const
213  {
214  return (m_pBody != NULL);
215  }
216 
217 #if defined LIBO_INTERNAL_ONLY
218 
220  explicit operator bool() const
221  {
222  return is();
223  }
224 #endif
225 
228  bool SAL_CALL operator== (const reference_type * pBody) const
229  {
230  return (m_pBody == pBody);
231  }
232 
233 
236  bool
237  SAL_CALL operator== (const Reference<reference_type> & handle) const
238  {
239  return (m_pBody == handle.m_pBody);
240  }
241 
242 
245  bool
246  SAL_CALL operator!= (const Reference<reference_type> & handle) const
247  {
248  return (m_pBody != handle.m_pBody);
249  }
250 
251 
254  bool
255  SAL_CALL operator< (const Reference<reference_type> & handle) const
256  {
257  return (m_pBody < handle.m_pBody);
258  }
259 
260 
263  bool
264  SAL_CALL operator> (const Reference<reference_type> & handle) const
265  {
266  return (m_pBody > handle.m_pBody);
267  }
268 };
269 
270 } // namespace rtl
271 
272 #if defined LIBO_INTERNAL_ONLY
273 namespace std
274 {
275 
277 
282 template<typename T>
283 struct hash<::rtl::Reference<T>>
284 {
285  std::size_t operator()(::rtl::Reference<T> const & s) const
286  { return std::size_t(s.get()); }
287 };
289 
290 }
291 
292 #endif
293 
294 #endif /* ! INCLUDED_RTL_REF_HXX */
295 
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
~Reference() COVERITY_NOEXCEPT_FALSE
Destructor...
Definition: ref.hxx:106
Template reference class for reference type.
Definition: ref.hxx:25
bool operator==(const reference_type *pBody) const
Returns True if this points to pBody.
Definition: ref.hxx:228
Reference< reference_type > & set(reference_type *pBody)
Set...
Definition: ref.hxx:116
__sal_NoAcquire
Definition: types.h:332
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:329
bool is() const
Returns True if the handle does point to a valid body.
Definition: ref.hxx:212
Reference< reference_type > & clear()
Unbind the body from this handle.
Definition: ref.hxx:170
Reference(reference_type *pBody)
Constructor...
Definition: ref.hxx:49
reference_type & operator*() const
Allows (*handle).someBodyOp().
Definition: ref.hxx:203
bool operator>(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:264
reference_type * operator->() const
Probably most common used: handle-&gt;someBodyOp().
Definition: ref.hxx:194
reference_type * get() const
Get the body.
Definition: ref.hxx:186
Reference(const Reference< reference_type > &handle)
Copy constructor...
Definition: ref.hxx:58
Reference< reference_type > & operator=(const Reference< reference_type > &handle)
Assignment.
Definition: ref.hxx:132
Reference()
Constructor...
Definition: ref.hxx:35
bool operator!=(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:246
Reference(reference_type *pBody, __sal_NoAcquire)
Constructor...
Definition: ref.hxx:42