Panda3D
 All Classes Functions Variables Enumerations
pointerTo.I
1 // Filename: pointerTo.I
2 // Created by: drose (10Feb99)
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: PointerTo::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 template<class T>
22 INLINE PointerTo<T>::
23 PointerTo(To *ptr) : PointerToBase<T>(ptr) {
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: PointerTo::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 template<class T>
32 INLINE PointerTo<T>::
33 PointerTo(const PointerTo<T> &copy) :
34  PointerToBase<T>((const PointerToBase<T> &)copy)
35 {
36 }
37 
38 #ifdef USE_MOVE_SEMANTICS
39 ////////////////////////////////////////////////////////////////////
40 // Function: PointerTo::Move Constructor
41 // Access: Public
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 template<class T>
45 INLINE PointerTo<T>::
46 PointerTo(PointerTo<T> &&from) NOEXCEPT :
47  PointerToBase<T>(move(from))
48 {
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: PointerTo::Move Assignment Operator
53 // Access: Public
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 template<class T>
58 operator = (PointerTo<T> &&from) NOEXCEPT {
59  this->reassign(move(from));
60  return *this;
61 }
62 #endif // USE_MOVE_SEMANTICS
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: PointerTo::Destructor
66 // Access: Public
67 // Description:
68 ////////////////////////////////////////////////////////////////////
69 template<class T>
70 INLINE PointerTo<T>::
71 ~PointerTo() {
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: PointerTo::Dereference operator
76 // Access: Public
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 template<class T>
80 INLINE TYPENAME PointerTo<T>::To &PointerTo<T>::
81 operator *() const {
82  return *((To *)(this->_void_ptr));
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: PointerTo::Member access operator
87 // Access: Public
88 // Description:
89 ////////////////////////////////////////////////////////////////////
90 template<class T>
91 INLINE TYPENAME PointerTo<T>::To *PointerTo<T>::
92 operator -> () const {
93  return (To *)(this->_void_ptr);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: PointerTo::Typecast operator
98 // Access: Public
99 // Description: We also have the typecast operator to automatically
100 // convert PointerTo's to the required kind of actual
101 // pointer. This introduces ambiguities which the
102 // compiler will resolve one way or the other, but we
103 // don't care which way it goes because either will be
104 // correct.
105 ////////////////////////////////////////////////////////////////////
106 template<class T>
107 INLINE PointerTo<T>::
108 operator T * () const {
109  return (To *)(this->_void_ptr);
110 }
111 
112 ////////////////////////////////////////////////////////////////////
113 // Function: PointerTo::cheat
114 // Access: Public
115 // Description: Returns a reference to the underlying pointer. This
116 // is a very unsafe method. It's only used by some
117 // interrogate code. If you think this method might be
118 // useful to you, you're probably wrong.
119 //
120 // Promise me you won't use this, okay?
121 ////////////////////////////////////////////////////////////////////
122 template<class T>
123 INLINE T *&PointerTo<T>::
124 cheat() {
125  return (To *&)(this->_void_ptr);
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: PointerTo::p
130 // Access: Published
131 // Description: Returns an ordinary pointer instead of a PointerTo.
132 // Useful to work around compiler problems, particularly
133 // for implicit upcasts.
134 ////////////////////////////////////////////////////////////////////
135 template<class T>
136 INLINE TYPENAME PointerTo<T>::To *PointerTo<T>::
137 p() const {
138  return (To *)(this->_void_ptr);
139 }
140 
141 ////////////////////////////////////////////////////////////////////
142 // Function: PointerTo::Assignment operator
143 // Access: Published
144 // Description:
145 ////////////////////////////////////////////////////////////////////
146 template<class T>
148 operator = (To *ptr) {
149  this->reassign(ptr);
150  return *this;
151 }
152 
153 ////////////////////////////////////////////////////////////////////
154 // Function: PointerTo::Assignment operator
155 // Access: Published
156 // Description:
157 ////////////////////////////////////////////////////////////////////
158 template<class T>
160 operator = (const PointerTo<T> &copy) {
161  this->reassign((const PointerToBase<T> &)copy);
162  return *this;
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: ConstPointerTo::Constructor
167 // Access: Public
168 // Description:
169 ////////////////////////////////////////////////////////////////////
170 template<class T>
171 INLINE ConstPointerTo<T>::
172 ConstPointerTo(const TYPENAME ConstPointerTo<T>::To *ptr) :
173  PointerToBase<T>((TYPENAME ConstPointerTo<T>::To *)ptr)
174 {
175 }
176 
177 ////////////////////////////////////////////////////////////////////
178 // Function: ConstPointerTo::Copy Constructor
179 // Access: Public
180 // Description:
181 ////////////////////////////////////////////////////////////////////
182 template<class T>
183 INLINE ConstPointerTo<T>::
184 ConstPointerTo(const PointerTo<T> &copy) :
185  PointerToBase<T>((const PointerToBase<T> &)copy)
186 {
187 }
188 
189 ////////////////////////////////////////////////////////////////////
190 // Function: ConstPointerTo::Destructor
191 // Access: Public
192 // Description:
193 ////////////////////////////////////////////////////////////////////
194 template<class T>
195 INLINE ConstPointerTo<T>::
196 ~ConstPointerTo() {
197 }
198 
199 ////////////////////////////////////////////////////////////////////
200 // Function: ConstPointerTo::Copy Constructor
201 // Access: Public
202 // Description:
203 ////////////////////////////////////////////////////////////////////
204 template<class T>
205 INLINE ConstPointerTo<T>::
206 ConstPointerTo(const ConstPointerTo<T> &copy) :
207  PointerToBase<T>((const PointerToBase<T> &)copy)
208 {
209 }
210 
211 #ifdef USE_MOVE_SEMANTICS
212 ////////////////////////////////////////////////////////////////////
213 // Function: ConstPointerTo::Move Constructor
214 // Access: Public
215 // Description:
216 ////////////////////////////////////////////////////////////////////
217 template<class T>
218 INLINE ConstPointerTo<T>::
219 ConstPointerTo(PointerTo<T> &&from) NOEXCEPT :
220  PointerToBase<T>(move(from))
221 {
222 }
223 
224 ////////////////////////////////////////////////////////////////////
225 // Function: ConstPointerTo::Move Constructor
226 // Access: Public
227 // Description:
228 ////////////////////////////////////////////////////////////////////
229 template<class T>
230 INLINE ConstPointerTo<T>::
231 ConstPointerTo(ConstPointerTo<T> &&from) NOEXCEPT :
232  PointerToBase<T>(move(from))
233 {
234 }
235 
236 ////////////////////////////////////////////////////////////////////
237 // Function: ConstPointerTo::Move Assignment Operator
238 // Access: Public
239 // Description:
240 ////////////////////////////////////////////////////////////////////
241 template<class T>
243 operator = (PointerTo<T> &&from) NOEXCEPT {
244  this->reassign(move(from));
245  return *this;
246 }
247 
248 ////////////////////////////////////////////////////////////////////
249 // Function: ConstPointerTo::Move Assignment Operator
250 // Access: Public
251 // Description:
252 ////////////////////////////////////////////////////////////////////
253 template<class T>
255 operator = (ConstPointerTo<T> &&from) NOEXCEPT {
256  this->reassign(move(from));
257  return *this;
258 }
259 #endif // USE_MOVE_SEMANTICS
260 
261 ////////////////////////////////////////////////////////////////////
262 // Function: ConstPointerTo::Dereference operator
263 // Access: Public
264 // Description:
265 ////////////////////////////////////////////////////////////////////
266 template<class T>
267 INLINE const TYPENAME ConstPointerTo<T>::To &ConstPointerTo<T>::
268 operator *() const {
269  return *((To *)(this->_void_ptr));
270 }
271 
272 ////////////////////////////////////////////////////////////////////
273 // Function: ConstPointerTo::Member access operator
274 // Access: Public
275 // Description:
276 ////////////////////////////////////////////////////////////////////
277 template<class T>
278 INLINE const TYPENAME ConstPointerTo<T>::To *ConstPointerTo<T>::
279 operator -> () const {
280  return (To *)(this->_void_ptr);
281 }
282 
283 ////////////////////////////////////////////////////////////////////
284 // Function: ConstPointerTo::Typecast operator
285 // Access: Public
286 // Description: We also have the typecast operator to automatically
287 // convert ConstPointerTo's to the required kind of actual
288 // pointer. This introduces ambiguities which the
289 // compiler will resolve one way or the other, but we
290 // don't care which way it goes because either will be
291 // correct.
292 ////////////////////////////////////////////////////////////////////
293 template<class T>
294 INLINE ConstPointerTo<T>::
295 operator const T * () const {
296 return (To *)(this->_void_ptr);
297 }
298 
299 ////////////////////////////////////////////////////////////////////
300 // Function: ConstPointerTo::cheat
301 // Access: Public
302 // Description: Returns a reference to the underlying pointer. This
303 // is a very unsafe method. It's only used by some
304 // interrogate code. If you think this method might be
305 // useful to you, you're probably wrong.
306 //
307 // Promise me you won't use this, okay?
308 ////////////////////////////////////////////////////////////////////
309 template<class T>
310 INLINE const T *&ConstPointerTo<T>::
311 cheat() {
312  return (const To *&)(this->_void_ptr);
313 }
314 
315 ////////////////////////////////////////////////////////////////////
316 // Function: ConstPointerTo::p
317 // Access: Published
318 // Description: Returns an ordinary pointer instead of a ConstPointerTo.
319 // Useful to work around compiler problems, particularly
320 // for implicit upcasts.
321 ////////////////////////////////////////////////////////////////////
322 template<class T>
323 INLINE const TYPENAME ConstPointerTo<T>::To *ConstPointerTo<T>::
324 p() const {
325  return (To *)(this->_void_ptr);
326 }
327 
328 ////////////////////////////////////////////////////////////////////
329 // Function: ConstPointerTo::Assignment operator
330 // Access: Published
331 // Description:
332 ////////////////////////////////////////////////////////////////////
333 template<class T>
335 operator = (const To *ptr) {
336  this->reassign((To *)ptr);
337  return *this;
338 }
339 
340 ////////////////////////////////////////////////////////////////////
341 // Function: ConstPointerTo::Assignment operator
342 // Access: Published
343 // Description:
344 ////////////////////////////////////////////////////////////////////
345 template<class T>
347 operator = (const PointerTo<T> &copy) {
348  this->reassign((const PointerToBase<T> &)copy);
349  return *this;
350 }
351 
352 ////////////////////////////////////////////////////////////////////
353 // Function: ConstPointerTo::Assignment operator
354 // Access: Published
355 // Description:
356 ////////////////////////////////////////////////////////////////////
357 template<class T>
359 operator = (const ConstPointerTo<T> &copy) {
360  this->reassign((const PointerToBase<T> &)copy);
361  return *this;
362 }
const T *& cheat()
Returns a reference to the underlying pointer.
Definition: pointerTo.I:311
const To * p() const
Returns an ordinary pointer instead of a ConstPointerTo.
Definition: pointerTo.I:324
This is the base class for PointerTo and ConstPointerTo.
Definition: pointerToBase.h:32
To * p() const
Returns an ordinary pointer instead of a PointerTo.
Definition: pointerTo.I:137
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144
PointerTo is a template class which implements a smart pointer to an object derived from ReferenceCou...
Definition: pointerTo.h:79
T *& cheat()
Returns a reference to the underlying pointer.
Definition: pointerTo.I:124