Eneboo - Documentación para desarrolladores
src/qt/include/qcleanuphandler.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qcleanuphandler.h   3.3.8   edited Jan 11 14:46 $
00003 **
00004 ** ...
00005 **
00006 ** Copyright (C) 2001-2007 Trolltech ASA.  All rights reserved.
00007 **
00008 ** This file is part of the tools module of the Qt GUI Toolkit.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech ASA of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00020 ** licenses may use this file in accordance with the Qt Commercial License
00021 ** Agreement provided with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #ifndef QCLEANUPHANDLER_H
00037 #define QCLEANUPHANDLER_H
00038 
00039 #ifndef QT_H
00040 #include "qptrlist.h"
00041 #endif // QT_H
00042 
00043 template<class Type>
00044 class QCleanupHandler
00045 {
00046 public:
00047     QCleanupHandler() : cleanupObjects( 0 ) {}
00048     ~QCleanupHandler() { clear(); }
00049 
00050     Type* add( Type **object ) {
00051         if ( !cleanupObjects )
00052             cleanupObjects = new QPtrList<Type*>;
00053         cleanupObjects->insert( 0, object );
00054         return *object;
00055     }
00056 
00057     void remove( Type **object ) {
00058         if ( !cleanupObjects )
00059             return;
00060         if ( cleanupObjects->findRef( object ) >= 0 )
00061             (void) cleanupObjects->take();
00062     }
00063 
00064     bool isEmpty() const {
00065         return cleanupObjects ? cleanupObjects->isEmpty() : TRUE;
00066     }
00067 
00068     void clear() {
00069         if ( !cleanupObjects )
00070             return;
00071         QPtrListIterator<Type*> it( *cleanupObjects );
00072         Type **object;
00073         while ( ( object = it.current() ) ) {
00074             delete *object;
00075             *object = 0;
00076             cleanupObjects->remove( object );
00077         }
00078         delete cleanupObjects;
00079         cleanupObjects = 0;
00080     }
00081 
00082 private:
00083     QPtrList<Type*> *cleanupObjects;
00084 };
00085 
00086 template<class Type>
00087 class QSingleCleanupHandler
00088 {
00089 public:
00090     QSingleCleanupHandler() : object( 0 ) {}
00091     ~QSingleCleanupHandler() {
00092         if ( object ) {
00093             delete *object;
00094             *object = 0;
00095         }
00096     }
00097     Type* set( Type **o ) {
00098         object = o;
00099         return *object;
00100     }
00101     void reset() { object = 0; }
00102 private:
00103     Type **object;
00104 };
00105 
00106 template<class Type>
00107 class QSharedCleanupHandler
00108 {
00109 public:
00110     QSharedCleanupHandler() : object( 0 ) {}
00111     ~QSharedCleanupHandler() {
00112         if ( object ) {
00113             if ( (*object)->deref() )
00114                 delete *object;
00115             *object = 0;
00116         }
00117     }
00118     Type* set( Type **o ) {
00119         object = o;
00120         return *object;
00121     }
00122     void reset() { object = 0; }
00123 private:
00124     Type **object;
00125 };
00126 
00127 #endif //QCLEANUPHANDLER_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'