diff --git a/include/boost/graph/named_function_params.hpp b/include/boost/graph/named_function_params.hpp index d1d41998..0d74ba2b 100644 --- a/include/boost/graph/named_function_params.hpp +++ b/include/boost/graph/named_function_params.hpp @@ -30,6 +30,10 @@ namespace boost { + struct distance_compare_t { enum { num = detail::distance_compare_num }; }; + struct distance_combine_t { enum { num = detail::distance_combine_num}; }; + struct distance_init_t { enum { num = detail::distance_init_num }; }; + template struct bgl_named_params : public Base { @@ -37,8 +41,8 @@ namespace boost { typedef Base next_type; typedef Tag tag_type; typedef T value_type; - bgl_named_params(const T& v) : m_value(v) { } - bgl_named_params(const T& v, const Base& b) : Base(b), m_value(v) { } + bgl_named_params(T v) : m_value(v) { } + bgl_named_params(T v, const Base& b) : Base(b), m_value(v) { } T m_value; template @@ -76,32 +80,53 @@ namespace boost { return Params(vis, *this); } + template + bgl_named_params + distance_compare(const Compare& cmp) { + typedef bgl_named_params Params; + return Params(cmp, *this); + } + + template + bgl_named_params + distance_combine(const Combine& cmb) { + typedef bgl_named_params Params; + return Params(cmb, *this); + } + + template + bgl_named_params + distance_init(const Init& init) { + typedef bgl_named_params Params; + return Params(init, *this); + } + }; template bgl_named_params - weight_map(const WeightMap& pmap) { + weight_map(WeightMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params - distance_map(const DistanceMap& pmap) { + distance_map(DistanceMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params - color_map(const ColorMap& pmap) { + color_map(ColorMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params - vertex_index_map(const IndexMap& pmap) { + vertex_index_map(IndexMap pmap) { typedef bgl_named_params Params; return Params(pmap); } @@ -113,6 +138,26 @@ namespace boost { return Params(vis); } + template + bgl_named_params + distance_compare(const Compare& cmp) { + typedef bgl_named_params Params; + return Params(cmp); + } + + template + bgl_named_params + distance_combine(const Combine& cmb) { + typedef bgl_named_params Params; + return Params(cmb); + } + + template + bgl_named_params + distance_init(const Init& init) { + typedef bgl_named_params Params; + return Params(init); + } //=========================================================================== // Functions for extracting parameters from bgl_named_params @@ -145,24 +190,79 @@ namespace boost { inline bool is_default_param(const detail::error_property_not_found&) { return true; } + namespace detail { + + struct choose_parameter { + template + struct bind { + typedef const P& const_result_type; + typedef P& result_type; + static const_result_type apply(const P& p, const Graph&, Tag&) + { return p; } + static result_type apply(P& p, Graph&, Tag&) + { return p; } + }; + }; + struct choose_default_param { + template + struct bind { + typedef typename property_map::type + result_type; + typedef typename property_map::const_type + const_result_type; + + static const_result_type + apply(const P& p, const Graph& g, Tag tag) { + return get(tag, g); + } + + static result_type + apply(const P& p, Graph& g, Tag tag) { + return get(tag, g); + } + }; + }; + + template + struct choose_property_map { + typedef choose_parameter type; + }; + template <> + struct choose_property_map { + typedef choose_default_param type; + }; + + template + struct choose_pmap_helper { + typedef typename choose_property_map::type Selector; + typedef typename Selector:: template bind type; + typedef typename type::result_type result_type; + typedef typename type::const_result_type const_result_type; + }; + + } // namespace detail + + // Use this function instead of choose_param() when you want // to avoid requiring get(tag, g) when it is not used. - template - typename property_map::const_type - choose_pmap(const detail::error_property_not_found&, - const Graph& g, PropertyTag tag) - { return get(tag, g); } - - template - typename property_map::type - choose_pmap(const detail::error_property_not_found&, - Graph& g, PropertyTag tag) - { return get(tag, g); } - - template - const P& - choose_pmap(const P& param, const Graph&, Tag) { return param; } + template + typename + detail::choose_pmap_helper::const_result_type + choose_pmap(const Param& p, const Graph& g, PropertyTag tag) + { + typedef typename + detail::choose_pmap_helper::type Choice; + return Choice::apply(p, g, tag); + } + template + typename detail::choose_pmap_helper::result_type + choose_pmap(Param& p, Graph& g, PropertyTag tag) + { + typedef typename + detail::choose_pmap_helper::type Choice; + return Choice::apply(p, g, tag); + } } // namespace boost