1:
2:
3: #ifndef WWWI_MIND_WATCHPTR_H
4: #define WWWI_MIND_WATCHPTR_H
5:
6: /*
7: * The WatchPtr class is used to allow a pointer to obtain automatic
8: * destruction when the current stack frame exits. This is primarily useful
9: * to clean up when exceptions occur and memory has been allocated with new.
10: */
11:
12: template <class T> class WatchPtr {
13: public:
14: WatchPtr(T &i_t) { m_tp = &i_t; m_bProtect=true; }
15: void Release(void) { m_bProtect = false; }
16: ~WatchPtr(void) { if (m_bProtect==false) return; SoftDelete(*m_tp); }
17: protected:
18: T *m_tp;
19: bool m_bProtect;
20: };
21:
22:
23: #endif
24:
25:
26: