2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file memutil/MEM_RefCounted.h
33 * @file MEM_RefCounted.h
34 * Declaration of MEM_RefCounted class.
37 #ifndef __MEM_REFCOUNTED_H__
38 #define __MEM_REFCOUNTED_H__
41 * An object with reference counting.
42 * Base class for objects with reference counting.
43 * When a shared object is ceated, it has reference count == 1.
44 * If the the reference count of a shared object reaches zero, the object self-destructs.
45 * The default destructor of this object has been made protected on purpose.
46 * This disables the creation of shared objects on the stack.
48 * @author Maarten Gribnau
49 * @date March 31, 2001
52 class MEM_RefCounted {
55 * Constructs a a shared object.
57 MEM_RefCounted() : m_refCount(1)
62 * Returns the reference count of this object.
63 * @return the reference count.
65 inline virtual int getRef() const;
68 * Increases the reference count of this object.
69 * @return the new reference count.
71 inline virtual int incRef();
74 * Decreases the reference count of this object.
75 * If the the reference count reaches zero, the object self-destructs.
76 * @return the new reference count.
78 inline virtual int decRef();
82 * Destructs a shared object.
83 * The destructor is protected to force the use of incRef and decRef.
85 virtual ~MEM_RefCounted()
90 /// The reference count.
95 inline int MEM_RefCounted::getRef() const
100 inline int MEM_RefCounted::incRef()
105 inline int MEM_RefCounted::decRef()
108 if (m_refCount == 0) {
115 #endif // __MEM_REFCOUNTED_H__