KDE3Support
k3staticdeleter.cpp
Go to the documentation of this file.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., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #include "k3staticdeleter.h" 00024 #include <kglobal.h> 00025 00026 #include <QtCore/QList> 00027 #include <QtCore/QCoreApplication> 00028 00029 typedef QList<K3StaticDeleterBase *> K3StaticDeleterList; 00030 00031 struct K3StaticDeleterPrivate 00032 { 00033 K3StaticDeleterPrivate() 00034 { 00035 qAddPostRoutine(deleteStaticDeleters); 00036 } 00037 ~K3StaticDeleterPrivate() 00038 { 00039 qRemovePostRoutine(deleteStaticDeleters); 00040 deleteStaticDeleters(); 00041 } 00042 static void deleteStaticDeleters(); 00043 00044 K3StaticDeleterList staticDeleters; 00045 }; 00046 00047 K_GLOBAL_STATIC(K3StaticDeleterPrivate, staticDeleterPrivate) 00048 00049 void K3StaticDeleterPrivate::deleteStaticDeleters() 00050 { 00051 if (staticDeleterPrivate.isDestroyed()) { 00052 return; 00053 } 00054 K3StaticDeleterPrivate *d = staticDeleterPrivate; 00055 while (!d->staticDeleters.isEmpty()) { 00056 d->staticDeleters.takeLast()->destructObject(); 00057 } 00058 } 00059 00060 void K3StaticDeleterHelpers::registerStaticDeleter(K3StaticDeleterBase *obj) 00061 { 00062 K3StaticDeleterPrivate *d = staticDeleterPrivate; 00063 if (d->staticDeleters.indexOf(obj) == -1) { 00064 d->staticDeleters.append(obj); 00065 } 00066 } 00067 00068 void K3StaticDeleterHelpers::unregisterStaticDeleter(K3StaticDeleterBase *obj) 00069 { 00070 if (staticDeleterPrivate.isDestroyed()) { 00071 return; 00072 } 00073 staticDeleterPrivate->staticDeleters.removeAll(obj); 00074 } 00075 00076 void K3StaticDeleterHelpers::deleteStaticDeleters() 00077 { 00078 staticDeleterPrivate->deleteStaticDeleters(); 00079 } 00080 00081 // this helps gcc to emit the vtbl for K3StaticDeleterBase 00082 // only once, here in this file, not every time it's 00083 // used, says Seli and thiago. 00084 K3StaticDeleterBase::~K3StaticDeleterBase() 00085 { 00086 } 00087 00088 void K3StaticDeleterBase::destructObject() 00089 { 00090 } 00091