2 Copyright (C) 2014 Waves Audio Ltd.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef WCREFMANAGER_H
21 #define WCREFMANAGER_H
24 #define SAFE_RELEASE(p) if (p) {p->Release(); p = NULL;}
27 //In order to use this interface, derive the Interface class
28 //from WCRefManager_Interface and derive the implementation class
29 //from WCRefManager_Impl. Further, in the implementation class
30 //declaration, place the macro WCREFMANAGER_IMPL.
31 class WCRefManager_Interface
35 WCRefManager_Interface() {};
37 virtual ~WCRefManager_Interface() {};
38 /// Adds a reference to class.
39 virtual void AddRef() = 0;
40 /// Decrements reference count and deletes the object if reference count becomes zero.
41 virtual void Release() = 0;
44 ///! See details at WCRefManager_Interface for how to use this.
45 class WCRefManager_Impl
48 WCRefManager_Impl () : m_RefCount(1) {}
49 virtual ~WCRefManager_Impl() {}
51 /// Variable to store reference count.
52 unsigned int m_RefCount;
54 /// Helper to put implementation in an interface derived class, don't forget to
55 /// derive the impl from WCRefManager_Impl
56 #define WCREFMAN_IMPL \
58 virtual void AddRef() {m_RefCount++;} \
59 virtual void Release() {m_RefCount--; if (m_RefCount<=0) delete this;}
70 virtual ~WCRefManager();
71 /// Adds a reference to class.
73 /// Decrements reference count and deletes the object if reference count becomes zero.
77 /// Variable to store reference count.
78 unsigned int m_RefCount;
81 #endif // WCREFMANAGER_H