add correct copyright statements to all files in Waves backend except those derived...
[ardour.git] / libs / backends / wavesaudio / wavesapi / refmanager / WCRefManager.h
1 /*
2     Copyright (C) 2014 Waves Audio Ltd.
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef WCREFMANAGER_H
21 #define WCREFMANAGER_H
22
23
24 #define SAFE_RELEASE(p) if (p) {p->Release(); p = NULL;}
25
26
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
32 {
33 public:
34         /// Constructor.
35         WCRefManager_Interface() {};
36         /// Destructor.
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;
42 };
43
44 ///! See details at WCRefManager_Interface for how to use this.
45 class WCRefManager_Impl
46 {
47 public:
48     WCRefManager_Impl () : m_RefCount(1) {}
49     virtual ~WCRefManager_Impl() {}
50 protected:
51         /// Variable to store reference count.
52         unsigned int m_RefCount;
53
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 \
57     public: \
58         virtual void AddRef() {m_RefCount++;} \
59         virtual void Release() {m_RefCount--; if (m_RefCount<=0) delete this;}
60
61 };
62
63
64 class WCRefManager
65 {
66 public:
67         /// Construcotr.
68         WCRefManager();
69         /// Destructor.
70         virtual ~WCRefManager();
71         /// Adds a reference to class.
72         void AddRef();
73         /// Decrements reference count and deletes the object if reference count becomes zero.
74         void Release();
75
76 private:
77         /// Variable to store reference count.
78         unsigned int m_RefCount;
79 };
80
81 #endif // WCREFMANAGER_H