Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66584 - in trunk: boost/msm/mpl_graph boost/msm/mpl_graph/detail libs/msm/example libs/msm/example/mpl_graph
From: gordon_at_[hidden]
Date: 2010-11-15 00:33:27


Author: gordon.woodhull
Date: 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
New Revision: 66584
URL: http://svn.boost.org/trac/boost/changeset/66584

Log:
first commit of mpl_graph as sublibrary of msm
Added:
   trunk/boost/msm/mpl_graph/
   trunk/boost/msm/mpl_graph/adjacency_list_graph.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/breadth_first_search.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/depth_first_search.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/detail/
   trunk/boost/msm/mpl_graph/detail/adjacency_list_graph.ipp (contents, props changed)
   trunk/boost/msm/mpl_graph/detail/as_mpl_map.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/detail/graph_implementation_interface.ipp (contents, props changed)
   trunk/boost/msm/mpl_graph/detail/incidence_list_graph.ipp (contents, props changed)
   trunk/boost/msm/mpl_graph/incidence_list_graph.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/mpl_graph.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/mpl_utils.hpp (contents, props changed)
   trunk/boost/msm/mpl_graph/search_colors.hpp (contents, props changed)
   trunk/libs/msm/example/
   trunk/libs/msm/example/mpl_graph/
   trunk/libs/msm/example/mpl_graph/Jamfile.v2 (contents, props changed)
   trunk/libs/msm/example/mpl_graph/adjacency_list_graph.cpp (contents, props changed)
   trunk/libs/msm/example/mpl_graph/breadth_first_search.cpp (contents, props changed)
   trunk/libs/msm/example/mpl_graph/depth_first_search.cpp (contents, props changed)
   trunk/libs/msm/example/mpl_graph/incidence_list_graph.cpp (contents, props changed)
   trunk/libs/msm/example/mpl_graph/msm_adaptor.cpp (contents, props changed)

Added: trunk/boost/msm/mpl_graph/adjacency_list_graph.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/adjacency_list_graph.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,35 @@
+// 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_METAGRAPH_MPL_GRAPH_ADJACENCY_LIST_GRAPH_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_ADJACENCY_LIST_GRAPH_HPP_INCLUDED
+
+// graph implementation based on an adjacency list
+// sequence< pair< source_vertex, sequence< pair<edge, target_vertex> > > >
+
+// adjacency_list_graph labels such a sequence as manipulable by the metafunctions
+// in the corresponding implementation header detail/adjacency_list_graph.ipp
+// to produce the metadata structures needed by mpl_graph.hpp
+
+// the public interface
+#include <boost/msm/mpl_graph/mpl_graph.hpp>
+
+// the implementation
+#include <boost/msm/mpl_graph/detail/adjacency_list_graph.ipp>
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+
+template<typename AdjacencyList>
+struct adjacency_list_graph {
+ typedef detail::adjacency_list_tag representation;
+ typedef AdjacencyList data;
+};
+
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_ADJACENCY_LIST_GRAPH_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/breadth_first_search.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/breadth_first_search.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,167 @@
+// 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_METAGRAPH_MPL_GRAPH_BREADTH_FIRST_SEARCH_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_BREADTH_FIRST_SEARCH_HPP_INCLUDED
+
+#include <boost/msm/mpl_graph/mpl_graph.hpp>
+
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/pop_front.hpp>
+#include <boost/mpl/empty.hpp>
+#include <boost/mpl/remove.hpp>
+
+#include "search_colors.hpp"
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+
+// bfs 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
+struct bfs_default_visitor_operations {
+ template<typename Vertex, typename Graph, typename State>
+ struct initialize_vertex {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct discover_vertex {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct examine_vertex {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct examine_edge {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct tree_edge {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct non_tree_edge {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct gray_target {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct black_target {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct finish_vertex {
+ typedef State type;
+ };
+};
+
+namespace detail {
+
+template<typename Graph, typename VisitorOps, typename VCQState, typename Edge>
+struct bfs_run_queue_examine_edge {
+ typedef typename VisitorOps::template examine_edge<Edge, Graph, typename mpl::at_c<VCQState, 0>::type>::type visitor_state;
+ typedef typename mpl::at_c<VCQState, 1>::type color_state;
+ typedef typename mpl::at_c<VCQState, 2>::type vertex_queue;
+
+ typedef typename mpl::if_<typename boost::is_same<typename search_color_map_ops::template get_color<typename mpl_graph::target<Edge, Graph>::type, color_state>::type, search_colors::White>::type,
+ // unseen target: tree edge, discover target, paint it gray, and enqueue
+ mpl::vector<typename VisitorOps::template discover_vertex<typename mpl_graph::target<Edge, Graph>::type, Graph,
+ typename VisitorOps::template tree_edge<Edge, Graph, visitor_state>::type>::type,
+ typename search_color_map_ops::template set_color<typename mpl_graph::target<Edge, Graph>::type, search_colors::Gray, color_state>::type,
+ typename mpl::push_back<vertex_queue, typename mpl_graph::target<Edge, Graph>::type >::type >,
+ // seen
+ mpl::vector<typename mpl::if_<typename boost::is_same<typename search_color_map_ops::template get_color<mpl_graph::target<Edge, Graph>, color_state>,
+ search_colors::Gray>::type,
+ typename VisitorOps::template gray_target<Edge, Graph, visitor_state>::type,
+ typename VisitorOps::template black_target<Edge, Graph, visitor_state>::type>::type,
+ color_state,
+ vertex_queue>
+ >::type type;
+};
+
+// runs bfs on a queue, passing the new queue forward on recursion
+// returns pair<visitor_state, color_state>
+template<typename Graph, typename VertexQueue, typename VisitorOps, typename VisitorState, typename ColorMap>
+struct bfs_run_queue {
+ // enter vertex
+ typedef typename mpl::front<VertexQueue>::type Vertex;
+ typedef typename mpl::pop_front<VertexQueue>::type Tail;
+ typedef typename VisitorOps::template examine_vertex<Vertex, Graph, VisitorState>::type examined_state;
+
+ // loop over out edges
+ typedef typename mpl::template
+ fold<typename mpl_graph::out_edges<Vertex, Graph>::type,
+ mpl::vector<examined_state, ColorMap, Tail>,
+ bfs_run_queue_examine_edge<Graph, VisitorOps, mpl::_1, mpl::_2>
+ >::type did_edges;
+
+ typedef typename VisitorOps::template
+ finish_vertex<Vertex, Graph, typename mpl::at_c<did_edges, 0>::type>::type
+ finished_vertex;
+ // does map insert always overwrite? i seem to remember this not working on msvc once
+ typedef typename search_color_map_ops::template
+ set_color<Vertex, search_colors::Black, typename mpl::at_c<did_edges, 1>::type>::type
+ colored_vertex;
+ typedef typename mpl::at_c<did_edges, 2>::type queued_targets;
+
+ typedef typename
+ mpl::if_<typename mpl::empty<queued_targets>::type,
+ mpl::pair<finished_vertex, colored_vertex>,
+ bfs_run_queue<Graph, queued_targets,
+ VisitorOps, finished_vertex,
+ colored_vertex> >::type::type type;
+};
+
+} // namespace detail
+
+template<typename Graph, typename VisitorOps, typename VisitorState,
+ typename Vertex,
+ typename ColorMap = create_search_color_map::type >
+struct breadth_first_search {
+ typedef typename VisitorOps::template
+ discover_vertex<Vertex, Graph, VisitorState>::type
+ discovered_state;
+ typedef typename search_color_map_ops::template
+ set_color<Vertex, search_colors::Gray, ColorMap>::type
+ discovered_colors;
+ typedef typename detail::
+ bfs_run_queue<Graph, mpl::vector<Vertex>,
+ VisitorOps, discovered_state,
+ discovered_colors>::type type;
+};
+
+template<typename Graph, typename VisitorOps, typename VisitorState,
+ typename FirstVertex = typename mpl::front<typename mpl_graph::vertices<Graph>::type>::type,
+ typename ColorMap = create_search_color_map::type>
+struct breadth_first_search_all : // visit "first" first, then visit any still white
+ mpl::fold<typename mpl_graph::vertices<Graph>::type,
+ typename breadth_first_search<Graph, VisitorOps, VisitorState, FirstVertex, ColorMap>::type,
+ mpl::if_<boost::is_same<search_color_map_ops::template get_color<mpl::_2, mpl::second<mpl::_1> >,
+ search_colors::White>,
+ breadth_first_search<Graph, VisitorOps, mpl::first<mpl::_1>,
+ mpl::_2, mpl::second<mpl::_1> >,
+ mpl::_1> >
+{};
+
+} // namespace mpl_graph
+} // namespace metagraph
+} // namespace boost
+
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_BREADTH_FIRST_SEARCH_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/depth_first_search.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/depth_first_search.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,122 @@
+// 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_METAGRAPH_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED
+
+#include <boost/msm/mpl_graph/mpl_graph.hpp>
+
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/has_key.hpp>
+
+#include "search_colors.hpp"
+
+namespace boost {
+namespace metagraph {
+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<Vertex, State>
+
+struct dfs_default_visitor_operations {
+ template<typename Vertex, typename Graph, typename State>
+ struct initialize_vertex {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct discover_vertex {
+ typedef State type;
+ };
+
+ template<typename Vertex, typename Graph, typename State>
+ struct finish_vertex {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct tree_edge {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct back_edge {
+ typedef State type;
+ };
+
+ template<typename Edge, typename Graph, typename State>
+ struct forward_or_cross_edge {
+ typedef State type;
+ };
+};
+
+// requires IncidenceGraph
+// returns pair<VisitorState, ColorState>
+template<typename Graph, typename VisitorOps, typename VisitorState,
+ typename Vertex,
+ typename ColorState = create_search_color_map::type >
+struct depth_first_search {
+ // enter vertex
+ typedef typename VisitorOps::template
+ discover_vertex<Vertex, Graph, VisitorState>::type
+ discovered_state;
+ typedef typename search_color_map_ops::template
+ set_color<Vertex, search_colors::Gray, ColorState>::type
+ discovered_colors;
+
+ // loop over out edges
+ typedef typename
+ mpl::fold<typename mpl_graph::out_edges<Vertex, Graph>::type,
+ mpl::pair<discovered_state, discovered_colors>,
+ mpl::if_<boost::is_same<search_color_map_ops::get_color<mpl_graph::target<mpl::_2, Graph>, mpl::second<mpl::_1> >,
+ search_colors::White>,
+ // unseen target: recurse
+ depth_first_search<Graph,
+ VisitorOps, typename VisitorOps::template tree_edge<mpl::_2, Graph, mpl::first<mpl::_1> >,
+ mpl_graph::target<mpl::_2, Graph>,
+ mpl::second<mpl::_1> >,
+ // seen: back or forward edge
+ mpl::pair<mpl::if_<boost::is_same<typename search_color_map_ops::template
+ get_color<mpl_graph::target<mpl::_2, Graph>, mpl::second<mpl::_1 > >,
+ search_colors::Gray>,
+ typename VisitorOps::template back_edge<mpl::_2, Graph, mpl::first<mpl::_1> >,
+ typename VisitorOps::template forward_or_cross_edge<mpl::_2, Graph, mpl::first<mpl::_1> > >, // Black
+ mpl::second<mpl::_1> > >
+ >::type after_outedges;
+
+ // leave vertex, and done!
+ typedef mpl::pair<typename VisitorOps::template finish_vertex<Vertex, Graph, typename mpl::first<after_outedges>::type >::type,
+ typename search_color_map_ops::template set_color<Vertex, search_colors::Black, typename mpl::second<after_outedges>::type>::type> type;
+};
+
+// requires IncidenceGraph, VertexListGraph
+template<typename Graph, typename VisitorOps, typename VisitorState,
+ typename FirstVertex = typename mpl::front<typename mpl_graph::vertices<Graph>::type>::type,
+ typename ColorState = create_search_color_map::type>
+struct depth_first_search_all : // visit first then rest
+ mpl::fold<typename mpl_graph::vertices<Graph>::type,
+ typename depth_first_search<Graph,
+ VisitorOps, VisitorState,
+ FirstVertex,
+ ColorState>::type,
+ mpl::if_<boost::is_same<search_color_map_ops::get_color<mpl::_2, mpl::second<mpl::_1> >,
+ search_colors::White>, // visit any yet unvisited
+ depth_first_search<Graph,
+ VisitorOps, mpl::first<mpl::_1>,
+ mpl::_2,
+ mpl::second<mpl::_1> >,
+ mpl::_1> >
+{};
+
+} // namespace mpl_graph
+} // namespace metagraph
+} // namespace boost
+
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/detail/adjacency_list_graph.ipp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/detail/adjacency_list_graph.ipp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,128 @@
+// 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_METAGRAPH_MPL_GRAPH_DETAIL_ADJACENCY_LIST_GRAPH_IPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_DETAIL_ADJACENCY_LIST_GRAPH_IPP_INCLUDED
+
+// implementation of a graph declared in adjacency list format
+// sequence< pair< source_vertex, sequence< pair<edge, target_vertex> > > >
+
+#include <boost/msm/mpl_graph/mpl_utils.hpp>
+#include <boost/msm/mpl_graph/detail/incidence_list_graph.ipp>
+
+#include <boost/mpl/copy.hpp>
+#include <boost/mpl/inserter.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/push_back.hpp>
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+namespace detail {
+
+// tag identifying graph implementation as adjacency list (not defined)
+struct adjacency_list_tag;
+
+// outs map is really just the same data with the sequences turned into maps
+// it might make sense to make another adjacency_map implementation for that case
+template<typename AdjacencyList>
+struct produce_al_outs_map :
+ mpl::reverse_fold<AdjacencyList,
+ mpl::map<>,
+ mpl::insert<mpl::_1,
+ mpl::pair<mpl::first<mpl::_2>, mpl_utils::as_map<mpl::second<mpl::_2> > > > >
+{};
+
+// Edge->Target map for a Source for out_*, degree
+template<typename Source, typename GraphData>
+struct produce_out_map<adjacency_list_tag, Source, GraphData> :
+ mpl::at<typename produce_al_outs_map<GraphData>::type, Source>
+{};
+
+template<typename InsMap, typename Source, typename Adjacencies>
+struct produce_in_adjacencies :
+ mpl::reverse_fold<Adjacencies,
+ InsMap,
+ mpl::insert<mpl::_1,
+ mpl::pair<mpl::second<mpl::_2>,
+ mpl::insert<mpl_utils::at_or_default<mpl::_1, mpl::second<mpl::_2>, mpl::map<> >,
+ mpl::pair<mpl::first<mpl::_2>, Source> > > > >
+{};
+
+template<typename AdjacencyList>
+struct produce_al_ins_map :
+ mpl::reverse_fold<AdjacencyList,
+ mpl::map<>,
+ produce_in_adjacencies<mpl::_1, mpl::first<mpl::_2>, mpl::second<mpl::_2> > >
+{};
+
+// Edge->Source map for a Target for in_*, degree
+template<typename Target, typename GraphData>
+struct produce_in_map<adjacency_list_tag, Target, GraphData> :
+ mpl::at<typename produce_al_ins_map<GraphData>::type, Target>
+{};
+
+// for everything else to do with edges,
+// just produce an incidence list and forward to that graph implementation
+// (produce_out_map could, and produce_in_map probably should, be implemented this way too)
+template<typename Incidences, typename Source, typename Adjacencies>
+struct produce_adjacencies_incidences : // adjacencies'
+ mpl::reverse_fold<Adjacencies,
+ Incidences,
+ mpl::push_back<mpl::_1,
+ mpl::vector3<mpl::first<mpl::_2>, Source, mpl::second<mpl::_2> > > >
+{};
+
+template<typename AdjacencyList>
+struct produce_incidence_list_from_adjacency_list :
+ mpl::reverse_fold<AdjacencyList,
+ mpl::vector<>,
+ produce_adjacencies_incidences<mpl::_1, mpl::first<mpl::_2>, mpl::second<mpl::_2> > >
+{};
+
+
+// Edge->pair<Source,Target> map for source, target
+template<typename GraphData>
+struct produce_edge_st_map<adjacency_list_tag, GraphData> :
+ produce_edge_st_map<incidence_list_tag,
+ typename produce_incidence_list_from_adjacency_list<GraphData>::type>
+{};
+
+
+// adjacency list supports zero-degree vertices, which incidence list does not
+template<typename VertexSet, typename Adjacencies>
+struct insert_adjacencies_targets : // adjacencies'
+ mpl::reverse_fold<Adjacencies,
+ VertexSet,
+ mpl::insert<mpl::_1, mpl::second<mpl::_2> > >
+{};
+
+template<typename GraphData>
+struct produce_vertex_set<adjacency_list_tag, GraphData> :
+ mpl::reverse_fold<GraphData,
+ mpl::set<>,
+ insert_adjacencies_targets<mpl::insert<mpl::_1, mpl::first<mpl::_2> >,
+ mpl::second<mpl::_2> > >
+{};
+
+
+// Edge set for EdgeListGraph
+template<typename GraphData>
+struct produce_edge_set<adjacency_list_tag, GraphData> :
+ produce_edge_set<incidence_list_tag,
+ typename produce_incidence_list_from_adjacency_list<GraphData>::type>
+{};
+
+
+} // namespaces
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_DETAIL_ADJACENCY_LIST_GRAPH_IPP_INCLUDED
+

Added: trunk/boost/msm/mpl_graph/detail/as_mpl_map.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/detail/as_mpl_map.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,100 @@
+// 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)
+
+// this is an experiment at implementing a metafunction that's
+// present in fusion but not in mpl
+// based on fusion/container/map/detail/as_map.hpp
+/*=============================================================================
+ Copyright (c) 2001-2006 Joel de Guzman
+
+ 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_PP_IS_ITERATING
+#if !defined(AS_MPL_MAP_HPP)
+#define AS_MPL_MAP_HPP
+
+#define AS_MPL_MAP_SIZE 20
+
+#include <boost/preprocessor/iterate.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/inc.hpp>
+#include <boost/preprocessor/dec.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/next.hpp>
+
+namespace boost { namespace mpl {
+
+ namespace detail {
+ template <int size>
+ struct as_map;
+
+ }
+ template<typename Seq>
+ struct as_map : detail::as_map<mpl::size<Seq>::value>::template
+ apply<typename mpl::begin<Seq>::type> {};
+
+ namespace detail
+{
+ template <int size>
+ struct as_map;
+
+ template <>
+ struct as_map<0>
+ {
+ template <typename Iterator>
+ struct apply
+ {
+ typedef map<> type;
+ };
+
+ };
+
+#define BOOST_AS_MPL_MAP_NEXT_ITERATOR(z, n, data) \
+ typedef typename mpl::next<BOOST_PP_CAT(I, n)>::type \
+ BOOST_PP_CAT(I, BOOST_PP_INC(n));
+
+#define BOOST_AS_MPL_MAP_DEREF_ITERATOR(z, n, data) \
+ typedef typename mpl::deref<BOOST_PP_CAT(I, n)>::type \
+ BOOST_PP_CAT(T, n);
+
+#define BOOST_PP_FILENAME_1 <boost/msm/mpl_graph/detail/as_mpl_map.hpp>
+#define BOOST_PP_ITERATION_LIMITS (1, AS_MPL_MAP_SIZE)
+#include BOOST_PP_ITERATE()
+
+#undef BOOST_AS_MPL_MAP_NEXT_ITERATOR
+#undef BOOST_AS_MPL_MAP_DEREF_ITERATOR
+
+}}}
+
+#endif
+#else // defined(BOOST_PP_IS_ITERATING)
+///////////////////////////////////////////////////////////////////////////////
+//
+// Preprocessor vertical repetition code
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#define N BOOST_PP_ITERATION()
+
+ template <>
+ struct as_map<N>
+ {
+ template <typename I0>
+ struct apply
+ {
+ BOOST_PP_REPEAT(N, BOOST_AS_MPL_MAP_NEXT_ITERATOR, _)
+ BOOST_PP_REPEAT(N, BOOST_AS_MPL_MAP_DEREF_ITERATOR, _)
+ typedef map<BOOST_PP_ENUM_PARAMS(N, T)> type;
+ };
+
+ };
+
+#undef N
+#endif // defined(BOOST_PP_IS_ITERATING)
+

Added: trunk/boost/msm/mpl_graph/detail/graph_implementation_interface.ipp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/detail/graph_implementation_interface.ipp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,42 @@
+// 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_METAGRAPH_MPL_GRAPH_DETAIL_GRAPH_IMPLEMENTATION_INTERFACE_IPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_DETAIL_GRAPH_IMPLEMENTATION_INTERFACE_IPP_INCLUDED
+
+// forward definitions of the producer metafunctions that need to be specialized for
+// each graph representation
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+namespace detail {
+
+ // Edge->Target map for a Source for out_*, degree
+ template<typename RepresentationTag, typename Source, typename GraphData>
+ struct produce_out_map;
+
+ // Edge->Source map for a Target for in_*, degree
+ template<typename RepresentationTag, typename Target, typename GraphData>
+ struct produce_in_map;
+
+ // Edge->pair<Source,Target> map for source, target
+ template<typename RepresentationTag, typename GraphData>
+ struct produce_edge_st_map;
+
+ // Vertex set for VertexListGraph
+ template<typename RepresentationTag, typename GraphData>
+ struct produce_vertex_set;
+
+ // Edge set for EdgeListGraph
+ template<typename RepresentationTag, typename GraphData>
+ struct produce_edge_set;
+
+} // namespaces
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_DETAIL_GRAPH_IMPLEMENTATION_INTERFACE_IPP_INCLUDED
+

Added: trunk/boost/msm/mpl_graph/detail/incidence_list_graph.ipp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/detail/incidence_list_graph.ipp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,106 @@
+// 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_METAGRAPH_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED
+
+#define BOOST_METAGRAPH_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED
+
+// these metafunctions provide the metadata structures needed by the public interface
+// in mpl_graph.hpp
+
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/copy.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/next.hpp>
+#include <boost/mpl/front.hpp>
+#include <boost/mpl/back.hpp>
+#include <boost/mpl/deref.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/mpl/erase_key.hpp>
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/inserter.hpp>
+#include <boost/mpl/back_inserter.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/filter_view.hpp>
+#include <boost/mpl/transform_view.hpp>
+#include <boost/mpl/equal.hpp>
+#include <boost/type_traits.hpp>
+
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+namespace detail {
+
+// tag to identify this graph implementation (not defined)
+struct incidence_list_tag;
+
+// clarifiers
+template<typename EST> struct fetch_edge :
+ mpl::front<EST> {};
+template<typename EST> struct fetch_source :
+ mpl::deref<typename mpl::next<typename mpl::begin<EST>::type>::type> {};
+template<typename EST> struct fetch_target :
+ mpl::back<EST> {};
+
+// Edge->Target map for an Source for out_*, adjacent_vertices
+template<typename Source, typename ESTSequence>
+struct produce_out_map<incidence_list_tag, Source, ESTSequence> :
+ mpl::fold<typename mpl::filter_view<ESTSequence, boost::is_same<fetch_source<mpl::_1>,Source> >::type,
+ mpl::map<>,
+ mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,fetch_target<mpl::_2> > > >
+{};
+
+// Edge->Source map for a Target for in_*, degree
+template<typename Target, typename ESTSequence>
+struct produce_in_map<incidence_list_tag, Target, ESTSequence> :
+ mpl::fold<typename mpl::filter_view<ESTSequence,
+ boost::is_same<fetch_target<mpl::_1>,Target> >::type,
+ mpl::map<>,
+ mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,fetch_source<mpl::_2> > > >
+
+{};
+// Edge->pair<Source,Target> map for source, target
+template<typename ESTSequence>
+struct produce_edge_st_map<incidence_list_tag, ESTSequence> :
+ mpl::fold<ESTSequence,
+ mpl::map<>,
+ mpl::insert<mpl::_1,mpl::pair<fetch_edge<mpl::_2>,
+ mpl::pair<fetch_source<mpl::_2>,
+ fetch_target<mpl::_2> > > > >
+{};
+// Vertex set for VertexListGraph
+template<typename ESTSequence>
+struct produce_vertex_set<incidence_list_tag, ESTSequence> :
+ mpl::fold<ESTSequence,
+ typename mpl::fold<ESTSequence,
+ mpl::set<>,
+ mpl::insert<mpl::_1,fetch_target<mpl::_2> >
+ >::type,
+ mpl::insert<mpl::_1, fetch_source<mpl::_2> > >
+{};
+// Edge set for EdgeListGraph
+template<typename ESTSequence>
+struct produce_edge_set<incidence_list_tag, ESTSequence> :
+ mpl::fold<ESTSequence,
+ mpl::set<>,
+ mpl::insert<mpl::_1,fetch_edge<mpl::_2> > >
+{};
+}
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/incidence_list_graph.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/incidence_list_graph.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,34 @@
+// 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_METAGRAPH_MPL_GRAPH_INCIDENCE_LIST_GRAPH_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_INCIDENCE_LIST_GRAPH_HPP_INCLUDED
+
+// graph implementation based on a an mpl sequence of sequences <Edge,Source,Target>
+
+// incidence_list_graph labels such a sequence as manipulable by the metafunctions
+// in the corresponding implementation header detail/incidence_list_graph.ipp
+// to produce the metadata structures needed by mpl_graph.hpp
+
+// the public interface
+#include <boost/msm/mpl_graph/mpl_graph.hpp>
+
+// the implementation
+#include <boost/msm/mpl_graph/detail/incidence_list_graph.ipp>
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+
+template<typename EdgeSequence>
+struct incidence_list_graph {
+ typedef detail::incidence_list_tag representation;
+ typedef EdgeSequence data;
+};
+
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_INCIDENCE_LIST_GRAPH_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/mpl_graph.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/mpl_graph.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,114 @@
+// 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)
+
+// mpl_graph - defines a metadata implementation of the BGL immutable graph concepts
+
+// (c) 2008 Gordon Woodhull
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSEmpl::_1_0.txt or copy at
+// http://www.boost.org/LICENSEmpl::_1_0.txt)
+
+#ifndef BOOST_METAGRAPH_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED
+
+#include <boost/msm/mpl_graph/detail/graph_implementation_interface.ipp>
+
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/push_back.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/mpl/plus.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/back_inserter.hpp>
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+
+// Boost Graph concepts, MPL style
+
+// The metafunctions of the public interface rely
+// metafunctions in the graph implementation to transform the input
+// into the maps which are required to deliver results. Since the
+// maps are produced lazily and are memoized, all of the graph
+// concepts can be supported with no cost until they are actually
+// used.
+
+// Each of these dispatch to the correct producer metafunctions based
+// on the representation inner type tag
+
+
+
+// IncidenceGraph
+template<typename Edge, typename Graph>
+struct source :
+ mpl::first<typename mpl::at<typename detail::produce_edge_st_map<typename Graph::representation, typename Graph::data>::type,Edge>::type>
+{};
+template<typename Edge, typename Graph>
+struct target :
+ mpl::second<typename mpl::at<typename detail::produce_edge_st_map<typename Graph::representation, typename Graph::data>::type,Edge>::type>
+{};
+template<typename Vertex, typename Graph>
+struct out_edges :
+ mpl::fold<typename detail::produce_out_map<typename Graph::representation, Vertex, typename Graph::data>::type,
+ mpl::vector<>,
+ mpl::push_back<mpl::_1, mpl::first<mpl::_2> > >
+{};
+template<typename Vertex, typename Graph>
+struct out_degree :
+ mpl::size<typename out_edges<Vertex, Graph>::type>
+{};
+
+// BidirectionalGraph
+template<typename Vertex, typename Graph>
+struct in_edges :
+ mpl::fold<typename detail::produce_in_map<typename Graph::representation, Vertex, typename Graph::data>::type,
+ mpl::vector<>,
+ mpl::push_back<mpl::_1, mpl::first<mpl::_2> > >
+{};
+template<typename Vertex, typename Graph>
+struct in_degree :
+ mpl::size<typename in_edges<Vertex, Graph>::type>
+{};
+template<typename Vertex, typename Graph>
+struct degree :
+ mpl::plus<typename out_degree<Vertex, Graph>::type,typename in_degree<Vertex, Graph>::type>
+{};
+
+// AdjacencyGraph
+template<typename Vertex, typename Graph>
+struct adjacent_vertices :
+ mpl::transform<typename detail::produce_out_map<typename Graph::representation, Vertex, typename Graph::data>::type,
+ mpl::second<mpl::_1>,
+ mpl::back_inserter<mpl::vector<> > >
+{};
+
+// VertexListGraph
+template<typename Graph>
+struct vertices :
+ detail::produce_vertex_set<typename Graph::representation, typename Graph::data>
+{};
+template<typename Graph>
+struct num_vertices :
+ mpl::size<typename vertices<Graph>::type>
+{};
+
+// EdgeListGraph
+template<typename Graph>
+struct edges :
+ detail::produce_edge_set<typename Graph::representation, typename Graph::data>
+{};
+template<typename Graph>
+struct num_edges :
+ mpl::size<typename edges<Graph>::type>
+{};
+// source and target are defined in IncidenceGraph
+
+} // mpl_graph
+} // metagraph
+} // boost
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/mpl_utils.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/mpl_utils.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,62 @@
+// 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_METAGRAPH_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED
+
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/has_key.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/and.hpp>
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+namespace mpl_utils {
+
+// This is a grab bag of little metafunctions I expect already
+// exist under some name I haven't looked for
+
+// I figure there are probably better ways to do all of these things,
+// but for now I'll just write some utilities to isolate my ignorance
+
+template<typename Seq>
+struct as_map :
+ mpl::fold<Seq,
+ mpl::map<>,
+ mpl::insert<mpl::_1, mpl::_2> >
+{};
+template<typename Seq>
+struct as_set :
+ mpl::fold<Seq,
+ mpl::set<>,
+ mpl::insert<mpl::_1, mpl::_2> >
+{};
+
+template<typename AssocSeq, typename Key, typename Default>
+struct at_or_default :
+ mpl::if_<typename mpl::has_key<AssocSeq, Key>::type,
+ typename mpl::at<AssocSeq, Key>::type,
+ Default>
+{};
+
+template<typename Seq1, typename Seq2>
+struct set_equal :
+ mpl::fold<Seq2,
+ mpl::true_,
+ mpl::and_<mpl::_1,
+ mpl::has_key<typename as_set<Seq1>::type,
+ mpl::_2 > > >
+{};
+
+}
+}
+}
+}
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED

Added: trunk/boost/msm/mpl_graph/search_colors.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/msm/mpl_graph/search_colors.hpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,39 @@
+// 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_METAGRAPH_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED
+#define BOOST_METAGRAPH_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED
+
+namespace boost {
+namespace metagraph {
+namespace mpl_graph {
+
+namespace search_colors {
+ struct White {};
+ struct Gray {};
+ struct Black {};
+};
+
+struct create_search_color_map : mpl::map<> {};
+
+struct search_color_map_ops {
+ template<typename Node, typename Color, typename State>
+ struct set_color :
+ mpl::insert<State, mpl::pair<Node, Color> >
+ {};
+ template<typename Node, typename State>
+ struct get_color :
+ mpl::if_<mpl::has_key<State, Node>,
+ mpl::at<State, Node>,
+ search_colors::White>
+ {};
+};
+
+
+} // namespace mpl_graph
+} // namespace metagraph
+} // namespace boost
+
+
+#endif // BOOST_METAGRAPH_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED

Added: trunk/libs/msm/example/mpl_graph/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/Jamfile.v2 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,34 @@
+# msm/example/mpl_graph/Jamfile.v2 tests the mpl_graph examples
+#
+# Copyright (c) 2010 Gordon Woodhull
+#
+# Use, modification and distribution is subject to 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)
+
+import testing ;
+
+project msm
+ :
+ requirements
+ <include>.
+ <toolset>gcc:<cxxflags>"-ftemplate-depth-300 -g0"
+ <toolset>darwin:<cxxflags>"-ftemplate-depth-300 -g0"
+ <toolset>intel:<cxxflags>"-g0"
+ <toolset>gcc:<optimization>off
+ <toolset>darwin:<optimization>off
+ <toolset>intel:<optimization>off
+ <library>/boost/test//boost_unit_test_framework/<link>static
+ <library>/boost/serialization//boost_serialization/<link>static
+ ;
+
+
+test-suite msm-unit-tests
+ :
+ [ compile adjacency_list_graph.cpp ]
+ [ compile depth_first_search.cpp ]
+ [ compile breadth_first_search.cpp ]
+ [ compile incidence_list_graph.cpp ]
+ [ compile msm_adaptor.cpp ]
+ ;
+

Added: trunk/libs/msm/example/mpl_graph/adjacency_list_graph.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/adjacency_list_graph.cpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,82 @@
+// 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)
+
+// mplgraph.cpp : Defines the entry point for the console application.
+//
+
+#include <boost/msm/mpl_graph/adjacency_list_graph.hpp>
+#include <boost/msm/mpl_graph/mpl_utils.hpp>
+#include <boost/mpl/equal.hpp>
+
+
+namespace mpl_graph = boost::metagraph::mpl_graph;
+namespace mpl_utils = mpl_graph::mpl_utils;
+namespace mpl = boost::mpl;
+
+/*
+ test graph and tests are almost identical to incidence_list_graph.cpp
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+ G // except this
+*/
+
+// vertices
+struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{}; struct G{};
+
+// edges
+struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
+
+typedef mpl::vector<
+ mpl::pair<A, mpl::vector<mpl::pair<A_B, B> > >,
+ mpl::pair<B, mpl::vector<mpl::pair<B_C, C>,
+ mpl::pair<B_F, F> > >,
+ mpl::pair<C, mpl::vector<mpl::pair<C_D, D>,
+ mpl::pair<C_E, E>,
+ mpl::pair<C_F, F> > >,
+ mpl::pair<G, mpl::vector<> > >
+ some_adjacency_list;
+typedef mpl_graph::adjacency_list_graph<some_adjacency_list> some_graph;
+
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<B_C,some_graph>::type, B> ));
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<C_D,some_graph>::type, C> ));
+
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<C_D,some_graph>::type, D> ));
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<B_F,some_graph>::type, F> ));
+
+
+// shouldn't assume the order but this seems to work
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<C,some_graph>::type, mpl::vector<C_D,C_E,C_F> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<B,some_graph>::type, mpl::vector<B_C,B_F> > ));
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<B,some_graph>::value), ==, 2 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<C,some_graph>::value), ==, 3 );
+
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<C,some_graph>::type, mpl::vector<B_C> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<F,some_graph>::type, mpl::vector<B_F,C_F> > ));
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<A,some_graph>::value), ==, 0 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<F,some_graph>::value), ==, 2 );
+
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<A,some_graph>::value), ==, 1 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<C,some_graph>::value), ==, 4 );
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<A,some_graph>::type, mpl::vector<B> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<C,some_graph>::type, mpl::vector<D,E,F> > ));
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::vertices<some_graph>::type, mpl::vector<A,B,C,D,E,F,G> > ));
+
+BOOST_MPL_ASSERT_RELATION( mpl_graph::num_vertices<some_graph>::value, ==, 7 );
+
+BOOST_MPL_ASSERT_RELATION( mpl_graph::num_edges<some_graph>::value, ==, 6 );
+
+
+int main(int argc, char* argv[])
+{
+ return 0;
+}
+

Added: trunk/libs/msm/example/mpl_graph/breadth_first_search.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/breadth_first_search.cpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,211 @@
+// 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)
+
+#include <boost/msm/mpl_graph/breadth_first_search.hpp>
+#include <boost/msm/mpl_graph/adjacency_list_graph.hpp>
+#include <boost/msm/mpl_graph/incidence_list_graph.hpp>
+
+#include <iostream>
+
+namespace mpl_graph = boost::metagraph::mpl_graph;
+namespace mpl = boost::mpl;
+
+// vertices
+struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{}; struct G{};
+
+// edges
+struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
+
+
+
+/*
+ incidence list test graph:
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+*/
+
+typedef mpl::vector<mpl::vector<A_B,A,B>,
+ mpl::vector<B_C,B,C>,
+ mpl::vector<C_D,C,D>,
+ mpl::vector<C_E,C,E>,
+ mpl::vector<C_F,C,F>,
+ mpl::vector<B_F,B,F> >
+ some_incidence_list;
+typedef mpl_graph::incidence_list_graph<some_incidence_list> some_incidence_list_graph;
+
+
+
+/*
+ adjacency list test graph:
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+ G
+*/
+
+typedef mpl::vector<
+ mpl::pair<A, mpl::vector<mpl::pair<A_B, B> > >,
+ mpl::pair<B, mpl::vector<mpl::pair<B_C, C>,
+ mpl::pair<B_F, F> > >,
+ mpl::pair<C, mpl::vector<mpl::pair<C_D, D>,
+ mpl::pair<C_E, E>,
+ mpl::pair<C_F, F> > >,
+ mpl::pair<G, mpl::vector<> > >
+ some_adjacency_list;
+typedef mpl_graph::adjacency_list_graph<some_adjacency_list> some_adjacency_list_graph;
+
+
+struct preordering_visitor : mpl_graph::bfs_default_visitor_operations {
+ template<typename Vertex, typename Graph, typename State>
+ struct discover_vertex :
+ mpl::push_back<State, Vertex>
+ {};
+};
+
+struct postordering_visitor : mpl_graph::bfs_default_visitor_operations {
+ template<typename Vertex, typename Graph, typename State>
+ struct finish_vertex :
+ mpl::push_back<State, Vertex>
+ {};
+};
+
+struct examine_edge_visitor : mpl_graph::bfs_default_visitor_operations {
+ template<typename Edge, typename Graph, typename State>
+ struct examine_edge :
+ mpl::push_back<State, Edge>
+ {};
+};
+
+struct tree_edge_visitor : mpl_graph::bfs_default_visitor_operations {
+ template<typename Edge, typename Graph, typename State>
+ struct tree_edge :
+ mpl::push_back<State, Edge>
+ {};
+};
+
+// adjacency list tests
+
+// preordering, start from A
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ A>::type>::type
+ preorder_adj_a;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj_a::type, mpl::vector<A,B,C,F,D,E> > ));
+
+// examine edges, start from A
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_adjacency_list_graph,
+ examine_edge_visitor,
+ mpl::vector<>,
+ A>::type>::type
+ ex_edges_adj_a;
+BOOST_MPL_ASSERT(( mpl::equal<ex_edges_adj_a::type, mpl::vector<A_B,B_C,B_F,C_D,C_E,C_F> > ));
+
+// tree edges, start from A
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_adjacency_list_graph,
+ tree_edge_visitor,
+ mpl::vector<>,
+ A>::type>::type
+ tree_edges_adj_a;
+BOOST_MPL_ASSERT(( mpl::equal<tree_edges_adj_a::type, mpl::vector<A_B,B_C,B_F,C_D,C_E> > ));
+
+// preordering, search all, default start node (first)
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<> >::type>::type
+ preorder_adj;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj::type, mpl::vector<A,B,C,F,D,E,G> > ));
+
+// postordering, starting at A (same as preordering because BFS fully processes one vertex b4 moving to next)
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_adjacency_list_graph,
+ postordering_visitor,
+ mpl::vector<>,
+ A>::type>::type
+ postorder_adj_a;
+BOOST_MPL_ASSERT(( mpl::equal<postorder_adj_a::type, mpl::vector<A,B,C,F,D,E> > ));
+
+// postordering, default start node (same as preordering because BFS fully processes one vertex b4 moving to next)
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_adjacency_list_graph,
+ postordering_visitor,
+ mpl::vector<> >::type>::type
+ postorder_adj;
+BOOST_MPL_ASSERT(( mpl::equal<postorder_adj::type, mpl::vector<A,B,C,F,D,E,G> > ));
+
+// preordering starting at C
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_adj_from_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj_from_c::type, mpl::vector<C,D,E,F> > ));
+
+// preordering, search all, starting at C
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_adj_from_c_all;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj_from_c_all::type, mpl::vector<C,D,E,F,A,B,G> > ));
+
+
+// incidence list tests
+
+// preordering, start from A
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ A>::type>::type
+ preorder_inc_a;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc_a::type, mpl::vector<A,B,C,F,D,E> > ));
+
+// preordering, start from C
+typedef mpl::first<mpl_graph::
+ breadth_first_search<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_inc_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc_c::type, mpl::vector<C,D,E,F> > ));
+
+// preordering, default start node (first)
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<> >::type>::type
+ preorder_inc;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc::type, mpl::vector<A,B,C,F,D,E> > ));
+
+// postordering, default start node
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_incidence_list_graph,
+ postordering_visitor,
+ mpl::vector<> >::type>::type
+ postorder_inc;
+BOOST_MPL_ASSERT(( mpl::equal<postorder_inc::type, mpl::vector<A,B,C,F,D,E> > ));
+
+// preordering, search all, starting at C
+typedef mpl::first<mpl_graph::
+ breadth_first_search_all<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_inc_from_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc_from_c::type, mpl::vector<C,D,E,F,A,B> > ));
+
+
+int main() {
+ return 0;
+}
\ No newline at end of file

Added: trunk/libs/msm/example/mpl_graph/depth_first_search.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/depth_first_search.cpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,153 @@
+// 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)
+
+#include <boost/msm/mpl_graph/depth_first_search.hpp>
+#include <boost/msm/mpl_graph/adjacency_list_graph.hpp>
+#include <boost/msm/mpl_graph/incidence_list_graph.hpp>
+
+#include <iostream>
+
+namespace mpl_graph = boost::metagraph::mpl_graph;
+namespace mpl = boost::mpl;
+
+// vertices
+struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{}; struct G{};
+
+// edges
+struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
+
+
+
+/*
+ incidence list test graph:
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+ G
+*/
+
+typedef mpl::vector<mpl::vector<A_B,A,B>,
+ mpl::vector<B_C,B,C>,
+ mpl::vector<C_D,C,D>,
+ mpl::vector<C_E,C,E>,
+ mpl::vector<C_F,C,F>,
+ mpl::vector<B_F,B,F> >
+ some_incidence_list;
+typedef mpl_graph::incidence_list_graph<some_incidence_list> some_incidence_list_graph;
+
+
+
+/*
+ adjacency list test graph:
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+ G
+*/
+
+typedef mpl::vector<
+ mpl::pair<A, mpl::vector<mpl::pair<A_B, B> > >,
+ mpl::pair<B, mpl::vector<mpl::pair<B_C, C>,
+ mpl::pair<B_F, F> > >,
+ mpl::pair<C, mpl::vector<mpl::pair<C_D, D>,
+ mpl::pair<C_E, E>,
+ mpl::pair<C_F, F> > >,
+ mpl::pair<G, mpl::vector<> > >
+ some_adjacency_list;
+typedef mpl_graph::adjacency_list_graph<some_adjacency_list> some_adjacency_list_graph;
+
+
+struct preordering_visitor : mpl_graph::dfs_default_visitor_operations {
+ template<typename Node, typename Graph, typename State>
+ struct discover_vertex :
+ mpl::push_back<State, Node>
+ {};
+};
+
+struct postordering_visitor : mpl_graph::dfs_default_visitor_operations {
+ template<typename Node, typename Graph, typename State>
+ struct finish_vertex :
+ mpl::push_back<State, Node>
+ {};
+};
+
+// adjacency list tests
+
+// preordering, default start node (first)
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<> >::type>::type
+ preorder_adj;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj::type, mpl::vector<A,B,C,D,E,F,G> > ));
+
+// postordering, default start node
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_adjacency_list_graph,
+ postordering_visitor,
+ mpl::vector<> >::type>::type
+ postorder_adj;
+BOOST_MPL_ASSERT(( mpl::equal<postorder_adj::type, mpl::vector<D,E,F,C,B,A,G> > ));
+
+// preordering all starting at C
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_adj_all_from_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj_all_from_c::type, mpl::vector<C,D,E,F,A,B,G> > ));
+
+// preordering just those starting at C
+typedef mpl::first<mpl_graph::
+ depth_first_search<some_adjacency_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_adj_from_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_adj_from_c::type, mpl::vector<C,D,E,F> > ));
+
+
+// incidence list tests
+
+// preordering, default start node (first)
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<> >::type>::type
+ preorder_inc;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc::type, mpl::vector<A,B,C,D,E,F> > ));
+
+// postordering, default start node
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_incidence_list_graph,
+ postordering_visitor,
+ mpl::vector<> >::type>::type
+ postorder_inc;
+BOOST_MPL_ASSERT(( mpl::equal<postorder_inc::type, mpl::vector<D,E,F,C,B,A> > ));
+
+// preordering starting at C
+typedef mpl::first<mpl_graph::
+ depth_first_search_all<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ C>::type>::type
+ preorder_inc_all_from_c;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc_all_from_c::type, mpl::vector<C,D,E,F,A,B> > ));
+
+// preordering starting at B
+typedef mpl::first<mpl_graph::
+ depth_first_search<some_incidence_list_graph,
+ preordering_visitor,
+ mpl::vector<>,
+ B>::type>::type
+ preorder_inc_from_b;
+BOOST_MPL_ASSERT(( mpl::equal<preorder_inc_from_b::type, mpl::vector<B,C,D,E,F> > ));
+
+
+int main() {
+ return 0;
+}
\ No newline at end of file

Added: trunk/libs/msm/example/mpl_graph/incidence_list_graph.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/incidence_list_graph.cpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,72 @@
+// 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)
+
+// mplgraph.cpp : Defines the entry point for the console application.
+//
+
+#include <boost/msm/mpl_graph/incidence_list_graph.hpp>
+#include <boost/msm/mpl_graph/mpl_utils.hpp>
+
+namespace mpl_graph = boost::metagraph::mpl_graph;
+namespace mpl_utils = mpl_graph::mpl_utils;
+namespace mpl = boost::mpl;
+/*
+ test graph:
+ A -> B -> C -\--> D
+ \ |--> E
+ \ \--> F
+ \-----/
+*/
+
+// vertices
+struct A{}; struct B{}; struct C{}; struct D{}; struct E{}; struct F{};
+
+// edges
+struct A_B{}; struct B_C{}; struct C_D{}; struct C_E{}; struct C_F{}; struct B_F{};
+
+typedef mpl::vector<mpl::vector<A_B,A,B>,
+ mpl::vector<B_C,B,C>,
+ mpl::vector<C_D,C,D>,
+ mpl::vector<C_E,C,E>,
+ mpl::vector<C_F,C,F>,
+ mpl::vector<B_F,B,F> >
+ some_incidence_list;
+typedef mpl_graph::incidence_list_graph<some_incidence_list> some_graph;
+
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<B_C,some_graph>::type, B> ));
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::source<C_D,some_graph>::type, C> ));
+
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<C_D,some_graph>::type, D> ));
+BOOST_MPL_ASSERT(( boost::is_same<mpl_graph::target<B_F,some_graph>::type, F> ));
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<C,some_graph>::type, mpl::vector<C_D,C_E,C_F> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::out_edges<B,some_graph>::type, mpl::vector<B_F,B_C> > ));
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<B,some_graph>::value), ==, 2 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::out_degree<C,some_graph>::value), ==, 3 );
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<C,some_graph>::type, mpl::vector<B_C> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::in_edges<F,some_graph>::type, mpl::vector<C_F,B_F> > ));
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<A,some_graph>::value), ==, 0 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::in_degree<F,some_graph>::value), ==, 2 );
+
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<A,some_graph>::value), ==, 1 );
+BOOST_MPL_ASSERT_RELATION( (mpl_graph::degree<C,some_graph>::value), ==, 4 );
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<A,some_graph>::type, mpl::vector<B> > ));
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::adjacent_vertices<C,some_graph>::type, mpl::vector<D,E,F> > ));
+
+BOOST_MPL_ASSERT(( mpl_utils::set_equal<mpl_graph::vertices<some_graph>::type, mpl::vector<A,B,C,D,E,F> > ));
+
+BOOST_MPL_ASSERT_RELATION( mpl_graph::num_vertices<some_graph>::value, ==, 6 );
+
+BOOST_MPL_ASSERT_RELATION( mpl_graph::num_edges<some_graph>::value, ==, 6 );
+
+
+int main(int argc, char* argv[])
+{
+ return 0;
+}
+

Added: trunk/libs/msm/example/mpl_graph/msm_adaptor.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/msm/example/mpl_graph/msm_adaptor.cpp 2010-11-15 00:33:19 EST (Mon, 15 Nov 2010)
@@ -0,0 +1,264 @@
+// Copyright 2010 Gordon Woodhull
+// modified from MSMv2.10/libs/msm/doc/HTML/examples/SimpleTutorial.cpp
+// for the purpose of showing how to run mpl_graph algorithms on MSMs
+// and distributed same license as source
+// Copyright 2008 Christophe Henry
+// henry UNDERSCORE christophe AT hotmail DOT com
+// This is an extended version of the state machine available in the boost::mpl library
+// Distributed under the same license as the original.
+// Copyright for the original version:
+// Copyright 2005 David Abrahams and Aleksey Gurtovoy. 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)
+
+#include <iostream>
+// back-end
+#include <boost/msm/back/state_machine.hpp>
+//front-end
+#include <boost/msm/front/state_machine_def.hpp>
+
+// mpl_graph graph implementation and depth first search
+#include <boost/msm/mpl_graph/incidence_list_graph.hpp>
+#include <boost/msm/mpl_graph/depth_first_search.hpp>
+#include <boost/msm/mpl_graph/breadth_first_search.hpp>
+
+namespace msm = boost::msm;
+namespace mpl = boost::mpl;
+
+namespace mpl_graph = boost::metagraph::mpl_graph;
+
+namespace
+{
+ // events
+ struct play {};
+ struct end_pause {};
+ struct stop {};
+ struct pause {};
+ struct open_close {};
+
+ // A "complicated" event type that carries some data.
+ enum DiskTypeEnum
+ {
+ DISK_CD=0,
+ DISK_DVD=1
+ };
+ struct cd_detected
+ {
+ cd_detected(std::string name, DiskTypeEnum diskType)
+ : name(name),
+ disc_type(diskType)
+ {}
+
+ std::string name;
+ DiskTypeEnum disc_type;
+ };
+
+ // front-end: define the FSM structure
+ struct player_ : public msm::front::state_machine_def<player_>
+ {
+ // The list of FSM states
+ struct Empty : public msm::front::state<>
+ {
+ // every (optional) entry/exit methods get the event passed.
+ template <class Event,class FSM>
+ void on_entry(Event const&,FSM& ) {std::cout << "entering: Empty" << std::endl;}
+ template <class Event,class FSM>
+ void on_exit(Event const&,FSM& ) {std::cout << "leaving: Empty" << std::endl;}
+ };
+ struct Open : public msm::front::state<>
+ {
+ template <class Event,class FSM>
+ void on_entry(Event const& ,FSM&) {std::cout << "entering: Open" << std::endl;}
+ template <class Event,class FSM>
+ void on_exit(Event const&,FSM& ) {std::cout << "leaving: Open" << std::endl;}
+ };
+
+ // sm_ptr still supported but deprecated as functors are a much better way to do the same thing
+ struct Stopped : public msm::front::state<msm::front::default_base_state,msm::front::sm_ptr>
+ {
+ template <class Event,class FSM>
+ void on_entry(Event const& ,FSM&) {std::cout << "entering: Stopped" << std::endl;}
+ template <class Event,class FSM>
+ void on_exit(Event const&,FSM& ) {std::cout << "leaving: Stopped" << std::endl;}
+ void set_sm_ptr(player_* pl)
+ {
+ m_player=pl;
+ }
+ player_* m_player;
+ };
+
+ struct Playing : public msm::front::state<>
+ {
+ template <class Event,class FSM>
+ void on_entry(Event const&,FSM& ) {std::cout << "entering: Playing" << std::endl;}
+ template <class Event,class FSM>
+ void on_exit(Event const&,FSM& ) {std::cout << "leaving: Playing" << std::endl;}
+ };
+
+ // state not defining any entry or exit
+ struct Paused : public msm::front::state<>
+ {
+ };
+
+ // the initial state of the player SM. Must be defined
+ typedef Empty initial_state;
+
+ // transition actions
+ void start_playback(play const&) { std::cout << "player::start_playback\n"; }
+ void open_drawer(open_close const&) { std::cout << "player::open_drawer\n"; }
+ void close_drawer(open_close const&) { std::cout << "player::close_drawer\n"; }
+ void store_cd_info(cd_detected const&) { std::cout << "player::store_cd_info\n"; }
+ void stop_playback(stop const&) { std::cout << "player::stop_playback\n"; }
+ void pause_playback(pause const&) { std::cout << "player::pause_playback\n"; }
+ void resume_playback(end_pause const&) { std::cout << "player::resume_playback\n"; }
+ void stop_and_open(open_close const&) { std::cout << "player::stop_and_open\n"; }
+ void stopped_again(stop const&) {std::cout << "player::stopped_again\n";}
+ // guard conditions
+ bool good_disk_format(cd_detected const& evt)
+ {
+ // to test a guard condition, let's say we understand only CDs, not DVD
+ if (evt.disc_type != DISK_CD)
+ {
+ std::cout << "wrong disk, sorry" << std::endl;
+ return false;
+ }
+ return true;
+ }
+ // used to show a transition conflict. This guard will simply deactivate one transition and thus
+ // solve the conflict
+ bool auto_start(cd_detected const&)
+ {
+ return false;
+ }
+
+ typedef player_ p; // makes transition table cleaner
+
+ // Transition table for player
+ struct transition_table : mpl::vector<
+ // Start Event Next Action Guard
+ // +---------+-------------+---------+---------------------+----------------------+
+ a_row < Stopped , play , Playing , &p::start_playback >,
+ a_row < Stopped , open_close , Open , &p::open_drawer >,
+ _row < Stopped , stop , Stopped >,
+ // +---------+-------------+---------+---------------------+----------------------+
+ a_row < Open , open_close , Empty , &p::close_drawer >,
+ // +---------+-------------+---------+---------------------+----------------------+
+ a_row < Empty , open_close , Open , &p::open_drawer >,
+ row < Empty , cd_detected , Stopped , &p::store_cd_info ,&p::good_disk_format >,
+ row < Empty , cd_detected , Playing , &p::store_cd_info ,&p::auto_start >,
+ // +---------+-------------+---------+---------------------+----------------------+
+ a_row < Playing , stop , Stopped , &p::stop_playback >,
+ a_row < Playing , pause , Paused , &p::pause_playback >,
+ a_row < Playing , open_close , Open , &p::stop_and_open >,
+ // +---------+-------------+---------+---------------------+----------------------+
+ a_row < Paused , end_pause , Playing , &p::resume_playback >,
+ a_row < Paused , stop , Stopped , &p::stop_playback >,
+ a_row < Paused , open_close , Open , &p::stop_and_open >
+ // +---------+-------------+---------+---------------------+----------------------+
+ > {};
+ // Replaces the default no-transition response.
+ template <class FSM,class Event>
+ void no_transition(Event const& e, FSM&,int state)
+ {
+ std::cout << "no transition from state " << state
+ << " on event " << typeid(e).name() << std::endl;
+ }
+
+
+ // transition table is already an incidence list;
+ // select Edge, Source, Target = pair<Start,Event>, Start, Next
+ // making Start part of Edge is necessary because Edge tags have to be unique
+
+ template<typename Row>
+ struct row_to_incidence :
+ mpl::vector<mpl::pair<typename Row::Target, typename Row::Evt>, typename Row::Source, typename Row::Target> {};
+
+ typedef mpl::fold<player_::transition_table,
+ mpl::vector<>,
+ mpl::push_back<mpl::_1, row_to_incidence<mpl::_2> > >::type
+ transition_incidence_list;
+
+ typedef mpl_graph::incidence_list_graph<transition_incidence_list>
+ transition_graph;
+
+ struct preordering_dfs_visitor : mpl_graph::dfs_default_visitor_operations {
+ template<typename Node, typename Graph, typename State>
+ struct discover_vertex :
+ mpl::push_back<State, Node>
+ {};
+ };
+
+ typedef mpl::first<mpl_graph::
+ depth_first_search<transition_graph,
+ preordering_dfs_visitor,
+ mpl::vector<>,
+ player_::initial_state>::type>::type
+ dfs_from_initial_state;
+
+ BOOST_MPL_ASSERT(( mpl::equal<dfs_from_initial_state,
+ mpl::vector<Empty,Open,Stopped,Playing,Paused> > ));
+
+ struct preordering_bfs_visitor : mpl_graph::bfs_default_visitor_operations {
+ template<typename Node, typename Graph, typename State>
+ struct discover_vertex :
+ mpl::push_back<State, Node>
+ {};
+ };
+ typedef mpl::first<mpl_graph::
+ breadth_first_search<transition_graph,
+ preordering_bfs_visitor,
+ mpl::vector<>,
+ player_::initial_state>::type>::type
+ bfs_from_initial_state;
+
+ // yawn, BFS happens to produce the same result as DFS for this example
+ BOOST_MPL_ASSERT(( mpl::equal<bfs_from_initial_state,
+ mpl::vector<Empty,Open,Stopped,Playing,Paused> > ));
+
+ };
+ // Pick a back-end
+ typedef msm::back::state_machine<player_> player;
+
+ //
+ // Testing utilities.
+ //
+ static char const* const state_names[] = { "Stopped", "Open", "Empty", "Playing", "Paused" };
+ void pstate(player const& p)
+ {
+ std::cout << " -> " << state_names[p.current_state()[0]] << std::endl;
+ }
+
+
+ void test()
+ {
+ player p;
+ // needed to start the highest-level SM. This will call on_entry and mark the start of the SM
+ p.start();
+ // go to Open, call on_exit on Empty, then action, then on_entry on Open
+ p.process_event(open_close()); pstate(p);
+ p.process_event(open_close()); pstate(p);
+ // will be rejected, wrong disk type
+ p.process_event(
+ cd_detected("louie, louie",DISK_DVD)); pstate(p);
+ p.process_event(
+ cd_detected("louie, louie",DISK_CD)); pstate(p);
+ p.process_event(play());
+
+ // at this point, Play is active
+ p.process_event(pause()); pstate(p);
+ // go back to Playing
+ p.process_event(end_pause()); pstate(p);
+ p.process_event(pause()); pstate(p);
+ p.process_event(stop()); pstate(p);
+ // event leading to the same state
+ // no action method called as it is not present in the transition table
+ p.process_event(stop()); pstate(p);
+ }
+}
+
+int main()
+{
+ test();
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk