VR-Forces 4.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 /*******************************************************************************
6 ** $RCSfile: dtqlist.h,v $ $Revision: 1.3 $ $State: Exp $
7 *******************************************************************************/
8 
11 
12 #ifndef DTQLIST_H_
13 #define DTQLIST_H_
14 
15 #include <QtCore/QList>
16 
19 
20 template <typename T>
21 class DtPtrQList : public QList<T>
22 {
23 
24 public:
25 
27 
28  DtPtrQList<T>(const DtPtrQList<T>& orig) : QList<T>(orig),
29  myAutoDelete(orig.myAutoDelete) {};
30 
31  virtual ~DtPtrQList<T>() { clear(); };
32 
33  void clear()
34  {
35  if (myAutoDelete)
36  {
37  typename DtPtrQList<T>::iterator it = this->begin();
38  while (it != this->end())
39  {
40  delete *it;
41  ++it;
42  }
43  }
44  QList<T>::clear();
45  };
46 
47  void setAutoDelete(bool b)
48  {
49  myAutoDelete = b;
50  };
51 
52  bool autoDelete() const
53  {
54  return myAutoDelete;
55  };
56 
58  {
59  T val = *pos;
60  typename DtPtrQList<T>::iterator retVal = QList<T>::erase(pos);
61  if (myAutoDelete)
62  {
63  delete val;
64  }
65  return retVal;
66  };
67 
69  typename DtPtrQList<T>::iterator first,
70  typename DtPtrQList<T>::iterator last)
71  {
72  while (first != last)
73  {
74  erase(first++);
75  }
76  return last;
77  };
78 
79  int findRef(T t) const
80  {
81  return find(t);
82  };
83 
84  int find(T t) const { return indexOf(t); };
85 
86  void removeRef(T t) { remove(t); };
87 
88  void remove(T t)
89  {
90  typename DtPtrQList<T>::iterator it = this->begin();
91  while (it != this->end())
92  {
93  if (*it == t)
94  {
95  erase(it);
96  break;
97  }
98  ++it;
99  }
100  };
101 
102  void removeAt(int i)
103  {
104  T val = this->at(i);
105  QList<T>::removeAt(i);
106  if (myAutoDelete)
107  {
108  delete val;
109  }
110  };
111 
112 protected:
113  bool myAutoDelete;
114 };
115 
116 #endif //DTQLIST_H_

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)