3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 * @file MEM_RefCounted.h
30 * Declaration of MEM_RefCounted class.
33 #ifndef _H_MEM_REF_COUNTED
34 #define _H_MEM_REF_COUNTED
37 * An object with reference counting.
38 * Base class for objects with reference counting.
39 * When a shared object is ceated, it has reference count == 1.
40 * If the the reference count of a shared object reaches zero, the object self-destructs.
41 * The default destructor of this object has been made protected on purpose.
42 * This disables the creation of shared objects on the stack.
44 * @author Maarten Gribnau
45 * @date March 31, 2001
48 class MEM_RefCounted {
51 * Constructs a a shared object.
53 MEM_RefCounted() : m_refCount(1)
58 * Returns the reference count of this object.
59 * @return the reference count.
61 inline virtual int getRef() const;
64 * Increases the reference count of this object.
65 * @return the new reference count.
67 inline virtual int incRef();
70 * Decreases the reference count of this object.
71 * If the the reference count reaches zero, the object self-destructs.
72 * @return the new reference count.
74 inline virtual int decRef();
78 * Destructs a shared object.
79 * The destructor is protected to force the use of incRef and decRef.
81 virtual ~MEM_RefCounted()
86 /// The reference count.
91 inline int MEM_RefCounted::getRef() const
96 inline int MEM_RefCounted::incRef()
101 inline int MEM_RefCounted::decRef()
104 if (m_refCount == 0) {
111 #endif // _H_MEM_REF_COUNTED