libbbb
1.2.1
Groups common code used in some applications and libraries.
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
refcnt.h
Go to the documentation of this file.
1
/* ========================================================================= */
2
/* ------------------------------------------------------------------------- */
/*
12
13
14
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
Please read COPYING and README files in root folder
16
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
*/
18
/* ------------------------------------------------------------------------- */
19
/* ========================================================================= */
20
#ifndef __REFCNT_INC__
21
#define __REFCNT_INC__
22
//
23
//
24
//
25
//
26
/* INCLUDES ------------------------------------------------------------ */
27
28
#include <libbbb/libbbb.h>
29
30
#ifdef REFCNT_DEBUG
31
#include <QMap>
32
#include <QString>
33
#endif
34
35
/* INCLUDES ============================================================ */
36
//
37
//
38
//
39
//
40
/* DEFINITIONS --------------------------------------------------------- */
41
42
namespace
bbb {
43
44
#define REMOVE_CONSTRUCTOR_REF(p) p->decRef()
45
46
#ifdef REFCNT_DEBUG
47
49
# define INC_REF(p,o) p->incRef(o, \
50
QString("Set owner %4 in %3 in file: %1, line %2")\
51
.arg( __FILE__ ) \
52
.arg( __LINE__ ) \
53
.arg( __func__ ) \
54
.arg( (quint64)o ) )
55
56
# define DEC_REF(p,o) p->decRef( o )
57
58
# define OWN_REF(p,crto,newo) p->changeRefOwner( crto, newo, \
59
QString("Owner changed from %4 to %5 in %3 in file: %1, line %2")\
60
.arg( __FILE__ ) \
61
.arg( __LINE__ ) \
62
.arg( __func__ ) \
63
.arg( (quint64)crto ) \
64
.arg( (quint64)newo ) )
65
66
# define OWN_CREF(p,newo) p->changeRefOwner( static_cast<libbbb::RefCnt*>(p), newo, \
67
QString("Owner changed from %4 to %5 in %3 in file: %1, line %2") \
68
.arg( __FILE__ ) \
69
.arg( __LINE__ ) \
70
.arg( __func__ ) \
71
.arg( (quint64)static_cast<libbbb::RefCnt*>(p) ) \
72
.arg( (quint64)newo ) )
73
74
#else
75
77
# define INC_REF(p,o) p->incRef()
78
79
# define DEC_REF(p,o) p->decRef()
80
81
# define OWN_REF(p,crto, newo)
82
83
# define OWN_CREF(p,newo)
84
85
86
#endif
87
88
/* DEFINITIONS ========================================================= */
89
//
90
//
91
//
92
//
93
/* CLASS --------------------------------------------------------------- */
94
105
class
106
BBBSHARED_EXPORT
107
RefCnt
{
108
109
//
110
//
111
//
112
//
113
/* DEFINITIONS ----------------------------------------------------- */
114
115
/* DEFINITIONS ===================================================== */
116
//
117
//
118
//
119
//
120
/* DATA ------------------------------------------------------------ */
121
122
private
:
123
127
unsigned
int
reference_cnt_;
128
129
#ifdef REFCNT_DEBUG
130
134
QMap<void*,QString> ref_list_;
135
136
#endif
137
138
/* DATA ============================================================ */
139
//
140
//
141
//
142
//
143
/* FUNCTIONS ------------------------------------------------------- */
144
145
public
:
146
147
151
RefCnt
(
void
);
152
153
154
protected
:
155
156
160
virtual
~
RefCnt
(
void
);
161
162
163
public
:
164
165
169
void
incRef (
void
)
170
{ reference_cnt_++; }
171
172
176
void
decRef (
void
);
177
178
182
unsigned
int
referenceCount (
void
)
183
{
return
reference_cnt_; }
184
185
186
#ifdef REFCNT_DEBUG
187
191
void
incRef (
void
* owner,
const
QString & s_descr );
192
196
void
decRef (
void
* owner );
197
201
void
changeRefOwner (
202
void
* current_owner,
203
void
* new_owner,
204
QString s_descr
205
);
206
210
void
printRefMap (
void
);
211
212
#endif
213
214
218
void
forceDelete (
void
)
219
{ reference_cnt_ = 0;
delete
this
; }
220
221
222
/* FUNCTIONS ======================================================= */
223
//
224
//
225
//
226
//
227
228
};
/* class RefCnt */
229
230
/* CLASS =============================================================== */
231
//
232
//
233
//
234
//
235
236
}
// namespace bbb
237
238
#endif // __REFCNT_INC__
239
/* ------------------------------------------------------------------------- */
240
/* ========================================================================= */
src
refcount
refcnt.h
Generated on Thu Aug 8 2013 20:10:33 for libbbb by
1.8.3.1