RefCnt Pile   version 0.0.1
C++ class implementing a simple reference counting mechanism.
refcnt.h
Go to the documentation of this file.
1 
10 #ifndef GUARD_REFCNT_H_INCLUDE
11 #define GUARD_REFCNT_H_INCLUDE
12 
13 #include <refcnt/refcnt-config.h>
14 
16 class REFCNT_EXPORT RefCnt {
17 
18 private:
19 
20  int ref_cnt_;
21 # ifdef REFCNT_DEBUG
22  void ** owners_list_;
23  int owners_list_used_;
24  int owners_list_alloc_;
26 # endif // REFCNT_DEBUG
28 
29 protected:
30 
32  RefCnt ();
33 
35  virtual ~RefCnt();
36 
37 public:
38 
39 
43  int
44  reference (
45  void * owner);
46 
50  int
51  dereference (
52  void * owner);
53 
58  int
59  release (
60  void * owner);
61 
62 
66  int
68  return ref_cnt_;
69  }
70 
74  int
75  forceRelease ();
76 
80 # ifdef REFCNT_DEBUG
81  void
82  changeOwner (
83  void * current_owner,
84  void * new_owner);
85 # else // REFCNT_DEBUG
86  inline void
88  void *,
89  void *) {}
90 # endif // REFCNT_DEBUG
91 
92 
93 
97 # ifdef REFCNT_DEBUG
98  bool
99  isOwner (
100  void * value);
101 # else // REFCNT_DEBUG
102  inline bool
104  void *) {
105  return false;
106  }
107 # endif // REFCNT_DEBUG
108 
109 
110 
111 # ifdef REFCNT_DEBUG
112  void
114  printReferenceList ();
115 
117  int
118  locateOwner (
119  void * owner);
120 # endif // REFCNT_DEBUG
121 
122 
123 };
124 
125 #endif // GUARD_REFCNT_H_INCLUDE
A reference counted base class.
Definition: refcnt.h:16
bool isOwner(void *)
Definition: refcnt.h:103
int referenceCount()
Definition: refcnt.h:67
void changeOwner(void *, void *)
Definition: refcnt.h:87