From 755c77e7c139b045172fda8ba2f819ee018d418c Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Tue, 3 Apr 2012 04:44:08 +0000 Subject: [PATCH] Added functions to get null_vertex and default starting vertex, added code to generate wrappers to allow user-visible Boost.Parameter-enabled versions of BGL functions [SVN r77732] --- include/boost/graph/named_function_params.hpp | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/boost/graph/named_function_params.hpp b/include/boost/graph/named_function_params.hpp index 0d65a032..15d216b3 100644 --- a/include/boost/graph/named_function_params.hpp +++ b/include/boost/graph/named_function_params.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -463,6 +464,36 @@ BOOST_BGL_DECLARE_NAMED_PARAMS >()(g, ap[t | 0]); } +#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(name, nfixed, nnamed_max) \ + /* Entry point for conversion from BGL-style named parameters */ \ + template \ + typename detail::BOOST_PP_CAT(name, _impl)::result_type \ + BOOST_PP_CAT(name, _with_named_params)(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) BOOST_PP_COMMA_IF(nfixed) const ArgPack& arg_pack) { \ + return detail::BOOST_PP_CAT(name, _impl)()(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ + } \ + /* Individual functions taking Boost.Parameter-style keyword arguments */ \ + BOOST_PP_REPEAT(nnamed_max, BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE, (name)(nfixed)) + +#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE(z, nnamed, seq) \ + BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, BOOST_PP_SEQ_ELEM(0, seq), BOOST_PP_SEQ_ELEM(1, seq)) + +#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, name, nfixed) \ + template \ + typename detail::BOOST_PP_CAT(name, _impl)::result_type \ + name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) \ + BOOST_PP_ENUM_TRAILING(nnamed, BOOST_GRAPH_MAKE_PAIR_PARAM, ~)) { \ + return detail::BOOST_PP_CAT(name, _impl)() \ + (BOOST_PP_ENUM_PARAMS(nfixed, param), \ + (boost::parameter::aux::empty_arg_list() BOOST_PP_ENUM_TRAILING_PARAMS(nnamed, kw))); \ + } + +#define BOOST_GRAPH_TEMPLATE_ARGS_FOR_IMPL(nnamed, nfixed) \ + BOOST_PP_ENUM_PARAMS(nfixed, Param), \ + BOOST_PP_REPEAT(nnamed, BOOST_GRAPH_OPENING_PART_OF_PAIR, BOOST_PP_DEC(nnamed)) boost::parameter::aux::empty_arg_list BOOST_PP_REPEAT(nnamed, > BOOST_PP_TUPLE_EAT(3), ~) + +#define BOOST_GRAPH_OPENING_PART_OF_PAIR(z, i, n) boost::parameter::aux::arg_list, +#define BOOST_GRAPH_MAKE_PAIR_PARAM(z, i, _) const boost::parameter::aux::tagged_argument& BOOST_PP_CAT(kw, i) + } namespace detail { @@ -619,6 +650,25 @@ BOOST_BGL_DECLARE_NAMED_PARAMS } }; + template + typename boost::graph_traits::vertex_descriptor + get_null_vertex(const G&) {return boost::graph_traits::null_vertex();} + + template + typename boost::graph_traits::vertex_descriptor + get_default_starting_vertex(const G& g) { + std::pair::vertex_iterator, typename boost::graph_traits::vertex_iterator> iters = vertices(g); + return (iters.first == iters.second) ? boost::graph_traits::null_vertex() : *iters.first; + } + + template + struct get_default_starting_vertex_t { + typedef typename boost::graph_traits::vertex_descriptor result_type; + const G& g; + get_default_starting_vertex_t(const G& g): g(g) {} + result_type operator()() const {return get_default_starting_vertex(g);} + }; + } // namespace detail } // namespace boost