//======================================================================= // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek // // This file is part of the Boost Graph Library // // You should have received a copy of the License Agreement for the // Boost Graph Library along with the software; see the file LICENSE. // If not, contact Office of Research, University of Notre Dame, Notre // Dame, IN 46556. // // Permission to modify the code and to distribute modified code is // granted, provided the text of this NOTICE is retained, a notice that // the code was modified is included with the above COPYRIGHT NOTICE and // with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE // file is distributed with the modified code. // // LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. // By way of example, but not limitation, Licensor MAKES NO // REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY // PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS // OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS // OR OTHER RIGHTS. //======================================================================= #ifndef BOOST_GRAPH_NAMED_FUNCTION_PARAMS_HPP #define BOOST_GRAPH_NAMED_FUNCTION_PARAMS_HPP #include #include namespace boost { struct distance_compare_t { }; struct distance_combine_t { }; struct distance_inf_t { }; struct distance_zero_t { }; struct buffer_param_t { }; struct edge_copy_t { }; struct vertex_copy_t { }; struct vertex_isomorphism_t { }; struct vertex_invariant_t { }; struct vertex_invariant1_t { }; struct vertex_invariant2_t { }; struct edge_compare_t { }; struct vertex_max_invariant_t { }; struct orig_to_copy_t { }; struct root_vertex_t { }; struct attractive_force_t { }; struct repulsive_force_t { }; struct force_pairs_t { }; struct cooling_t { }; struct vertex_displacement_t { }; struct terminate_t { }; struct rank_map2_t { }; namespace detail { template struct wrap_ref { wrap_ref(T& r) : ref(r) {} T& ref; }; template struct get_bgl_list_type { typedef typename T::list_type type; }; template<> struct get_bgl_list_type { typedef nil type; }; template struct to_named_params_list { template static list, typename Base::list_type> get(Tag, const T& value, const Base& base) { return (base.to_named_params_list(), keyword() = value); } }; template<> struct to_named_params_list { template static list > get(Tag, const T& value, const no_property&) { return list >(keyword() = value, nil()); } }; } template struct bgl_named_params : public Base { typedef bgl_named_params self; typedef Base next_type; typedef Tag tag_type; typedef T value_type; 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 bgl_named_params weight_map(const WeightMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params weight_map2(const WeightMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params distance_map(const DistanceMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params predecessor_map(const PredecessorMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params rank_map(const RankMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params rank_map2(const RankMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params root_map(const RootMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params root_vertex(const Vertex& r) const { typedef bgl_named_params Params; return Params(r, *this); } template bgl_named_params edge_centrality_map(const EdgeCentralityMap& r) const { typedef bgl_named_params Params; return Params(r, *this); } template bgl_named_params centrality_map(const CentralityMap& r) const { typedef bgl_named_params Params; return Params(r, *this); } template bgl_named_params color_map(const ColorMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params vertex_color_map(const ColorMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params edge_color_map(const ColorMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params capacity_map(CapacityMap pmap) { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params residual_capacity_map(Residual_CapacityMap pmap) { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params reverse_edge_map(ReverseMap pmap) { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params discover_time_map(const DiscoverTimeMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params vertex_index_map(const IndexMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params vertex_index1_map(const IndexMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params vertex_index2_map(const IndexMap& pmap) const { typedef bgl_named_params Params; return Params(pmap, *this); } template bgl_named_params visitor(const Visitor& vis) const { typedef bgl_named_params Params; return Params(vis, *this); } template bgl_named_params distance_compare(Compare cmp) const { typedef bgl_named_params Params; return Params(cmp, *this); } template bgl_named_params distance_combine(Combine cmb) const { typedef bgl_named_params Params; return Params(cmb, *this); } template bgl_named_params distance_inf(Init init) const { typedef bgl_named_params Params; return Params(init, *this); } template bgl_named_params distance_zero(Init init) const { typedef bgl_named_params Params; return Params(init, *this); } template bgl_named_params, buffer_param_t, self> buffer(Buffer& b) const { typedef bgl_named_params, buffer_param_t, self> Params; return Params(detail::wrap_ref(b), *this); } template bgl_named_params edge_copy(const Copier& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params vertex_copy(const Copier& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params orig_to_copy(const Orig2CopyMap& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params isomorphism_map(const IsoMap& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params vertex_invariant(const VertexInvar& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params displacement_map(const VertexDisplacement& c) const { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params attractive_force(const AttractiveForce& c) { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params repulsive_force(const RepulsiveForce& c) { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params force_pairs(const ForcePairs& c) { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params cooling(const Cooling& c) { typedef bgl_named_params Params; return Params(c, *this); } template bgl_named_params terminate(const Terminate& c) { typedef bgl_named_params Params; return Params(c, *this); } typedef detail::list, typename detail::get_bgl_list_type::type> list_type; list_type to_named_params_list() const { return detail::to_named_params_list::get(Tag(), m_value, *this); } }; namespace graph_detail { template struct by_value_keyword : public keyword { using keyword::operator=; template bgl_named_params operator()(T x) const { return bgl_named_params(x); } }; } template bgl_named_params weight_map(WeightMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params weight_map2(WeightMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params distance_map(DistanceMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params predecessor_map(PredecessorMap pmap) { typedef bgl_named_params Params; return Params(pmap); } namespace { graph_detail::by_value_keyword rank_map; graph_detail::by_value_keyword rank_map2; } template bgl_named_params root_map(RootMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params root_vertex(const Vertex& r) { typedef bgl_named_params Params; return Params(r); } template bgl_named_params edge_centrality_map(const EdgeCentralityMap& r) { typedef bgl_named_params Params; return Params(r); } template bgl_named_params centrality_map(const CentralityMap& r) { typedef bgl_named_params Params; return Params(r); } template bgl_named_params color_map(ColorMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params capacity_map(CapacityMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params residual_capacity_map(Residual_CapacityMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params reverse_edge_map(ReverseMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params discover_time_map(DiscoverTimeMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params vertex_index_map(IndexMap pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params vertex_index1_map(const IndexMap& pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params vertex_index2_map(const IndexMap& pmap) { typedef bgl_named_params Params; return Params(pmap); } template bgl_named_params visitor(const Visitor& vis) { typedef bgl_named_params Params; return Params(vis); } template bgl_named_params distance_compare(Compare cmp) { typedef bgl_named_params Params; return Params(cmp); } template bgl_named_params distance_combine(Combine cmb) { typedef bgl_named_params Params; return Params(cmb); } template bgl_named_params distance_inf(Init init) { typedef bgl_named_params Params; return Params(init); } template bgl_named_params distance_zero(Init init) { typedef bgl_named_params Params; return Params(init); } template bgl_named_params, buffer_param_t> buffer(Buffer& b) { typedef bgl_named_params, buffer_param_t> Params; return Params(detail::wrap_ref(b)); } template bgl_named_params edge_copy(const Copier& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params vertex_copy(const Copier& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params orig_to_copy(const Orig2CopyMap& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params isomorphism_map(const IsoMap& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params vertex_invariant(const VertexInvar& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params displacement_map(const VertexDisplacement& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params attractive_force(const AttractiveForce& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params repulsive_force(const RepulsiveForce& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params force_pairs(const ForcePairs& c) { typedef bgl_named_params Params; return Params(c); } template bgl_named_params cooling(const Cooling& c) { typedef bgl_named_params Params; return Params(c); } namespace { graph_detail::by_value_keyword terminate; } //=========================================================================== // Functions for extracting parameters from bgl_named_params template inline typename property_value< bgl_named_params, Tag2>::type get_param(const bgl_named_params& p, Tag2 tag2) { enum { match = detail::same_property::value }; typedef typename property_value< bgl_named_params, Tag2>::type T2; T2* t2 = 0; typedef detail::property_value_dispatch Dispatcher; return Dispatcher::const_get_value(p, t2, tag2); } namespace detail { // MSVC++ workaround template struct choose_param_helper { template struct result { typedef Param type; }; template static const Param& apply(const Param& p, const Default&) { return p; } }; template <> struct choose_param_helper { template struct result { typedef Default type; }; template static const Default& apply(const error_property_not_found&, const Default& d) { return d; } }; } // namespace detail template const typename detail::choose_param_helper

::template result::type& choose_param(const P& param, const Default& d) { return detail::choose_param_helper

::apply(param, d); } template inline bool is_default_param(const T&) { return false; } 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 const P& result_type; typedef P type; }; template static typename bind_::const_result_type const_apply(const P& p, const Graph&, Tag&) { return p; } template static typename bind_::result_type apply(const 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; typedef typename property_map::const_type type; }; template static typename bind_::const_result_type const_apply(const P&, const Graph& g, Tag tag) { return get(tag, g); } template static typename bind_::result_type apply(const 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_ Bind; typedef Bind type; typedef typename Bind::result_type result_type; typedef typename Bind::const_result_type const_result_type; typedef typename Bind::type result; }; // used in the max-flow algorithms template struct edge_capacity_value { typedef bgl_named_params Params; typedef typename property_value< Params, edge_capacity_t>::type Param; typedef typename detail::choose_pmap_helper::result CapacityEdgeMap; typedef typename property_traits::value_type 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 detail::choose_pmap_helper::const_result_type choose_const_pmap(const Param& p, const Graph& g, PropertyTag tag) { typedef typename detail::choose_pmap_helper::Selector Choice; return Choice::const_apply(p, g, tag); } template typename detail::choose_pmap_helper::result_type choose_pmap(const Param& p, Graph& g, PropertyTag tag) { typedef typename detail::choose_pmap_helper::Selector Choice; return Choice::apply(p, g, tag); } } // namespace boost #endif // BOOST_GRAPH_NAMED_FUNCTION_PARAMS_HPP