2nd attempt at updated Waves audio backend, with added -fms-extensions as previously...
[ardour.git] / libs / backends / wavesaudio / wavesapi / refmanager / WCRefManager.h
1 #ifndef WCREFMANAGER_H
2 #define WCREFMANAGER_H
3
4
5 #define SAFE_RELEASE(p) if (p) {p->Release(); p = NULL;}
6
7
8 //In order to use this interface, derive the Interface class
9 //from WCRefManager_Interface and derive the implementation class
10 //from WCRefManager_Impl. Further, in the implementation class
11 //declaration, place the macro WCREFMANAGER_IMPL.
12 class WCRefManager_Interface
13 {
14 public:
15         /// Constructor.
16         WCRefManager_Interface() {};
17         /// Destructor.
18         virtual ~WCRefManager_Interface() {};
19         /// Adds a reference to class.
20         virtual void AddRef() = 0;
21         /// Decrements reference count and deletes the object if reference count becomes zero.
22         virtual void Release() = 0;
23 };
24
25 ///! See details at WCRefManager_Interface for how to use this.
26 class WCRefManager_Impl
27 {
28 public:
29     WCRefManager_Impl () : m_RefCount(1) {}
30     virtual ~WCRefManager_Impl() {}
31 protected:
32         /// Variable to store reference count.
33         unsigned int m_RefCount;
34
35 /// Helper to put implementation in an interface derived class, don't forget to
36 /// derive the impl from WCRefManager_Impl
37 #define WCREFMAN_IMPL \
38     public: \
39         virtual void AddRef() {m_RefCount++;} \
40         virtual void Release() {m_RefCount--; if (m_RefCount<=0) delete this;}
41
42 };
43
44
45 class WCRefManager
46 {
47 public:
48         /// Construcotr.
49         WCRefManager();
50         /// Destructor.
51         virtual ~WCRefManager();
52         /// Adds a reference to class.
53         void AddRef();
54         /// Decrements reference count and deletes the object if reference count becomes zero.
55         void Release();
56
57 private:
58         /// Variable to store reference count.
59         unsigned int m_RefCount;
60 };
61
62 #endif // WCREFMANAGER_H