summaryrefslogtreecommitdiffstats
path: root/qtinterface/tqcleanuphandler.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-08-04 01:44:13 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-08-04 01:44:13 +0000
commitc9dc3907763cbf0b0e6164d793291bd2659f1534 (patch)
tree3359387715ee5e306451f1bcb74b900b608c9946 /qtinterface/tqcleanuphandler.h
parent4c3c7eaa2d225ecc0c16644f1a23e848bf539164 (diff)
downloadtqtinterface-c9dc3907763cbf0b0e6164d793291bd2659f1534.tar.gz
tqtinterface-c9dc3907763cbf0b0e6164d793291bd2659f1534.zip
Now compiles kdelibs/dcop folder properly...
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/dependencies/tqtinterface@1158880 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'qtinterface/tqcleanuphandler.h')
-rw-r--r--qtinterface/tqcleanuphandler.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/qtinterface/tqcleanuphandler.h b/qtinterface/tqcleanuphandler.h
index 1a5b6e8..faabf35 100644
--- a/qtinterface/tqcleanuphandler.h
+++ b/qtinterface/tqcleanuphandler.h
@@ -40,6 +40,92 @@ Boston, MA 02110-1301, USA.
//#include <Qt/qcleanuphandler.h>
+#include "tqptrlist.h"
+
+template<class Type>
+class TQCleanupHandler
+{
+public:
+ TQCleanupHandler() : cleanupObjects( 0 ) {}
+ ~TQCleanupHandler() { clear(); }
+
+ Type* add( Type **object ) {
+ if ( !cleanupObjects )
+ cleanupObjects = new Q3PtrList<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;
+ Q3PtrListIterator<Type*> it( *cleanupObjects );
+ Type **object;
+ while ( ( object = it.current() ) ) {
+ delete *object;
+ *object = 0;
+ cleanupObjects->remove( object );
+ }
+ delete cleanupObjects;
+ cleanupObjects = 0;
+ }
+
+private:
+ Q3PtrList<Type*> *cleanupObjects;
+};
+
+template<class Type>
+class TQSingleCleanupHandler
+{
+public:
+ TQSingleCleanupHandler() : object( 0 ) {}
+ ~TQSingleCleanupHandler() {
+ if ( object ) {
+ delete *object;
+ *object = 0;
+ }
+ }
+ Type* set( Type **o ) {
+ object = o;
+ return *object;
+ }
+ void reset() { object = 0; }
+private:
+ Type **object;
+};
+
+template<class Type>
+class TQSharedCleanupHandler
+{
+public:
+ TQSharedCleanupHandler() : object( 0 ) {}
+ ~TQSharedCleanupHandler() {
+ if ( object ) {
+ if ( (*object)->deref() )
+ delete *object;
+ *object = 0;
+ }
+ }
+ Type* set( Type **o ) {
+ object = o;
+ return *object;
+ }
+ void reset() { object = 0; }
+private:
+ Type **object;
+};
+
#endif // USE_QT4
#endif /* TQCLEANUPHANDLER_H */ \ No newline at end of file