Panda3D
 All Classes Functions Variables Enumerations
weakPointerTo.h
1 // Filename: weakPointerTo.h
2 // Created by: drose (27Sep04)
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 #ifndef WEAKPOINTERTO_H
16 #define WEAKPOINTERTO_H
17 
18 #include "pandabase.h"
19 #include "weakPointerToBase.h"
20 #include "pointerTo.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : WeakPointerTo
24 // Description : WeakPointerTo is similar to PointerTo, except that it
25 // does not actually prevent the referenced pointer from
26 // deleting. Instead, the referenced pointer is allowed
27 // to delete, but if this happens then was_deleted()
28 // will return true, and it will be an assertion error to
29 // dereference the pointer thereafter.
30 ////////////////////////////////////////////////////////////////////
31 template <class T>
32 class WeakPointerTo : public WeakPointerToBase<T> {
33 public:
34  typedef TYPENAME WeakPointerToBase<T>::To To;
35 PUBLISHED:
36  INLINE WeakPointerTo(To *ptr = (To *)NULL);
37  INLINE WeakPointerTo(const PointerTo<T> &copy);
38  INLINE WeakPointerTo(const WeakPointerTo<T> &copy);
39 
40 public:
41  INLINE To &operator *() const;
42  INLINE To *operator -> () const;
43  // MSVC.NET 2005 insists that we use T *, and not To *, here.
44  INLINE operator T *() const;
45 
46 PUBLISHED:
47  INLINE To *p() const;
48  INLINE To *get_orig() const;
49 
50  INLINE WeakPointerTo<T> &operator = (To *ptr);
51  INLINE WeakPointerTo<T> &operator = (const PointerTo<T> &copy);
52  INLINE WeakPointerTo<T> &operator = (const WeakPointerTo<T> &copy);
53 
54  // This function normally wouldn't need to be redefined here, but
55  // we do so anyway just to help out interrogate (which doesn't seem
56  // to want to automatically export the WeakPointerToBase class). When
57  // this works again in interrogate, we can remove this.
58  INLINE void clear() { WeakPointerToBase<T>::clear(); }
59 };
60 
61 
62 ////////////////////////////////////////////////////////////////////
63 // Class : WeakConstPointerTo
64 // Description : A WeakConstPointerTo is similar to a WeakPointerTo,
65 // except it keeps a const pointer to the thing, that
66 // will be cleared to NULL when the thing deleted.
67 ////////////////////////////////////////////////////////////////////
68 template <class T>
70 public:
71  typedef TYPENAME WeakPointerToBase<T>::To To;
72 PUBLISHED:
73  INLINE WeakConstPointerTo(const To *ptr = (const To *)NULL);
74  INLINE WeakConstPointerTo(const PointerTo<T> &copy);
75  INLINE WeakConstPointerTo(const ConstPointerTo<T> &copy);
76  INLINE WeakConstPointerTo(const WeakPointerTo<T> &copy);
77  INLINE WeakConstPointerTo(const WeakConstPointerTo<T> &copy);
78 
79 public:
80  INLINE const To &operator *() const;
81  INLINE const To *operator -> () const;
82  INLINE operator const T *() const;
83 
84 PUBLISHED:
85  INLINE const To *p() const;
86  INLINE const To *get_orig() const;
87 
88  INLINE WeakConstPointerTo<T> &operator = (const To *ptr);
89  INLINE WeakConstPointerTo<T> &operator = (const PointerTo<T> &copy);
90  INLINE WeakConstPointerTo<T> &operator = (const ConstPointerTo<T> &copy);
91  INLINE WeakConstPointerTo<T> &operator = (const WeakPointerTo<T> &copy);
92  INLINE WeakConstPointerTo<T> &operator = (const WeakConstPointerTo<T> &copy);
93 
94  // These functions normally wouldn't need to be redefined here, but
95  // we do so anyway just to help out interrogate (which doesn't seem
96  // to want to automatically export the WeakPointerToBase class). When
97  // this works again in interrogate, we can remove these.
98  INLINE bool is_null() const { return WeakPointerToBase<T>::is_null(); }
99  INLINE void clear() { WeakPointerToBase<T>::clear(); }
100 };
101 
102 #define WPT(type) WeakPointerTo< type >
103 #define WCPT(type) WeakConstPointerTo< type >
104 
105 #include "weakPointerTo.I"
106 
107 #endif
WeakPointerTo is similar to PointerTo, except that it does not actually prevent the referenced pointe...
Definition: weakPointerTo.h:32
void clear()
A convenient way to set the PointerTo object to NULL.
const To * p() const
Returns an ordinary pointer instead of a WeakConstPointerTo.
To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.
To * p() const
Returns an ordinary pointer instead of a WeakPointerTo.
bool is_null() const
Returns true if the PointerTo is a NULL pointer, false otherwise.
Definition: pointerToVoid.I:54
A WeakConstPointerTo is similar to a WeakPointerTo, except it keeps a const pointer to the thing...
Definition: weakPointerTo.h:69
A ConstPointerTo is similar to a PointerTo, except it keeps a const pointer to the thing...
Definition: pointerTo.h:144
const To * get_orig() const
Returns the original pointer value, even if the object has since been deleted.
PointerTo is a template class which implements a smart pointer to an object derived from ReferenceCou...
Definition: pointerTo.h:79
This is the base class for PointerTo and ConstPointerTo.