summaryrefslogtreecommitdiff
path: root/core/launcher/qcleanuphandler_p.h
authorkergoth <kergoth>2002-01-31 17:03:37 (UTC)
committer kergoth <kergoth>2002-01-31 17:03:37 (UTC)
commit48a922e687e82dc8ebe2bc3cb17dcaa8dcae62bd (patch) (side-by-side diff)
treef9ebebbfabe319b455d6f166b17d4206a15e5ff2 /core/launcher/qcleanuphandler_p.h
parentd872285d1f6a2e29fabe3604e699eeb62da91a80 (diff)
downloadopie-48a922e687e82dc8ebe2bc3cb17dcaa8dcae62bd.zip
opie-48a922e687e82dc8ebe2bc3cb17dcaa8dcae62bd.tar.gz
opie-48a922e687e82dc8ebe2bc3cb17dcaa8dcae62bd.tar.bz2
Initial revision
Diffstat (limited to 'core/launcher/qcleanuphandler_p.h') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/qcleanuphandler_p.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/core/launcher/qcleanuphandler_p.h b/core/launcher/qcleanuphandler_p.h
new file mode 100644
index 0000000..d8cddac
--- a/dev/null
+++ b/core/launcher/qcleanuphandler_p.h
@@ -0,0 +1,51 @@
+#ifndef QCLEANUPHANDLER_H
+#define QCLEANUPHANDLER_H
+
+#ifndef QT_H
+#include <qlist.h>
+#endif // QT_H
+
+template<class Type>
+class Q_EXPORT QCleanupHandler
+{
+public:
+ QCleanupHandler() : cleanupObjects( 0 ) {}
+ ~QCleanupHandler() { clear(); }
+
+ Type* add( Type **object ) {
+ if ( !cleanupObjects )
+ cleanupObjects = new QList<Type*>;
+ cleanupObjects->insert( 0, object );
+ return *object;
+ }
+
+ void remove( Type **object ) {
+ if ( !cleanupObjects )
+ return;
+ if ( cleanupObjects->findRef( object ) >= 0 )
+ (void) cleanupObjects->take();
+ }
+
+ bool isEmpty() const {
+ return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
+ }
+
+ void clear() {
+ if ( !cleanupObjects )
+ return;
+ QListIterator<Type*> it( *cleanupObjects );
+ Type **object;
+ while ( ( object = it.current() ) ) {
+ delete *object;
+ *object = 0;
+ cleanupObjects->remove( object );
+ }
+ delete cleanupObjects;
+ cleanupObjects = 0;
+ }
+
+private:
+ QList<Type*> *cleanupObjects;
+};
+
+#endif //QCLEANUPHANDLER_H