Panda3D
Public Member Functions | Static Public Member Functions | Protected Member Functions
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 Light LwoPolygons::Polygon MaxNodeDesc MayaApi MayaBlendDesc MayaNodeDesc ModelRoot::ModelReference MouseWatcherGroup Multifile NodePathComponent NodeReferenceCount NurbsCurveEvaluator NurbsCurveResult NurbsSurfaceEvaluator NurbsSurfaceResult PandaNode ParametricCurveCollection PartBundleHandle PathReplace PhysxShapeDesc PhysxVehicleDesc PhysxWheelDesc PNMBrush PreparedGraphicsObjects PStatClientVersion PStatCollectorForwardBase PStatMonitor PStatThreadData QtessSurface RecorderBase RefCountObj< Base > RefCountProxy< Base > Shader::ShaderFile SoftNodeDesc SpriteAnim TextGlyph TexturePeeker TypedReferenceCount TypedWritableReferenceCount VertexDataBlock VertexDataSaveBlock VirtualFileList XFileDataObject XFileNode

List of all members.

Public Member Functions

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

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Protected Member Functions

 ReferenceCount ()
 The ReferenceCount constructor is protected because you almost never want to create just a ReferenceCount object by itself, and it's probably a mistake if you try.
 ReferenceCount (const ReferenceCount &)
 The copies of reference-counted objects do not themselves inherit the reference count!
bool do_test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.
bool do_test_ref_count_nonzero () const
 Returns true if the reference count is nonzero, false otherwise.
void operator= (const ReferenceCount &)
 The copies of reference-counted objects do not themselves inherit the reference count!

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.


Constructor & Destructor Documentation

ReferenceCount::ReferenceCount ( ) [inline, protected]

The ReferenceCount constructor is protected because you almost never want to create just a ReferenceCount object by itself, and it's probably a mistake if you try.

ReferenceCount doesn't store any useful information in its own right; its only purpose is to add reference-counting to some other class via inheritance.

Definition at line 35 of file referenceCount.I.

ReferenceCount::ReferenceCount ( const ReferenceCount ) [inline, protected]

The copies of reference-counted objects do not themselves inherit the reference count!

This copy constructor is protected because you almost never want to create just a ReferenceCount object by itself, and it's probably a mistake if you try.

Definition at line 54 of file referenceCount.I.


Member Function Documentation

bool ReferenceCount::do_test_ref_count_integrity ( ) const [protected]

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

Returns true if ok, false otherwise.

Reimplemented in NodeCachedReferenceCount, NodeReferenceCount, and CachedTypedWritableReferenceCount.

Definition at line 29 of file referenceCount.cxx.

Referenced by do_test_ref_count_nonzero(), and test_ref_count_integrity().

bool ReferenceCount::do_test_ref_count_nonzero ( ) const [protected]

Returns true if the reference count is nonzero, false otherwise.

Definition at line 56 of file referenceCount.cxx.

References do_test_ref_count_integrity().

Referenced by test_ref_count_nonzero().

int ReferenceCount::get_ref_count ( ) 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 307 of file referenceCount.I.

Referenced by weak_ref().

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

Referenced by weak_unref().

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

Referenced by BoundingSphere::around_finite(), PGTop::cull_callback(), Texture::do_clear(), BoundingSphere::extend_by_finite(), BoundingSphere::extend_by_hexahedron(), AsyncTaskManager::find_task(), AsyncTaskManager::find_tasks(), and AsyncTaskManager::find_tasks_matching().

void ReferenceCount::operator= ( const ReferenceCount ) [inline, protected]

The copies of reference-counted objects do not themselves inherit the reference count!

This copy assignment operator is protected because you almost never want to copy just a ReferenceCount object by itself, and it's probably a mistake if you try. Instead, this should only be called from a derived class that implements this operator and then calls up the inheritance chain.

Definition at line 76 of file referenceCount.I.

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 test_ref_count_integrity().

Referenced by CachedTypedWritableReferenceCount::cache_ref(), TypedWritable::decode_raw_from_bam_stream(), Texture::make_this_from_bam(), NodeReferenceCount::node_ref(), NodeCachedReferenceCount::node_ref(), BamCacheRecord::set_data(), CullableObject::set_draw_callback(), and ModelRoot::set_reference().

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

Returns true if ok, false otherwise.

Reimplemented in NodeCachedReferenceCount, NodeReferenceCount, and CachedTypedWritableReferenceCount.

Definition at line 236 of file referenceCount.I.

References do_test_ref_count_integrity().

Referenced by EggGroupNode::add_child(), InternalName::find_ancestor(), InternalName::get_ancestor(), get_ref_count(), InternalName::get_top(), ref(), MouseWatcher::throw_event_pattern(), unref(), and EggNode::update_under().

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

References do_test_ref_count_nonzero().

Referenced by CopyOnWritePointer::test_ref_count_nonzero().

bool ReferenceCount::unref ( ) const [inline, virtual]

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

References test_ref_count_integrity().

Referenced by CachedTypedWritableReferenceCount::cache_unref(), TypedWritable::decode_raw_from_bam_stream(), RenderEffect::finalize(), Texture::finalize(), NodeReferenceCount::node_unref(), NodeCachedReferenceCount::node_unref(), RocketRenderInterface::ReleaseTexture(), InternalName::unref(), GeomVertexFormat::unref(), GeomVertexArrayFormat::unref(), RenderAttrib::unref(), RenderEffects::unref(), RenderState::unref(), and TransformState::unref().

void ReferenceCount::weak_ref ( WeakPointerToVoid ptv) [inline]

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

Definition at line 321 of file referenceCount.I.

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

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

References has_weak_list().


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