IvfSingletonDestroyer.h

00001 //
00002 // Copyright 1999-2006 by Structural Mechanics, Lund University.
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Library General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Library General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Library General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00017 // USA.
00018 //
00019 // Please report all bugs and problems to "ivf@byggmek.lth.se".
00020 //
00021 //
00022 // Written by Jonas Lindemann
00023 //
00024 
00025 #ifndef _CIvfSingletonDestroyer_h_
00026 #define _CIvfSingletonDestroyer_h_
00027 
00028 //
00029 // The following code based on code from the article
00030 //
00031 // To Kill a Singleton
00032 // John Vlissides
00033 //
00034 // John Vlissides is a member of the research staff at IBM's
00035 // Thomas J. Watson Research Center in Hawthorne, New York.
00036 // He can be reached at vlis@watson.ibm.com
00037 //
00038 
00045 template <class T>
00046 class CIvfSingletonDestroyer {
00047 public:
00049         CIvfSingletonDestroyer(T* = 0);
00050 
00052         ~CIvfSingletonDestroyer();
00053 
00054         void setSingleton(T*);
00055 private:
00056         // Prevent users from making copies of a
00057         // CIvfSingletonDestroyer to avoid double deletion:
00058         CIvfSingletonDestroyer(const CIvfSingletonDestroyer<T>&);
00059         CIvfSingletonDestroyer<T>& operator=(const CIvfSingletonDestroyer<T>&);
00060 private:
00061         T* _T;
00062 };
00063 
00064 template <class T>
00065 CIvfSingletonDestroyer<T>::CIvfSingletonDestroyer (T* d) {
00066         _T = d;
00067 }
00068 
00069 template <class T>
00070 CIvfSingletonDestroyer<T>::~CIvfSingletonDestroyer () {
00071         delete _T;
00072 }
00073 
00074 template <class T>
00075 void CIvfSingletonDestroyer<T>::setSingleton (T* d) {
00076         _T = d;
00077 }
00078 
00079 #endif

Generated on Fri Sep 1 15:36:46 2006 for Interactive Visualisation Framework - Ivf++ by  doxygen 1.4.6-NO