QhullIterator.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/libqhullcpp/QhullIterator.h#5 $$Change: 1382 $
00005 ** $DateTime: 2011/05/14 10:45:42 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 #ifndef QHULLITERATOR_H
00010 #define QHULLITERATOR_H
00011 
00012 extern "C" {
00013     #include "libqhull/qhull_a.h"
00014 }
00015 
00016 #include <assert.h>
00017 #include <string>
00018 #include <vector>
00020 namespace std { struct bidirectional_iterator_tag; struct random_access_iterator_tag; }
00021 
00022 namespace orgQhull {
00023 
00024 #//Defined here
00025 
00026 
00027 
00028 
00029 
00030 
00031 // Changed c to C* as in Mutable...  Assumes c does not go away.
00032 #define QHULL_DECLARE_SEQUENTIAL_ITERATOR(C, T) \
00033     \
00034     class C##Iterator \
00035     { \
00036         typedef C::const_iterator const_iterator; \
00037         const C *c; \
00038         const_iterator i; \
00039         public: \
00040         inline C##Iterator(const C &container) \
00041         : c(&container), i(c->constBegin()) {} \
00042         inline C##Iterator &operator=(const C &container) \
00043         { c = &container; i = c->constBegin(); return *this; } \
00044         inline void toFront() { i = c->constBegin(); } \
00045         inline void toBack() { i = c->constEnd(); } \
00046         inline bool hasNext() const { return i != c->constEnd(); } \
00047         inline const T &next() { return *i++; } \
00048         inline const T &peekNext() const { return *i; } \
00049         inline bool hasPrevious() const { return i != c->constBegin(); } \
00050         inline const T &previous() { return *--i; } \
00051         inline const T &peekPrevious() const { const_iterator p = i; return *--p; } \
00052         inline bool findNext(const T &t) \
00053         { while (i != c->constEnd()) if (*i++ == t) return true; return false; } \
00054         inline bool findPrevious(const T &t) \
00055         { while (i != c->constBegin()) if (*(--i) == t) return true; \
00056         return false;  } \
00057     };//C##Iterator
00058 
00059 // Remove setShareable() from Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR
00060 // Uses QHULL_ASSERT (assert.h)
00061 // Duplicated in MutablePointIterator without insert or remove
00062 #define QHULL_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C, T) \
00063     class Mutable##C##Iterator \
00064     { \
00065         typedef C::iterator iterator; \
00066         typedef C::const_iterator const_iterator; \
00067         C *c; \
00068         iterator i, n; \
00069         inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
00070         public: \
00071         inline Mutable##C##Iterator(C &container) \
00072         : c(&container) \
00073         { i = c->begin(); n = c->end(); } \
00074         inline ~Mutable##C##Iterator() \
00075         {} \
00076         inline Mutable##C##Iterator &operator=(C &container) \
00077         { c = &container; \
00078         i = c->begin(); n = c->end(); return *this; } \
00079         inline void toFront() { i = c->begin(); n = c->end(); } \
00080         inline void toBack() { i = c->end(); n = i; } \
00081         inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \
00082         inline T &next() { n = i++; return *n; } \
00083         inline T &peekNext() const { return *i; } \
00084         inline bool hasPrevious() const { return c->constBegin() != const_iterator(i); } \
00085         inline T &previous() { n = --i; return *n; } \
00086         inline T &peekPrevious() const { iterator p = i; return *--p; } \
00087         inline void remove() \
00088         { if (c->constEnd() != const_iterator(n)) { i = c->erase(n); n = c->end(); } } \
00089         inline void setValue(const T &t) const { if (c->constEnd() != const_iterator(n)) *n = t; } \
00090         inline T &value() { QHULL_ASSERT(item_exists()); return *n; } \
00091         inline const T &value() const { QHULL_ASSERT(item_exists()); return *n; } \
00092         inline void insert(const T &t) { n = i = c->insert(i, t); ++i; } \
00093         inline bool findNext(const T &t) \
00094         { while (c->constEnd() != const_iterator(n = i)) if (*i++ == t) return true; return false; } \
00095         inline bool findPrevious(const T &t) \
00096         { while (c->constBegin() != const_iterator(i)) if (*(n = --i) == t) return true; \
00097         n = c->end(); return false;  } \
00098     };//Mutable##C##Iterator
00099 
00100 #define QHULL_DECLARE_SET_ITERATOR(C) \
00101 \
00102     template <class T> \
00103     class Qhull##C##Iterator \
00104     { \
00105         typedef typename Qhull##C<T>::const_iterator const_iterator; \
00106         Qhull##C<T> c; \
00107         const_iterator i; \
00108     public: \
00109         inline Qhull##C##Iterator(const Qhull##C<T> &container) \
00110         : c(container), i(c.constBegin()) {} \
00111         inline Qhull##C##Iterator &operator=(const Qhull##C<T> &container) \
00112         { c = container; i = c.constBegin(); return *this; } \
00113         inline void toFront() { i = c.constBegin(); } \
00114         inline void toBack() { i = c.constEnd(); } \
00115         inline bool hasNext() const { return i != c.constEnd(); } \
00116         inline const T &next() { return *i++; } \
00117         inline const T &peekNext() const { return *i; } \
00118         inline bool hasPrevious() const { return i != c.constBegin(); } \
00119         inline const T &previous() { return *--i; } \
00120         inline const T &peekPrevious() const { const_iterator p = i; return *--p; } \
00121         inline bool findNext(const T &t) \
00122         { while (i != c.constEnd()) if (*i++ == t) return true; return false; } \
00123         inline bool findPrevious(const T &t) \
00124         { while (i != c.constBegin()) if (*(--i) == t) return true; \
00125         return false;  } \
00126     };//Qhull##C##Iterator
00127 
00128 #define QHULL_DECLARE_MUTABLE_SET_ITERATOR(C) \
00129 \
00130 template <class T> \
00131 class QhullMutable##C##Iterator \
00132 { \
00133     typedef typename Qhull##C::iterator iterator; \
00134     typedef typename Qhull##C::const_iterator const_iterator; \
00135     Qhull##C *c; \
00136     iterator i, n; \
00137     inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \
00138 public: \
00139     inline Mutable##C##Iterator(Qhull##C &container) \
00140         : c(&container) \
00141     { c->setSharable(false); i = c->begin(); n = c->end(); } \
00142     inline ~Mutable##C##Iterator() \
00143     { c->setSharable(true); } \
00144     inline Mutable##C##Iterator &operator=(Qhull##C &container) \
00145     { c->setSharable(true); c = &container; c->setSharable(false); \
00146       i = c->begin(); n = c->end(); return *this; } \
00147     inline void toFront() { i = c->begin(); n = c->end(); } \
00148     inline void toBack() { i = c->end(); n = i; } \
00149     inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \
00150     inline T &next() { n = i++; return *n; } \
00151     inline T &peekNext() const { return *i; } \
00152     inline bool hasPrevious() const { return c->constBegin() != const_iterator(i); } \
00153     inline T &previous() { n = --i; return *n; } \
00154     inline T &peekPrevious() const { iterator p = i; return *--p; } \
00155     inline void remove() \
00156     { if (c->constEnd() != const_iterator(n)) { i = c->erase(n); n = c->end(); } } \
00157     inline void setValue(const T &t) const { if (c->constEnd() != const_iterator(n)) *n = t; } \
00158     inline T &value() { Q_ASSERT(item_exists()); return *n; } \
00159     inline const T &value() const { Q_ASSERT(item_exists()); return *n; } \
00160     inline void insert(const T &t) { n = i = c->insert(i, t); ++i; } \
00161     inline bool findNext(const T &t) \
00162     { while (c->constEnd() != const_iterator(n = i)) if (*i++ == t) return true; return false; } \
00163     inline bool findPrevious(const T &t) \
00164     { while (c->constBegin() != const_iterator(i)) if (*(n = --i) == t) return true; \
00165       n = c->end(); return false;  } \
00166 };//QhullMutable##C##Iterator
00167 
00168 }//namespace orgQhull
00169 
00170 #endif // QHULLITERATOR_H
00171 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50