Class File + fixes in _free methods.
[qshowdiff.git] / utils.h
blobd2734e6f7d3dd6a9e7907d97f30437a4debc6da7
1 #ifndef _UTILS_H_
2 #define _UTILS_H_
4 #include <vector>
6 /**
7 * Iterator for vectors containing pointers to Type.
8 * Attention: Dereferenced iterator returns copy of the Type
9 * (not pointer to Type)!
10 * For usage it should be enough to public inherit from this class and
11 * declare some friend methods (functions).
12 * Example:
14 * class Cl{
15 * public:
16 * class iterator;
18 * iterator begin() const;
19 * iterator end() const;
21 * class iterator : public VectorPointerIterator<QString>{
22 * public:
23 * friend iterator Cl::begin() const;
24 * friend iterator Cl::end() const;
25 * };
26 * };
29 template<class Type>
30 class VectorPointerIterator{
31 protected:
32 typedef typename std::vector<Type *>::const_iterator iterator_t;
33 iterator_t it;
35 public:
36 VectorPointerIterator(){}
37 VectorPointerIterator(const VectorPointerIterator &iter) : it(iter.it){}
38 virtual VectorPointerIterator
39 &operator=(const VectorPointerIterator& iter)
40 { it = iter.it; return *this; }
41 virtual bool
42 operator==(const VectorPointerIterator& iter){ return it == iter.it; }
43 virtual bool
44 operator!=(const VectorPointerIterator& iter){ return it != iter.it; }
45 virtual VectorPointerIterator &operator++(){ it++; return *this; }
46 virtual VectorPointerIterator &operator++(int){ it++; return *this; }
47 virtual VectorPointerIterator &operator--(){ it--; return *this; }
48 virtual VectorPointerIterator &operator--(int){ it--; return *this; }
49 virtual Type operator*() const{ return **it; }
51 #endif