summaryrefslogtreecommitdiff
path: root/library/qcleanuphandler_p.h
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/qcleanuphandler_p.h
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'library/qcleanuphandler_p.h') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qcleanuphandler_p.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/library/qcleanuphandler_p.h b/library/qcleanuphandler_p.h
new file mode 100644
index 0000000..d8cddac
--- a/dev/null
+++ b/library/qcleanuphandler_p.h
@@ -0,0 +1,51 @@
1#ifndef QCLEANUPHANDLER_H
2#define QCLEANUPHANDLER_H
3
4#ifndef QT_H
5#include <qlist.h>
6#endif // QT_H
7
8template<class Type>
9class Q_EXPORT QCleanupHandler
10{
11public:
12 QCleanupHandler() : cleanupObjects( 0 ) {}
13 ~QCleanupHandler() { clear(); }
14
15 Type* add( Type **object ) {
16 if ( !cleanupObjects )
17 cleanupObjects = new QList<Type*>;
18 cleanupObjects->insert( 0, object );
19 return *object;
20 }
21
22 void remove( Type **object ) {
23 if ( !cleanupObjects )
24 return;
25 if ( cleanupObjects->findRef( object ) >= 0 )
26 (void) cleanupObjects->take();
27 }
28
29 bool isEmpty() const {
30 return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
31 }
32
33 void clear() {
34 if ( !cleanupObjects )
35 return;
36 QListIterator<Type*> it( *cleanupObjects );
37 Type **object;
38 while ( ( object = it.current() ) ) {
39 delete *object;
40 *object = 0;
41 cleanupObjects->remove( object );
42 }
43 delete cleanupObjects;
44 cleanupObjects = 0;
45 }
46
47private:
48 QList<Type*> *cleanupObjects;
49};
50
51#endif //QCLEANUPHANDLER_H