author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (side-by-side diff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/qcleanuphandler_p.h | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
-rw-r--r-- | library/qcleanuphandler_p.h | 51 |
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 @@ +#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 |