Panda3D

threadSafePointerTo.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file threadSafePointerTo.I
10 * @author drose
11 * @date 2006-04-28
12 */
13
14 /**
15 *
16 */
17 template<class T>
18 INLINE ThreadSafePointerTo<T>::
19 ThreadSafePointerTo(To *ptr) : ThreadSafePointerToBase<T>(ptr) {
20 }
21
22 /**
23 *
24 */
25 template<class T>
26 INLINE ThreadSafePointerTo<T>::
27 ThreadSafePointerTo(const ThreadSafePointerTo<T> &copy) :
28 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
29 {
30 }
31
32 /**
33 *
34 */
35 template<class T>
36 INLINE ThreadSafePointerTo<T>::
37 ~ThreadSafePointerTo() {
38 }
39
40 /**
41 *
42 */
43 template<class T>
44 INLINE typename ThreadSafePointerTo<T>::To &ThreadSafePointerTo<T>::
45 operator *() const {
46 return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
47 }
48
49 /**
50 *
51 */
52 template<class T>
53 INLINE typename ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
54 operator -> () const {
55 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
56 }
57
58 /**
59 * We also have the typecast operator to automatically convert
60 * ThreadSafePointerTo's to the required kind of actual pointer. This
61 * introduces ambiguities which the compiler will resolve one way or the
62 * other, but we don't care which way it goes because either will be correct.
63 */
64 template<class T>
65 INLINE ThreadSafePointerTo<T>::
66 operator T * () const {
67 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
68 }
69
70 /**
71 * Returns an ordinary pointer instead of a ThreadSafePointerTo. Useful to
72 * work around compiler problems, particularly for implicit upcasts.
73 */
74 template<class T>
75 INLINE typename ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
76 p() const {
77 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
78 }
79
80 /**
81 *
82 */
83 template<class T>
84 INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>::
85 operator = (To *ptr) {
86 this->reassign(ptr);
87 return *this;
88 }
89
90 /**
91 *
92 */
93 template<class T>
94 INLINE ThreadSafePointerTo<T> &ThreadSafePointerTo<T>::
95 operator = (const ThreadSafePointerTo<T> &copy) {
96 this->reassign((const ThreadSafePointerToBase<T> &)copy);
97 return *this;
98 }
99
100 /**
101 *
102 */
103 template<class T>
104 INLINE ThreadSafeConstPointerTo<T>::
105 ThreadSafeConstPointerTo(const typename ThreadSafeConstPointerTo<T>::To *ptr) :
106 ThreadSafePointerToBase<T>((typename ThreadSafeConstPointerTo<T>::To *)ptr)
107 {
108 }
109
110 /**
111 *
112 */
113 template<class T>
114 INLINE ThreadSafeConstPointerTo<T>::
115 ThreadSafeConstPointerTo(const ThreadSafePointerTo<T> &copy) :
116 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
117 {
118 }
119
120 /**
121 *
122 */
123 template<class T>
124 INLINE ThreadSafeConstPointerTo<T>::
125 ~ThreadSafeConstPointerTo() {
126 }
127
128 /**
129 *
130 */
131 template<class T>
132 INLINE ThreadSafeConstPointerTo<T>::
133 ThreadSafeConstPointerTo(const ThreadSafeConstPointerTo<T> &copy) :
134 ThreadSafePointerToBase<T>((const ThreadSafePointerToBase<T> &)copy)
135 {
136 }
137
138 /**
139 *
140 */
141 template<class T>
142 INLINE const typename ThreadSafeConstPointerTo<T>::To &ThreadSafeConstPointerTo<T>::
143 operator *() const {
144 return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
145 }
146
147 /**
148 *
149 */
150 template<class T>
151 INLINE const typename ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
152 operator -> () const {
153 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
154 }
155
156 /**
157 * We also have the typecast operator to automatically convert
158 * ThreadSafeConstPointerTo's to the required kind of actual pointer. This
159 * introduces ambiguities which the compiler will resolve one way or the
160 * other, but we don't care which way it goes because either will be correct.
161 */
162
163 template<class T>
164 INLINE ThreadSafeConstPointerTo<T>::
165 operator const T * () const {
166 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
167 }
168
169 /**
170 * Returns an ordinary pointer instead of a ThreadSafeConstPointerTo. Useful
171 * to work around compiler problems, particularly for implicit upcasts.
172 */
173 template<class T>
174 INLINE const typename ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
175 p() const {
176 return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
177 }
178
179 /**
180 *
181 */
182 template<class T>
183 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
184 operator = (const To *ptr) {
185 this->reassign((To *)ptr);
186 return *this;
187 }
188
189 /**
190 *
191 */
192 template<class T>
193 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
194 operator = (const ThreadSafePointerTo<T> &copy) {
195 this->reassign((const ThreadSafePointerToBase<T> &)copy);
196 return *this;
197 }
198
199 /**
200 *
201 */
202 template<class T>
203 INLINE ThreadSafeConstPointerTo<T> &ThreadSafeConstPointerTo<T>::
204 operator = (const ThreadSafeConstPointerTo<T> &copy) {
205 this->reassign((const ThreadSafePointerToBase<T> &)copy);
206 return *this;
207 }
AtomicAdjustDummyImpl::get_ptr
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
Definition: atomicAdjustDummyImpl.I:81
ThreadSafeConstPointerTo
Definition: threadSafePointerTo.h:72
ThreadSafeConstPointerTo::p
const To * p() const
Returns an ordinary pointer instead of a ThreadSafeConstPointerTo.
Definition: threadSafePointerTo.I:175
ThreadSafePointerToBase
This is the base class for ThreadSafePointerTo and ThreadSafeConstPointerTo.
Definition: threadSafePointerToBase.h:31
ThreadSafePointerTo
This works exactly like PointerTo, except that the object is designed to be thread-safe: it is genera...
Definition: threadSafePointerTo.h:27
ThreadSafePointerTo::p
To * p() const
Returns an ordinary pointer instead of a ThreadSafePointerTo.
Definition: threadSafePointerTo.I:76