Panda3D
nodeReferenceCount.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 nodeReferenceCount.h
10  * @author drose
11  * @date 2006-05-01
12  */
13 
14 #ifndef NODEREFERENCECOUNT_H
15 #define NODEREFERENCECOUNT_H
16 
17 #include "pandabase.h"
18 
19 #include "referenceCount.h"
20 
21 /**
22  * This class specializes ReferenceCount to add an additional counter, called
23  * node_ref_count, for the purposes of counting the number of times the object
24  * is referenced by a "node", whatever that may mean in context.
25  *
26  * The new methods node_ref() and node_unref() automatically increment and
27  * decrement the primary reference count as well. There also exists a
28  * NodePointerTo<> class to maintain the node_ref counters automatically.
29  *
30  * See also CachedTypedWritableReferenceCount, which is similar in principle,
31  * as well as NodeCachedReferenceCount, which combines both of these.
32  */
33 class EXPCL_PANDA_EXPRESS NodeReferenceCount : public ReferenceCount {
34 protected:
35  INLINE NodeReferenceCount();
36  INLINE NodeReferenceCount(const NodeReferenceCount &copy);
37  INLINE void operator = (const NodeReferenceCount &copy);
38  INLINE ~NodeReferenceCount();
39 
40 PUBLISHED:
41  INLINE int get_node_ref_count() const;
42  INLINE void node_ref() const;
43  INLINE bool node_unref() const;
44  INLINE bool test_ref_count_integrity() const;
45  INLINE void node_unref_only() const;
46 
47 protected:
48  bool do_test_ref_count_integrity() const;
49 
50 private:
51  mutable AtomicAdjust::Integer _node_ref_count;
52 
53 public:
54  static TypeHandle get_class_type() {
55  return _type_handle;
56  }
57 
58  static void init_type() {
59  ReferenceCount::init_type();
60  register_type(_type_handle, "NodeReferenceCount",
61  ReferenceCount::get_class_type());
62  }
63 
64 private:
65  static TypeHandle _type_handle;
66 };
67 
68 template<class RefCountType>
69 INLINE void node_unref_delete(RefCountType *ptr);
70 
71 /**
72  * This works like RefCountObj, but it inherits from NodeReferenceCount
73  * instead of ReferenceCount.
74  */
75 template<class Base>
76 class NodeRefCountObj : public NodeReferenceCount, public Base {
77 public:
78  INLINE NodeRefCountObj();
79  INLINE NodeRefCountObj(const Base &copy);
80  ALLOC_DELETED_CHAIN(NodeRefCountObj<Base>);
81 
82  static TypeHandle get_class_type() {
83  return _type_handle;
84  }
85  static void init_type();
86 
87 private:
88  static TypeHandle _type_handle;
89 };
90 
91 #include "nodeReferenceCount.I"
92 
93 #endif
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
This class specializes ReferenceCount to add an additional counter, called node_ref_count,...
This works like RefCountObj, but it inherits from NodeReferenceCount instead of ReferenceCount.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81
void node_unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...