Chris@16: // Copyright 2008-2010 Gordon Woodhull Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_MSM_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED Chris@16: #define BOOST_MSM_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include "search_colors.hpp" Chris@16: Chris@16: namespace boost { Chris@16: namespace msm { Chris@16: namespace mpl_graph { Chris@16: Chris@16: // dfs takes a visitor which has all the bgl-like metafunctions encapsulated in an Chris@16: // "operations" member class, and also a state. the operations are expected to return a new state Chris@16: // in addition, the visitor operations are expected to update the colors of vertices Chris@16: // and need to support a new metafunction get_color Chris@16: Chris@16: struct dfs_default_visitor_operations { Chris@16: template Chris@16: struct initialize_vertex { Chris@16: typedef State type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct discover_vertex { Chris@16: typedef State type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct finish_vertex { Chris@16: typedef State type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct tree_edge { Chris@16: typedef State type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct back_edge { Chris@16: typedef State type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct forward_or_cross_edge { Chris@16: typedef State type; Chris@16: }; Chris@16: }; Chris@16: Chris@16: // requires IncidenceGraph Chris@16: // returns pair Chris@16: template Chris@16: struct depth_first_search { Chris@16: // enter vertex Chris@16: typedef typename VisitorOps::template Chris@16: discover_vertex::type Chris@16: discovered_state; Chris@16: typedef typename search_color_map_ops::template Chris@16: set_color::type Chris@16: discovered_colors; Chris@16: Chris@16: // loop over out edges Chris@16: typedef typename Chris@16: mpl::fold::type, Chris@16: mpl::pair, Chris@16: mpl::if_, mpl::second >, Chris@16: search_colors::White>, Chris@16: // unseen target: recurse Chris@16: depth_first_search >, Chris@16: mpl_graph::target, Chris@16: mpl::second >, Chris@16: // seen: back or forward edge Chris@16: mpl::pair, mpl::second >, Chris@16: search_colors::Gray>, Chris@16: typename VisitorOps::template back_edge >, Chris@16: typename VisitorOps::template forward_or_cross_edge > >, // Black Chris@16: mpl::second > > Chris@16: >::type after_outedges; Chris@16: Chris@16: // leave vertex, and done! Chris@16: typedef mpl::pair::type >::type, Chris@16: typename search_color_map_ops::template set_color::type>::type> type; Chris@16: }; Chris@16: Chris@16: // requires IncidenceGraph, VertexListGraph Chris@16: template::type>::type, Chris@16: typename ColorState = create_search_color_map::type> Chris@16: struct depth_first_search_all : // visit first then rest Chris@16: mpl::fold::type, Chris@16: typename depth_first_search::type, Chris@16: mpl::if_ >, Chris@16: search_colors::White>, // visit any yet unvisited Chris@16: depth_first_search, Chris@16: mpl::_2, Chris@16: mpl::second >, Chris@16: mpl::_1> > Chris@16: {}; Chris@16: Chris@16: } // namespace mpl_graph Chris@16: } // namespace msm Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_MSM_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED