Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qcleanuphandler_p.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef QCLEANUPHANDLER_H
00022 #define QCLEANUPHANDLER_H
00023 
00024 #ifndef QT_H
00025 #include <qlist.h>
00026 #endif // QT_H
00027 
00028 template<class Type>
00029 class Q_EXPORT QCleanupHandler
00030 {
00031 public:
00032     QCleanupHandler() : cleanupObjects( 0 ) {}
00033     ~QCleanupHandler() { clear(); }
00034 
00035     Type* add( Type **object ) {
00036         if ( !cleanupObjects )
00037             cleanupObjects = new QList<Type*>;
00038         cleanupObjects->insert( 0, object );
00039         return *object;
00040     }
00041 
00042     void remove( Type **object ) {
00043         if ( !cleanupObjects )
00044             return;
00045         if ( cleanupObjects->findRef( object ) >= 0 )
00046             (void) cleanupObjects->take();
00047     }
00048 
00049     bool isEmpty() const {
00050         return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
00051     }
00052 
00053     void clear() {
00054         if ( !cleanupObjects )
00055             return;
00056         QListIterator<Type*> it( *cleanupObjects );
00057         Type **object;
00058         while ( ( object = it.current() ) ) {
00059             delete *object;
00060             *object = 0;
00061             cleanupObjects->remove( object );
00062         }
00063         delete cleanupObjects;
00064         cleanupObjects = 0;
00065     }
00066 
00067 private:
00068     QList<Type*> *cleanupObjects;
00069 };
00070 
00071 #endif //QCLEANUPHANDLER_H

Generated on Sat Nov 5 16:15:31 2005 for OPIE by  doxygen 1.4.2