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