Panda3D
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ReferenceCount Class Reference

A base class for all things that want to be reference-counted. More...

#include "referenceCount.h"

Inheritance diagram for ReferenceCount:
MemoryBase AICharacter BamReader::AuxData BaseIntegrator BaseParticleEmitter BaseParticleFactory BaseParticleRenderer Buffer ClockObject ColorInterpolationManager ColorInterpolationSegment Connection CullPlanes CullResult DownloadDb::FileRecord DownloadDb::MultifileRecord GeomCacheEntry GeomVertexArrayDataHandle GraphicsEngine LwoPolygons::Polygon MaxNodeDesc MayaApi MayaBlendDesc MayaNodeDesc ModelRoot::ModelReference MouseWatcherGroup Multifile NodePathComponent NodeReferenceCount NurbsCurveEvaluator NurbsCurveResult NurbsSurfaceEvaluator NurbsSurfaceResult ParametricCurveCollection PartBundleHandle PathReplace PhysxShapeDesc PhysxVehicleDesc PhysxWheelDesc PNMBrush PreparedGraphicsObjects PStatClientVersion PStatCollectorForwardBase PStatMonitor PStatThreadData QtessSurface RefCountObj< Base > RefCountProxy< Base > RPLight Shader::ShaderFile ShadowManager SpriteAnim TexturePeeker TypedReferenceCount TypedWritableReferenceCount VertexDataBlock VertexDataSaveBlock VirtualFileList XFileDataObject XFileNode

Public Member Functions

int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static void init_type ()
 

Public Attributes

 get_ref_count
 Returns the current reference count. More...
 

Detailed Description

A base class for all things that want to be reference-counted.

ReferenceCount works in conjunction with PointerTo to automatically delete objects when the last pointer to them goes away.

Definition at line 38 of file referenceCount.h.

Member Function Documentation

◆ get_weak_list()

WeakReferenceList * ReferenceCount::get_weak_list ( ) const
inline

Returns the WeakReferenceList associated with this ReferenceCount object.

If there has never been a WeakReferenceList associated with this object, creates one now.

The returned object will be deleted automatically when all weak and strong references to the object have gone.

Definition at line 257 of file referenceCount.I.

References AtomicAdjustDummyImpl::get_ptr().

◆ has_weak_list()

bool ReferenceCount::has_weak_list ( ) const
inline

Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise.

In general, this will be true if there was ever a WeakPointerTo created for this object (even if there is not any for it now).

Definition at line 244 of file referenceCount.I.

◆ local_object()

void ReferenceCount::local_object ( )
inline

This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack.

This allows the object to be passed to functions that will increment and decrement the object's reference count temporarily, and it will prevent the object from being deleted (inappropriately), when the reference count returns to zero. It actually achieves this by setting a large positive value in the reference count field.

Definition at line 229 of file referenceCount.I.

Referenced by AsyncTaskManager::find_task(), AsyncTaskManager::find_tasks(), and AsyncTaskManager::find_tasks_matching().

◆ ref()

void ReferenceCount::ref ( ) const
inline

Explicitly increments the reference count.

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

Definition at line 151 of file referenceCount.I.

Referenced by CPT(), and PT().

◆ ref_if_nonzero()

bool ReferenceCount::ref_if_nonzero ( ) const
inline

Atomically increases the reference count of this object if it is not zero.

Do not use this. This exists only to implement a special case for weak pointers.

Returns
true if the reference count was incremented, false if it was zero.

Definition at line 306 of file referenceCount.I.

References AtomicAdjustDummyImpl::compare_and_exchange(), AtomicAdjustDummyImpl::get(), and test_ref_count_integrity().

◆ test_ref_count_integrity()

bool ReferenceCount::test_ref_count_integrity ( ) const
inline

Does some easy checks to make sure that the reference count isn't completely bogus.

Returns true if ok, false otherwise.

Definition at line 197 of file referenceCount.I.

Referenced by EggGroupNode::add_child(), InternalName::find_ancestor(), InternalName::get_ancestor(), InternalName::get_top(), ref_if_nonzero(), and split_vertex().

◆ test_ref_count_nonzero()

bool ReferenceCount::test_ref_count_nonzero ( ) const
inline

Does some easy checks to make sure that the reference count isn't zero, or completely bogus.

Returns true if ok, false otherwise.

Definition at line 210 of file referenceCount.I.

◆ unref()

bool ReferenceCount::unref ( ) const
inlinevirtual

Explicitly decrements the reference count.

Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic.) However, see the helper function unref_delete().

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is true if the new reference count is nonzero, false if it is zero.

Reimplemented in TransformState, RenderState, RenderEffects, RenderAttrib, GeomVertexArrayFormat, GeomVertexFormat, and InternalName.

Definition at line 179 of file referenceCount.I.

Referenced by RenderEffect::finalize(), Texture::finalize(), NodeReferenceCount::node_unref(), NodeCachedReferenceCount::node_unref(), InternalName::unref(), GeomVertexFormat::unref(), and GeomVertexArrayFormat::unref().

◆ weak_ref()

WeakReferenceList * ReferenceCount::weak_ref ( )
inline

Adds the indicated PointerToVoid as a weak reference to this object.

Returns an object that will persist as long as any reference (strong or weak) exists, for calling unref() or checking whether the object still exists.

Definition at line 271 of file referenceCount.I.

◆ weak_unref()

void ReferenceCount::weak_unref ( )
inline

Removes the indicated PointerToVoid as a weak reference to this object.

It must have previously been added via a call to weak_ref().

Definition at line 288 of file referenceCount.I.

Member Data Documentation

◆ get_ref_count

int ReferenceCount::get_ref_count
inline

Returns the current reference count.

Definition at line 53 of file referenceCount.h.

Referenced by RenderState::list_cycles().


The documentation for this class was generated from the following files: