Panda3D
Public Member Functions | Static Public Member Functions | 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 BamReader::AuxData BaseIntegrator BaseParticleEmitter BaseParticleFactory BaseParticleRenderer Buffer CFChannel ClockObject ColladaInput ColladaPrimitive 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 > Shader::ShaderFile SoftNodeDesc SpriteAnim TexturePeeker TypedReferenceCount TypedWritableReferenceCount VertexDataBlock VertexDataSaveBlock VirtualFileList XFileDataObject XFileNode

Public Member Functions

int get_ref_count () const
 Returns the current reference count. More...
 
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 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...
 
void weak_ref (WeakPointerToVoid *ptv)
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref (WeakPointerToVoid *ptv)
 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 ()
 

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 41 of file referenceCount.h.

Member Function Documentation

◆ get_ref_count()

int ReferenceCount::get_ref_count ( ) const
inline

◆ 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.

Definition at line 306 of file referenceCount.I.

References AtomicAdjustDummyImpl::get_ptr(), and weak_ref().

Referenced by has_weak_list(), and weak_ref().

◆ 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 293 of file referenceCount.I.

References get_weak_list().

Referenced by local_object(), and weak_unref().

◆ 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 275 of file referenceCount.I.

References has_weak_list().

Referenced by BoundingSphere::as_bounding_sphere(), PGTop::cull_callback(), CullTraverser::draw_bounding_volume(), Texture::ensure_loader_type(), AsyncTaskManager::find_task(), AsyncTaskManager::find_tasks(), AsyncTaskManager::find_tasks_matching(), EggLoader::make_polyset(), test_ref_count_nonzero(), and LODNode::verify_child_bounds().

◆ 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 179 of file referenceCount.I.

References AtomicAdjustDummyImpl::inc(), test_ref_count_integrity(), and unref().

Referenced by CachedTypedWritableReferenceCount::cache_ref(), Geom::calc_tight_bounds(), TypedWritable::decode_raw_from_bam_stream(), Texture::finalize(), BamReader::get_factory(), FmodAudioSound::get_finished_event(), get_ref_count(), NodeReferenceCount::node_ref(), NodeCachedReferenceCount::node_ref(), EggGroupNode::rebuild_vertex_pools(), EggGroupNode::recompute_vertex_normals(), BamCacheRecord::set_data(), ModelRoot::set_reference(), AudioManager::shutdown(), Thread::start(), RenderAttrib::validate_attribs(), and ShaderGenerator::~ShaderGenerator().

◆ 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 235 of file referenceCount.I.

References test_ref_count_nonzero().

Referenced by EggGroupNode::add_child(), EggPrimitive::copy_vertices(), get_ref_count(), EggVertex::has_pref(), MouseWatcher::note_activity(), EggNode::parse_egg(), EggGroupNode::rebuild_vertex_pools(), ProjectionScreen::recompute_if_stale(), ref(), EggGroup::steal_vrefs(), unref(), weak_ref(), and weak_unref().

◆ 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 251 of file referenceCount.I.

References local_object().

Referenced by test_ref_count_integrity().

◆ 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 FINAL, RenderState, RenderEffects, RenderAttrib, FINAL, FINAL, and FINAL.

Definition at line 214 of file referenceCount.I.

References AtomicAdjustDummyImpl::dec(), and test_ref_count_integrity().

Referenced by CachedTypedWritableReferenceCount::cache_unref(), RenderState::cull_callback(), RenderAttrib::cull_callback(), TypedWritable::decode_raw_from_bam_stream(), RenderEffect::finalize(), RenderEffects::finalize(), Texture::finalize(), NodeReferenceCount::node_unref(), NodeCachedReferenceCount::node_unref(), ref(), GeomCacheEntry::refresh(), and RenderEffects::safe_to_transform().

◆ weak_ref()

void ReferenceCount::weak_ref ( WeakPointerToVoid ptv)
inline

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

Definition at line 320 of file referenceCount.I.

References WeakReferenceList::add_reference(), get_weak_list(), test_ref_count_integrity(), and weak_unref().

Referenced by get_weak_list().

◆ weak_unref()

void ReferenceCount::weak_unref ( WeakPointerToVoid ptv)
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 336 of file referenceCount.I.

References has_weak_list(), and test_ref_count_integrity().

Referenced by weak_ref().


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