kdecore Library API Documentation

kstaticdeleter.h

00001 /*
00002  * This file is part of the KDE Libraries
00003  * Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
00004  *               2001 KDE Team
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public License
00017  * along with this library; see the file COPYING.LIB.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  *
00021  */
00022 
00023 #ifndef _KSTATIC_DELETER_H_
00024 #define _KSTATIC_DELETER_H_
00025 
00026 #include <kglobal.h>
00027 
00039 class KStaticDeleterBase {
00040 public:
00041     virtual ~KStaticDeleterBase() { }
00047     virtual void destructObject();
00048 };
00049 
00066 template<class type> class KStaticDeleter : public KStaticDeleterBase {
00067 public:
00068     KStaticDeleter() { deleteit = 0; globalReference = 0; array = false; }
00077     KDE_DEPRECATED type *setObject( type *obj, bool isArray = false) {
00078         deleteit = obj;
00079         globalReference = 0;
00080     array = isArray;
00081     if (obj)
00082             KGlobal::registerStaticDeleter(this);
00083     else
00084         KGlobal::unregisterStaticDeleter(this);
00085         return obj;
00086     }
00096     type *setObject( type* & globalRef, type *obj, bool isArray = false) {
00097         globalReference = &globalRef;
00098         deleteit = obj;
00099     array = isArray;
00100     if (obj)
00101             KGlobal::registerStaticDeleter(this);
00102     else
00103         KGlobal::unregisterStaticDeleter(this);
00104         globalRef = obj;
00105     return obj;
00106     }
00107 
00112     virtual void destructObject() {
00113         if (globalReference)
00114            *globalReference = 0;
00115     if (array)
00116        delete [] deleteit;
00117     else
00118        delete deleteit;
00119         deleteit = 0;
00120     }
00121     virtual ~KStaticDeleter() {
00122         KGlobal::unregisterStaticDeleter(this);
00123     destructObject();
00124     }
00125 private:
00126     type *deleteit;
00127     type **globalReference;
00128     bool array;
00129 };
00130 
00131 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 14 09:16:08 2006 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003