BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Filtered_kernel/Cartesian_coordinate_iterator_2.h
Go to the documentation of this file.
00001 // Copyright (c) 2006  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Filtered_kernel/include/CGAL/Filtered_kernel/Cartesian_coordinate_iterator_2.h $
00016 // $Id: Cartesian_coordinate_iterator_2.h 42821 2008-04-09 18:06:00Z spion $
00017 //
00018 //
00019 // Author(s)     : Andreas Fabri, Sylvain Pion
00020 
00021 #ifndef CGAL_CARTESIAN_COORDINATE_ITERATOR_2_H
00022 #define CGAL_CARTESIAN_COORDINATE_ITERATOR_2_H
00023 
00024 #include <cstddef>
00025 #include <iterator>
00026 #include <boost/variant.hpp>
00027 
00028 CGAL_BEGIN_NAMESPACE
00029 
00030 // This class should go away.
00031 // It is now only used by the Filtered_kernel.
00032 // It allows to iterate over the coordinates of both a Point_2 and a Vector_2,
00033 // using a boost::variant, as the iterator types are the same at the kernel level.
00034 
00035 template <class K>
00036 class Cartesian_coordinate_iterator_2
00037 {
00038 
00039 protected:
00040   typedef typename K::Point_2 P;
00041   typedef typename K::Vector_2 V;
00042   boost::variant<const P*, const V*> var;
00043   int index;
00044   typedef Cartesian_coordinate_iterator_2<K> Self;
00045 
00046 public:
00047 
00048   typedef typename K::FT FT;
00049 
00050   typedef std::random_access_iterator_tag iterator_category;
00051   typedef FT                              value_type;
00052   typedef std::ptrdiff_t                  difference_type;
00053   typedef const value_type&               reference;
00054   typedef const value_type*               pointer;
00055 
00056   Cartesian_coordinate_iterator_2()
00057     : var((const P*) NULL), index(0) {}
00058 
00059   Cartesian_coordinate_iterator_2(const P * const p, int _index = 0)
00060     : var(p), index(_index) {}
00061 
00062   Cartesian_coordinate_iterator_2(const V * const v, int _index = 0)
00063     : var(v), index(_index) {}
00064 
00065 
00066   const FT
00067   operator*() const {
00068     if (const P* const* p = boost::get<const P*>(&var))
00069       return (*p)->cartesian(index);
00070     if (const V* const* v = boost::get<const V*>(&var))
00071       return (*v)->cartesian(index);
00072     // std::cerr << "type of var = " << var.type().name() << std::endl;
00073     CGAL_error();
00074     std::abort(); // to kill warning
00075   }
00076 
00077   Self&  operator++() {
00078     index++;
00079     return *this;
00080   }
00081 
00082   Self&
00083   operator--() {
00084     index--;
00085     return *this;
00086   }
00087 
00088   Self
00089   operator++(int) {
00090     Self tmp(*this);
00091     ++(*this);
00092     return tmp;
00093   }
00094 
00095   Self
00096   operator--(int) {
00097     Self tmp(*this);
00098     --(*this);
00099     return tmp;
00100   }
00101 
00102   Self&
00103   operator+=(difference_type i) {
00104     index+=i;
00105     return *this;
00106   }
00107 
00108   Self&
00109   operator-=(difference_type i) {
00110     index -= i;
00111     return *this;
00112   }
00113 
00114   Self
00115   operator+(difference_type i) const {
00116     Self tmp=*this;
00117     return tmp += i;
00118   }
00119 
00120   Self operator-(difference_type i) const {
00121     Self tmp=*this;
00122     return tmp -= i;
00123   }
00124 
00125   difference_type
00126   operator-(const Self& x) const {
00127     CGAL_kernel_assertion(var == x.var);
00128     return index - x.index;
00129   }
00130 
00131   reference operator[](difference_type i) const {
00132     return *(*this + i);
00133   }
00134 
00135   bool operator==(const Self& x) const {
00136     return (var == x.var) && (index == x.index);
00137   }
00138 
00139   bool operator!=(const Self& x) const {
00140     return ! (*this==x);
00141   }
00142 
00143   bool operator<(const Self& x) const
00144   {
00145     return (x - *this) > 0;
00146   }
00147 
00148 };
00149 
00150 CGAL_END_NAMESPACE
00151 
00152 #endif // CGAL_CARTESIAN_COORDINATE_ITERATOR_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines