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 */
17template<class T>
18ALWAYS_INLINE PointerTo<T>::
19PointerTo(To *ptr) noexcept : PointerToBase<T>(ptr) {
20}
21
22/**
23 *
24 */
25template<class T>
26INLINE PointerTo<T>::
27PointerTo(const PointerTo<T> &copy) :
28 PointerToBase<T>((const PointerToBase<T> &)copy)
29{
30}
31
32/**
33 *
34 */
35template<class T>
36INLINE PointerTo<T>::
37PointerTo(PointerTo<T> &&from) noexcept :
38 PointerToBase<T>(std::move(from))
39{
40}
41
42#ifndef CPPPARSER
43/**
44 *
45 */
46template<class T>
47template<class Y>
48ALWAYS_INLINE PointerTo<T>::
49PointerTo(Y *ptr) noexcept :
51{
52}
53
54/**
55 *
56 */
57template<class T>
58template<class Y>
59ALWAYS_INLINE PointerTo<T>::
60PointerTo(const PointerTo<Y> &r) noexcept :
61 PointerToBase<T>(r.p())
62{
63}
64
65/**
66 *
67 */
68template<class T>
69template<class Y>
70ALWAYS_INLINE PointerTo<T>::
71PointerTo(PointerTo<Y> &&r) noexcept :
72 PointerToBase<T>(std::move(r))
73{
74}
75#endif // !CPPPARSER
76
77/**
78 *
79 */
80template<class T>
82operator = (PointerTo<T> &&from) noexcept {
83 this->reassign(std::move(from));
84 return *this;
85}
86
87#ifndef CPPPARSER
88/**
89 *
90 */
91template<class T>
92template<class Y>
93ALWAYS_INLINE PointerTo<T> &PointerTo<T>::
94operator = (const PointerTo<Y> &r) noexcept {
95 this->reassign(r.p());
96 return *this;
97}
99/**
101 */
102template<class T>
103template<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 */
114template<class T>
115constexpr typename PointerTo<T>::To &PointerTo<T>::
116operator *() const noexcept {
117 return *((To *)(this->_void_ptr));
118}
119
120/**
121 *
122 */
123template<class T>
124constexpr typename PointerTo<T>::To *PointerTo<T>::
125operator -> () 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 */
135template<class T>
136constexpr 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 */
148template<class T>
150cheat() {
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 */
158template<class T>
159constexpr typename PointerTo<T>::To *PointerTo<T>::
160p() const noexcept {
161 return (To *)(this->_void_ptr);
162}
163
164/**
165 *
166 */
167template<class T>
169operator = (To *ptr) {
170 this->reassign(ptr);
171 return *this;
172}
173
174/**
175 *
176 */
177template<class T>
179operator = (const PointerTo<T> &copy) {
180 this->reassign((const PointerToBase<T> &)copy);
181 return *this;
182}
184/**
186 */
187template<class T>
189ConstPointerTo(const typename ConstPointerTo<T>::To *ptr) noexcept :
190 PointerToBase<T>((typename ConstPointerTo<T>::To *)ptr)
191{
192}
193
194/**
195 *
196 */
197template<class T>
199ConstPointerTo(const PointerTo<T> &copy) :
200 PointerToBase<T>((const PointerToBase<T> &)copy)
201{
202}
203
204/**
205 *
206 */
207template<class T>
210 PointerToBase<T>((const PointerToBase<T> &)copy)
211{
212}
213
214/**
215 *
216 */
217template<class T>
219ConstPointerTo(PointerTo<T> &&from) noexcept :
220 PointerToBase<T>(std::move(from))
221{
222}
223
224/**
225 *
226 */
227template<class T>
229ConstPointerTo(ConstPointerTo<T> &&from) noexcept :
230 PointerToBase<T>(std::move(from))
231{
232}
233
234#ifndef CPPPARSER
235/**
236 *
237 */
238template<class T>
239template<class Y>
240ALWAYS_INLINE ConstPointerTo<T>::
241ConstPointerTo(const Y *ptr) noexcept :
242 PointerToBase<T>((Y *)ptr)
243{
244}
245
246/**
247 *
248 */
249template<class T>
250template<class Y>
251ALWAYS_INLINE ConstPointerTo<T>::
252ConstPointerTo(const PointerTo<Y> &r) noexcept :
253 PointerToBase<T>(r.p())
254{
255}
256
257/**
258 *
259 */
260template<class T>
261template<class Y>
262ALWAYS_INLINE ConstPointerTo<T>::
263ConstPointerTo(const ConstPointerTo<Y> &r) noexcept :
264 PointerToBase<T>((Y *)r.p())
265{
266}
267
268/**
269 *
270 */
271template<class T>
272template<class Y>
273ALWAYS_INLINE ConstPointerTo<T>::
274ConstPointerTo(PointerTo<Y> &&r) noexcept :
275 PointerToBase<T>(std::move(r))
276{
277}
278
279/**
280 *
281 */
282template<class T>
283template<class Y>
284ALWAYS_INLINE ConstPointerTo<T>::
285ConstPointerTo(ConstPointerTo<Y> &&r) noexcept :
286 PointerToBase<T>(std::move(r))
287{
288}
289#endif // !CPPPARSER
290
291/**
292 *
293 */
294template<class T>
296operator = (PointerTo<T> &&from) noexcept {
297 this->reassign(std::move(from));
298 return *this;
299}
300
301/**
302 *
303 */
304template<class T>
306operator = (ConstPointerTo<T> &&from) noexcept {
307 this->reassign(std::move(from));
308 return *this;
309}
310
311#ifndef CPPPARSER
312/**
313 *
314 */
315template<class T>
316template<class Y>
318operator = (const PointerTo<Y> &r) noexcept {
319 this->reassign(r.p());
320 return *this;
321}
322
323/**
324 *
325 */
326template<class T>
327template<class Y>
329operator = (const ConstPointerTo<Y> &r) noexcept {
330 this->reassign((Y *)r.p());
331 return *this;
332}
333
334/**
335 *
336 */
337template<class T>
338template<class Y>
340operator = (PointerTo<Y> &&r) noexcept {
341 this->reassign(std::move(r));
342 return *this;
343}
344
345/**
346 *
347 */
348template<class T>
349template<class Y>
351operator = (ConstPointerTo<Y> &&r) noexcept {
352 this->reassign(std::move(r));
353 return *this;
354}
355#endif // !CPPPARSER
356
357/**
358 *
359 */
360template<class T>
361constexpr const typename ConstPointerTo<T>::To &ConstPointerTo<T>::
362operator *() const noexcept {
363 return *((To *)(this->_void_ptr));
364}
365
366/**
367 *
368 */
369template<class T>
370constexpr const typename ConstPointerTo<T>::To *ConstPointerTo<T>::
371operator -> () 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 */
381template<class T>
383operator const T * () const noexcept {
384return (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 */
394template<class T>
395INLINE const T *&ConstPointerTo<T>::
396cheat() {
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 */
404template<class T>
405constexpr const typename ConstPointerTo<T>::To *ConstPointerTo<T>::
406p() const noexcept {
407 return (To *)(this->_void_ptr);
408}
409
410/**
411 *
412 */
413template<class T>
415operator = (const To *ptr) {
416 this->reassign((To *)ptr);
417 return *this;
418}
419
420/**
421 *
422 */
423template<class T>
425operator = (const PointerTo<T> &copy) {
426 this->reassign((const PointerToBase<T> &)copy);
427 return *this;
428}
429
430/**
431 *
432 */
433template<class T>
435operator = (const ConstPointerTo<T> &copy) {
436 this->reassign((const PointerToBase<T> &)copy);
437 return *this;
438}
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing.
Definition pointerTo.h:144
constexpr const To * p() const noexcept
Returns an ordinary pointer instead of a ConstPointerTo.
Definition pointerTo.I:406
const T *& cheat()
Returns a reference to the underlying pointer.
Definition pointerTo.I:396
This is the base class for PointerTo and ConstPointerTo.
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
Definition pointerTo.h:69
T *& cheat()
Returns a reference to the underlying pointer.
Definition pointerTo.I:150
constexpr To * p() const noexcept
Returns an ordinary pointer instead of a PointerTo.
Definition pointerTo.I:160