Panda3D

Loading...
Searching...
No Matches
pointerTo.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 pointerTo.I
10 * @author drose
11 * @date 1999-02-10
12 */
13
14/**
15 *
16 */
17 template<class T>
18ALWAYS_INLINE PointerTo<T>::
19 PointerTo(To *ptr) noexcept : PointerToBase<T>(ptr) {
20}
21
22/**
23 *
24 */
25 template<class T>
26INLINE PointerTo<T>::
27 PointerTo(const PointerTo<T> &copy) :
28 PointerToBase<T>((const PointerToBase<T> &)copy)
29{
30}
31
32/**
33 *
34 */
35 template<class T>
36INLINE PointerTo<T>::
37 PointerTo(PointerTo<T> &&from) noexcept :
38 PointerToBase<T>(std::move(from))
39{
40}
41
42#ifndef CPPPARSER
43/**
44 *
45 */
46 template<class T>
47 template<class Y>
48ALWAYS_INLINE PointerTo<T>::
49 PointerTo(Y *ptr) noexcept :
50 PointerToBase<T>(ptr)
51{
52}
53
54/**
55 *
56 */
57 template<class T>
58 template<class Y>
59ALWAYS_INLINE PointerTo<T>::
60 PointerTo(const PointerTo<Y> &r) noexcept :
61 PointerToBase<T>(r.p())
62{
63}
64
65/**
66 *
67 */
68 template<class T>
69 template<class Y>
70ALWAYS_INLINE PointerTo<T>::
71 PointerTo(PointerTo<Y> &&r) noexcept :
72 PointerToBase<T>(std::move(r))
73{
74}
75#endif // !CPPPARSER
76
77/**
78 *
79 */
80 template<class T>
81INLINE PointerTo<T> &PointerTo<T>::
82 operator = (PointerTo<T> &&from) noexcept {
83 this->reassign(std::move(from));
84 return *this;
85}
86
87#ifndef CPPPARSER
88/**
89 *
90 */
91 template<class T>
92 template<class Y>
93ALWAYS_INLINE PointerTo<T> &PointerTo<T>::
94 operator = (const PointerTo<Y> &r) noexcept {
95 this->reassign(r.p());
96 return *this;
97}
98
99/**
100 *
101 */
102 template<class T>
103 template<class Y>
104ALWAYS_INLINE PointerTo<T> &PointerTo<T>::
105operator = (PointerTo<Y> &&r) noexcept {
106 this->reassign(std::move(r));
107 return *this;
108}
109#endif // !CPPPARSER
110
111/**
112 *
113 */
114 template<class T>
115 constexpr typename PointerTo<T>::To &PointerTo<T>::
116operator *() const noexcept {
117 return *((To *)(this->_void_ptr));
118}
119
120/**
121 *
122 */
123 template<class T>
124 constexpr typename PointerTo<T>::To *PointerTo<T>::
125 operator -> () const noexcept {
126 return (To *)(this->_void_ptr);
127}
128
129/**
130 * We also have the typecast operator to automatically convert PointerTo's to
131 * the required kind of actual pointer. This introduces ambiguities which the
132 * compiler will resolve one way or the other, but we don't care which way it
133 * goes because either will be correct.
134 */
135 template<class T>
136 constexpr PointerTo<T>::
137operator T * () const noexcept {
138 return (To *)(this->_void_ptr);
139}
140
141/**
142 * Returns a reference to the underlying pointer. This is a very unsafe
143 * method. It's only used by some interrogate code. If you think this method
144 * might be useful to you, you're probably wrong.
145 *
146 * Promise me you won't use this, okay?
147 */
148 template<class T>
149INLINE T *&PointerTo<T>::
150 cheat() {
151 return (To *&)(this->_void_ptr);
152}
153
154/**
155 * Returns an ordinary pointer instead of a PointerTo. Useful to work around
156 * compiler problems, particularly for implicit upcasts.
157 */
158 template<class T>
159 constexpr typename PointerTo<T>::To *PointerTo<T>::
160 p() const noexcept {
161 return (To *)(this->_void_ptr);
162}
163
164/**
165 *
166 */
167 template<class T>
168INLINE PointerTo<T> &PointerTo<T>::
169 operator = (To *ptr) {
170 this->reassign(ptr);
171 return *this;
172}
173
174/**
175 *
176 */
177 template<class T>
178INLINE PointerTo<T> &PointerTo<T>::
179 operator = (const PointerTo<T> &copy) {
180 this->reassign((const PointerToBase<T> &)copy);
181 return *this;
182}
183
184/**
185 *
186 */
187 template<class T>
188ALWAYS_INLINE ConstPointerTo<T>::
189ConstPointerTo(const typename ConstPointerTo<T>::To *ptr) noexcept :
190 PointerToBase<T>((typename ConstPointerTo<T>::To *)ptr)
191{
192}
193
194/**
195 *
196 */
197 template<class T>
198INLINE ConstPointerTo<T>::
199 ConstPointerTo(const PointerTo<T> &copy) :
200 PointerToBase<T>((const PointerToBase<T> &)copy)
201{
202}
203
204/**
205 *
206 */
207 template<class T>
208INLINE ConstPointerTo<T>::
209 ConstPointerTo(const ConstPointerTo<T> &copy) :
210 PointerToBase<T>((const PointerToBase<T> &)copy)
211{
212}
213
214/**
215 *
216 */
217 template<class T>
218INLINE ConstPointerTo<T>::
219 ConstPointerTo(PointerTo<T> &&from) noexcept :
220 PointerToBase<T>(std::move(from))
221{
222}
223
224/**
225 *
226 */
227 template<class T>
228INLINE ConstPointerTo<T>::
229 ConstPointerTo(ConstPointerTo<T> &&from) noexcept :
230 PointerToBase<T>(std::move(from))
231{
232}
233
234#ifndef CPPPARSER
235/**
236 *
237 */
238 template<class T>
239 template<class Y>
240ALWAYS_INLINE ConstPointerTo<T>::
241 ConstPointerTo(const Y *ptr) noexcept :
242 PointerToBase<T>((Y *)ptr)
243{
244}
245
246/**
247 *
248 */
249 template<class T>
250 template<class Y>
251ALWAYS_INLINE ConstPointerTo<T>::
252 ConstPointerTo(const PointerTo<Y> &r) noexcept :
253 PointerToBase<T>(r.p())
254{
255}
256
257/**
258 *
259 */
260 template<class T>
261 template<class Y>
262ALWAYS_INLINE ConstPointerTo<T>::
263 ConstPointerTo(const ConstPointerTo<Y> &r) noexcept :
264 PointerToBase<T>((Y *)r.p())
265{
266}
267
268/**
269 *
270 */
271 template<class T>
272 template<class Y>
273ALWAYS_INLINE ConstPointerTo<T>::
274 ConstPointerTo(PointerTo<Y> &&r) noexcept :
275 PointerToBase<T>(std::move(r))
276{
277}
278
279/**
280 *
281 */
282 template<class T>
283 template<class Y>
284ALWAYS_INLINE ConstPointerTo<T>::
285 ConstPointerTo(ConstPointerTo<Y> &&r) noexcept :
286 PointerToBase<T>(std::move(r))
287{
288}
289#endif // !CPPPARSER
290
291/**
292 *
293 */
294 template<class T>
295INLINE ConstPointerTo<T> &ConstPointerTo<T>::
296 operator = (PointerTo<T> &&from) noexcept {
297 this->reassign(std::move(from));
298 return *this;
299}
300
301/**
302 *
303 */
304 template<class T>
305INLINE ConstPointerTo<T> &ConstPointerTo<T>::
306 operator = (ConstPointerTo<T> &&from) noexcept {
307 this->reassign(std::move(from));
308 return *this;
309}
310
311#ifndef CPPPARSER
312/**
313 *
314 */
315 template<class T>
316 template<class Y>
317ALWAYS_INLINE ConstPointerTo<T> &ConstPointerTo<T>::
318 operator = (const PointerTo<Y> &r) noexcept {
319 this->reassign(r.p());
320 return *this;
321}
322
323/**
324 *
325 */
326 template<class T>
327 template<class Y>
328ALWAYS_INLINE ConstPointerTo<T> &ConstPointerTo<T>::
329 operator = (const ConstPointerTo<Y> &r) noexcept {
330 this->reassign((Y *)r.p());
331 return *this;
332}
333
334/**
335 *
336 */
337 template<class T>
338 template<class Y>
339ALWAYS_INLINE ConstPointerTo<T> &ConstPointerTo<T>::
340 operator = (PointerTo<Y> &&r) noexcept {
341 this->reassign(std::move(r));
342 return *this;
343}
344
345/**
346 *
347 */
348 template<class T>
349 template<class Y>
350ALWAYS_INLINE ConstPointerTo<T> &ConstPointerTo<T>::
351 operator = (ConstPointerTo<Y> &&r) noexcept {
352 this->reassign(std::move(r));
353 return *this;
354}
355#endif // !CPPPARSER
356
357/**
358 *
359 */
360 template<class T>
361 constexpr const typename ConstPointerTo<T>::To &ConstPointerTo<T>::
362 operator *() const noexcept {
363 return *((To *)(this->_void_ptr));
364}
365
366/**
367 *
368 */
369 template<class T>
370 constexpr const typename ConstPointerTo<T>::To *ConstPointerTo<T>::
371 operator -> () const noexcept {
372 return (To *)(this->_void_ptr);
373}
374
375/**
376 * We also have the typecast operator to automatically convert
377 * ConstPointerTo's to the required kind of actual pointer. This introduces
378 * ambiguities which the compiler will resolve one way or the other, but we
379 * don't care which way it goes because either will be correct.
380 */
381 template<class T>
382 constexpr ConstPointerTo<T>::
383operator const T * () const noexcept {
384 return (To *)(this->_void_ptr);
385}
386
387/**
388 * Returns a reference to the underlying pointer. This is a very unsafe
389 * method. It's only used by some interrogate code. If you think this method
390 * might be useful to you, you're probably wrong.
391 *
392 * Promise me you won't use this, okay?
393 */
394 template<class T>
395INLINE const T *&ConstPointerTo<T>::
396 cheat() {
397 return (const To *&)(this->_void_ptr);
398}
399
400/**
401 * Returns an ordinary pointer instead of a ConstPointerTo. Useful to work
402 * around compiler problems, particularly for implicit upcasts.
403 */
404 template<class T>
405 constexpr const typename ConstPointerTo<T>::To *ConstPointerTo<T>::
406 p() const noexcept {
407 return (To *)(this->_void_ptr);
408}
409
410/**
411 *
412 */
413 template<class T>
414INLINE ConstPointerTo<T> &ConstPointerTo<T>::
415 operator = (const To *ptr) {
416 this->reassign((To *)ptr);
417 return *this;
418}
419
420/**
421 *
422 */
423 template<class T>
424INLINE ConstPointerTo<T> &ConstPointerTo<T>::
425 operator = (const PointerTo<T> &copy) {
426 this->reassign((const PointerToBase<T> &)copy);
427 return *this;
428}
429
430/**
431 *
432 */
433 template<class T>
434INLINE ConstPointerTo<T> &ConstPointerTo<T>::
435 operator = (const ConstPointerTo<T> &copy) {
436 this->reassign((const PointerToBase<T> &)copy);
437 return *this;
438}
ConstPointerTo
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition pointerTo.h:144
ConstPointerTo::p
constexpr const To * p() const noexcept
Returns an ordinary pointer instead of a ConstPointerTo.
Definition pointerTo.I:406
ConstPointerTo::cheat
const T *& cheat()
Returns a reference to the underlying pointer.
Definition pointerTo.I:396
To
PointerToBase
This is the base class for PointerTo and ConstPointerTo.
Definition pointerToBase.h:29
PointerTo
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
Definition pointerTo.h:69
PointerTo::cheat
T *& cheat()
Returns a reference to the underlying pointer.
Definition pointerTo.I:150
PointerTo::p
constexpr To * p() const noexcept
Returns an ordinary pointer instead of a PointerTo.
Definition pointerTo.I:160