home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
qt3_emx.zip
/
include
/
qcleanuphandler.h
< prev
next >
Wrap
C/C++ Source or Header
|
2001-06-01
|
1KB
|
52 lines
#ifndef QCLEANUPHANDLER_H
#define QCLEANUPHANDLER_H
#ifndef QT_H
#include <qptrlist.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 QPtrList<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;
QPtrListIterator<Type*> it( *cleanupObjects );
Type **object;
while ( ( object = it.current() ) ) {
delete *object;
*object = 0;
cleanupObjects->remove( object );
}
delete cleanupObjects;
cleanupObjects = 0;
}
private:
QPtrList<Type*> *cleanupObjects;
};
#endif //QCLEANUPHANDLER_H