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