QtCore/qiterator.h Source File
Go to the documentation of this file.
51 # if defined(_LIBCPP_VERSION)
58 # if defined(Q_CC_CLANG)
59 # pragma GCC diagnostic push
60 # pragma GCC diagnostic ignored "-Wc++11-extensions"
63 _LIBCPP_BEGIN_NAMESPACE_STD
64 struct bidirectional_iterator_tag;
65 struct random_access_iterator_tag;
66 _LIBCPP_END_NAMESPACE_STD
68 # if defined(Q_CC_CLANG)
69 # pragma GCC diagnostic pop
73 struct bidirectional_iterator_tag;
74 struct random_access_iterator_tag;
83 #define Q_DECLARE_SEQUENTIAL_ITERATOR(C) \
86 class Q##C##Iterator \
88 typedef typename Q##C<T>::const_iterator const_iterator; \
92 inline Q##C##Iterator(const Q##C<T> &container) \
93 : c(container), i(c.constBegin()) {} \
94 inline Q##C##Iterator &operator=(const Q##C<T> &container) \
95 { c = container; i = c.constBegin(); return *this; } \
96 inline void toFront() { i = c.constBegin(); } \
97 inline void toBack() { i = c.constEnd(); } \
98 inline bool hasNext() const { return i != c.constEnd(); } \
99 inline const T &next() { return *i++; } \
100 inline const T &peekNext() const { return *i; } \
101 inline bool hasPrevious() const { return i != c.constBegin(); } \
102 inline const T &previous() { return *--i; } \
103 inline const T &peekPrevious() const { const_iterator p = i; return *--p; } \
104 inline bool findNext(const T &t) \
105 { while (i != c.constEnd()) if (*i++ == t) return true; return false; } \
106 inline bool findPrevious(const T &t) \
107 { while (i != c.constBegin()) if (*(--i) == t) return true; \
111 #define Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C) \
114 class QMutable##C##Iterator \
116 typedef typename Q##C<T>::iterator iterator; \
117 typedef typename Q##C<T>::const_iterator const_iterator; \
120 inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
122 inline QMutable##C##Iterator(Q##C<T> &container) \
124 { c->setSharable(false); i = c->begin(); n = c->end(); } \
125 inline ~QMutable##C##Iterator() \
126 { c->setSharable(true); } \
127 inline QMutable##C##Iterator &operator=(Q##C<T> &container) \
128 { c->setSharable(true); c = &container; c->setSharable(false); \
129 i = c->begin(); n = c->end(); return *this; } \
130 inline void toFront() { i = c->begin(); n = c->end(); } \
131 inline void toBack() { i = c->end(); n = i; } \
132 inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \
133 inline T &next() { n = i++; return *n; } \
134 inline T &peekNext() const { return *i; } \
135 inline bool hasPrevious() const { return c->constBegin() != const_iterator(i); } \
136 inline T &previous() { n = --i; return *n; } \
137 inline T &peekPrevious() const { iterator p = i; return *--p; } \
138 inline void remove() \
139 { if (c->constEnd() != const_iterator(n)) { i = c->erase(n); n = c->end(); } } \
140 inline void setValue(const T &t) const { if (c->constEnd() != const_iterator(n)) *n = t; } \
141 inline T &value() { Q_ASSERT(item_exists()); return *n; } \
142 inline const T &value() const { Q_ASSERT(item_exists()); return *n; } \
143 inline void insert(const T &t) { n = i = c->insert(i, t); ++i; } \
144 inline bool findNext(const T &t) \
145 { while (c->constEnd() != const_iterator(n = i)) if (*i++ == t) return true; return false; } \
146 inline bool findPrevious(const T &t) \
147 { while (c->constBegin() != const_iterator(i)) if (*(n = --i) == t) return true; \
148 n = c->end(); return false; } \
151 #define Q_DECLARE_ASSOCIATIVE_ITERATOR(C) \
153 template <class Key, class T> \
154 class Q##C##Iterator \
156 typedef typename Q##C<Key,T>::const_iterator const_iterator; \
157 typedef const_iterator Item; \
159 const_iterator i, n; \
160 inline bool item_exists() const { return n != c.constEnd(); } \
162 inline Q##C##Iterator(const Q##C<Key,T> &container) \
163 : c(container), i(c.constBegin()), n(c.constEnd()) {} \
164 inline Q##C##Iterator &operator=(const Q##C<Key,T> &container) \
165 { c = container; i = c.constBegin(); n = c.constEnd(); return *this; } \
166 inline void toFront() { i = c.constBegin(); n = c.constEnd(); } \
167 inline void toBack() { i = c.constEnd(); n = c.constEnd(); } \
168 inline bool hasNext() const { return i != c.constEnd(); } \
169 inline Item next() { n = i++; return n; } \
170 inline Item peekNext() const { return i; } \
171 inline bool hasPrevious() const { return i != c.constBegin(); } \
172 inline Item previous() { n = --i; return n; } \
173 inline Item peekPrevious() const { const_iterator p = i; return --p; } \
174 inline const T &value() const { Q_ASSERT(item_exists()); return *n; } \
175 inline const Key &key() const { Q_ASSERT(item_exists()); return n.key(); } \
176 inline bool findNext(const T &t) \
177 { while ((n = i) != c.constEnd()) if (*i++ == t) return true; return false; } \
178 inline bool findPrevious(const T &t) \
179 { while (i != c.constBegin()) if (*(n = --i) == t) return true; \
180 n = c.constEnd(); return false; } \
183 #define Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(C) \
185 template <class Key, class T> \
186 class QMutable##C##Iterator \
188 typedef typename Q##C<Key,T>::iterator iterator; \
189 typedef typename Q##C<Key,T>::const_iterator const_iterator; \
190 typedef iterator Item; \
193 inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
195 inline QMutable##C##Iterator(Q##C<Key,T> &container) \
197 { c->setSharable(false); i = c->begin(); n = c->end(); } \
198 inline ~QMutable##C##Iterator() \
199 { c->setSharable(true); } \
200 inline QMutable##C##Iterator &operator=(Q##C<Key,T> &container) \
201 { c->setSharable(true); c = &container; c->setSharable(false); i = c->begin(); n = c->end(); return *this; } \
202 inline void toFront() { i = c->begin(); n = c->end(); } \
203 inline void toBack() { i = c->end(); n = c->end(); } \
204 inline bool hasNext() const { return const_iterator(i) != c->constEnd(); } \
205 inline Item next() { n = i++; return n; } \
206 inline Item peekNext() const { return i; } \
207 inline bool hasPrevious() const { return const_iterator(i) != c->constBegin(); } \
208 inline Item previous() { n = --i; return n; } \
209 inline Item peekPrevious() const { iterator p = i; return --p; } \
210 inline void remove() \
211 { if (const_iterator(n) != c->constEnd()) { i = c->erase(n); n = c->end(); } } \
212 inline void setValue(const T &t) { if (const_iterator(n) != c->constEnd()) *n = t; } \
213 inline T &value() { Q_ASSERT(item_exists()); return *n; } \
214 inline const T &value() const { Q_ASSERT(item_exists()); return *n; } \
215 inline const Key &key() const { Q_ASSERT(item_exists()); return n.key(); } \
216 inline bool findNext(const T &t) \
217 { while (const_iterator(n = i) != c->constEnd()) if (*i++ == t) return true; return false; } \
218 inline bool findPrevious(const T &t) \
219 { while (const_iterator(i) != c->constBegin()) if (*(n = --i) == t) return true; \
220 n = c->end(); return false; } \
227 #endif // QITERATOR_H
#define QT_BEGIN_NAMESPACE