VR-Forces 4.1.1 Class Documentation
dictIter.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2002 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: dictIter.h,v $ $Revision: 1.5 $ $State: Exp $
7 *********************************************************************/
8 
11 
12 
13 #ifndef DtDictIter_H_
14 #define DtDictIter_H_
15 
19 
20 #include <QHash>
21 
22 template<typename Key, typename Type>
23 class DtDictIterator : public QHash<Key, Type>::iterator
24 {
25 public:
26  DtDictIterator(QHash<Key, Type> &d) : myPosition(0), myCurrentDict(NULL) { addDataDict(&d); toFirst(); };
27 
29 
31  unsigned int count() { return myCurrentDict->count(); };
32 
34  bool isEmpty() const { return myCurrentDict->count() == 0; };
35 
38  Type toFirst() { if (myPosition >= (unsigned int)myList.count()) myPosition = 0; return reset(myPosition); };
39 
41  bool remove( const Key &k ) { return ((QHash<Key, Type>*)myCurrentDict)->remove(k); }
42 
44  Type operator++()
45  {
47 
50  if (*this == myCurrentDict->end())
51  {
52  return nextList();
53  }
54  else
55  {
56  return QHash<Key, Type>::iterator::operator*();
57  }
58  };
59 
61  Type operator+=(uint j)
62  {
63  Type result = NULL;
64 
65  while (j > 0)
66  {
67  result = ++(*this);
68 
69  if (!result && (myPosition == myList.count()))
70  {
71  return NULL;
72  }
73 
74  j--;
75  }
76 
77  return result;
78  };
79 
80  void operator=(const typename QHash<Key, Type>::iterator& iter)
81  {
83  }
84 
85  Type current()
86  {
87  if ((myCurrentDict == NULL) ||
88  (*this == myCurrentDict->end()))
89 
90  {
91  return NULL;
92  }
93 
94  return **this;
95  }
96 
98  Type reset(int toPosition = 0, bool findFirstValid = true)
99  {
100  myPosition = toPosition;
101 
102  if ((myPosition >= (unsigned int)myList.count()) || (myPosition < 0))
103  {
104  return NULL;
105  }
106 
108 
109  if (!findFirstValid)
110  {
111  *this = myCurrentDict->begin();
112  return *myCurrentDict->begin();
113  }
114 
115  Type result = NULL;
116 
117  do
118  {
119  *this = myCurrentDict->begin();
120 
121  if (myCurrentDict->begin() == myCurrentDict->end())
122  {
123  result = NULL;
124  }
125  else
126  {
127  result = *myCurrentDict->begin();
128  }
129 
130  if (!result)
131  {
132  if (myPosition == myList.count())
133  {
134  return NULL;
135  }
136  else
137  {
138  if (++myPosition == myList.count())
139  {
140  return NULL;
141  }
142  else
143  {
145  }
146  }
147  }
148  }
149  while (!result);
150 
151  return result;
152  };
153 
155  void addDataDict(QHash<Key, Type> *dict)
156  {
157  if (!myCurrentDict)
158  {
159  myCurrentDict = dict;
160  }
161 
162  myList.append(dict);
163  };
164 
167  Type find(const Key &key)
168  {
169  Type result = NULL;
170  int limit = myList.count();
171 
172  for (int i = 0; i < limit; i++)
173  {
174  if (result = myList.at(i)->value(key))
175  {
176  return result;
177  }
178  }
179 
180  return NULL;
181  }
182 
185  Type nextList()
186  {
187  if (++myPosition == myList.count())
188  {
189  return NULL;
190  }
191  else
192  {
194  return toFirst();
195  }
196  };
197 
198 protected:
199  QHash<Key, Type>* myCurrentDict;
201  unsigned int myPosition;
202 };
203 
204 #endif
205 

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)