Qtopia library API Documentation

qcleanuphandler_p.h

00001 #ifndef QCLEANUPHANDLER_H
00002 #define QCLEANUPHANDLER_H
00003 
00004 #ifndef QT_H
00005 #include <qlist.h>
00006 #endif // QT_H
00007 
00008 template<class Type>
00009 class Q_EXPORT QCleanupHandler
00010 {
00011 public:
00012     QCleanupHandler() : cleanupObjects( 0 ) {}
00013     ~QCleanupHandler() { clear(); }
00014 
00015     Type* add( Type **object ) {
00016     if ( !cleanupObjects )
00017         cleanupObjects = new QList<Type*>;
00018     cleanupObjects->insert( 0, object );
00019     return *object;
00020     }
00021 
00022     void remove( Type **object ) {
00023     if ( !cleanupObjects )
00024         return;
00025     if ( cleanupObjects->findRef( object ) >= 0 )
00026         (void) cleanupObjects->take();
00027     }
00028 
00029     bool isEmpty() const {
00030     return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
00031     }
00032 
00033     void clear() {
00034     if ( !cleanupObjects )
00035         return;
00036     QListIterator<Type*> it( *cleanupObjects );
00037     Type **object;
00038     while ( ( object = it.current() ) ) {
00039         delete *object;
00040         *object = 0;
00041         cleanupObjects->remove( object );
00042     }
00043     delete cleanupObjects;
00044     cleanupObjects = 0;
00045     }
00046 
00047 private:
00048     QList<Type*> *cleanupObjects;
00049 };
00050 
00051 #endif //QCLEANUPHANDLER_H
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:06 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001