Panda3D
 All Classes Functions Variables Enumerations
cachedTypedWritableReferenceCount.h
1 // Filename: cachedTypedWritableReferenceCount.h
2 // Created by: drose (25Jan05)
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 CACHEDTYPEDWRITABLEREFERENCECOUNT_H
16 #define CACHEDTYPEDWRITABLEREFERENCECOUNT_H
17 
18 #include "pandabase.h"
19 
20 #include "typedWritableReferenceCount.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : CachedTypedWritableReferenceCount
24 // Description : This is a special extension to ReferenceCount that
25 // includes dual reference counts: the standard
26 // reference count number, which includes all references
27 // to the object, and a separate number (the cache
28 // reference count) that counts the number of references
29 // to the object just within its cache alone. When
30 // get_ref_count() == get_cache_ref_count(), the object
31 // is not referenced outside the cache.
32 //
33 // The cache refs must be explicitly maintained; there
34 // is no PointerTo<> class to maintain the cache
35 // reference counts automatically. The cache reference
36 // count is automatically included in the overall
37 // reference count: calling cache_ref() and
38 // cache_unref() automatically calls ref() and unref().
39 ////////////////////////////////////////////////////////////////////
41 protected:
43  INLINE CachedTypedWritableReferenceCount(const CachedTypedWritableReferenceCount &copy);
44  INLINE void operator = (const CachedTypedWritableReferenceCount &copy);
45  INLINE ~CachedTypedWritableReferenceCount();
46 
47 PUBLISHED:
48  INLINE int get_cache_ref_count() const;
49  INLINE void cache_ref() const;
50  INLINE bool cache_unref() const;
51  INLINE bool test_ref_count_integrity() const;
52 
53 protected:
54  INLINE void cache_unref_only() const;
55  bool do_test_ref_count_integrity() const;
56 
57 private:
58  AtomicAdjust::Integer _cache_ref_count;
59 
60 public:
61  static TypeHandle get_class_type() {
62  return _type_handle;
63  }
64 
65  static void init_type() {
66  TypedWritableReferenceCount::init_type();
67  register_type(_type_handle, "CachedTypedWritableReferenceCount",
68  TypedWritableReferenceCount::get_class_type());
69  }
70 
71 private:
72  static TypeHandle _type_handle;
73 };
74 
75 template<class RefCountType>
76 INLINE void cache_unref_delete(RefCountType *ptr);
77 
78 #include "cachedTypedWritableReferenceCount.I"
79 
80 #endif
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn&#39;t completely bogus.
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85