00001 // Filename: weakPointerToVoid.I 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 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: WeakPointerToVoid::Constructor 00018 // Access: Protected 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE WeakPointerToVoid:: 00022 WeakPointerToVoid() { 00023 _ptr_was_deleted = false; 00024 _callback = NULL; 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: WeakPointerToVoid::Destructor 00029 // Access: Protected 00030 // Description: 00031 //////////////////////////////////////////////////////////////////// 00032 INLINE WeakPointerToVoid:: 00033 ~WeakPointerToVoid() { 00034 } 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Function: WeakPointerToVoid::mark_deleted 00038 // Access: Public 00039 // Description: This is intended only to be called by the 00040 // WeakPointerList destructor. It indicates that the 00041 // object that we were pointing to has just been 00042 // deleted. 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE void WeakPointerToVoid:: 00045 mark_deleted() { 00046 nassertv(!_ptr_was_deleted); 00047 _ptr_was_deleted = true; 00048 if (_callback != (WeakPointerCallback *)NULL) { 00049 _callback->wp_callback(_void_ptr); 00050 } 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: WeakPointerToVoid::set_callback 00055 // Access: Public 00056 // Description: Sets a callback that will be made when the pointer is 00057 // deleted. If a previous callback has already been 00058 // set, it will be replaced. 00059 // 00060 // If the pointer has already been deleted, the callback 00061 // will be made immediately. 00062 //////////////////////////////////////////////////////////////////// 00063 INLINE void WeakPointerToVoid:: 00064 set_callback(WeakPointerCallback *callback) { 00065 _callback = callback; 00066 if (_ptr_was_deleted && _callback != (WeakPointerCallback *)NULL) { 00067 _callback->wp_callback(_void_ptr); 00068 } 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: WeakPointerToVoid::get_callback 00073 // Access: Public 00074 // Description: Returns the callback that will be made when the 00075 // pointer is deleted, or NULL if no callback has been 00076 // set. 00077 //////////////////////////////////////////////////////////////////// 00078 INLINE WeakPointerCallback *WeakPointerToVoid:: 00079 get_callback() const { 00080 return _callback; 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: WeakPointerToVoid::was_deleted 00085 // Access: Published 00086 // Description: Returns true if the object we are pointing to has 00087 // been deleted, false otherwise. 00088 //////////////////////////////////////////////////////////////////// 00089 INLINE bool WeakPointerToVoid:: 00090 was_deleted() const { 00091 return _ptr_was_deleted; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: WeakPointerToVoid::is_valid_pointer 00096 // Access: Published 00097 // Description: Returns true if the pointer is not null and the 00098 // object has not been deleted. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE bool WeakPointerToVoid:: 00101 is_valid_pointer() const { 00102 return (_void_ptr != (void *)NULL) && !_ptr_was_deleted; 00103 }