BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Filtered_kernel/Cartesian_coordinate_iterator_3.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_3.h $
00016 // $Id: Cartesian_coordinate_iterator_3.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_3_H
00022 #define CGAL_CARTESIAN_COORDINATE_ITERATOR_3_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_3 and a Vector_3,
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_3
00037 {
00038   typedef typename K::Point_3 P;
00039   typedef typename K::Vector_3 V;
00040   boost::variant<const P*, const V*> var;
00041   int index;
00042   typedef Cartesian_coordinate_iterator_3<K> Self;
00043 
00044 public:
00045 
00046   typedef typename K::FT FT;
00047 
00048   typedef std::random_access_iterator_tag iterator_category;
00049   typedef FT                              value_type;
00050   typedef std::ptrdiff_t                  difference_type;
00051   typedef const value_type&               reference;
00052   typedef const value_type*               pointer;
00053 
00054   Cartesian_coordinate_iterator_3()
00055     : var((const P*) NULL), index(0) {}
00056 
00057   Cartesian_coordinate_iterator_3(const P *const p, int _index = 0)
00058     : var(p), index(_index) {}
00059 
00060   Cartesian_coordinate_iterator_3(const V *const v, int _index = 0)
00061     : var(v), index(_index) {}
00062 
00063   const FT
00064   operator*() const {
00065     if (const P* const* p = boost::get<const P*>(&var))
00066       return (*p)->cartesian(index);
00067     if (const V* const* v = boost::get<const V*>(&var))
00068       return (*v)->cartesian(index);
00069     // std::cerr << "type of var = " << var.type().name() << std::endl;
00070     CGAL_error();
00071     std::abort(); // to kill warning
00072   }
00073 
00074   Self&  operator++() {
00075     index++;
00076     return *this;
00077   }
00078 
00079   Self&
00080   operator--() {
00081     index--;
00082     return *this;
00083   }
00084 
00085   Self
00086   operator++(int) {
00087     Self tmp(*this);
00088     ++(*this);
00089     return tmp;
00090   }
00091 
00092   Self
00093   operator--(int) {
00094     Self tmp(*this);
00095     --(*this);
00096     return tmp;
00097   }
00098 
00099   Self&
00100   operator+=(difference_type i) {
00101     index+=i;
00102     return *this;
00103   }
00104 
00105   Self&
00106   operator-=(difference_type i) {
00107     index -= i;
00108     return *this;
00109   }
00110 
00111   Self
00112   operator+(difference_type i) const {
00113     Self tmp=*this;
00114     return tmp += i;
00115   }
00116 
00117   Self operator-(difference_type i) const {
00118     Self tmp=*this;
00119     return tmp -= i;
00120   }
00121 
00122   difference_type
00123   operator-(const Self& x) const {
00124     CGAL_kernel_assertion(var == x.var);
00125     return index - x.index;
00126   }
00127 
00128   reference operator[](difference_type i) const {
00129     return *(*this + i);
00130   }
00131 
00132   bool operator==(const Self& x) const {
00133     return (var == x.var) && (index == x.index) ;
00134   }
00135 
00136   bool operator!=(const Self& x) const {
00137     return ! (*this==x);
00138   }
00139 
00140   bool operator<(const Self& x) const
00141   {
00142     return (x - *this) > 0;
00143   }
00144 
00145 };
00146 
00147 CGAL_END_NAMESPACE
00148 
00149 #endif // CGAL_CARTESIAN_COORDINATE_ITERATOR_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines