BWAPI
|
00001 // Copyright (c) 1997 INRIA Sophia-Antipolis (France). 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/Triangulation_2/include/CGAL/Triangulation_ds_iterators_2.h $ 00015 // $Id: Triangulation_ds_iterators_2.h 48844 2009-04-21 18:28:04Z spion $ 00016 // 00017 // 00018 // Author(s) : Mariette Yvinec 00019 00020 #ifndef CGAL_TRIANGULATION_DS_ITERATORS_2_H 00021 #define CGAL_TRIANGULATION_DS_ITERATORS_2_H 00022 00023 #include <iterator> 00024 #include <CGAL/triangulation_assertions.h> 00025 //#include <CGAL/Triangulation_iterator_adaptator.h> 00026 00027 CGAL_BEGIN_NAMESPACE 00028 00029 template <class Tds> 00030 class Triangulation_ds_edge_iterator_2 00031 { 00032 public: 00033 typedef typename Tds::Edge Edge; 00034 typedef typename Tds::Face_iterator Face_iterator; 00035 typedef typename Tds::Face_handle Face_handle; 00036 00037 typedef Edge value_type; 00038 typedef Edge* pointer; 00039 typedef Edge& reference; 00040 typedef std::size_t size_type; 00041 typedef std::ptrdiff_t difference_type; 00042 typedef std::bidirectional_iterator_tag iterator_category; 00043 00044 typedef Triangulation_ds_edge_iterator_2<Tds> Edge_iterator; 00045 00046 private: 00047 const Tds* _tds; 00048 Face_iterator pos; 00049 mutable Edge edge; 00050 00051 public: 00052 Triangulation_ds_edge_iterator_2() {} 00053 Triangulation_ds_edge_iterator_2(const Tds * tds); 00054 Triangulation_ds_edge_iterator_2(const Tds* tds, int ); 00055 00056 bool operator==(const Edge_iterator& fi) const ; 00057 bool operator!=(const Edge_iterator& fi) const {return !(*this== fi);} 00058 Edge_iterator& operator++(); 00059 Edge_iterator& operator--(); 00060 Edge_iterator operator++(int); 00061 Edge_iterator operator--(int); 00062 Edge* operator->() const; 00063 Edge& operator*() const ; 00064 00065 private: 00066 void increment(); 00067 void decrement(); 00068 bool associated_edge(); 00069 }; 00070 00071 00072 // Edge iterator implementation 00073 00074 template<class Tds> 00075 Triangulation_ds_edge_iterator_2<Tds> :: 00076 Triangulation_ds_edge_iterator_2(const Tds * tds) 00077 : _tds(tds) 00078 { 00079 edge.second = 0; 00080 if (_tds->dimension()<= 0) { 00081 pos = _tds->faces().end(); // there is no edge 00082 return; 00083 } 00084 pos = _tds->faces().begin(); 00085 if (_tds->dimension() == 1) edge.second = 2; 00086 while ( pos != _tds->faces().end() 00087 && !associated_edge() ) increment(); 00088 } 00089 00090 template<class Tds> 00091 Triangulation_ds_edge_iterator_2<Tds> :: 00092 Triangulation_ds_edge_iterator_2(const Tds * tds, int ) 00093 : _tds(tds) 00094 { 00095 pos = tds->faces().end(); 00096 edge.second = 0; 00097 if (_tds->dimension() == 1) {edge.second = 2;} 00098 } 00099 00100 00101 template<class Tds> 00102 inline 00103 bool 00104 Triangulation_ds_edge_iterator_2<Tds> :: 00105 operator==(const Edge_iterator& fi) const 00106 { 00107 return _tds == fi._tds && pos == fi.pos && edge.second == fi.edge.second; 00108 } 00109 00110 template<class Tds> 00111 inline 00112 void 00113 Triangulation_ds_edge_iterator_2<Tds> :: 00114 increment() 00115 { 00116 CGAL_triangulation_precondition(_tds->dimension() >= 1); 00117 if (_tds->dimension() == 1) ++pos; 00118 else if (edge.second == 2) {edge.second = 0; ++pos;} 00119 else edge.second += 1; 00120 return; 00121 } 00122 00123 template<class Tds> 00124 inline 00125 void 00126 Triangulation_ds_edge_iterator_2<Tds> :: 00127 decrement() 00128 { 00129 CGAL_triangulation_precondition(_tds->dimension() >= 1); 00130 if (_tds->dimension() == 1) --pos; 00131 else if (edge.second == 0) { edge.second = 2; --pos;} 00132 else edge.second -= 1; 00133 return; 00134 } 00135 00136 template<class Tds> 00137 inline 00138 bool 00139 Triangulation_ds_edge_iterator_2<Tds> :: 00140 associated_edge() 00141 { 00142 if (_tds->dimension() == 1) {return true;} 00143 return Face_handle(pos) < pos->neighbor(edge.second); 00144 } 00145 00146 template<class Tds> 00147 inline 00148 Triangulation_ds_edge_iterator_2<Tds>& 00149 Triangulation_ds_edge_iterator_2<Tds> :: 00150 operator++() 00151 { 00152 //CGAL_triangulation_precondition(pos != Iterator_base() && 00153 // pos != _tds->faces().end()); 00154 do increment(); 00155 while( pos != _tds->faces().end() && !associated_edge()); 00156 return *this; 00157 } 00158 00159 00160 template<class Tds> 00161 inline 00162 Triangulation_ds_edge_iterator_2<Tds>& 00163 Triangulation_ds_edge_iterator_2<Tds> :: 00164 operator--() 00165 { 00166 // CGAL_triangulation_precondition(pos != Iterator_base() 00167 // && *this != Edge_iterator(_tds)); 00168 do decrement(); 00169 while ( !associated_edge() && *this != Edge_iterator(_tds) ); 00170 return *this; 00171 } 00172 00173 00174 template<class Tds> 00175 inline 00176 Triangulation_ds_edge_iterator_2<Tds> 00177 Triangulation_ds_edge_iterator_2<Tds> :: 00178 operator++(int) 00179 { 00180 Edge_iterator tmp(*this); 00181 ++(*this); 00182 return tmp; 00183 } 00184 00185 template<class Tds> 00186 inline 00187 Triangulation_ds_edge_iterator_2<Tds> 00188 Triangulation_ds_edge_iterator_2<Tds> :: 00189 operator--(int) 00190 { 00191 Edge_iterator tmp(*this); 00192 --(*this); 00193 return tmp; 00194 } 00195 00196 template<class Tds> 00197 inline 00198 typename Triangulation_ds_edge_iterator_2<Tds>::Edge* 00199 Triangulation_ds_edge_iterator_2<Tds> :: 00200 operator->() const 00201 { 00202 edge.first = pos; 00203 return &edge; 00204 } 00205 00206 template<class Tds> 00207 inline 00208 typename Triangulation_ds_edge_iterator_2<Tds>::Edge& 00209 Triangulation_ds_edge_iterator_2<Tds> :: 00210 operator*() const 00211 { 00212 edge.first = pos; 00213 return edge; 00214 } 00215 CGAL_END_NAMESPACE 00216 00217 #endif //CGAL_TRIANGULATION_DS_ITERATORS_2_H 00218