QhullLinkedList.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/QhullLinkedList.h#6 $$Change: 2066 $
5 ** $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #ifndef QHULLLINKEDLIST_H
10 #define QHULLLINKEDLIST_H
11 
12 extern "C" {
13  #include "libqhull_r/qhull_ra.h"
14 }
15 #include "libqhullcpp/QhullError.h"
16 
17 #include <cstddef> // ptrdiff_t, size_t
18 
19 #ifdef QHULL_USES_QT
20 #include <QtCore/QList>
21 #endif
22 
23 #ifndef QHULL_NO_STL
24 #include <algorithm>
25 #include <iterator>
26 #include <vector>
27 #endif
28 
29 namespace orgQhull {
30 
31 #
32 
43 template <typename T>
44 class QhullLinkedList
45 {
46 #
47 public:
48  class const_iterator;
49  class iterator;
51  typedef iterator Iterator;
52  typedef ptrdiff_t difference_type;
53  typedef countT size_type;
54  typedef T value_type;
55  typedef const value_type *const_pointer;
56  typedef const value_type &const_reference;
57  typedef value_type *pointer;
59 
60 #
61 private:
64 
65 #
66 public:
67  QhullLinkedList<T>(T b, T e) : begin_node(b), end_node(e) {}
71  QhullLinkedList<T> & operator=(const QhullLinkedList<T> &other) { begin_node= other.begin_node; end_node= other.end_node; return *this; }
72  ~QhullLinkedList<T>() {}
73 
74 private:
77 
78 public:
79 
80 #
81 #ifndef QHULL_NO_STL
82  std::vector<T> toStdVector() const;
83 #endif
84 #ifdef QHULL_USES_QT
85  QList<T> toQList() const;
86 #endif
87 
88 #
89  countT count() const;
90  //count(t) under #//!\name Search
91  bool isEmpty() const { return (begin_node==end_node); }
92  bool operator==(const QhullLinkedList<T> &o) const;
93  bool operator!=(const QhullLinkedList<T> &o) const { return !operator==(o); }
94  size_t size() const { return count(); }
95 
96 #
97  const T back() const { return last(); }
99  T back() { return last(); }
100  const T & first() const { QHULL_ASSERT(!isEmpty()); return begin_node; }
101  T & first() { QHULL_ASSERT(!isEmpty()); return begin_node; }
102  const T & front() const { return first(); }
103  T & front() { return first(); }
104  const T last() const { QHULL_ASSERT(!isEmpty()); return *--end(); }
105  T last() { QHULL_ASSERT(!isEmpty()); return *--end(); }
106 
107 #
108 
109 #
110  bool contains(const T &t) const;
111  countT count(const T &t) const;
112 
113 #
114  iterator begin() { return begin_node; }
115  const_iterator begin() const { return begin_node; }
116  const_iterator constBegin() const { return begin_node; }
117  const_iterator constEnd() const { return end_node; }
118  iterator end() { return end_node; }
119  const_iterator end() const { return end_node; }
120 
121  class iterator {
122 
123  private:
124  T i;
125  friend class const_iterator;
126 
127  public:
128  typedef std::bidirectional_iterator_tag iterator_category;
129  typedef T value_type;
130  typedef value_type *pointer;
132  typedef ptrdiff_t difference_type;
133 
134  iterator() : i() {}
135  iterator(const T &t) : i(t) {}
136  iterator(const iterator &o) : i(o.i) {}
137  iterator & operator=(const iterator &o) { i= o.i; return *this; }
138 
139  const T & operator*() const { return i; }
140  T & operator*() { return i; }
141  // Do not define operator[]
142  const T * operator->() const { return &i; }
143  T * operator->() { return &i; }
144  bool operator==(const iterator &o) const { return i == o.i; }
145  bool operator!=(const iterator &o) const { return !operator==(o); }
146  bool operator==(const const_iterator &o) const { return i==reinterpret_cast<const iterator &>(o).i; }
147  bool operator!=(const const_iterator &o) const { return !operator==(o); }
148  iterator & operator++() { i= i.next(); return *this; }
149  iterator operator++(int) { iterator o= i; i= i.next(); return o; }
150  iterator & operator--() { i= i.previous(); return *this; }
151  iterator operator--(int) { iterator o= i; i= i.previous(); return o; }
152  iterator operator+(int j) const;
153  iterator operator-(int j) const { return operator+(-j); }
154  iterator & operator+=(int j) { return (*this= *this + j); }
155  iterator & operator-=(int j) { return (*this= *this - j); }
156  };//QhullLinkedList::iterator
157 
158  class const_iterator {
159 
160  private:
161  T i;
162 
163  public:
164  typedef std::bidirectional_iterator_tag iterator_category;
165  typedef T value_type;
166  typedef const value_type *pointer;
167  typedef const value_type &reference;
168  typedef ptrdiff_t difference_type;
169 
170  const_iterator() : i() {}
171  const_iterator(const T &t) : i(t) {}
172  const_iterator(const iterator &o) : i(o.i) {}
173  const_iterator(const const_iterator &o) : i(o.i) {}
174  const_iterator &operator=(const const_iterator &o) { i= o.i; return *this; }
175 
176  const T & operator*() const { return i; }
177  const T * operator->() const { return i; }
178  bool operator==(const const_iterator &o) const { return i == o.i; }
179  bool operator!=(const const_iterator &o) const { return !operator==(o); }
180  // No comparisons or iterator diff
181  const_iterator &operator++() { i= i.next(); return *this; }
182  const_iterator operator++(int) { const_iterator o= i; i= i.next(); return o; }
183  const_iterator &operator--() { i= i.previous(); return *this; }
184  const_iterator operator--(int) { const_iterator o= i; i= i.previous(); return o; }
185  const_iterator operator+(int j) const;
186  const_iterator operator-(int j) const { return operator+(-j); }
187  const_iterator &operator+=(int j) { return (*this= *this + j); }
188  const_iterator &operator-=(int j) { return (*this= *this - j); }
189  };//QhullLinkedList::const_iterator
190 
191 };//QhullLinkedList
192 
193 template <typename T>
194 class QhullLinkedListIterator // FIXUP QH11016 define QhullMutableLinkedListIterator
195 {
197  const QhullLinkedList<T> *c;
199 
200 public:
201  QhullLinkedListIterator(const QhullLinkedList<T> &container) : c(&container), i(c->constBegin()) {}
202  QhullLinkedListIterator & operator=(const QhullLinkedList<T> &container) { c= &container; i= c->constBegin(); return *this; }
203  bool findNext(const T &t);
204  bool findPrevious(const T &t);
205  bool hasNext() const { return i != c->constEnd(); }
206  bool hasPrevious() const { return i != c->constBegin(); }
207  T next() { return *i++; }
208  T peekNext() const { return *i; }
209  T peekPrevious() const { const_iterator p= i; return *--p; }
210  T previous() { return *--i; }
211  void toFront() { i= c->constBegin(); }
212  void toBack() { i= c->constEnd(); }
213 };//QhullLinkedListIterator
214 
215 #
216 
217 #
218 
219 #ifndef QHULL_NO_STL
220 template <typename T>
221 std::vector<T> QhullLinkedList<T>::
222 toStdVector() const
223 {
224  std::vector<T> tmp;
225  std::copy(constBegin(), constEnd(), std::back_inserter(tmp));
226  return tmp;
227 }//toStdVector
228 #endif
229 
230 #ifdef QHULL_USES_QT
231 template <typename T>
232 QList<T> QhullLinkedList<T>::
233 toQList() const
234 {
236  QList<T> ls;
237  while(i.hasNext()){
238  ls.append(i.next());
239  }
240  return ls;
241 }//toQList
242 #endif
243 
244 #
245 
246 template <typename T>
248 count() const
249 {
250  const_iterator i= begin_node;
251  countT c= 0;
252  while(i != end_node){
253  c++;
254  i++;
255  }
256  return c;
257 }//count
258 
259 #
260 
261 template <typename T>
263 contains(const T &t) const
264 {
265  const_iterator i= begin_node;
266  while(i != end_node){
267  if(i==t){
268  return true;
269  }
270  i++;
271  }
272  return false;
273 }//contains
274 
275 template <typename T>
277 count(const T &t) const
278 {
279  const_iterator i= begin_node;
280  countT c= 0;
281  while(i != end_node){
282  if(i==t){
283  c++;
284  }
285  i++;
286  }
287  return c;
288 }//count
289 
290 template <typename T>
292 operator==(const QhullLinkedList<T> &l) const
293 {
294  if(begin_node==l.begin_node){
295  return (end_node==l.end_node);
296  }
297  T i= begin_node;
298  T il= l.begin_node;
299  while(i != end_node){
300  if(i != il){
301  return false;
302  }
303  i= static_cast<T>(i.next());
304  il= static_cast<T>(il.next());
305  }
306  if(il != l.end_node){
307  return false;
308  }
309  return true;
310 }//operator==
311 
312 #
313 
314 template <typename T>
315 typename QhullLinkedList<T>::iterator QhullLinkedList<T>::iterator::
316 operator+(int j) const
317 {
318  T n= i;
319  if(j>0){
320  while(j--){
321  n= n.next();
322  }
323  }else{
324  while(j++){
325  n= n.previous();
326  }
327  }
328  return iterator(n);
329 }//operator+
330 
331 template <typename T>
332 typename QhullLinkedList<T>::const_iterator QhullLinkedList<T>::const_iterator::
333 operator+(int j) const
334 {
335  T n= i;
336  if(j>0){
337  while(j--){
338  n= n.next();
339  }
340  }else{
341  while(j++){
342  n= n.previous();
343  }
344  }
345  return const_iterator(n);
346 }//operator+
347 
348 #
349 
350 template <typename T>
352 findNext(const T &t)
353 {
354  while(i != c->constEnd()){
355  if (*i++ == t){
356  return true;
357  }
358  }
359  return false;
360 }//findNext
361 
362 template <typename T>
364 findPrevious(const T &t)
365 {
366  while(i!=c->constBegin()){
367  if(*(--i)==t){
368  return true;
369  }
370  }
371  return false;
372 }//findNext
373 
374 }//namespace orgQhull
375 
376 #
377 
378 template <typename T>
379 std::ostream &
380 operator<<(std::ostream &os, const orgQhull::QhullLinkedList<T> &qs)
381 {
383  for(i= qs.begin(); i != qs.end(); ++i){
384  os << *i;
385  }
386  return os;
387 }//operator<<
388 
389 #endif // QHULLLINKEDLIST_H
390 
orgQhull::QhullLinkedList::const_iterator::operator+
const_iterator operator+(int j) const
Definition: QhullLinkedList.h:339
orgQhull::QhullLinkedList::begin_node
T begin_node
Definition: QhullLinkedList.h:68
orgQhull::QhullLinkedList::iterator::operator=
iterator & operator=(const iterator &o)
Definition: QhullLinkedList.h:143
orgQhull::QhullLinkedList::const_iterator::value_type
T value_type
Definition: QhullLinkedList.h:171
countT
int countT
Definition: user_r.h:182
orgQhull::QhullLinkedListIterator::peekPrevious
T peekPrevious() const
Definition: QhullLinkedList.h:215
orgQhull::QhullLinkedListIterator::const_iterator
QhullLinkedList< T >::const_iterator const_iterator
Definition: QhullLinkedList.h:202
orgQhull::QhullLinkedList::toStdVector
std::vector< T > toStdVector() const
Definition: QhullLinkedList.h:228
orgQhull::QhullLinkedList::back
const T back() const
For back() and last(), return T instead of T& (T is computed)
Definition: QhullLinkedList.h:104
orgQhull::QhullLinkedList::iterator::value_type
T value_type
Definition: QhullLinkedList.h:135
orgQhull::QhullLinkedList::end
iterator end()
Definition: QhullLinkedList.h:124
orgQhull
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
orgQhull::QhullLinkedList::const_iterator::operator=
const_iterator & operator=(const const_iterator &o)
Definition: QhullLinkedList.h:180
orgQhull::QhullLinkedList::count
countT count() const
Definition: QhullLinkedList.h:254
orgQhull::QhullLinkedList::iterator::operator-=
iterator & operator-=(int j)
Definition: QhullLinkedList.h:161
orgQhull::QhullLinkedList::iterator::operator->
const T * operator->() const
Definition: QhullLinkedList.h:148
orgQhull::QhullLinkedListIterator::findNext
bool findNext(const T &t)
Definition: QhullLinkedList.h:358
orgQhull::QhullLinkedList::iterator::operator!=
bool operator!=(const iterator &o) const
Definition: QhullLinkedList.h:151
orgQhull::QhullLinkedList::const_iterator::operator==
bool operator==(const const_iterator &o) const
Definition: QhullLinkedList.h:184
orgQhull::QhullLinkedList::iterator::pointer
value_type * pointer
Definition: QhullLinkedList.h:136
orgQhull::QhullLinkedList::const_iterator::operator!=
bool operator!=(const const_iterator &o) const
Definition: QhullLinkedList.h:185
orgQhull::QhullLinkedList::value_type
T value_type
Definition: QhullLinkedList.h:60
orgQhull::QhullLinkedList::end_node
T end_node
Definition: QhullLinkedList.h:69
orgQhull::QhullLinkedList::constEnd
const_iterator constEnd() const
Definition: QhullLinkedList.h:123
orgQhull::QhullLinkedList::iterator::operator*
const T & operator*() const
Definition: QhullLinkedList.h:145
orgQhull::QhullLinkedList::iterator::difference_type
ptrdiff_t difference_type
Definition: QhullLinkedList.h:138
orgQhull::QhullLinkedListIterator::hasNext
bool hasNext() const
Definition: QhullLinkedList.h:211
orgQhull::QhullLinkedList::const_pointer
const typedef value_type * const_pointer
Definition: QhullLinkedList.h:61
operator<<
std::ostream & operator<<(std::ostream &os, const orgQhull::QhullLinkedList< T > &qs)
Definition: QhullLinkedList.h:380
orgQhull::QhullLinkedList::const_iterator::pointer
const typedef value_type * pointer
Definition: QhullLinkedList.h:172
orgQhull::QhullLinkedList::const_iterator::operator-=
const_iterator & operator-=(int j)
Definition: QhullLinkedList.h:194
orgQhull::QhullLinkedList::iterator::operator==
bool operator==(const iterator &o) const
Definition: QhullLinkedList.h:150
orgQhull::QhullLinkedList::const_iterator::i
T i
Definition: QhullLinkedList.h:167
orgQhull::QhullLinkedList::iterator
Definition: QhullLinkedList.h:127
c
c
orgQhull::QhullLinkedList::const_iterator
Definition: QhullLinkedList.h:164
orgQhull::QhullLinkedList::iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: QhullLinkedList.h:134
orgQhull::QhullLinkedList::iterator::operator+
iterator operator+(int j) const
Definition: QhullLinkedList.h:322
orgQhull::QhullLinkedList::const_iterator::const_iterator
const_iterator()
Definition: QhullLinkedList.h:176
orgQhull::QhullLinkedList::operator!=
bool operator!=(const QhullLinkedList< T > &o) const
Definition: QhullLinkedList.h:99
generate_distance_plot.ls
ls
Definition: generate_distance_plot.py:47
orgQhull::QhullLinkedListIterator::previous
T previous()
Definition: QhullLinkedList.h:216
orgQhull::QhullLinkedList::const_iterator::operator+=
const_iterator & operator+=(int j)
Definition: QhullLinkedList.h:193
orgQhull::QhullLinkedList::iterator::i
T i
Definition: QhullLinkedList.h:130
orgQhull::QhullLinkedListIterator::i
const_iterator i
Definition: QhullLinkedList.h:204
orgQhull::QhullLinkedListIterator::next
T next()
Definition: QhullLinkedList.h:213
orgQhull::QhullLinkedList::contains
bool contains(const T &t) const
Definition: QhullLinkedList.h:269
t
tuple t
qhull_ra.h
orgQhull::QhullLinkedList::const_iterator::operator--
const_iterator & operator--()
Definition: QhullLinkedList.h:189
orgQhull::QhullLinkedList::size
size_t size() const
Definition: QhullLinkedList.h:100
orgQhull::QhullLinkedList::const_iterator::operator++
const_iterator & operator++()
Definition: QhullLinkedList.h:187
orgQhull::QhullLinkedListIterator::toBack
void toBack()
Definition: QhullLinkedList.h:218
orgQhull::QhullLinkedList::pointer
value_type * pointer
Definition: QhullLinkedList.h:63
orgQhull::QhullLinkedList::operator=
QhullLinkedList< T > & operator=(const QhullLinkedList< T > &other)
Copy assignment copies begin_node and end_node, but not the list elements.
Definition: QhullLinkedList.h:77
orgQhull::QhullLinkedList::begin
iterator begin()
Definition: QhullLinkedList.h:120
orgQhull::QhullLinkedList::iterator::operator++
iterator & operator++()
Definition: QhullLinkedList.h:154
orgQhull::QhullLinkedList::iterator::operator--
iterator & operator--()
Definition: QhullLinkedList.h:156
orgQhull::QhullFacet
A QhullFacet is the C++ equivalent to Qhull's facetT*.
Definition: QhullFacet.h:43
generate_distance_plot.b
float b
Definition: generate_distance_plot.py:7
orgQhull::QhullLinkedList::const_iterator::operator-
const_iterator operator-(int j) const
Definition: QhullLinkedList.h:192
orgQhull::QhullLinkedListIterator::QhullLinkedListIterator
QhullLinkedListIterator(const QhullLinkedList< T > &container)
Definition: QhullLinkedList.h:207
orgQhull::QhullLinkedList::isEmpty
bool isEmpty() const
Definition: QhullLinkedList.h:97
orgQhull::QhullLinkedList::const_iterator::operator->
const T * operator->() const
Definition: QhullLinkedList.h:183
orgQhull::QhullLinkedList::first
const T & first() const
Definition: QhullLinkedList.h:106
orgQhull::QhullLinkedList::iterator::operator+=
iterator & operator+=(int j)
Definition: QhullLinkedList.h:160
orgQhull::QhullLinkedListIterator::hasPrevious
bool hasPrevious() const
Definition: QhullLinkedList.h:212
orgQhull::QhullLinkedList::reference
value_type & reference
Definition: QhullLinkedList.h:64
orgQhull::QhullLinkedList::Iterator
iterator Iterator
Definition: QhullLinkedList.h:57
orgQhull::QhullLinkedList::const_iterator::difference_type
ptrdiff_t difference_type
Definition: QhullLinkedList.h:174
orgQhull::QhullLinkedListIterator
Definition: QhullLinkedList.h:200
orgQhull::QhullLinkedList
Definition: QhullLinkedList.h:50
orgQhull::QhullLinkedListIterator::findPrevious
bool findPrevious(const T &t)
Definition: QhullLinkedList.h:370
orgQhull::QhullLinkedListIterator::peekNext
T peekNext() const
Definition: QhullLinkedList.h:214
orgQhull::QhullLinkedList::difference_type
ptrdiff_t difference_type
Definition: QhullLinkedList.h:58
orgQhull::QhullLinkedListIterator::operator=
QhullLinkedListIterator & operator=(const QhullLinkedList< T > &container)
Definition: QhullLinkedList.h:208
orgQhull::QhullLinkedList::iterator::const_iterator
friend class const_iterator
Definition: QhullLinkedList.h:131
orgQhull::QhullLinkedList::const_iterator::operator*
const T & operator*() const
Definition: QhullLinkedList.h:182
orgQhull::QhullLinkedList::operator==
bool operator==(const QhullLinkedList< T > &o) const
Definition: QhullLinkedList.h:298
orgQhull::QhullLinkedList::iterator::operator-
iterator operator-(int j) const
Definition: QhullLinkedList.h:159
orgQhull::QhullLinkedList::iterator::iterator
iterator()
Definition: QhullLinkedList.h:140
QHULL_ASSERT
#define QHULL_ASSERT
Definition: QhullError.h:16
orgQhull::QhullLinkedList::constBegin
const_iterator constBegin() const
Definition: QhullLinkedList.h:122
orgQhull::QhullLinkedList::const_iterator::reference
const typedef value_type & reference
Definition: QhullLinkedList.h:173
orgQhull::QhullLinkedList::ConstIterator
const_iterator ConstIterator
Definition: QhullLinkedList.h:55
orgQhull::QhullLinkedList::size_type
countT size_type
Definition: QhullLinkedList.h:59
orgQhull::QhullLinkedList::iterator::reference
value_type & reference
Definition: QhullLinkedList.h:137
orgQhull::QhullLinkedList::front
const T & front() const
Definition: QhullLinkedList.h:108
orgQhull::QhullLinkedList::const_iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: QhullLinkedList.h:170
QhullError.h
orgQhull::QhullLinkedList::last
const T last() const
Definition: QhullLinkedList.h:110
orgQhull::QhullLinkedListIterator::toFront
void toFront()
Definition: QhullLinkedList.h:217
orgQhull::QhullLinkedList::const_reference
const typedef value_type & const_reference
Definition: QhullLinkedList.h:62
orgQhull::QhullLinkedListIterator::c
const QhullLinkedList< T > * c
Definition: QhullLinkedList.h:203


hpp-fcl
Author(s):
autogenerated on Fri Jan 26 2024 03:46:14