00001 // Filename: nodeCachedReferenceCount.h 00002 // Created by: drose (07May05) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef NODECACHEDREFERENCECOUNT_H 00016 #define NODECACHEDREFERENCECOUNT_H 00017 00018 #include "pandabase.h" 00019 00020 #include "cachedTypedWritableReferenceCount.h" 00021 #include "nodeReferenceCount.h" // for node_unref_delete() 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : NodeCachedReferenceCount 00025 // Description : This class further specializes 00026 // CachedTypedWritableReferenceCount to also add a 00027 // node_ref_count, for the purposes of counting the 00028 // number of times the object is referenced by a "node", 00029 // presumably a PandaNode. 00030 // 00031 // This essentially combines the functionality of 00032 // NodeReferenceCount and 00033 // CachedTypedWritableReferenceCount, so that a 00034 // derivative of this object actually has three 00035 // counters: the standard reference count, the "cache" 00036 // reference count, and the "node" reference count. 00037 // Rather than multiply inheriting from the two 00038 // reference count classes, we inherit only from 00039 // CachedTypedWritableReferenceCount and simply 00040 // duplicate the functionality of NodeReferenceCount, to 00041 // avoid all of the problems associated with multiple 00042 // inheritance. 00043 // 00044 // The intended design is to use this as a base class 00045 // for RenderState and TransformState, both of which are 00046 // held by PandaNodes, and also have caches which are 00047 // independently maintained. By keeping track of how 00048 // many nodes hold a pointer to a particular object, we 00049 // can classify each object into node-referenced, 00050 // cache-referenced, or other, which is primarily useful 00051 // for PStats reporting. 00052 // 00053 // As with CachedTypedWritableReferenceCount's 00054 // cache_ref() and cache_unref(), the new methods 00055 // node_ref() and node_unref() automatically increment 00056 // and decrement the primary reference count as well. 00057 // In this case, however, there does exist a 00058 // NodePointerTo<> class to maintain the node_ref 00059 // counters automatically. 00060 //////////////////////////////////////////////////////////////////// 00061 class EXPCL_PANDA_PUTIL NodeCachedReferenceCount : public CachedTypedWritableReferenceCount { 00062 protected: 00063 INLINE NodeCachedReferenceCount(); 00064 INLINE NodeCachedReferenceCount(const NodeCachedReferenceCount ©); 00065 INLINE void operator = (const NodeCachedReferenceCount ©); 00066 INLINE ~NodeCachedReferenceCount(); 00067 00068 PUBLISHED: 00069 INLINE int get_node_ref_count() const; 00070 INLINE void node_ref() const; 00071 INLINE bool node_unref() const; 00072 INLINE bool test_ref_count_integrity() const; 00073 00074 enum Referenced { 00075 R_node = 0x001, 00076 R_cache = 0x002, 00077 }; 00078 00079 INLINE int get_referenced_bits() const; 00080 00081 protected: 00082 INLINE void node_unref_only() const; 00083 bool do_test_ref_count_integrity() const; 00084 00085 private: 00086 AtomicAdjust::Integer _node_ref_count; 00087 00088 public: 00089 static TypeHandle get_class_type() { 00090 return _type_handle; 00091 } 00092 00093 static void init_type() { 00094 CachedTypedWritableReferenceCount::init_type(); 00095 register_type(_type_handle, "NodeCachedReferenceCount", 00096 CachedTypedWritableReferenceCount::get_class_type()); 00097 } 00098 00099 private: 00100 static TypeHandle _type_handle; 00101 }; 00102 00103 #include "nodeCachedReferenceCount.I" 00104 00105 #endif 00106