DumontEXE 0.0.1
qxtpointerlist.h
00001 
00002 /****************************************************************************
00003 **
00004 ** Copyright (C) Qxt Foundation. Some rights reserved.
00005 **
00006 ** This file is part of the QxtCore module of the Qt eXTension library
00007 **
00008 ** This library is free software; you can redistribute it and/or modify it
00009 ** under the terms of th Common Public License, version 1.0, as published by
00010 ** IBM.
00011 **
00012 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
00013 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
00014 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
00015 ** FITNESS FOR A PARTICULAR PURPOSE.
00016 **
00017 ** You should have received a copy of the CPL along with this file.
00018 ** See the LICENSE file and the cpl1.0.txt file included with the source
00019 ** distribution for more information. If you did not receive a copy of the
00020 ** license, contact the Qxt Foundation.
00021 **
00022 ** <http://libqxt.sourceforge.net>  <foundation@libqxt.org>
00023 **
00024 ****************************************************************************/
00025 
00026 
00027 #ifndef QxtPointerList_Header_Guard
00028 #define QxtPointerList_Header_Guard
00029 
00030 #include <QList>
00031 #include <QObject>
00032 
00033 class QxtPointerListDeleter : public QObject
00034 {
00035     Q_OBJECT
00036     protected:
00037         virtual void removeThisObject(QObject * obj)=0;
00038 private slots:
00039     void removeSender()
00040     {
00041         removeThisObject(QObject::sender());
00042     }
00043 };
00044 
00045 
00046 template<class T>
00047 class QxtPointerList : public QxtPointerListDeleter, public QList<T*>
00048 {
00049 public:
00050     ///constructs a new QxtPointerList
00051     QxtPointerList ():QList<T*>()
00052     {
00053     }
00054     ///destructs the QxtPointerList
00055     ~QxtPointerList()
00056     {
00057         QList<T*>::clear();
00058     }
00059     ///
00060     QxtPointerList ( const QxtPointerList<T> & other ):QxtPointerListDeleter(),QList<T*>(other)
00061     {
00062         for(int i=0;i<other.size();i++)
00063         {
00064             QObject::connect(other.at(i),SIGNAL(destroyed( QObject *  )),this,SLOT(removeSender()));
00065         }
00066     }
00067     ///
00068     void append (  T*  value )
00069     {
00070         QObject::connect(value,SIGNAL(destroyed( QObject *  )),this,SLOT(removeSender()));
00071         QList<T*>::append(value);
00072     }
00073     ///
00074     void insert ( int i, T * value )
00075     {
00076         QObject::connect(value,SIGNAL(destroyed( QObject *  )),this,SLOT(removeSender()));
00077         QList<T*>::insert(i,value);
00078     }
00079     ///
00080     typename QList<T*>::iterator insert ( typename QList<T*>::iterator before,  T*  value )
00081     {
00082         QObject::connect(value,SIGNAL(destroyed( QObject *  )),this,SLOT(removeSender()));
00083         return QList<T*>::insert(before,value);
00084     }
00085     ///
00086     QxtPointerList<T> operator+ ( const QxtPointerList<T> & other ) const
00087     {
00088         QxtPointerList<T> m=*this;
00089         m+=other;
00090         return m;
00091     }
00092     ///
00093     QxtPointerList<T> & operator+= ( const QxtPointerList<T> & other )
00094     {
00095         foreach(T*t,other)
00096         {
00097             *this<<t;
00098         }
00099         return *this;
00100     }
00101     ///
00102     QxtPointerList<T> & operator+= ( T*  value )
00103     {
00104         QObject::connect(value,SIGNAL(destroyed( QObject *  )),this,SLOT(removeSender()));
00105         QList<T*>::operator+=(value);
00106         return *this;
00107     }
00108     ///
00109     QxtPointerList<T> & operator<< ( const QxtPointerList<T> & other )
00110     {
00111         *this+=other;
00112         return *this;
00113     }
00114     ///
00115     QxtPointerList<T> & operator<< ( T* value )
00116     {
00117         *this+=value;
00118         return *this;
00119     }
00120     ///
00121     QxtPointerList<T> & operator= ( const QxtPointerList<T> & other )
00122     {
00123         QList<T*>::clear();
00124         foreach(T*t,other)
00125         {
00126             *this<<t;
00127         }
00128         return *this;
00129     }
00130 
00131 protected:
00132     ///
00133     virtual void removeThisObject(QObject * obj)
00134     {
00135         removeAll(reinterpret_cast<T*>(obj));
00136     }
00137 };
00138 
00139 
00140 #endif
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com