3 * ***** BEGIN GPL/BL DUAL 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. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
35 * Copyright (C) 2001 NaN Technologies B.V.
36 * @author Maarten Gribnau
37 * @date March 31, 2001
40 #ifndef _H_MEM_REF_COUNTED
41 #define _H_MEM_REF_COUNTED
44 * An object with reference counting.
45 * Base class for objects with reference counting.
46 * When a shared object is ceated, it has reference count == 1.
47 * If the the reference count of a shared object reaches zero, the object self-destructs.
48 * The default destructor of this object has been made protected on purpose.
49 * This disables the creation of shared objects on the stack.
51 * @author Maarten Gribnau
52 * @date March 31, 2001
55 class MEM_RefCounted {
58 * Constructs a a shared object.
60 MEM_RefCounted() : m_refCount(1)
65 * Returns the reference count of this object.
66 * @return the reference count.
68 inline virtual int getRef() const;
71 * Increases the reference count of this object.
72 * @return the new reference count.
74 inline virtual int incRef();
77 * Decreases the reference count of this object.
78 * If the the reference count reaches zero, the object self-destructs.
79 * @return the new reference count.
81 inline virtual int decRef();
85 * Destructs a shared object.
86 * The destructor is protected to force the use of incRef and decRef.
88 virtual ~MEM_RefCounted()
93 /// The reference count.
98 inline int MEM_RefCounted::getRef() const
103 inline int MEM_RefCounted::incRef()
108 inline int MEM_RefCounted::decRef()
111 if (m_refCount == 0) {
118 #endif // _H_MEM_REF_COUNTED