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

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)