chalk

kis_shared_ptr_vector.h
1/*
2 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#ifndef KIS_SHARED_PTR_VECTOR_H
20#define KIS_SHARED_PTR_VECTOR_H
21
22#include <tqvaluevector.h>
23
24#include <ksharedptr.h>
25
33template <class T>
34class KisSharedPtrVector : public TQValueVector< TDESharedPtr<T> >
35{
36 typedef TQValueVector< TDESharedPtr<T> > super;
37public:
38 KisSharedPtrVector() {}
39
40 void pop_back()
41 {
42 if (!super::empty()) {
43 super::back() = 0;
44 super::pop_back();
45 }
46 }
47
48 typename super::iterator erase(typename super::iterator it)
49 {
50 *it = 0;
51 return super::erase(it);
52 }
53
54 typename super::iterator erase(typename super::iterator first, typename super::iterator last)
55 {
56 tqFill(first, last, 0);
57 return super::erase(first, last);
58 }
59
60 bool contains(TDESharedPtr<T> ptr) const
61 {
62 for (int i = 0, n = super::count(); i < n; ++i)
63 if (super::at(i) == ptr)
64 return true;
65 return false;
66 }
67};
68
69#endif // KIS_SHARED_PTR_VECTOR_H
70