00001 00027 #ifndef MSMAZES_CORE_MAZE_STRUCT_HPP 00028 #define MSMAZES_CORE_MAZE_STRUCT_HPP 00029 00030 // boost::graph_traits 00031 #include <boost/graph/graph_traits.hpp> 00032 // boost::vecS, boost::listS, and boost::bidirectionalS 00033 #include <boost/graph/graph_selectors.hpp> 00034 // boost::property, boost::no_property, boost::vertex_index1_t, 00035 // boost::vertex_index2_t, and boost::edge_index_t 00036 #include <boost/graph/properties.hpp> 00037 // boost::adjacency_list 00038 #include <boost/graph/adjacency_list.hpp> 00039 00040 namespace msmazes { 00041 00043 00075 template < 00076 #ifndef MSMAZES_DOX 00077 typename CellIndex 00078 #endif /* MSMAZES_DOX */ 00079 > 00080 class MazeStruct 00081 { 00082 public: 00088 #ifdef MSMAZES_DOX 00089 typedef implementation_defined EdgeIndex; 00090 #else 00091 typedef std::size_t // The member typedef vertices_size_type of Graph. 00092 EdgeIndex; 00093 #endif /* MSMAZES_DOX */ 00094 00141 #ifdef MSMAZES_DOX 00142 typedef implementation_defined Graph; 00143 #else 00144 typedef boost::adjacency_list< 00145 boost::listS 00146 , boost::vecS 00147 , boost::bidirectionalS // For easier path-making. 00148 , boost::property< 00149 boost::vertex_index1_t 00150 , CellIndex 00151 , boost::property< 00152 boost::vertex_index2_t 00153 , CellIndex 00154 > 00155 > 00156 , boost::property< 00157 boost::edge_index_t 00158 , EdgeIndex 00159 > 00160 , boost::no_property 00161 > 00162 Graph; 00163 #endif /* MSMAZES_DOX */ 00164 00169 #ifdef MSMAZES_DOX 00170 typedef implementation_defined Vertex; 00171 #else 00172 typedef typename boost::graph_traits<Graph>::vertex_descriptor 00173 Vertex; 00174 #endif /* MSMAZES_DOX */ 00175 00176 private: 00177 Graph _graph; 00178 Vertex _source; 00179 Vertex _target; 00180 EdgeIndex _max_out_degree; 00181 00182 MazeStruct(const MazeStruct& copy) 00183 { 00184 } 00185 00186 public: 00188 00191 MazeStruct() 00192 : _graph() 00193 , _source(boost::graph_traits<Graph>::null_vertex()) 00194 , _target(boost::graph_traits<Graph>::null_vertex()) 00195 , _max_out_degree() 00196 { 00197 } 00198 00205 inline Graph& getGraph() 00206 { 00207 return _graph; 00208 } 00209 00216 inline const Graph& getGraph() const 00217 { 00218 return _graph; 00219 } 00220 00226 inline Vertex getSourceVertex() const 00227 { 00228 return _source; 00229 } 00230 00238 inline void setSourceVertex(const Vertex vertex) 00239 { 00240 _source = vertex; 00241 } 00242 00248 inline Vertex getTargetVertex() const 00249 { 00250 return _target; 00251 } 00252 00260 inline void setTargetVertex(const Vertex vertex) 00261 { 00262 _target = vertex; 00263 } 00264 00271 inline EdgeIndex getMaxOutDegree() const 00272 { 00273 return _max_out_degree; 00274 } 00275 00284 void setMaxOutDegree(const EdgeIndex max_out_degree) 00285 { 00286 _max_out_degree = max_out_degree; 00287 00288 if (!_max_out_degree) 00289 { 00290 typename boost::graph_traits<Graph>::vertex_iterator vi, vi_end; 00291 EdgeIndex degree; 00292 00293 for ( 00294 boost::tie(vi, vi_end) = boost::vertices(_graph); 00295 vi != vi_end; 00296 ++vi 00297 ) 00298 { 00299 degree = boost::out_degree(*vi, _graph); 00300 00301 if (_max_out_degree < degree) 00302 { 00303 _max_out_degree = degree; 00304 } 00305 } 00306 } 00307 } 00308 }; 00309 } // namespace msmazes 00310 00311 #endif /* MSMAZES_CORE_MAZE_STRUCT_HPP */
Multi-State Mazes in C++ is hosted by . Use the Table of Contents for navigation.