xref: /trunk/main/vos/inc/vos/ref.inl (revision 45373f17)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25#if (defined(OS2) && defined(ICC))
26#define CAST_TO_IREFERENCE(p) ((IReference*)(p))
27#else
28#define CAST_TO_IREFERENCE(p) (p)
29#endif
30
31template <class T>
32inline ORef<T>::ORef()
33{
34	m_refBody= 0;
35}
36
37template <class T>
38inline ORef<T>::ORef(T* pBody)
39{
40	m_refBody= pBody;
41
42	if (m_refBody)
43		CAST_TO_IREFERENCE(m_refBody)->acquire();
44}
45
46template <class T>
47inline ORef<T>::ORef(const ORef<T>& handle)
48{
49	m_refBody= handle.m_refBody;
50
51	if (m_refBody)
52		CAST_TO_IREFERENCE(m_refBody)->acquire();
53}
54
55template <class T>
56inline ORef<T>::~ORef()
57{
58	if (m_refBody)
59		CAST_TO_IREFERENCE(m_refBody)->release();
60}
61
62template <class T>
63inline ORef<T>& ORef<T>::operator= (const ORef<T>& handle)
64{
65	if (m_refBody)
66		CAST_TO_IREFERENCE(m_refBody)->release();
67
68	m_refBody= handle.m_refBody;
69
70	if (m_refBody)
71		CAST_TO_IREFERENCE(m_refBody)->acquire();
72
73	return *this;
74}
75
76template <class T>
77inline void ORef<T>::bind(T* pBody)
78{
79	if (m_refBody)
80		CAST_TO_IREFERENCE(m_refBody)->release();
81
82	m_refBody= pBody;
83
84	if (m_refBody)
85		CAST_TO_IREFERENCE(m_refBody)->acquire();
86}
87
88template <class T>
89inline ORef<T>& ORef<T>::unbind()
90{
91	if (m_refBody)
92	{
93		CAST_TO_IREFERENCE(m_refBody)->release();
94		m_refBody = 0;
95	}
96	return *this;
97}
98
99template <class T>
100inline void ORef<T>::operator= (T* pBody)
101{
102	bind(pBody);
103}
104
105template <class T>
106inline T& ORef<T>::operator() () const
107{
108	VOS_PRECOND(m_refBody, "ORef::operator(): can't deref nil body!");
109	return *m_refBody;
110}
111
112template <class T>
113inline T& ORef<T>::operator* () const
114{
115	VOS_PRECOND(m_refBody, "ORef::operator*: can't deref nil body!");
116	return *m_refBody;
117}
118
119template <class T>
120inline T* ORef<T>::operator->() const
121{
122	VOS_PRECOND(m_refBody, "ORef::operator->: nil body!");
123	return m_refBody;
124}
125
126template <class T>
127inline T& ORef<T>::getBody() const
128{
129	VOS_PRECOND(m_refBody, "ORef::getBody(): can't deref nil body!");
130	return *m_refBody;
131}
132
133template <class T>
134inline T* ORef<T>::getBodyPtr() const
135{
136	// might be nil
137	return m_refBody;
138}
139
140template <class T>
141inline sal_Bool ORef<T>::isEmpty() const
142{
143	return m_refBody == 0;
144}
145
146template <class T>
147inline sal_Bool ORef<T>::isValid() const
148{
149	return m_refBody != 0;
150}
151
152template <class T>
153inline sal_Bool ORef<T>::isEqualBody(const ORef<T>& handle) const
154{
155	return m_refBody == handle.m_refBody;
156}
157
158template <class T>
159inline sal_Bool ORef<T>::operator== (const ORef<T>& handle) const
160{
161	return m_refBody == handle.m_refBody;
162}
163
164template <class T>
165inline sal_Bool ORef<T>::operator!= (const ORef<T>& handle) const
166{
167	return m_refBody != handle.m_refBody;
168}
169
170template <class T>
171inline sal_Bool ORef<T>::operator== (const T* pBody) const
172{
173	return m_refBody == pBody;
174}
175
176template <class T>
177inline sal_Bool ORef<T>::operator< (const ORef<T>& handle) const
178{
179	return m_refBody < handle.m_refBody;
180}
181
182template <class T>
183inline sal_Bool ORef<T>::operator> (const ORef<T>& handle) const
184{
185	return m_refBody > handle.m_refBody;
186}
187
188
189