krita

kis_shared_ptr_vector.h

00001 /*
00002  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef KIS_SHARED_PTR_VECTOR_H
00020 #define KIS_SHARED_PTR_VECTOR_H
00021 
00022 #include <qvaluevector.h>
00023 
00024 #include <ksharedptr.h>
00025 
00033 template <class T>
00034 class KisSharedPtrVector : public QValueVector< KSharedPtr<T> >
00035 {
00036     typedef QValueVector< KSharedPtr<T> > super;
00037 public:
00038     KisSharedPtrVector() {}
00039 
00040     void pop_back()
00041     {
00042             if (!super::empty()) {
00043             super::back() = 0;
00044             super::pop_back();
00045         }
00046     }
00047 
00048     typename super::iterator erase(typename super::iterator it)
00049     {
00050         *it = 0;
00051         return super::erase(it);
00052     }
00053 
00054     typename super::iterator erase(typename super::iterator first, typename super::iterator last)
00055     {
00056         qFill(first, last, 0);
00057         return super::erase(first, last);
00058     }
00059 
00060     bool contains(KSharedPtr<T> ptr) const
00061     {
00062         for (int i = 0, n = super::count(); i < n; ++i)
00063             if (super::at(i) == ptr)
00064                 return true;
00065         return false;
00066     }
00067 };
00068 
00069 #endif // KIS_SHARED_PTR_VECTOR_H
00070 
KDE Home | KDE Accessibility Home | Description of Access Keys