00001 // Filename: weakPointerTo.h 00002 // Created by: drose (27Sep04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef WEAKPOINTERTO_H 00016 #define WEAKPOINTERTO_H 00017 00018 #include "pandabase.h" 00019 #include "weakPointerToBase.h" 00020 #include "pointerTo.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : WeakPointerTo 00024 // Description : WeakPointerTo is similar to PointerTo, except that it 00025 // does not actually prevent the referenced pointer from 00026 // deleting. Instead, the referenced pointer is allowed 00027 // to delete, but if this happens then was_deleted() 00028 // will return true, and it will be an assertion error to 00029 // dereference the pointer thereafter. 00030 //////////////////////////////////////////////////////////////////// 00031 template <class T> 00032 class WeakPointerTo : public WeakPointerToBase<T> { 00033 public: 00034 typedef TYPENAME WeakPointerToBase<T>::To To; 00035 PUBLISHED: 00036 INLINE WeakPointerTo(To *ptr = (To *)NULL); 00037 INLINE WeakPointerTo(const PointerTo<T> ©); 00038 INLINE WeakPointerTo(const WeakPointerTo<T> ©); 00039 00040 public: 00041 INLINE To &operator *() const; 00042 INLINE To *operator -> () const; 00043 // MSVC.NET 2005 insists that we use T *, and not To *, here. 00044 INLINE operator T *() const; 00045 00046 PUBLISHED: 00047 INLINE To *p() const; 00048 INLINE To *get_orig() const; 00049 00050 INLINE WeakPointerTo<T> &operator = (To *ptr); 00051 INLINE WeakPointerTo<T> &operator = (const PointerTo<T> ©); 00052 INLINE WeakPointerTo<T> &operator = (const WeakPointerTo<T> ©); 00053 00054 // This function normally wouldn't need to be redefined here, but 00055 // we do so anyway just to help out interrogate (which doesn't seem 00056 // to want to automatically export the WeakPointerToBase class). When 00057 // this works again in interrogate, we can remove this. 00058 INLINE void clear() { WeakPointerToBase<T>::clear(); } 00059 }; 00060 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Class : WeakConstPointerTo 00064 // Description : A WeakConstPointerTo is similar to a WeakPointerTo, 00065 // except it keeps a const pointer to the thing, that 00066 // will be cleared to NULL when the thing deleted. 00067 //////////////////////////////////////////////////////////////////// 00068 template <class T> 00069 class WeakConstPointerTo : public WeakPointerToBase<T> { 00070 public: 00071 typedef TYPENAME WeakPointerToBase<T>::To To; 00072 PUBLISHED: 00073 INLINE WeakConstPointerTo(const To *ptr = (const To *)NULL); 00074 INLINE WeakConstPointerTo(const PointerTo<T> ©); 00075 INLINE WeakConstPointerTo(const ConstPointerTo<T> ©); 00076 INLINE WeakConstPointerTo(const WeakPointerTo<T> ©); 00077 INLINE WeakConstPointerTo(const WeakConstPointerTo<T> ©); 00078 00079 public: 00080 INLINE const To &operator *() const; 00081 INLINE const To *operator -> () const; 00082 INLINE operator const T *() const; 00083 00084 PUBLISHED: 00085 INLINE const To *p() const; 00086 INLINE const To *get_orig() const; 00087 00088 INLINE WeakConstPointerTo<T> &operator = (const To *ptr); 00089 INLINE WeakConstPointerTo<T> &operator = (const PointerTo<T> ©); 00090 INLINE WeakConstPointerTo<T> &operator = (const ConstPointerTo<T> ©); 00091 INLINE WeakConstPointerTo<T> &operator = (const WeakPointerTo<T> ©); 00092 INLINE WeakConstPointerTo<T> &operator = (const WeakConstPointerTo<T> ©); 00093 00094 // These functions normally wouldn't need to be redefined here, but 00095 // we do so anyway just to help out interrogate (which doesn't seem 00096 // to want to automatically export the WeakPointerToBase class). When 00097 // this works again in interrogate, we can remove these. 00098 INLINE bool is_null() const { return WeakPointerToBase<T>::is_null(); } 00099 INLINE void clear() { WeakPointerToBase<T>::clear(); } 00100 }; 00101 00102 #define WPT(type) WeakPointerTo< type > 00103 #define WCPT(type) WeakConstPointerTo< type > 00104 00105 #include "weakPointerTo.I" 00106 00107 #endif