VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
8 
9 #pragma once
10 #include <QtCore/QList>
11 
14 
15 template <typename T>
16 class DtPtrQList : public QList<T>
17 {
18 
19 public:
20 
22 
23  DtPtrQList<T>(const DtPtrQList<T>& orig) : QList<T>(orig),
24  myAutoDelete(orig.myAutoDelete) {};
25 
26  virtual ~DtPtrQList<T>() { clear(); };
27 
28  void clear()
29  {
30  if (myAutoDelete)
31  {
32  typename DtPtrQList<T>::iterator it = this->begin();
33  while (it != this->end())
34  {
35  delete *it;
36  ++it;
37  }
38  }
39  QList<T>::clear();
40  };
41 
42  void setAutoDelete(bool b)
43  {
44  myAutoDelete = b;
45  };
46 
47  bool autoDelete() const
48  {
49  return myAutoDelete;
50  };
51 
53  {
54  T val = *pos;
55  typename DtPtrQList<T>::iterator retVal = QList<T>::erase(pos);
56  if (myAutoDelete)
57  {
58  delete val;
59  }
60  return retVal;
61  };
62 
64  typename DtPtrQList<T>::iterator first,
65  typename DtPtrQList<T>::iterator last)
66  {
67  while (first != last)
68  {
69  erase(first++);
70  }
71  return last;
72  };
73 
74  int findRef(T t) const
75  {
76  return find(t);
77  };
78 
79  int find(T t) const { return indexOf(t); };
80 
81  void removeRef(T t) { remove(t); };
82 
83  void remove(T t)
84  {
85  typename DtPtrQList<T>::iterator it = this->begin();
86  while (it != this->end())
87  {
88  if (*it == t)
89  {
90  erase(it);
91  break;
92  }
93  ++it;
94  }
95  };
96 
97  void removeAt(int i)
98  {
99  T val = this->at(i);
100  QList<T>::removeAt(i);
101  if (myAutoDelete)
102  {
103  delete val;
104  }
105  };
106 
107 protected:
108  bool myAutoDelete;
109 };
int findRef(T t) const
Definition: DtPtrQList.h:74
int find(T t) const
Definition: DtPtrQList.h:79
void clear()
Definition: DtPtrQList.h:28
void setAutoDelete(bool b)
Definition: DtPtrQList.h:42
DtPtrQList< T >::iterator erase(typename DtPtrQList< T >::iterator first, typename DtPtrQList< T >::iterator last)
Definition: DtPtrQList.h:63
bool myAutoDelete
Definition: DtPtrQList.h:105
DtPtrQList< T >::iterator erase(typename DtPtrQList< T >::iterator pos)
Definition: DtPtrQList.h:52
bool autoDelete() const
Definition: DtPtrQList.h:47
This class has been extended from the QList class to provide some convenience methods as well as auto...
Definition: DtPtrQList.h:16
Definition: translator.h:58
void removeRef(T t)
Definition: DtPtrQList.h:81
void removeAt(int i)
Definition: DtPtrQList.h:97

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)