BWAPI
|
00001 // Copyright (c) 2007 GeometryFactory (France). All rights reserved. 00002 // 00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public License as 00005 // published by the Free Software Foundation; version 2.1 of the License. 00006 // See the file LICENSE.LGPL 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/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h $ 00015 // $Id: graph_traits_HalfedgeDS.h 42705 2008-04-01 16:15:55Z fcacciola $ 00016 // 00017 // 00018 // Author(s) : Andreas Fabri, Fernando Cacciola 00019 00020 #ifndef CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H 00021 #define CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H 00022 00023 #include <boost/config.hpp> 00024 #include <boost/iterator_adaptors.hpp> 00025 #include <boost/graph/graph_traits.hpp> 00026 #include <boost/graph/properties.hpp> 00027 00028 #include <CGAL/basic.h> 00029 #include <CGAL/Counting_iterator.h> 00030 00031 CGAL_BEGIN_NAMESPACE 00032 00033 template <class Circ, class E> 00034 class HDS_in_halfedge_circulator : public Circ 00035 { 00036 private: 00037 mutable E e; 00038 00039 public: 00040 00041 typedef E value_type; 00042 typedef E* pointer; 00043 typedef E& reference; 00044 00045 HDS_in_halfedge_circulator() 00046 : Circ() 00047 {} 00048 00049 HDS_in_halfedge_circulator(Circ c) 00050 : Circ(c) 00051 {} 00052 00053 const E& operator*() const 00054 { 00055 e = *this; 00056 return e; 00057 } 00058 }; 00059 00060 template <class Circ, class E> 00061 class HDS_out_halfedge_circulator : public Circ 00062 { 00063 private: 00064 mutable E e; 00065 00066 public: 00067 00068 typedef E value_type; 00069 typedef E* pointer; 00070 typedef E& reference; 00071 00072 HDS_out_halfedge_circulator() 00073 : Circ() 00074 {} 00075 00076 HDS_out_halfedge_circulator(Circ c) 00077 : Circ(c) 00078 {} 00079 00080 const E& operator*() const 00081 { 00082 e = *this; 00083 e = e->opposite(); 00084 return e; 00085 } 00086 }; 00087 00088 00089 // The vertex iterator of the bgl must evaluate to a vertex handle, not to a vertex 00090 template < class HDS, class Vertex_iterator, class Vertex_handle> 00091 class HDS_all_vertices_iterator_base { 00092 protected: 00093 Vertex_iterator nt; 00094 public: 00095 typedef Vertex_iterator Iterator; 00096 typedef HDS_all_vertices_iterator_base<HDS,Vertex_iterator,Vertex_handle> Self; 00097 00098 typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category; 00099 typedef typename std::iterator_traits<Iterator>::difference_type difference_type; 00100 typedef Vertex_handle value_type; 00101 typedef value_type reference; 00102 typedef value_type pointer; 00103 00104 protected: 00105 00106 HDS_all_vertices_iterator_base() {} 00107 HDS_all_vertices_iterator_base( Iterator j) : nt(j) {} 00108 00109 public: 00110 00111 // OPERATIONS Forward Category 00112 // --------------------------- 00113 00114 bool operator==( const Self& i) const { return ( nt == i.nt); } 00115 bool operator!=( const Self& i) const { return !(nt == i.nt ); } 00116 value_type operator*() const { return nt; } 00117 value_type operator->() { return nt; } 00118 00119 Self& operator++() { 00120 ++nt; 00121 return *this; 00122 } 00123 00124 Self operator++(int) { 00125 Self tmp = *this; 00126 ++*this; 00127 return tmp; 00128 } 00129 }; 00130 00131 template < class HDS > 00132 class HDS_all_vertices_const_iterator 00133 : public HDS_all_vertices_iterator_base<HDS,typename HDS::Vertex_const_iterator,typename HDS::Vertex_const_handle> 00134 { 00135 typedef HDS_all_vertices_iterator_base<HDS,typename HDS::Vertex_const_iterator,typename HDS::Vertex_const_handle> Base ; 00136 00137 public: 00138 00139 typedef typename HDS::Vertex_const_iterator Iterator; 00140 00141 HDS_all_vertices_const_iterator() {} 00142 HDS_all_vertices_const_iterator( Iterator j) : Base(j) {} 00143 }; 00144 00145 00146 template < class HDS > 00147 class HDS_all_vertices_iterator 00148 : public HDS_all_vertices_iterator_base<HDS,typename HDS::Vertex_iterator,typename HDS::Vertex_handle> 00149 { 00150 typedef HDS_all_vertices_iterator_base<HDS,typename HDS::Vertex_iterator,typename HDS::Vertex_handle> Base ; 00151 00152 public: 00153 00154 typedef typename HDS::Vertex_iterator Iterator; 00155 00156 HDS_all_vertices_iterator() {} 00157 HDS_all_vertices_iterator( Iterator j) : Base(j) {} 00158 }; 00159 00160 template < class HDS, class Iterator_, class Value_type> 00161 class HDS_all_edges_iterator_base { 00162 protected: 00163 Iterator_ nt; 00164 public: 00165 typedef Iterator_ Iterator; 00166 typedef HDS_all_edges_iterator_base<HDS,Iterator_,Value_type> Self; 00167 00168 typedef typename std::iterator_traits<Iterator>::iterator_category iterator_category; 00169 typedef typename std::iterator_traits<Iterator>::difference_type difference_type; 00170 typedef Value_type value_type; 00171 typedef value_type reference; 00172 typedef value_type pointer; 00173 00174 protected: 00175 00176 HDS_all_edges_iterator_base() {} 00177 HDS_all_edges_iterator_base( Iterator j) : nt(j) {} 00178 00179 public: 00180 00181 // OPERATIONS Forward Category 00182 // --------------------------- 00183 00184 00185 bool operator==( const Self& i) const { return ( nt == i.nt); } 00186 bool operator!=( const Self& i) const { return !(nt == i.nt ); } 00187 value_type operator*() const { return nt; } 00188 value_type operator->() { return nt; } 00189 00190 Self& operator++() { 00191 ++nt; 00192 return *this; 00193 } 00194 00195 Self operator++(int) { 00196 Self tmp = *this; 00197 ++*this; 00198 return tmp; 00199 } 00200 }; 00201 00202 template < class HDS > 00203 class HDS_all_halfedges_const_iterator 00204 : public HDS_all_edges_iterator_base<HDS,typename HDS::Halfedge_const_iterator,typename HDS::Halfedge_const_handle> 00205 { 00206 typedef HDS_all_edges_iterator_base<HDS,typename HDS::Halfedge_const_iterator,typename HDS::Halfedge_const_handle> Base ; 00207 00208 public: 00209 00210 typedef typename HDS::Halfedge_const_iterator Iterator; 00211 00212 HDS_all_halfedges_const_iterator() {} 00213 HDS_all_halfedges_const_iterator( Iterator j) : Base(j) {} 00214 }; 00215 00216 template < class HDS > 00217 class HDS_all_halfedges_iterator 00218 : public HDS_all_edges_iterator_base<HDS,typename HDS::Halfedge_iterator,typename HDS::Halfedge_handle> 00219 { 00220 typedef HDS_all_edges_iterator_base<HDS,typename HDS::Halfedge_iterator,typename HDS::Halfedge_handle> Base ; 00221 00222 public: 00223 00224 typedef typename HDS::Halfedge_iterator Iterator; 00225 00226 HDS_all_halfedges_iterator() {} 00227 HDS_all_halfedges_iterator( Iterator j) : Base(j) {} 00228 }; 00229 00230 template <class HDS_> 00231 struct HDS_graph_traits 00232 { 00233 public : 00234 00235 struct HDS_graph_traversal_category : public virtual boost::bidirectional_graph_tag, 00236 public virtual boost::vertex_list_graph_tag, 00237 public virtual boost::edge_list_graph_tag 00238 {}; 00239 00240 typedef HDS_ HDS; 00241 00242 typedef typename HDS::Vertex_handle vertex_descriptor; 00243 typedef typename HDS::Halfedge_handle edge_descriptor; 00244 00245 typedef HDS_all_vertices_iterator<HDS> vertex_iterator; 00246 typedef HDS_all_halfedges_iterator<HDS> edge_iterator; 00247 00248 private: 00249 00250 typedef typename HDS::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator ; 00251 00252 typedef HDS_out_halfedge_circulator<Halfedge_around_vertex_circulator,edge_descriptor> out_edge_circulator ; 00253 typedef HDS_in_halfedge_circulator <Halfedge_around_vertex_circulator,edge_descriptor> in_edge_circulator ; 00254 00255 public : 00256 00257 typedef Counting_iterator<out_edge_circulator, edge_descriptor> out_edge_iterator; 00258 typedef Counting_iterator<in_edge_circulator , edge_descriptor> in_edge_iterator; 00259 00260 typedef boost::directed_tag directed_category; 00261 typedef boost::disallow_parallel_edge_tag edge_parallel_category; 00262 typedef HDS_graph_traversal_category traversal_category; 00263 00264 typedef typename HDS::size_type vertices_size_type; 00265 typedef vertices_size_type edges_size_type; 00266 typedef vertices_size_type degree_size_type; 00267 }; 00268 00269 00270 CGAL_END_NAMESPACE 00271 00272 #endif // CGAL_BOOST_GRAPH_GRAPH_TRAITS_HALFEDGEDS_H