cout_utility.hpp

Go to the documentation of this file.
00001 
00029 #ifndef MSMAZES_CORE_DEBUG_COUT_UTILITY_HPP
00030 #define MSMAZES_CORE_DEBUG_COUT_UTILITY_HPP
00031 
00032 #include <iostream>  // std::ostream and std::cout
00033 #include <boost/utility.hpp>  // boost::tie
00034 #include <boost/property_map.hpp>  // boost::property_map and boost::get
00035 #include <boost/graph/graph_traits.hpp>  // boost::graph_traits
00036 //#include <boost/graph/adjacency_list.hpp> must be included before this file.
00037 
00038 namespace msmazes {
00039 
00041 
00058 template <typename EventFilter>
00059 struct COutVertexVisitor
00060 {
00061     typedef EventFilter
00062             event_filter;
00063 
00064     template <typename Vertex, typename Graph>
00065     void operator()(Vertex v, Graph& g)
00066     {
00067         typename boost::property_map<Graph,boost::vertex_index_t>::type
00068           index_map = boost::get(boost::vertex_index_t(), g);
00069 
00070         std::cout << "  Vertex <" << boost::get(index_map, v) << std::endl;
00071     }
00072 };
00073 
00075 
00092 template <typename EventFilter>
00093 struct COutEdgeVisitor
00094 {
00095     typedef EventFilter
00096             event_filter;
00097 
00098     template <typename Edge, typename Graph>
00099     void operator()(Edge e, Graph& g)
00100     {
00101         typename boost::property_map<Graph,boost::vertex_index_t>::type
00102           index_map = boost::get(boost::vertex_index_t(), g);
00103 
00104         std::cout << "  Edge <" << boost::get(index_map, boost::source(e, g));
00105         std::cout << "," << boost::get(index_map, boost::target(e, g));
00106         std::cout << ">" << std::endl;
00107     }
00108 };
00109 
00111 
00138 template <
00139     typename PathIterator
00140   , typename VertexIDMap
00141 >
00142 void
00143     coutPath(
00144         PathIterator begin
00145       , PathIterator end
00146       , const VertexIDMap id_map
00147     )
00148 {
00149     std::cout << boost::get(id_map, *begin);
00150 
00151     while (++begin != end)
00152     {
00153         std::cout << " -> " << boost::get(id_map, *begin);
00154     }
00155 
00156     std::cout << std::endl;
00157 }
00158 
00160 
00187 template <
00188     typename VertexListGraph
00189   , typename VertexIDMap
00190   , typename PredecessorMap
00191 >
00192 void
00193     coutPredecessorMap(
00194         const VertexListGraph& g
00195       , const VertexIDMap id_map
00196       , const PredecessorMap p_map
00197     )
00198 {
00199     typename boost::graph_traits<VertexListGraph>::vertex_iterator vi, vend;
00200 
00201     for (boost::tie(vi, vend) = boost::vertices(g); vi != vend; ++vi)
00202     {
00203         std::cout << "Vertex " << boost::get(id_map, *vi);
00204         std::cout << ", predecessor ";
00205         std::cout << boost::get(id_map, boost::get(p_map, *vi));
00206         std::cout << std::endl;
00207     }
00208 
00209     std::cout << std::endl;
00210 }
00211 
00213 
00242 template <
00243     typename VertexListGraph
00244   , typename VertexIDMap
00245   , typename PropertyMap
00246 >
00247 void
00248     coutVertexPmap(
00249         const VertexListGraph& g
00250       , const VertexIDMap id_map
00251       , const PropertyMap p_map
00252     )
00253 {
00254     typename boost::graph_traits<VertexListGraph>::vertex_iterator vi, vend;
00255 
00256     for (boost::tie(vi, vend) = boost::vertices(g); vi != vend; ++vi)
00257     {
00258         std::cout << "Vertex "  << boost::get(id_map, *vi);
00259         std::cout << ", value " << boost::get(p_map, *vi);
00260         std::cout << std::endl;
00261     }
00262 
00263     std::cout << std::endl;
00264 }
00265 
00267 
00299 template <
00300     typename EdgeListGraph
00301   , typename VertexIDMap
00302   , typename PropertyMap
00303 >
00304 void
00305     coutEdgePmap(
00306         const EdgeListGraph& g
00307       , const VertexIDMap id_map
00308       , const PropertyMap p_map
00309     )
00310 {
00311     typename boost::graph_traits<EdgeListGraph>::edge_iterator ei, eend;
00312 
00313     for (boost::tie(ei, eend) = boost::edges(g); ei != eend; ++ei)
00314     {
00315         std::cout << "Edge " << boost::get(id_map, boost::source(*ei, g));
00316         std::cout << "-"     << boost::get(id_map, boost::target(*ei, g));
00317         std::cout << ", value " << boost::get(p_map, *ei);
00318         std::cout << std::endl;
00319     }
00320 
00321     std::cout << std::endl;
00322 }
00323 }  // namespace msmazes
00324 
00325 #endif  /* MSMAZES_CORE_DEBUG_COUT_UTILITY_HPP */

Multi-State Mazes in C++ is hosted by SourceForge.net. Use the Table of Contents for navigation.