Diffstat (limited to 'core/launcher/qcleanuphandler_p.h') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/qcleanuphandler_p.h | 51 |
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 @@ | |||
1 | #ifndef QCLEANUPHANDLER_H | ||
2 | #define QCLEANUPHANDLER_H | ||
3 | |||
4 | #ifndef QT_H | ||
5 | #include <qlist.h> | ||
6 | #endif // QT_H | ||
7 | |||
8 | template<class Type> | ||
9 | class Q_EXPORT QCleanupHandler | ||
10 | { | ||
11 | public: | ||
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 | |||
47 | private: | ||
48 | QList<Type*> *cleanupObjects; | ||
49 | }; | ||
50 | |||
51 | #endif //QCLEANUPHANDLER_H | ||