Panda3D
 All Classes Functions Variables Enumerations
threadSafePointerTo.I
1 // Filename: threadSafePointerTo.I
2 // Created by: drose (28Apr06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: ThreadSafePointerTo::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 template<class T>
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: ThreadSafePointerTo::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 template<class T>
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: ThreadSafePointerTo::Destructor
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 template<class T>
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: ThreadSafePointerTo::Dereference operator
50 // Access: Public
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 template<class T>
54 INLINE TYPENAME ThreadSafePointerTo<T>::To &ThreadSafePointerTo<T>::
55 operator *() const {
56  return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: ThreadSafePointerTo::Member access operator
61 // Access: Public
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 template<class T>
65 INLINE TYPENAME ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
66 operator -> () const {
67  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: ThreadSafePointerTo::Typecast operator
72 // Access: Public
73 // Description: We also have the typecast operator to automatically
74 // convert ThreadSafePointerTo's to the required kind of actual
75 // pointer. This introduces ambiguities which the
76 // compiler will resolve one way or the other, but we
77 // don't care which way it goes because either will be
78 // correct.
79 ////////////////////////////////////////////////////////////////////
80 template<class T>
82 operator T * () const {
83  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: ThreadSafePointerTo::p
88 // Access: Published
89 // Description: Returns an ordinary pointer instead of a ThreadSafePointerTo.
90 // Useful to work around compiler problems, particularly
91 // for implicit upcasts.
92 ////////////////////////////////////////////////////////////////////
93 template<class T>
94 INLINE TYPENAME ThreadSafePointerTo<T>::To *ThreadSafePointerTo<T>::
95 p() const {
96  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: ThreadSafePointerTo::Assignment operator
101 // Access: Published
102 // Description:
103 ////////////////////////////////////////////////////////////////////
104 template<class T>
106 operator = (To *ptr) {
107  this->reassign(ptr);
108  return *this;
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: ThreadSafePointerTo::Assignment operator
113 // Access: Published
114 // Description:
115 ////////////////////////////////////////////////////////////////////
116 template<class T>
118 operator = (const ThreadSafePointerTo<T> &copy) {
119  this->reassign((const ThreadSafePointerToBase<T> &)copy);
120  return *this;
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: ThreadSafeConstPointerTo::Constructor
125 // Access: Public
126 // Description:
127 ////////////////////////////////////////////////////////////////////
128 template<class T>
130 ThreadSafeConstPointerTo(const TYPENAME ThreadSafeConstPointerTo<T>::To *ptr) :
131  ThreadSafePointerToBase<T>((TYPENAME ThreadSafeConstPointerTo<T>::To *)ptr)
132 {
133 }
134 
135 ////////////////////////////////////////////////////////////////////
136 // Function: ThreadSafeConstPointerTo::Copy Constructor
137 // Access: Public
138 // Description:
139 ////////////////////////////////////////////////////////////////////
140 template<class T>
144 {
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: ThreadSafeConstPointerTo::Destructor
149 // Access: Public
150 // Description:
151 ////////////////////////////////////////////////////////////////////
152 template<class T>
155 }
156 
157 ////////////////////////////////////////////////////////////////////
158 // Function: ThreadSafeConstPointerTo::Copy Constructor
159 // Access: Public
160 // Description:
161 ////////////////////////////////////////////////////////////////////
162 template<class T>
166 {
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: ThreadSafeConstPointerTo::Dereference operator
171 // Access: Public
172 // Description:
173 ////////////////////////////////////////////////////////////////////
174 template<class T>
175 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To &ThreadSafeConstPointerTo<T>::
176 operator *() const {
177  return *((To *)AtomicAdjust::get_ptr(this->_void_ptr));
178 }
179 
180 ////////////////////////////////////////////////////////////////////
181 // Function: ThreadSafeConstPointerTo::Member access operator
182 // Access: Public
183 // Description:
184 ////////////////////////////////////////////////////////////////////
185 template<class T>
186 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
187 operator -> () const {
188  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
189 }
190 
191 ////////////////////////////////////////////////////////////////////
192 // Function: ThreadSafeConstPointerTo::Typecast operator
193 // Access: Public
194 // Description: We also have the typecast operator to automatically
195 // convert ThreadSafeConstPointerTo's to the required kind of actual
196 // pointer. This introduces ambiguities which the
197 // compiler will resolve one way or the other, but we
198 // don't care which way it goes because either will be
199 // correct.
200 ////////////////////////////////////////////////////////////////////
201 
202 template<class T>
204 operator const T * () const {
205  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
206 }
207 
208 ////////////////////////////////////////////////////////////////////
209 // Function: ThreadSafeConstPointerTo::p
210 // Access: Published
211 // Description: Returns an ordinary pointer instead of a ThreadSafeConstPointerTo.
212 // Useful to work around compiler problems, particularly
213 // for implicit upcasts.
214 ////////////////////////////////////////////////////////////////////
215 template<class T>
216 INLINE const TYPENAME ThreadSafeConstPointerTo<T>::To *ThreadSafeConstPointerTo<T>::
217 p() const {
218  return (To *)AtomicAdjust::get_ptr(this->_void_ptr);
219 }
220 
221 ////////////////////////////////////////////////////////////////////
222 // Function: ThreadSafeConstPointerTo::Assignment operator
223 // Access: Published
224 // Description:
225 ////////////////////////////////////////////////////////////////////
226 template<class T>
228 operator = (const To *ptr) {
229  this->reassign((To *)ptr);
230  return *this;
231 }
232 
233 ////////////////////////////////////////////////////////////////////
234 // Function: ThreadSafeConstPointerTo::Assignment operator
235 // Access: Published
236 // Description:
237 ////////////////////////////////////////////////////////////////////
238 template<class T>
240 operator = (const ThreadSafePointerTo<T> &copy) {
241  this->reassign((const ThreadSafePointerToBase<T> &)copy);
242  return *this;
243 }
244 
245 ////////////////////////////////////////////////////////////////////
246 // Function: ThreadSafeConstPointerTo::Assignment operator
247 // Access: Published
248 // Description:
249 ////////////////////////////////////////////////////////////////////
250 template<class T>
253  this->reassign((const ThreadSafePointerToBase<T> &)copy);
254  return *this;
255 }
static Pointer get_ptr(const Pointer &var)
Atomically retrieves the snapshot value of the indicated variable.
To * p() const
Returns an ordinary pointer instead of a ThreadSafePointerTo.
const To * p() const
Returns an ordinary pointer instead of a ThreadSafeConstPointerTo.
This is the base class for ThreadSafePointerTo and ThreadSafeConstPointerTo.
This works exactly like PointerTo, except that the object is designed to be thread-safe: it is genera...