Panda3D
cachedTypedWritableReferenceCount.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 cachedTypedWritableReferenceCount.h
10  * @author drose
11  * @date 2005-01-25
12  */
13 
14 #ifndef CACHEDTYPEDWRITABLEREFERENCECOUNT_H
15 #define CACHEDTYPEDWRITABLEREFERENCECOUNT_H
16 
17 #include "pandabase.h"
18 
20 
21 /**
22  * This is a special extension to ReferenceCount that includes dual reference
23  * counts: the standard reference count number, which includes all references
24  * to the object, and a separate number (the cache reference count) that
25  * counts the number of references to the object just within its cache alone.
26  * When get_ref_count() == get_cache_ref_count(), the object is not referenced
27  * outside the cache.
28  *
29  * The cache refs must be explicitly maintained; there is no PointerTo<> class
30  * to maintain the cache reference counts automatically. The cache reference
31  * count is automatically included in the overall reference count: calling
32  * cache_ref() and cache_unref() automatically calls ref() and unref().
33  */
35 protected:
38  INLINE void operator = (const CachedTypedWritableReferenceCount &copy);
40 
41 PUBLISHED:
42  INLINE int get_cache_ref_count() const;
43  INLINE void cache_ref() const;
44  INLINE bool cache_unref() const;
45  INLINE bool test_ref_count_integrity() const;
46 
47  MAKE_PROPERTY(cache_ref_count, get_cache_ref_count);
48 
49 public:
50  INLINE void cache_ref_only() const;
51 
52 protected:
53  INLINE void cache_unref_only() const;
54  bool do_test_ref_count_integrity() const;
55 
56 private:
57  mutable AtomicAdjust::Integer _cache_ref_count;
58 
59 public:
60  static TypeHandle get_class_type() {
61  return _type_handle;
62  }
63 
64  static void init_type() {
65  TypedWritableReferenceCount::init_type();
66  register_type(_type_handle, "CachedTypedWritableReferenceCount",
67  TypedWritableReferenceCount::get_class_type());
68  }
69 
70 private:
71  static TypeHandle _type_handle;
72 };
73 
74 template<class RefCountType>
75 INLINE void cache_unref_delete(RefCountType *ptr);
76 
78 
79 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void cache_unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
This is a special extension to ReferenceCount that includes dual reference counts: the standard refer...
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.
bool test_ref_count_integrity() const
Does some easy checks to make sure that the reference count isn't completely bogus.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:81