Panda3D
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions

NodeCachedReferenceCount Class Reference

This class further specializes CachedTypedWritableReferenceCount to also add a node_ref_count, for the purposes of counting the number of times the object is referenced by a "node", presumably a PandaNode. More...

#include "nodeCachedReferenceCount.h"

Inheritance diagram for NodeCachedReferenceCount:
CachedTypedWritableReferenceCount TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase RenderState TransformState

List of all members.

Public Types

enum  Referenced { R_node = 0x001, R_cache = 0x002 }

Public Member Functions

int get_node_ref_count () const
 Returns the current reference count.
int get_referenced_bits () const
 Returns the union of the values defined in the Referenced enum that represents the various things that appear to be holding a pointer to this object.
void node_ref () const
 Explicitly increments the reference count.
bool node_unref () const
 Explicitly decrements the node reference count and the normal reference count simultaneously.
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.

Static Public Member Functions

static TypeHandle get_class_type ()
static void init_type ()

Protected Member Functions

 NodeCachedReferenceCount ()
 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.
 NodeCachedReferenceCount (const NodeCachedReferenceCount &copy)
 The copies of reference-counted objects do not themselves inherit the reference count!
 ~NodeCachedReferenceCount ()
 The ReferenceCount destructor is protected to discourage users from accidentally trying to delete a ReferenceCount pointer directly.
bool do_test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.
void node_unref_only () const
 Decrements the node reference count without affecting the normal reference count.
void operator= (const NodeCachedReferenceCount &copy)
 The copies of reference-counted objects do not themselves inherit the reference count!

Detailed Description

This class further specializes CachedTypedWritableReferenceCount to also add a node_ref_count, for the purposes of counting the number of times the object is referenced by a "node", presumably a PandaNode.

This essentially combines the functionality of NodeReferenceCount and CachedTypedWritableReferenceCount, so that a derivative of this object actually has three counters: the standard reference count, the "cache" reference count, and the "node" reference count. Rather than multiply inheriting from the two reference count classes, we inherit only from CachedTypedWritableReferenceCount and simply duplicate the functionality of NodeReferenceCount, to avoid all of the problems associated with multiple inheritance.

The intended design is to use this as a base class for RenderState and TransformState, both of which are held by PandaNodes, and also have caches which are independently maintained. By keeping track of how many nodes hold a pointer to a particular object, we can classify each object into node-referenced, cache-referenced, or other, which is primarily useful for PStats reporting.

As with CachedTypedWritableReferenceCount's cache_ref() and cache_unref(), the new methods node_ref() and node_unref() automatically increment and decrement the primary reference count as well. In this case, however, there does exist a NodePointerTo<> class to maintain the node_ref counters automatically.

Definition at line 61 of file nodeCachedReferenceCount.h.


Constructor & Destructor Documentation

NodeCachedReferenceCount::NodeCachedReferenceCount ( ) [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 30 of file nodeCachedReferenceCount.I.

NodeCachedReferenceCount::NodeCachedReferenceCount ( const NodeCachedReferenceCount copy) [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 45 of file nodeCachedReferenceCount.I.

NodeCachedReferenceCount::~NodeCachedReferenceCount ( ) [inline, protected]

The ReferenceCount destructor is protected to discourage users from accidentally trying to delete a ReferenceCount pointer directly.

This is almost always a bad idea, since the destructor is not virtual, and you've almost certainly got some pointer to something that inherits from ReferenceCount, not just a plain old ReferenceCount object.

Definition at line 90 of file nodeCachedReferenceCount.I.


Member Function Documentation

bool NodeCachedReferenceCount::do_test_ref_count_integrity ( ) const [protected]

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

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 26 of file nodeCachedReferenceCount.cxx.

Referenced by test_ref_count_integrity().

int NodeCachedReferenceCount::get_node_ref_count ( ) const [inline]

Returns the current reference count.

Definition at line 133 of file nodeCachedReferenceCount.I.

References test_ref_count_integrity().

Referenced by get_referenced_bits().

int NodeCachedReferenceCount::get_referenced_bits ( ) const [inline]

Returns the union of the values defined in the Referenced enum that represents the various things that appear to be holding a pointer to this object.

If R_node is included, at least one node is holding a pointer; if R_cache is included, at least one cache element is.

Definition at line 204 of file nodeCachedReferenceCount.I.

References CachedTypedWritableReferenceCount::get_cache_ref_count(), and get_node_ref_count().

Referenced by TransformState::cache_ref(), RenderState::cache_ref(), TransformState::cache_unref(), RenderState::cache_unref(), TransformState::node_ref(), RenderState::node_ref(), TransformState::node_unref(), and RenderState::node_unref().

void NodeCachedReferenceCount::node_ref ( ) const [inline]

Explicitly increments the reference count.

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.

Reimplemented in RenderState, and TransformState.

Definition at line 153 of file nodeCachedReferenceCount.I.

References ReferenceCount::ref(), and test_ref_count_integrity().

bool NodeCachedReferenceCount::node_unref ( ) const [inline]

Explicitly decrements the node reference count and the normal reference count simultaneously.

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

Reimplemented in RenderState, and TransformState.

Definition at line 172 of file nodeCachedReferenceCount.I.

References node_unref_only(), and ReferenceCount::unref().

void NodeCachedReferenceCount::node_unref_only ( ) const [inline, protected]

Decrements the node reference count without affecting the normal reference count.

Intended to be called by derived classes only, presumably to reimplement node_unref().

Definition at line 225 of file nodeCachedReferenceCount.I.

References test_ref_count_integrity().

Referenced by node_unref().

void NodeCachedReferenceCount::operator= ( const NodeCachedReferenceCount copy) [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 63 of file nodeCachedReferenceCount.I.

bool NodeCachedReferenceCount::test_ref_count_integrity ( ) const [inline]

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

Reimplemented from CachedTypedWritableReferenceCount.

Definition at line 184 of file nodeCachedReferenceCount.I.

References do_test_ref_count_integrity().

Referenced by get_node_ref_count(), node_ref(), and node_unref_only().


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