Added boost header

This commit is contained in:
Christophe Riccio
2012-01-08 01:26:07 +00:00
parent 9c3faaca40
commit c7d752cdf8
8946 changed files with 1732316 additions and 0 deletions

View File

@@ -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_MSM_MPL_GRAPH_ADJACENCY_LIST_GRAPH_HPP_INCLUDED
#define BOOST_MSM_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 msm {
namespace mpl_graph {
template<typename AdjacencyList>
struct adjacency_list_graph {
typedef detail::adjacency_list_tag representation;
typedef AdjacencyList data;
};
}
}
}
#endif // BOOST_MSM_MPL_GRAPH_ADJACENCY_LIST_GRAPH_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_BREADTH_FIRST_SEARCH_HPP_INCLUDED
#define BOOST_MSM_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 msm {
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 msm
} // namespace boost
#endif // BOOST_MSM_MPL_GRAPH_BREADTH_FIRST_SEARCH_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED
#define BOOST_MSM_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 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<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 msm
} // namespace boost
#endif // BOOST_MSM_MPL_GRAPH_DEPTH_FIRST_SEARCH_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_DETAIL_ADJACENCY_LIST_GRAPH_IPP_INCLUDED
#define BOOST_MSM_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 msm {
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_MSM_MPL_GRAPH_DETAIL_ADJACENCY_LIST_GRAPH_IPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_DETAIL_GRAPH_IMPLEMENTATION_INTERFACE_IPP_INCLUDED
#define BOOST_MSM_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 msm {
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_MSM_MPL_GRAPH_DETAIL_GRAPH_IMPLEMENTATION_INTERFACE_IPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED
#define BOOST_MSM_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 msm {
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_MSM_MPL_GRAPH_DETAIL_INCIDENCE_LIST_GRAPH_IPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_INCIDENCE_LIST_GRAPH_HPP_INCLUDED
#define BOOST_MSM_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 msm {
namespace mpl_graph {
template<typename EdgeSequence>
struct incidence_list_graph {
typedef detail::incidence_list_tag representation;
typedef EdgeSequence data;
};
}
}
}
#endif // BOOST_MSM_MPL_GRAPH_INCIDENCE_LIST_GRAPH_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED
#define BOOST_MSM_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 msm {
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
} // msm
} // boost
#endif // BOOST_MSM_MPL_GRAPH_MPL_GRAPH_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED
#define BOOST_MSM_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 msm {
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_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED

View File

@@ -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_MSM_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED
#define BOOST_MSM_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED
namespace boost {
namespace msm {
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 msm
} // namespace boost
#endif // BOOST_MSM_MPL_GRAPH_SEARCH_COLORS_HPP_INCLUDED