VR-Forces 4.1.1 Class Documentation
dtqlist.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2007 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <QtCore/QList>
12 
15 
16 template <typename T>
17 class DtPtrQList : public QList<T>
18 {
19 
20 public:
21 
23 
24  DtPtrQList<T>(const DtPtrQList<T>& orig) : QList<T>(orig),
25  myAutoDelete(orig.myAutoDelete) {};
26 
27  virtual ~DtPtrQList<T>() { clear(); };
28 
29  void clear()
30  {
31  if (myAutoDelete)
32  {
33  typename DtPtrQList<T>::iterator it = this->begin();
34  while (it != this->end())
35  {
36  delete *it;
37  ++it;
38  }
39  }
40  QList<T>::clear();
41  };
42 
43  void setAutoDelete(bool b)
44  {
45  myAutoDelete = b;
46  };
47 
48  bool autoDelete() const
49  {
50  return myAutoDelete;
51  };
52 
54  {
55  T val = *pos;
56  typename DtPtrQList<T>::iterator retVal = QList<T>::erase(pos);
57  if (myAutoDelete)
58  {
59  delete val;
60  }
61  return retVal;
62  };
63 
65  typename DtPtrQList<T>::iterator first,
66  typename DtPtrQList<T>::iterator last)
67  {
68  while (first != last)
69  {
70  erase(first++);
71  }
72  return last;
73  };
74 
75  int findRef(T t) const
76  {
77  return find(t);
78  };
79 
80  int find(T t) const { return this->indexOf(t); };
81 
82  void removeRef(T t) { remove(t); };
83 
84  void remove(T t)
85  {
86  typename DtPtrQList<T>::iterator it = this->begin();
87  while (it != this->end())
88  {
89  if (*it == t)
90  {
91  erase(it);
92  break;
93  }
94  ++it;
95  }
96  };
97 
98  void removeAt(int i)
99  {
100  T val = this->at(i);
101  QList<T>::removeAt(i);
102  if (myAutoDelete)
103  {
104  delete val;
105  }
106  };
107 
108 protected:
109  bool myAutoDelete;
110 };
111 

Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)