00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // Destroyer.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (C) 1997-2002 Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 //------------------------------------------------------------------------------ 00012 #ifndef _Destroyer_h 00013 #define _Destroyer_h 00014 00015 namespace ASSA { 00016 00023 template <class T> 00024 class Destroyer 00025 { 00026 public: 00030 Destroyer(T* d_=0) : m_otg (d_) { /* empty */ } 00031 00032 /* Destructor - deletes object T it owns. 00033 */ 00034 ~Destroyer() { 00035 if ( m_otg ) { 00036 delete m_otg; 00037 } 00038 } 00039 00043 void setGuard(T* d_) { 00044 m_otg = d_; 00045 } 00046 00047 private: 00048 Destroyer(const Destroyer<T>&); 00049 Destroyer<T>& operator=(const Destroyer<T>&); 00050 00051 private: 00053 T* m_otg; 00054 }; 00055 00056 } // end namespace ASSA 00057 00058 #endif