BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Polygon_2/Polygon_2_edge_iterator.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_edge_iterator.h $
00019 // $Id: Polygon_2_edge_iterator.h 45787 2008-09-25 19:15:00Z spion $
00020 // 
00021 //
00022 // Author(s)     : Wieger Wesselink, Geert-Jan Giezeman <geert@cs.uu.nl>
00023 
00024 #ifndef CGAL_POLYGON_2_EDGE_ITERATOR_H
00025 #define CGAL_POLYGON_2_EDGE_ITERATOR_H
00026 
00027 #include <iterator>
00028 #include <CGAL/circulator.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00032 template <class Traits_, class Container_> class Polygon_2;
00033 
00034 template <class Segment_>
00035 class Polygon_2__Segment_ptr
00036 {
00037 public:
00038     typedef Segment_ Segment;
00039     Polygon_2__Segment_ptr(Segment const &seg) :m_seg(seg){}
00040     Segment* operator->() {return &m_seg;}
00041 private:
00042     Segment m_seg;
00043 };
00044 
00045 template <class Traits_, class Container_>
00046 class Polygon_2_edge_iterator {
00047   public:
00048     typedef typename std::iterator_traits<typename Container_::iterator>::iterator_category iterator_category;
00049     typedef typename Traits_::Segment_2 Segment_2;
00050     typedef typename Traits_::Segment_2 value_type;
00051     typedef Container_ Container;
00052     typedef typename Container_::const_iterator const_iterator;
00053     typedef typename Container_::difference_type difference_type;
00054     typedef Segment_2*           pointer;
00055     typedef Segment_2&           reference;
00056   private:
00057     const Container_* container;   // needed for dereferencing the last edge
00058     const_iterator first_vertex;   // points to the first vertex of the edge
00059   public:
00060     Polygon_2_edge_iterator() {}
00061     Polygon_2_edge_iterator(const Container_* c, const_iterator f)
00062       : container(c), first_vertex(f) {}
00063 
00064     bool operator==(
00065       const Polygon_2_edge_iterator<Traits_, Container_>& x) const
00066     {
00067       return first_vertex == x.first_vertex;
00068     }
00069     
00070     bool operator!=(
00071       const Polygon_2_edge_iterator<Traits_, Container_>& x) const
00072     {
00073       return !(first_vertex == x.first_vertex);
00074     }
00075 
00076     Segment_2 operator*() const {
00077       const_iterator second_vertex = first_vertex;
00078       ++second_vertex;
00079       if (second_vertex == container->end())
00080         second_vertex = container->begin();
00081       typename Traits_::Construct_segment_2 construct_segment_2 = 
00082             Traits_().construct_segment_2_object();
00083       return construct_segment_2(*first_vertex, *second_vertex);
00084     }
00085     
00086     Polygon_2__Segment_ptr<Segment_2> operator->() const
00087         {return Polygon_2__Segment_ptr<Segment_2>(operator*());}
00088 
00089     Polygon_2_edge_iterator<Traits_, Container_>& operator++() {
00090       ++first_vertex;
00091       return *this;
00092     }
00093 
00094     Polygon_2_edge_iterator<Traits_, Container_> operator++(int) {
00095       Polygon_2_edge_iterator<Traits_, Container_> tmp = *this;
00096       ++*this;
00097       return tmp;
00098     }
00099 
00100     Polygon_2_edge_iterator<Traits_, Container_>& operator--() {
00101       --first_vertex;
00102       return *this;
00103     }
00104 
00105     Polygon_2_edge_iterator<Traits_, Container_> operator--(int) {
00106       Polygon_2_edge_iterator<Traits_, Container_> tmp = *this;
00107       --*this;
00108       return tmp;
00109     }
00110 
00111 // random access iterator requirements
00112     Polygon_2_edge_iterator<Traits_, Container_>&
00113     operator+=(difference_type n) {
00114       first_vertex += n;
00115       return *this;
00116     }
00117 
00118     Polygon_2_edge_iterator<Traits_, Container_>
00119     operator+(difference_type n) const {
00120       return Polygon_2_edge_iterator<Traits_, Container_>(
00121         container, first_vertex + n);
00122     }
00123 
00124     Polygon_2_edge_iterator<Traits_, Container_>&
00125     operator-=(difference_type n) {
00126       return (*this) -= n;
00127     }
00128 
00129     Polygon_2_edge_iterator<Traits_, Container_>
00130     operator-(difference_type n) const {
00131       return Polygon_2_edge_iterator<Traits_, Container_>(
00132         container, first_vertex - n);
00133     }
00134 
00135     difference_type
00136     operator-(const Polygon_2_edge_iterator<Traits_, Container_>& a) const {
00137       return first_vertex - a.first_vertex;
00138     }
00139 
00140     Segment_2 operator[](int n) const {
00141       return *Polygon_2_edge_iterator<Traits_, Container_>(
00142         container, first_vertex+n);
00143     }
00144 
00145     bool operator<(const Polygon_2_edge_iterator<Traits_, Container_>& a) const
00146     {
00147       return first_vertex < a.first_vertex;
00148     }
00149 
00150     bool operator>(const Polygon_2_edge_iterator<Traits_, Container_>& a) const
00151     {
00152       return first_vertex > a.first_vertex;
00153     }
00154 
00155     bool operator<=(const Polygon_2_edge_iterator<Traits_, Container_>& a) const
00156     {
00157       return first_vertex <= a.first_vertex;
00158     }
00159 
00160     bool operator>=(const Polygon_2_edge_iterator<Traits_, Container_>& a) const
00161     {
00162       return first_vertex >= a.first_vertex;
00163     }
00164 
00165 };
00166 
00167 
00168 template <class Traits_,  class Container_>
00169 typename Container_::difference_type
00170 distance_type(const Polygon_2_edge_iterator<Traits_,Container_>&)
00171 { return Container_::difference_type(); }
00172 
00173 template <class Traits_,  class Container_>
00174 typename Traits_::Segment_2*
00175 value_type(const Polygon_2_edge_iterator<Traits_,Container_>&)
00176 { return (typename Traits_::Segment_2 *)(0); }
00177 
00178 
00179 //-----------------------------------------------------------------------//
00180 //                          implementation
00181 //-----------------------------------------------------------------------//
00182 
00183 //--------------------------------------------------------------------//
00184 // I don't know how to implement the following function:
00185 //
00186 // template <class Traits_, class Container_>
00187 // inline
00188 // Polygon_2_edge_iterator<Traits_, Container_>
00189 // operator+(Container_::difference_type n,
00190 //           Polygon_2_edge_iterator<Traits_, Container_>& a)
00191 // { return a+n; }
00192 //--------------------------------------------------------------------//
00193 
00194 CGAL_END_NAMESPACE
00195 
00196 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines