1 // -*- c++ -*- 2 //------------------------------------------------------------------------------ 3 // Destroyer.h 4 //------------------------------------------------------------------------------ 5 // Copyright (C) 1997-2002 Vladislav Grinchenko 6 // 7 // This library is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU Library General Public 9 // License as published by the Free Software Foundation; either 10 // version 2 of the License, or (at your option) any later version. 11 //------------------------------------------------------------------------------ 12 #ifndef _Destroyer_h 13 #define _Destroyer_h 14 15 namespace ASSA { 16 17 /** @file Destroyer.h 18 19 Destroyer is the helper class for class Singleton. 20 @see Singleton 21 */ 22 23 template <class T> 24 class Destroyer 25 { 26 public: 27 /** Constructor. 28 @param d_ pointer to the object to guard. 29 */ m_otg(d_)30 Destroyer(T* d_=0) : m_otg (d_) { /* empty */ } 31 32 /* Destructor - deletes object T it owns. 33 */ ~Destroyer()34 ~Destroyer() { 35 if ( m_otg ) { 36 delete m_otg; 37 } 38 } 39 40 /** Transfer ownership of object T to Destroyer class. 41 @param d_ - object T to guard 42 */ setGuard(T * d_)43 void setGuard(T* d_) { 44 m_otg = d_; 45 } 46 47 private: 48 Destroyer(const Destroyer<T>&); 49 Destroyer<T>& operator=(const Destroyer<T>&); 50 51 private: 52 /// Object T to guard 53 T* m_otg; 54 }; 55 56 } // end namespace ASSA 57 58 #endif 59