Panda3D

Loading...
Searching...
No Matches
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
19#include "cachedTypedWritableReferenceCount.h"
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 */
49 class EXPCL_PANDA_PUTIL NodeCachedReferenceCount : public CachedTypedWritableReferenceCount {
50 protected:
51 INLINE NodeCachedReferenceCount();
52 INLINE NodeCachedReferenceCount(const NodeCachedReferenceCount &copy);
53 INLINE void operator = (const NodeCachedReferenceCount &copy);
54 INLINE ~NodeCachedReferenceCount();
55
56PUBLISHED:
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
91#include "nodeCachedReferenceCount.I"
92
93#endif
cachedTypedWritableReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
CachedTypedWritableReferenceCount::test_ref_count_integrity
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
Definition cachedTypedWritableReferenceCount.I:155
NodeCachedReferenceCount::node_unref
bool node_unref() const
Explicitly decrements the node reference count and the normal reference count simultaneously.
Definition nodeCachedReferenceCount.I:140
NodeCachedReferenceCount::node_ref
void node_ref() const
Explicitly increments the reference count.
Definition nodeCachedReferenceCount.I:123
NodeCachedReferenceCount::get_node_ref_count
int get_node_ref_count() const
Returns the current reference count.
Definition nodeCachedReferenceCount.I:107
NodeCachedReferenceCount::get_referenced_bits
int get_referenced_bits() const
Returns the union of the values defined in the Referenced enum that represents the various things tha...
Definition nodeCachedReferenceCount.I:167
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
nodeCachedReferenceCount.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodeReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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