Panda3D
 All Classes Functions Variables Enumerations
nodeReferenceCount.h
1 // Filename: nodeReferenceCount.h
2 // Created by: drose (01May06)
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 NODEREFERENCECOUNT_H
16 #define NODEREFERENCECOUNT_H
17 
18 #include "pandabase.h"
19 
20 #include "referenceCount.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : NodeReferenceCount
24 // Description : This class specializes ReferenceCount to add an
25 // additional counter, called node_ref_count, for the
26 // purposes of counting the number of times the object
27 // is referenced by a "node", whatever that may mean in
28 // context.
29 //
30 // The new methods node_ref() and node_unref()
31 // automatically increment and decrement the primary
32 // reference count as well. There also exists a
33 // NodePointerTo<> class to maintain the node_ref
34 // counters automatically.
35 //
36 // See also CachedTypedWritableReferenceCount, which is
37 // similar in principle, as well as
38 // NodeCachedReferenceCount, which combines both of
39 // these.
40 ////////////////////////////////////////////////////////////////////
41 class EXPCL_PANDAEXPRESS NodeReferenceCount : public ReferenceCount {
42 protected:
43  INLINE NodeReferenceCount();
44  INLINE NodeReferenceCount(const NodeReferenceCount &copy);
45  INLINE void operator = (const NodeReferenceCount &copy);
46  INLINE ~NodeReferenceCount();
47 
48 PUBLISHED:
49  INLINE int get_node_ref_count() const;
50  INLINE void node_ref() const;
51  INLINE bool node_unref() const;
52  INLINE bool test_ref_count_integrity() const;
53 
54 protected:
55  INLINE void node_unref_only() const;
56 
57  bool do_test_ref_count_integrity() const;
58 
59 private:
60  AtomicAdjust::Integer _node_ref_count;
61 
62 public:
63  static TypeHandle get_class_type() {
64  return _type_handle;
65  }
66 
67  static void init_type() {
68  ReferenceCount::init_type();
69  register_type(_type_handle, "NodeReferenceCount",
70  ReferenceCount::get_class_type());
71  }
72 
73 private:
74  static TypeHandle _type_handle;
75 };
76 
77 template<class RefCountType>
78 INLINE void node_unref_delete(RefCountType *ptr);
79 
80 ////////////////////////////////////////////////////////////////////
81 // Class : NodeRefCountObj
82 // Description : This works like RefCountObj, but it inherits from
83 // NodeReferenceCount instead of ReferenceCount.
84 ////////////////////////////////////////////////////////////////////
85 template<class Base>
86 class NodeRefCountObj : public NodeReferenceCount, public Base {
87 public:
88  INLINE NodeRefCountObj();
89  INLINE NodeRefCountObj(const Base &copy);
90  ALLOC_DELETED_CHAIN(NodeRefCountObj<Base>);
91 
92  static TypeHandle get_class_type() {
93  return _type_handle;
94  }
95  static void init_type();
96 
97 private:
98  static TypeHandle _type_handle;
99 };
100 
101 #include "nodeReferenceCount.I"
102 
103 #endif
104 
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn&#39;t completely bogus.
This class specializes ReferenceCount to add an additional counter, called node_ref_count, for the purposes of counting the number of times the object is referenced by a &quot;node&quot;, whatever that may mean in context.
This works like RefCountObj, but it inherits from NodeReferenceCount instead of ReferenceCount.
A base class for all things that want to be reference-counted.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85