2 Copyright (C) 2013 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.
19 #ifndef WCREFMANAGER_H
20 #define WCREFMANAGER_H
23 #define SAFE_RELEASE(p) if (p) {p->Release(); p = NULL;}
26 //In order to use this interface, derive the Interface class
27 //from WCRefManager_Interface and derive the implementation class
28 //from WCRefManager_Impl. Further, in the implementation class
29 //declaration, place the macro WCREFMANAGER_IMPL.
30 class WCRefManager_Interface
34 WCRefManager_Interface() {};
36 virtual ~WCRefManager_Interface() {};
37 /// Adds a reference to class.
38 virtual void AddRef() = 0;
39 /// Decrements reference count and deletes the object if reference count becomes zero.
40 virtual void Release() = 0;
43 ///! See details at WCRefManager_Interface for how to use this.
44 class WCRefManager_Impl
47 WCRefManager_Impl () : m_RefCount(1) {}
48 virtual ~WCRefManager_Impl() {}
50 /// Variable to store reference count.
51 unsigned int m_RefCount;
53 /// Helper to put implementation in an interface derived class, don't forget to
54 /// derive the impl from WCRefManager_Impl
55 #define WCREFMAN_IMPL \
57 virtual void AddRef() {m_RefCount++;} \
58 virtual void Release() {m_RefCount--; if (m_RefCount<=0) delete this;}
69 virtual ~WCRefManager();
70 /// Adds a reference to class.
72 /// Decrements reference count and deletes the object if reference count becomes zero.
76 /// Variable to store reference count.
77 unsigned int m_RefCount;
80 #endif // WCREFMANAGER_H