BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polygon_2/Polygon_2_vertex_circulator.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Polygon/include/CGAL/Polygon_2/Polygon_2_vertex_circulator.h $
00019 // $Id: Polygon_2_vertex_circulator.h 44130 2008-07-12 21:58:52Z spion $
00020 // 
00021 //
00022 // Author(s)     : Geert-Jan Giezeman <geert@cs.uu.nl>
00023 
00024 #ifndef CGAL_POLYGON_2_VERTEX_CIRCULATOR_H
00025 #define CGAL_POLYGON_2_VERTEX_CIRCULATOR_H
00026 
00027 namespace CGAL {
00028 
00029 template < class  Ctnr>
00030 class Polygon_circulator {
00031 public:
00032 // TYPES
00033 
00034     typedef Polygon_circulator<Ctnr> Self;
00035     typedef Circulator_from_container<Ctnr>       Mutable;
00036     typedef Ctnr                                  Container;
00037     typedef typename Ctnr::iterator               iterator;
00038     typedef typename Ctnr::const_iterator         const_iterator;
00039     typedef typename Ctnr::value_type             value_type;
00040     typedef typename Ctnr::const_reference        reference;
00041     typedef const value_type*                     pointer;
00042     typedef typename Ctnr::size_type              size_type;
00043     typedef typename Ctnr::difference_type        difference_type;
00044 
00045     typedef std::iterator_traits<const_iterator>  ITraits;
00046     typedef typename ITraits::iterator_category   Icategory;
00047     typedef I_Circulator_from_iterator_traits<Icategory> CTraits;
00048     typedef typename CTraits::iterator_category   iterator_category;
00049 
00050 private:
00051     const Ctnr*    ctnr;
00052     iterator i;
00053 
00054 public:
00055 // CREATION
00056 
00057     Polygon_circulator() : ctnr(NULL) {}
00058     Polygon_circulator( const Ctnr* c)
00059         : ctnr(c), i(c->begin()) {}
00060     Polygon_circulator( const Ctnr* c, iterator j)
00061         : ctnr(c), i(j) {}
00062     Polygon_circulator( const Mutable& c)
00063         : ctnr( c.container()), i( c.current_iterator()) {}
00064 
00065 // Gnu-bug workaround: define operator= explicitly.
00066     Self& operator=( const Self& c) {
00067         ctnr = c.ctnr;
00068         i    = c.i;
00069         return *this;
00070     }
00071 
00072 // OPERATIONS
00073 
00074     bool operator==( Nullptr_t p) const {
00075         CGAL_assertion( p == NULL);
00076         return (ctnr == NULL) || (ctnr->begin() == ctnr->end());
00077     }
00078     bool operator!=( Nullptr_t p) const { return !(*this == p); }
00079     bool operator==( const Self& c) const { return i == c.i; }
00080     bool operator!=( const Self& c) const { return !(*this == c); }
00081     reference  operator*() const {
00082         CGAL_assertion( ctnr != NULL);
00083         CGAL_assertion( current_iterator() != ctnr->end());
00084         return *i;
00085     }
00086 
00087 private:
00088 // For cases where iterator is a pointer.
00089     template < typename T >
00090     static pointer deref(const T& t) { return t.operator->(); }
00091     template < typename T >
00092     static pointer deref(T* t) { return t; }
00093 
00094 public:
00095 
00096     pointer  operator->() const {
00097         CGAL_assertion( ctnr != NULL);
00098         CGAL_assertion( current_iterator() != ctnr->end());
00099         return deref(i);
00100     }
00101     Self& operator++() {
00102         CGAL_assertion( ctnr != NULL);
00103         CGAL_assertion( current_iterator() != ctnr->end());
00104         ++i;
00105         if ( current_iterator() == ctnr->end())
00106             i = const_cast<Container*>(ctnr)->begin();
00107         return *this;
00108     }
00109     Self operator++(int) {
00110         Self tmp= *this;
00111         ++*this;
00112         return tmp;
00113     }
00114     Self& operator--() {
00115         CGAL_assertion( ctnr != NULL);
00116         CGAL_assertion( current_iterator() != ctnr->end());
00117         if ( current_iterator() == ctnr->begin())
00118             i = const_cast<Container*>(ctnr)->end();
00119         --i;
00120         return *this;
00121     }
00122     Self operator--(int) {
00123         Self tmp = *this;
00124         --*this;
00125         return tmp;
00126     }
00127     Self& operator+=( difference_type n) {
00128         CGAL_assertion( ctnr != NULL);
00129         CGAL_assertion( current_iterator() != ctnr->end());
00130         typename Ctnr::difference_type j = current_iterator() - ctnr->begin();
00131         typename Ctnr::difference_type size = ctnr->size();
00132         CGAL_assertion( j    >= 0);
00133         CGAL_assertion( size >= 0);
00134         j = non_negative_mod( j + n, size);
00135         CGAL_assertion( j >= 0);
00136         CGAL_assertion( j < size);
00137         i = const_cast<Container*>(ctnr)->begin() + j;
00138         return *this;
00139     }
00140     Self operator+( difference_type n) const {
00141         Self tmp = *this;
00142         return tmp += n;
00143     }
00144     Self& operator-=( difference_type n) { return operator+=( -n); }
00145     Self operator-( difference_type n) const {
00146         Self tmp = *this;
00147         return tmp += -n;
00148     }
00149     difference_type operator-( const Self& c) const {
00150         CGAL_assertion( ctnr != NULL);
00151         CGAL_assertion( c.ctnr != NULL);
00152         return i - c.i;
00153     }
00154     reference  operator[]( difference_type n) const {
00155         Self tmp = *this;
00156         tmp += n;
00157         return *tmp;
00158     }
00159     const_iterator current_iterator() const { return i;}
00160     iterator       mod_iterator()     const { return i;}
00161     Self           min_circulator()   const { return Self(ctnr); }
00162     const Ctnr*    container()        const { return ctnr; }
00163 };
00164 
00165 template <class Ctnr>
00166 inline
00167 Polygon_circulator<Ctnr>
00168 operator+( typename Polygon_circulator<Ctnr>::
00169                difference_type n,
00170            const Polygon_circulator<Ctnr>& c) {
00171     Polygon_circulator<Ctnr> tmp = c;
00172     return tmp += n;
00173 }
00174 
00175 }  // end of namespace CGAL
00176 
00177 #endif  // CGAL_POLYGON_2_VERTEX_CIRCULATOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines