Panda3D
 All Classes Functions Variables Enumerations
nodeCachedReferenceCount.h
1 // Filename: nodeCachedReferenceCount.h
2 // Created by: drose (07May05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NODECACHEDREFERENCECOUNT_H
16 #define NODECACHEDREFERENCECOUNT_H
17 
18 #include "pandabase.h"
19 
20 #include "cachedTypedWritableReferenceCount.h"
21 #include "nodeReferenceCount.h" // for node_unref_delete()
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : NodeCachedReferenceCount
25 // Description : This class further specializes
26 // CachedTypedWritableReferenceCount to also add a
27 // node_ref_count, for the purposes of counting the
28 // number of times the object is referenced by a "node",
29 // presumably a PandaNode.
30 //
31 // This essentially combines the functionality of
32 // NodeReferenceCount and
33 // CachedTypedWritableReferenceCount, so that a
34 // derivative of this object actually has three
35 // counters: the standard reference count, the "cache"
36 // reference count, and the "node" reference count.
37 // Rather than multiply inheriting from the two
38 // reference count classes, we inherit only from
39 // CachedTypedWritableReferenceCount and simply
40 // duplicate the functionality of NodeReferenceCount, to
41 // avoid all of the problems associated with multiple
42 // inheritance.
43 //
44 // The intended design is to use this as a base class
45 // for RenderState and TransformState, both of which are
46 // held by PandaNodes, and also have caches which are
47 // independently maintained. By keeping track of how
48 // many nodes hold a pointer to a particular object, we
49 // can classify each object into node-referenced,
50 // cache-referenced, or other, which is primarily useful
51 // for PStats reporting.
52 //
53 // As with CachedTypedWritableReferenceCount's
54 // cache_ref() and cache_unref(), the new methods
55 // node_ref() and node_unref() automatically increment
56 // and decrement the primary reference count as well.
57 // In this case, however, there does exist a
58 // NodePointerTo<> class to maintain the node_ref
59 // counters automatically.
60 ////////////////////////////////////////////////////////////////////
62 protected:
63  INLINE NodeCachedReferenceCount();
64  INLINE NodeCachedReferenceCount(const NodeCachedReferenceCount &copy);
65  INLINE void operator = (const NodeCachedReferenceCount &copy);
66  INLINE ~NodeCachedReferenceCount();
67 
68 PUBLISHED:
69  INLINE int get_node_ref_count() const;
70  INLINE void node_ref() const;
71  INLINE bool node_unref() const;
72  INLINE bool test_ref_count_integrity() const;
73 
74  enum Referenced {
75  R_node = 0x001,
76  R_cache = 0x002,
77  };
78 
79  INLINE int get_referenced_bits() const;
80 
81 protected:
82  INLINE void node_unref_only() const;
83  bool do_test_ref_count_integrity() const;
84 
85 private:
86  AtomicAdjust::Integer _node_ref_count;
87 
88 public:
89  static TypeHandle get_class_type() {
90  return _type_handle;
91  }
92 
93  static void init_type() {
94  CachedTypedWritableReferenceCount::init_type();
95  register_type(_type_handle, "NodeCachedReferenceCount",
96  CachedTypedWritableReferenceCount::get_class_type());
97  }
98 
99 private:
100  static TypeHandle _type_handle;
101 };
102 
103 #include "nodeCachedReferenceCount.I"
104 
105 #endif
106 
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn&#39;t completely bogus.
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 &quot;node&quot;, presumably a PandaNode.
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85