Panda3D
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

WeakPointerTo< T > Class Template Reference

WeakPointerTo is similar to PointerTo, except that it does not actually prevent the referenced pointer from deleting. More...

#include "weakPointerTo.h"

Inheritance diagram for WeakPointerTo< T >:
WeakPointerToBase< T > WeakPointerToVoid PointerToVoid MemoryBase

List of all members.

Public Types

typedef WeakPointerToBase< T >::To To

Public Member Functions

 WeakPointerTo (To *ptr=(To *) NULL)
 WeakPointerTo (const PointerTo< T > &copy)
 WeakPointerTo (const WeakPointerTo< T > &copy)
void clear ()
 A convenient way to set the PointerTo object to NULL.
WeakPointerCallbackget_callback () const
 Returns the callback that will be made when the pointer is deleted, or NULL if no callback has been set.
size_t get_hash () const
To * get_orig () const
 Returns the original pointer value, even if the object has since been deleted.
bool is_null () const
 Returns true if the PointerTo is a NULL pointer, false otherwise.
bool is_valid_pointer () const
 Returns true if the pointer is not null and the object has not been deleted.
void mark_deleted ()
 This is intended only to be called by the WeakPointerList destructor.
void operator delete (void *ptr)
void operator delete (void *ptr, void *)
void operator delete[] (void *ptr)
void operator delete[] (void *, void *)
void * operator new (size_t size)
void * operator new (size_t size, void *ptr)
void * operator new[] (size_t size, void *ptr)
void * operator new[] (size_t size)
 operator T * () const
 We also have the typecast operator to automatically convert WeakPointerTo's to the required kind of actual pointer.
bool operator!= (const To *other) const
bool operator!= (To *other) const
bool operator!= (const WeakPointerToBase< To > &other) const
bool operator!= (const PointerToBase< To > &other) const
bool operator!= (const PointerToVoid &other) const
To & operator* () const
To * operator-> () const
bool operator< (const To *other) const
bool operator< (const WeakPointerToBase< To > &other) const
bool operator< (const PointerToBase< To > &other) const
bool operator< (const void *other) const
bool operator< (const PointerToVoid &other) const
bool operator<= (const To *other) const
bool operator<= (To *other) const
bool operator<= (const WeakPointerToBase< To > &other) const
bool operator<= (const PointerToBase< To > &other) const
WeakPointerTo< T > & operator= (const PointerTo< T > &copy)
WeakPointerTo< T > & operator= (To *ptr)
WeakPointerTo< T > & operator= (const WeakPointerTo< T > &copy)
bool operator== (To *other) const
bool operator== (const PointerToBase< To > &other) const
bool operator== (const WeakPointerToBase< To > &other) const
bool operator== (const PointerToVoid &other) const
bool operator== (const To *other) const
bool operator> (const WeakPointerToBase< To > &other) const
bool operator> (To *other) const
bool operator> (const PointerToBase< To > &other) const
bool operator> (const To *other) const
bool operator>= (To *other) const
bool operator>= (const PointerToBase< To > &other) const
bool operator>= (const To *other) const
bool operator>= (const WeakPointerToBase< To > &other) const
void output (ostream &out) const
 A handy function to output PointerTo's as a hex pointer followed by a reference count.
To * p () const
 Returns an ordinary pointer instead of a WeakPointerTo.
void refresh () const
 Informs the WeakPointerTo object that its pointer is no longer deleted.
void set_callback (WeakPointerCallback *callback)
 Sets a callback that will be made when the pointer is deleted.
bool was_deleted () const
 Returns true if the object we are pointing to has been deleted, false otherwise.

Protected Member Functions

void reassign (To *ptr)
 This is the main work of the PointerTo family.
void reassign (const WeakPointerToBase< To > &copy)
void reassign (const PointerToBase< To > &copy)

Protected Attributes

WeakPointerCallback_callback
bool _ptr_was_deleted
void * _void_ptr

Detailed Description

template<class T>
class WeakPointerTo< T >

WeakPointerTo is similar to PointerTo, except that it does not actually prevent the referenced pointer from deleting.

Instead, the referenced pointer is allowed to delete, but if this happens then was_deleted() will return true, and it will be an assertion error to dereference the pointer thereafter.

Definition at line 32 of file weakPointerTo.h.


Member Function Documentation

template<class T>
void WeakPointerTo< T >::clear ( ) [inline]

A convenient way to set the PointerTo object to NULL.

(Assignment to a NULL pointer also works, of course.)

Reimplemented from WeakPointerToBase< T >.

Definition at line 58 of file weakPointerTo.h.

WeakPointerCallback * WeakPointerToVoid::get_callback ( ) const [inline, inherited]

Returns the callback that will be made when the pointer is deleted, or NULL if no callback has been set.

Definition at line 79 of file weakPointerToVoid.I.

template<class T >
WeakPointerTo< T >::To * WeakPointerTo< T >::get_orig ( ) const [inline]

Returns the original pointer value, even if the object has since been deleted.

Definition at line 113 of file weakPointerTo.I.

bool PointerToVoid::is_null ( ) const [inline, inherited]

Returns true if the PointerTo is a NULL pointer, false otherwise.

(Direct comparison to a NULL pointer also works.)

Reimplemented in PointerTo< T >, ThreadSafePointerTo< T >, and WeakConstPointerTo< T >.

Definition at line 54 of file pointerToVoid.I.

Referenced by TexturePeeker::is_valid().

bool WeakPointerToVoid::is_valid_pointer ( ) const [inline, inherited]

Returns true if the pointer is not null and the object has not been deleted.

Definition at line 101 of file weakPointerToVoid.I.

void WeakPointerToVoid::mark_deleted ( ) [inline, inherited]

This is intended only to be called by the WeakPointerList destructor.

It indicates that the object that we were pointing to has just been deleted.

Definition at line 45 of file weakPointerToVoid.I.

template<class T >
WeakPointerTo< T >::operator T * ( ) const [inline]

We also have the typecast operator to automatically convert WeakPointerTo's to the required kind of actual pointer.

This introduces ambiguities which the compiler will resolve one way or the other, but we don't care which way it goes because either will be correct.

Definition at line 86 of file weakPointerTo.I.

template<class T >
void WeakPointerToBase< T >::output ( ostream &  out) const [inline, inherited]

A handy function to output PointerTo's as a hex pointer followed by a reference count.

Definition at line 424 of file weakPointerToBase.I.

template<class T >
WeakPointerTo< T >::To * WeakPointerTo< T >::p ( ) const [inline]

Returns an ordinary pointer instead of a WeakPointerTo.

Useful to work around compiler problems, particularly for implicit upcasts.

Definition at line 100 of file weakPointerTo.I.

template<class T >
void WeakPointerToBase< T >::reassign ( To *  ptr) [protected, inherited]

This is the main work of the PointerTo family.

When the pointer is reassigned, decrement the old reference count and increment the new one.

Definition at line 69 of file weakPointerToBase.I.

References TypeHandle::none().

template<class T >
void WeakPointerToBase< T >::refresh ( ) const [inline, inherited]

Informs the WeakPointerTo object that its pointer is no longer deleted.

This may be used after a WeakPointerTo has deleted a deleted pointer, and then a new pointer has been reallocated. It's equivalent to simply reassigning the pointer to its new (i.e. original) value, but has the advantage that it is const, so can be used for WeakPointers used as keys in STL maps and sets.

Definition at line 412 of file weakPointerToBase.I.

void WeakPointerToVoid::set_callback ( WeakPointerCallback callback) [inline, inherited]

Sets a callback that will be made when the pointer is deleted.

If a previous callback has already been set, it will be replaced.

If the pointer has already been deleted, the callback will be made immediately.

Definition at line 64 of file weakPointerToVoid.I.

bool WeakPointerToVoid::was_deleted ( ) const [inline, inherited]

Returns true if the object we are pointing to has been deleted, false otherwise.

Definition at line 90 of file weakPointerToVoid.I.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations