MAK Data Logger API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
orderedKeyList.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 1992-2015 VT MAK
3 ** All rights reserved.
4 *******************************************************************************/
7 #pragma once
8 
12 
13 #include <QList>
14 #include <omtReader/entityMapperKey.h>
15 
16 template <typename T>
17 class DtOrderedKeyList : public QList<T>
18 {
19 public:
22 
24 
25  virtual ~DtOrderedKeyList();
26 
27  void clear();
28  void copyList(const DtOrderedKeyList&);
29 
31  void addEntry(T, bool replace = false);
32  T removeEntry(const DtEntityMapperKey& key);
33  T find(const DtEntityMapperKey& key) const;
34 };
35 
36 template <typename T>
38 {
39 }
40 
41 template <typename T>
43 {
44  clear();
45  copyList(orig);
46 }
47 
48 template <typename T>
50 {
51  if (this != &rhs)
52  {
53  clear();
54  copyList(rhs);
55  }
56 
57  return *this;
58 }
59 
60 template <typename T>
62 {
63  clear();
64 }
65 
66 template <typename T>
68 {
69  typename QList<T>::iterator it = this->begin();
70 
71  while (it != this->end())
72  {
73  delete *it;
74  ++it;
75  }
76 
77  QList<T>::clear();
78 }
79 
80 template <typename T>
82 {
83  typename QList<T>::const_iterator it = rhs.begin();
84 
85  while (it != rhs.end())
86  {
87  addEntry(*it);
88  ++it;
89  }
90 }
91 
92 template <typename T>
93 void DtOrderedKeyList<T>::addEntry(T entry, bool replace)
94 {
95  if (this->count() == 0)
96  {
97  this->append(entry);
98  return;
99  }
100 
102  T item = this->last();
103  DtEntityMapperKey sdKey = *entry;
104 
105  if (*item < sdKey)
106  {
107  this->append(entry);
108  return;
109  }
110 
111  item = this->first();
112 
113  if (*item > sdKey)
114  {
115  this->insert(0, entry);
116  return;
117  }
118 
119  QString strKey = entry->string().c_str();
120 
121  unsigned int iLower = 0;
122  unsigned int iUpper = this->count() - 1;
123 
124  while ((iUpper - iLower) != 1)
125  {
126  int iPos = (iUpper + iLower) / 2;
127 
128  if (sdKey < *this->at(iPos))
129  {
130  iUpper = iPos;
131  }
132  else if (sdKey > *this->at(iPos))
133  {
134  iLower = iPos;
135  }
136  else if ((sdKey == *this->at(iPos)) && replace)
137  {
138  *this->at(iPos) = *entry;
139 
140  return;
141  }
142  }
143 
144  this->insert(iLower + 1, entry);
145 }
146 
147 template <typename T>
149 {
150  typename QList<T>::const_iterator iter = this->begin();
151 
152  while (iter != this->end())
153  {
154  if (**iter == key)
155  {
156  return *iter;
157  }
158 
159  ++iter;
160  }
161 
162  return T();
163 }
164 
165 template <typename T>
167 {
168  typename QList<T>::iterator iter = this->begin();
169 
170  while (iter != this->end())
171  {
172  if (**iter == key)
173  {
174  T item = *iter;
175 
176  erase(iter);
177 
178  return item;
179  }
180 
181  ++iter;
182  }
183 
184  return NULL;
185 }
186 
virtual ~DtOrderedKeyList()
Definition: orderedKeyList.h:61
void copyList(const DtOrderedKeyList &)
Definition: orderedKeyList.h:81
DtOrderedKeyList()
Definition: orderedKeyList.h:37
void addEntry(T, bool replace=false)
Adds a new entry, ordering it by key type.
Definition: orderedKeyList.h:93
T find(const DtEntityMapperKey &key) const
Definition: orderedKeyList.h:148
void clear()
Definition: orderedKeyList.h:67
Definition: entityMapperKey.h:15
T removeEntry(const DtEntityMapperKey &key)
Definition: orderedKeyList.h:166
DtOrderedKeyList & operator=(const DtOrderedKeyList &)
Definition: orderedKeyList.h:49
An ordered key list will allow lookup by entity key type.
Definition: orderedKeyList.h:17

Document ID: Generated on Thu Sep 2 15:35:22 EDT 2021 from SVN revision 233992
Copyright © 2021 MAK Technologies. All Rights Reserved (www.mak.com)