QhullIterator.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2008-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/QhullIterator.h#3 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #ifndef QHULLITERATOR_H
10 #define QHULLITERATOR_H
11 
12 extern "C" {
13  #include "libqhull_r/qhull_ra.h"
14 }
15 
16 #include <assert.h>
17 #include <iterator>
18 #include <string>
19 #include <vector>
20 
21 namespace orgQhull {
22 
23 #
24 
31 // Stores C* as done in Mutable... Assumes the container is not deleted.
32 // C::const_iterator is an STL-style iterator that returns T&
33 #define QHULL_DECLARE_SEQUENTIAL_ITERATOR(C, T) \
34  \
35  class C##Iterator \
36  { \
37  typedef C::const_iterator const_iterator; \
38  const C *c; \
39  const_iterator i; \
40  public: \
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; \
57  return false; } \
58  };//C##Iterator
59 
60 // Remove setShareable() from Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR
61 // Uses QHULL_ASSERT (assert.h)
62 // Duplicated in MutablePointIterator without insert or remove
63 // Not used in libqhullcpp. See Coordinates.h
64 #define QHULL_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C, T) \
65  class Mutable##C##Iterator \
66  { \
67  typedef C::iterator iterator; \
68  typedef C::const_iterator const_iterator; \
69  C *c; \
70  iterator i, n; \
71  inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
72  public: \
73  inline Mutable##C##Iterator(C &container) \
74  : c(&container) \
75  { i = c->begin(); n = c->end(); } \
76  inline ~Mutable##C##Iterator() \
77  {} \
78  inline Mutable##C##Iterator &operator=(C &container) \
79  { 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
101 
102 // Not used in libqhullcpp.
103 #define QHULL_DECLARE_SET_ITERATOR(C) \
104 \
105  template <class T> \
106  class Qhull##C##Iterator \
107  { \
108  typedef typename Qhull##C<T>::const_iterator const_iterator; \
109  Qhull##C<T> c; \
110  const_iterator i; \
111  public: \
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; \
128  return false; } \
129  };//Qhull##C##Iterator
130 
131 // Not used in libqhullcpp.
132 #define QHULL_DECLARE_MUTABLE_SET_ITERATOR(C) \
133 \
134 template <class T> \
135 class QhullMutable##C##Iterator \
136 { \
137  typedef typename Qhull##C::iterator iterator; \
138  typedef typename Qhull##C::const_iterator const_iterator; \
139  Qhull##C *c; \
140  iterator i, n; \
141  inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
142 public: \
143  inline Mutable##C##Iterator(Qhull##C &container) \
144  : 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
171 
172 }//namespace orgQhull
173 
174 #endif // QHULLITERATOR_H
175 
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:02