9 #ifndef QHULLITERATOR_H 10 #define QHULLITERATOR_H 33 #define QHULL_DECLARE_SEQUENTIAL_ITERATOR(C, T) \ 37 typedef C::const_iterator const_iterator; \ 41 inline C##Iterator(const C &container) \ 42 : c(&container), i(c->constBegin()) {} \ 43 inline C##Iterator &operator=(const C &container) \ 44 { c = &container; i = c->constBegin(); return *this; } \ 45 inline void toFront() { i = c->constBegin(); } \ 46 inline void toBack() { i = c->constEnd(); } \ 47 inline bool hasNext() const { return i != c->constEnd(); } \ 48 inline const T &next() { return *i++; } \ 49 inline const T &peekNext() const { return *i; } \ 50 inline bool hasPrevious() const { return i != c->constBegin(); } \ 51 inline const T &previous() { return *--i; } \ 52 inline const T &peekPrevious() const { const_iterator p = i; return *--p; } \ 53 inline bool findNext(const T &t) \ 54 { while (i != c->constEnd()) if (*i++ == t) return true; return false; } \ 55 inline bool findPrevious(const T &t) \ 56 { while (i != c->constBegin()) if (*(--i) == t) return true; \ 64 #define QHULL_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C, T) \ 65 class Mutable##C##Iterator \ 67 typedef C::iterator iterator; \ 68 typedef C::const_iterator const_iterator; \ 71 inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \ 73 inline Mutable##C##Iterator(C &container) \ 75 { i = c->begin(); n = c->end(); } \ 76 inline ~Mutable##C##Iterator() \ 78 inline Mutable##C##Iterator &operator=(C &container) \ 80 i = c->begin(); n = c->end(); return *this; } \ 81 inline void toFront() { i = c->begin(); n = c->end(); } \ 82 inline void toBack() { i = c->end(); n = i; } \ 83 inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \ 84 inline T &next() { n = i++; return *n; } \ 85 inline T &peekNext() const { return *i; } \ 86 inline bool hasPrevious() const { return c->constBegin() != const_iterator(i); } \ 87 inline T &previous() { n = --i; return *n; } \ 88 inline T &peekPrevious() const { iterator p = i; return *--p; } \ 89 inline void remove() \ 90 { if (c->constEnd() != const_iterator(n)) { i = c->erase(n); n = c->end(); } } \ 91 inline void setValue(const T &t) const { if (c->constEnd() != const_iterator(n)) *n = t; } \ 92 inline T &value() { QHULL_ASSERT(item_exists()); return *n; } \ 93 inline const T &value() const { QHULL_ASSERT(item_exists()); return *n; } \ 94 inline void insert(const T &t) { n = i = c->insert(i, t); ++i; } \ 95 inline bool findNext(const T &t) \ 96 { while (c->constEnd() != const_iterator(n = i)) if (*i++ == t) return true; return false; } \ 97 inline bool findPrevious(const T &t) \ 98 { while (c->constBegin() != const_iterator(i)) if (*(n = --i) == t) return true; \ 99 n = c->end(); return false; } \ 100 };//Mutable##C##Iterator 103 #define QHULL_DECLARE_SET_ITERATOR(C) \ 106 class Qhull##C##Iterator \ 108 typedef typename Qhull##C<T>::const_iterator const_iterator; \ 112 inline Qhull##C##Iterator(const Qhull##C<T> &container) \ 113 : c(container), i(c.constBegin()) {} \ 114 inline Qhull##C##Iterator &operator=(const Qhull##C<T> &container) \ 115 { c = container; i = c.constBegin(); return *this; } \ 116 inline void toFront() { i = c.constBegin(); } \ 117 inline void toBack() { i = c.constEnd(); } \ 118 inline bool hasNext() const { return i != c.constEnd(); } \ 119 inline const T &next() { return *i++; } \ 120 inline const T &peekNext() const { return *i; } \ 121 inline bool hasPrevious() const { return i != c.constBegin(); } \ 122 inline const T &previous() { return *--i; } \ 123 inline const T &peekPrevious() const { const_iterator p = i; return *--p; } \ 124 inline bool findNext(const T &t) \ 125 { while (i != c.constEnd()) if (*i++ == t) return true; return false; } \ 126 inline bool findPrevious(const T &t) \ 127 { while (i != c.constBegin()) if (*(--i) == t) return true; \ 129 };//Qhull##C##Iterator 132 #define QHULL_DECLARE_MUTABLE_SET_ITERATOR(C) \ 135 class QhullMutable##C##Iterator \ 137 typedef typename Qhull##C::iterator iterator; \ 138 typedef typename Qhull##C::const_iterator const_iterator; \ 141 inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \ 143 inline Mutable##C##Iterator(Qhull##C &container) \ 145 { c->setSharable(false); i = c->begin(); n = c->end(); } \ 146 inline ~Mutable##C##Iterator() \ 147 { c->setSharable(true); } \ 148 inline Mutable##C##Iterator &operator=(Qhull##C &container) \ 149 { c->setSharable(true); c = &container; c->setSharable(false); \ 150 i = c->begin(); n = c->end(); return *this; } \ 151 inline void toFront() { i = c->begin(); n = c->end(); } \ 152 inline void toBack() { i = c->end(); n = i; } \ 153 inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \ 154 inline T &next() { n = i++; return *n; } \ 155 inline T &peekNext() const { return *i; } \ 156 inline bool hasPrevious() const { return c->constBegin() != const_iterator(i); } \ 157 inline T &previous() { n = --i; return *n; } \ 158 inline T &peekPrevious() const { iterator p = i; return *--p; } \ 159 inline void remove() \ 160 { if (c->constEnd() != const_iterator(n)) { i = c->erase(n); n = c->end(); } } \ 161 inline void setValue(const T &t) const { if (c->constEnd() != const_iterator(n)) *n = t; } \ 162 inline T &value() { Q_ASSERT(item_exists()); return *n; } \ 163 inline const T &value() const { Q_ASSERT(item_exists()); return *n; } \ 164 inline void insert(const T &t) { n = i = c->insert(i, t); ++i; } \ 165 inline bool findNext(const T &t) \ 166 { while (c->constEnd() != const_iterator(n = i)) if (*i++ == t) return true; return false; } \ 167 inline bool findPrevious(const T &t) \ 168 { while (c->constBegin() != const_iterator(i)) if (*(n = --i) == t) return true; \ 169 n = c->end(); return false; } \ 170 };//QhullMutable##C##Iterator 174 #endif // QHULLITERATOR_H QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.