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>
45 {
46 #
47 public:
48  class const_iterator;
49  class iterator;
50  typedef const_iterator ConstIterator;
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;
58  typedef value_type &reference;
59 
60 #
61 private:
64 
65 #
66 public:
69  QhullLinkedList<T>(const QhullLinkedList<T> &other) : begin_node(other.begin_node), end_node(other.end_node) {}
71  QhullLinkedList<T> & operator=(const QhullLinkedList<T> &other) { begin_node= other.begin_node; end_node= other.end_node; return *this; }
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;
131  typedef value_type &reference;
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 
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 {
198  const_iterator i;
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 {
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 {
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 {
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>
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>
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>
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 
bool operator!=(const const_iterator &o) const
const value_type * const_pointer
QhullRidge – Qhull&#39;s ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:21
std::bidirectional_iterator_tag iterator_category
bool operator==(const QhullLinkedList< T > &o) const
bool operator!=(const iterator &o) const
t
iterator(const T &t)
Automatic conversion to iterator.
const_iterator(const T &t)
Automatic conversion to const_iterator.
std::bidirectional_iterator_tag iterator_category
QhullLinkedList< T > & operator=(const QhullLinkedList< T > &other)
Copy assignment copies begin_node and end_node, but not the list elements.
c
bool operator==(const const_iterator &o) const
std::vector< T > toStdVector() const
bool operator!=(const const_iterator &o) const
bool operator==(const const_iterator &o) const
QhullLinkedListIterator & operator=(const QhullLinkedList< T > &container)
#define QHULL_ASSERT
Definition: QhullError.h:16
QhullLinkedList< T >::const_iterator const_iterator
const_iterator end() const
const value_type & const_reference
const QhullLinkedList< T > * c
const_iterator constBegin() const
bool contains(const T &t) const
const_iterator begin() const
bool operator==(const iterator &o) const
bool operator!=(const QhullLinkedList< T > &o) const
const_iterator & operator=(const const_iterator &o)
QhullLinkedListIterator(const QhullLinkedList< T > &container)
iterator & operator=(const iterator &o)
int countT
Definition: user_r.h:182
const_iterator operator-(int j) const
const_iterator constEnd() const
const_iterator ConstIterator
const_iterator operator+(int j) const


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