BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Tel-Aviv University (Israel).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Polygon_2_curve_iterator.h $
00015 // $Id: Polygon_2_curve_iterator.h 28831 2006-02-27 14:28:18Z baruchzu $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 
00020 #ifndef CGAL_CGAL_POLYGON_2_CURVE_ITERATOR_H
00021 #define CGAL_CGAL_POLYGON_2_CURVE_ITERATOR_H
00022 
00023 #include <iterator>
00024 
00025 CGAL_BEGIN_NAMESPACE
00026 
00027 
00028 
00029 template <class Xcurve>
00030 class Polygon_2_curve_ptr
00031 {
00032 public:
00033     typedef Xcurve X_monotnoe_curve_2;
00034     Polygon_2_curve_ptr(X_monotnoe_curve_2 const &c) :m_curve(c){}
00035     X_monotnoe_curve_2* operator->() {return &m_curve;}
00036 
00037 private:
00038     X_monotnoe_curve_2 m_curve;
00039 };
00040 
00041 template <class X_monotone_curve_2_, class Polygon_>
00042 class Polygon_2_curve_iterator 
00043 {
00044 public:
00045     typedef Polygon_2_curve_iterator< X_monotone_curve_2_, Polygon_ >    Self;
00046  
00047     
00048     typedef X_monotone_curve_2_                           X_monotone_curve_2;
00049     typedef typename Polygon_::Container                  Container;
00050     typedef typename Container::iterator                  Container_iterator;
00051     typedef typename std::iterator_traits<Container_iterator>::iterator_category 
00052                                                           iterator_category;
00053     typedef X_monotone_curve_2                            value_type;
00054     typedef X_monotone_curve_2*                           pointer;
00055     typedef X_monotone_curve_2&                           reference;
00056 
00057 
00058     typedef Polygon_                                      Polygon;
00059     typedef typename Polygon::Edge_const_iterator         Edge_const_iterator;
00060     typedef typename Edge_const_iterator::difference_type difference_type;
00061  
00062   private:
00063     const Polygon*      m_pgn;   // needed for dereferencing the last edge
00064     Edge_const_iterator m_curr_edge;   // points to the current edge iterator
00065   
00066 public:
00067     Polygon_2_curve_iterator< X_monotone_curve_2_, Polygon_ >(){}
00068 
00069     Polygon_2_curve_iterator< X_monotone_curve_2_, Polygon_ >
00070       (const Polygon* pgn, Edge_const_iterator ci) : m_pgn(pgn),
00071                                                      m_curr_edge(ci) {}
00072 
00073     bool operator==(const Self& x) const
00074     {
00075       return (m_curr_edge == x.m_curr_edge);
00076     }
00077     
00078     bool operator!=(const Self& x) const
00079     {
00080       return !(m_curr_edge == x.m_curr_edge);
00081     }
00082 
00083     X_monotone_curve_2 operator*() 
00084     {
00085       return X_monotone_curve_2(*m_curr_edge);
00086     }
00087     
00088     Polygon_2_curve_ptr<X_monotone_curve_2> operator->()
00089     {
00090       return Polygon_2_curve_ptr<X_monotone_curve_2>(operator*());
00091     }
00092 
00093     Self& operator++()
00094     {
00095       ++m_curr_edge;
00096       return *this;
00097     }
00098 
00099     Self operator++(int)
00100     {
00101       Self tmp = *this;
00102       ++*this;
00103       return tmp;
00104     }
00105 
00106     Self& operator--() 
00107     {
00108       --m_curr_edge;
00109       return *this;
00110     }
00111 
00112     Self operator--(int) {
00113       Self tmp = *this;
00114       --*this;
00115       return tmp;
00116     }
00117 
00118     // random access iterator requirements
00119     Self& operator+=(difference_type n) 
00120     {
00121       m_curr_edge += n;
00122       return *this;
00123     }
00124 
00125     Self operator+(difference_type n)
00126     {
00127       return Self(m_pgn, m_curr_edge + n);
00128     }
00129 
00130     Self& operator-=(difference_type n) 
00131     {
00132       return (*this) -= n;
00133     }
00134 
00135     Self operator-(difference_type n) 
00136     {
00137       return Self(m_pgn, m_curr_edge - n);
00138     }
00139 
00140     difference_type operator-(const Self& a) const
00141     {
00142       return (const_cast<Edge_const_iterator&>(m_curr_edge) - a.m_curr_edge);
00143     }
00144 
00145     X_monotone_curve_2 operator[](int n) 
00146     {
00147       return *Self(m_pgn, m_curr_edge+n);
00148     }
00149 
00150     bool operator<(const Self& a)
00151     {
00152       return m_curr_edge < a.m_curr_edge;
00153     }
00154 
00155     bool operator>(const Self& a)
00156     {
00157       return m_curr_edge > a.m_curr_edge;
00158     }
00159 
00160     bool operator<=(const Self& a)
00161     {
00162       return m_curr_edge <= a.m_curr_edge;
00163     }
00164 
00165     bool operator>=(const Self& a)
00166     {
00167       return m_curr_edge >= a.m_curr_edge;
00168     }
00169 
00170 };
00171 
00172 
00173 template <class X_monotone_curve_2_,  class Polygon_>
00174 typename Polygon_2_curve_iterator<X_monotone_curve_2_,Polygon_>::difference_type
00175 distance_type(const Polygon_2_curve_iterator<X_monotone_curve_2_,Polygon_>&)
00176 { 
00177   return Polygon_2_curve_iterator<X_monotone_curve_2_,Polygon_>::difference_type(); 
00178 }
00179 
00180 template <class X_monotone_curve_2_,  class Polygon_>
00181 X_monotone_curve_2_*
00182 value_type(const Polygon_2_curve_iterator<X_monotone_curve_2_,Polygon_>&)
00183 {
00184   return (X_monotone_curve_2_*)(0); 
00185 }
00186 
00187 
00188 
00189 CGAL_END_NAMESPACE
00190 
00191 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines