LibreOffice LibreOffice 4.1 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 * 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 _RTL_REF_HXX_
21 #define _RTL_REF_HXX_
22
23 #include <sal/types.h>
24 #include <osl/diagnose.h>
25 #include <osl/interlck.h>
26
27 namespace rtl
28 {
29
32 class IReference
33 {
34 public:
37 virtual oslInterlockedCount SAL_CALL acquire() = 0;
38
41 virtual oslInterlockedCount SAL_CALL release() = 0;
42
43 #if !defined _MSC_VER // public -> protected changes mangled names there
44 protected:
45 #endif
46 ~IReference() {}
47 // avoid warnings about virtual members and non-virtual dtor
48 };
49
50
53 template <class reference_type>
54 class Reference
55 {
58 reference_type * m_pBody;
59
60
61 public:
64 inline Reference()
65 : m_pBody (0)
66 {}
67
68
71 inline Reference (reference_type * pBody)
72 : m_pBody (pBody)
73 {
74 if (m_pBody)
75 m_pBody->acquire();
76 }
77
78
81 inline Reference (const Reference<reference_type> & handle)
82 : m_pBody (handle.m_pBody)
83 {
84 if (m_pBody)
85 m_pBody->acquire();
86 }
87
88
91 inline ~Reference()
92 {
93 if (m_pBody)
94 m_pBody->release();
95 }
96
100 inline Reference<reference_type> &
101 SAL_CALL set (reference_type * pBody)
102 {
103 if (pBody)
104 pBody->acquire();
105 reference_type * const pOld = m_pBody;
106 m_pBody = pBody;
107 if (pOld)
108 pOld->release();
109 return *this;
110 }
111
116 inline Reference<reference_type> &
117 SAL_CALL operator= (const Reference<reference_type> & handle)
118 {
119 return set( handle.m_pBody );
120 }
121
124 inline Reference<reference_type> &
125 SAL_CALL operator= (reference_type * pBody)
126 {
127 return set( pBody );
128 }
129
137 inline Reference<reference_type> & SAL_CALL clear()
138 {
139 if (m_pBody)
140 {
141 reference_type * const pOld = m_pBody;
142 m_pBody = 0;
143 pOld->release();
144 }
145 return *this;
146 }
147
148
153 inline reference_type * SAL_CALL get() const
154 {
155 return m_pBody;
156 }
157
158
161 inline reference_type * SAL_CALL operator->() const
162 {
163 OSL_PRECOND(m_pBody, "Reference::operator->() : null body");
164 return m_pBody;
165 }
166
167
170 inline reference_type & SAL_CALL operator*() const
171 {
172 OSL_PRECOND(m_pBody, "Reference::operator*() : null body");
173 return *m_pBody;
174 }
175
176
179 inline sal_Bool SAL_CALL is() const
180 {
181 return (m_pBody != 0);
182 }
183
184
187 inline sal_Bool SAL_CALL operator== (const reference_type * pBody) const
188 {
189 return (m_pBody == pBody);
190 }
191
192
195 inline sal_Bool
196 SAL_CALL operator== (const Reference<reference_type> & handle) const
197 {
198 return (m_pBody == handle.m_pBody);
199 }
200
201
204 inline sal_Bool
205 SAL_CALL operator!= (const Reference<reference_type> & handle) const
206 {
207 return (m_pBody != handle.m_pBody);
208 }
209
210
213 inline sal_Bool
214 SAL_CALL operator< (const Reference<reference_type> & handle) const
215 {
216 return (m_pBody < handle.m_pBody);
217 }
218
219
222 inline sal_Bool
223 SAL_CALL operator> (const Reference<reference_type> & handle) const
224 {
225 return (m_pBody > handle.m_pBody);
226 }
227 };
228
230
232 template <typename T>
233 inline T * get_pointer( Reference<T> const& r )
234 {
235 return r.get();
236 }
238
239 } // namespace rtl
240
241 #endif /* !_RTL_REF_HXX_ */
242
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl::Reference::operator=
Reference< reference_type > & operator=(const Reference< reference_type > &handle)
Assignment.
Definition: ref.hxx:117
rtl::Reference::Reference
Reference(const Reference< reference_type > &handle)
Copy constructor...
Definition: ref.hxx:81
rtl::IReference::~IReference
~IReference()
Definition: ref.hxx:46
rtl::IReference::release
virtual oslInterlockedCount release()=0
rtl::Reference::clear
Reference< reference_type > & clear()
Unbind the body from this handle.
Definition: ref.hxx:137
OSL_PRECOND
#define OSL_PRECOND(c, m)
Definition: diagnose.h:159
rtl::Reference::operator*
reference_type & operator*() const
Allows (*handle).someBodyOp().
Definition: ref.hxx:170
interlck.h
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition: interlck.h:32
diagnose.h
rtl::Reference::~Reference
~Reference()
Destructor...
Definition: ref.hxx:91
rtl::IReference::acquire
virtual oslInterlockedCount acquire()=0
rtl::Reference::Reference
Reference()
Constructor...
Definition: ref.hxx:64
rtl::Reference::set
Reference< reference_type > & set(reference_type *pBody)
Set...
Definition: ref.hxx:101
rtl::Reference::operator->
reference_type * operator->() const
Probably most common used: handle->someBodyOp().
Definition: ref.hxx:161
rtl::Reference::operator==
sal_Bool operator==(const reference_type *pBody) const
Returns True if this points to pBody.
Definition: ref.hxx:187
sal_Bool
unsigned char sal_Bool
Definition: types.h:37
rtl::Reference
Template reference class for reference type derived from IReference.
Definition: ref.hxx:54
rtl::Reference::operator>
sal_Bool operator>(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:223
rtl::Reference::is
sal_Bool is() const
Returns True if the handle does point to a valid body.
Definition: ref.hxx:179
rtl::IReference
Interface for a reference type.
Definition: ref.hxx:32
rtl::Reference::Reference
Reference(reference_type *pBody)
Constructor...
Definition: ref.hxx:71
rtl::Reference::operator!=
sal_Bool operator!=(const Reference< reference_type > &handle) const
Needed to place References into STL collection.
Definition: ref.hxx:205
types.h