5 #define SAFE_RELEASE(p) if (p) {p->Release(); p = NULL;}
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
16 WCRefManager_Interface() {};
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;
25 ///! See details at WCRefManager_Interface for how to use this.
26 class WCRefManager_Impl
29 WCRefManager_Impl () : m_RefCount(1) {}
30 virtual ~WCRefManager_Impl() {}
32 /// Variable to store reference count.
33 unsigned int m_RefCount;
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 \
39 virtual void AddRef() {m_RefCount++;} \
40 virtual void Release() {m_RefCount--; if (m_RefCount<=0) delete this;}
51 virtual ~WCRefManager();
52 /// Adds a reference to class.
54 /// Decrements reference count and deletes the object if reference count becomes zero.
58 /// Variable to store reference count.
59 unsigned int m_RefCount;
62 #endif // WCREFMANAGER_H