blob: 684cd2105a18568b23b7cd893cc7528c19aaa9ce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
/***************************************************************************
referencecounted.h - description
-------------------
begin : Mo Apr 18 2005
copyright : (C) 2005 by Dominik Seichter
email : domseichter@web.de
***************************************************************************/
/***************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#ifndef REFERENCE_COUNTED_H
#define REFERENCE_COUNTED_H
/**
* A class to make objects reference counted.
* Most likely you will want to subclass this class.
* @see TCanvasItem for an example.
*
* Whenever you get a reference to a ReferenceCounted
* object, call addRef(). Whenever you do not need
* the object anymore, call remRef().
*
* When the reference count reaches 0, the object
* deletes itself.
*/
class ReferenceCounted {
public:
ReferenceCounted():m_counter(0) {}
virtual ~ReferenceCounted() {}
inline void addRef()
{
m_counter++;
}
inline void remRef()
{
if(--m_counter == 0) delete this;
}
inline unsigned int refCount()
{
return m_counter;
}
private:
unsigned int m_counter;
};
#endif // REFERENCE_COUNTED_H
|