1 | /* |
---|
2 | Base class interface |
---|
3 | Copyright (C) 1998,1999 by Andrew Zabolotny |
---|
4 | |
---|
5 | This library is free software; you can redistribute it and/or |
---|
6 | modify it under the terms of the GNU Library General Public |
---|
7 | License as published by the Free Software Foundation; either |
---|
8 | version 2 of the License, or (at your option) any later version. |
---|
9 | |
---|
10 | This library is distributed in the hope that it will be useful, |
---|
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | Library General Public License for more details. |
---|
14 | |
---|
15 | You should have received a copy of the GNU Library General Public |
---|
16 | License along with this library; if not, write to the Free |
---|
17 | Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
18 | */ |
---|
19 | |
---|
20 | #include "Base.h" |
---|
21 | |
---|
22 | Base::~Base () |
---|
23 | { |
---|
24 | } |
---|
25 | |
---|
26 | /** |
---|
27 | * Decrement object's reference count; as soon as the last reference |
---|
28 | * to the object is removed, it is destroyed. |
---|
29 | */ |
---|
30 | |
---|
31 | void Base::DecRef () |
---|
32 | { |
---|
33 | if (!--RefCount) |
---|
34 | delete this; |
---|
35 | } |
---|
36 | |
---|
37 | /** |
---|
38 | * Object initialization. The initial reference count is set to one; |
---|
39 | * this means if you call DecRef() immediately after creating the object, |
---|
40 | * it will be destroyed. |
---|
41 | */ |
---|
42 | Base::Base () |
---|
43 | { |
---|
44 | RefCount = 1; |
---|
45 | } |
---|
46 | |
---|
47 | /** |
---|
48 | * Increment reference count. |
---|
49 | * Every time when you copy a pointer to a object and store it for |
---|
50 | * later use you MUST call IncRef() on it; this will allow to keep |
---|
51 | * objects as long as they are referenced by some entity. |
---|
52 | */ |
---|
53 | void Base::IncRef () |
---|
54 | { |
---|
55 | ++RefCount; |
---|
56 | |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Query number of references to this object. |
---|
61 | * I would rather prefer to have the reference counter strictly private, |
---|
62 | * but sometimes, mostly for debugging, such a function can help. |
---|
63 | */ |
---|
64 | int Base::GetRefCount () |
---|
65 | { |
---|
66 | return RefCount; |
---|
67 | } |
---|