annotate DEPENDENCIES/generic/include/boost/graph/graph_as_tree.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
rev   line source
Chris@16 1 //
Chris@16 2 //=======================================================================
Chris@16 3 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
Chris@16 4 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
Chris@16 5 //
Chris@16 6 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 7 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 8 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //=======================================================================
Chris@16 10 //
Chris@16 11 #ifndef BOOST_GRAPH_GRAPH_AS_TREE_HPP
Chris@16 12 #define BOOST_GRAPH_GRAPH_AS_TREE_HPP
Chris@16 13
Chris@16 14 #include <vector>
Chris@16 15 #include <boost/config.hpp>
Chris@16 16 #include <boost/property_map/property_map.hpp>
Chris@16 17 #include <boost/graph/tree_traits.hpp>
Chris@16 18 #include <boost/graph/graph_traits.hpp>
Chris@16 19 #include <boost/graph/breadth_first_search.hpp>
Chris@16 20 #include <boost/graph/visitors.hpp>
Chris@16 21
Chris@16 22 namespace boost {
Chris@16 23
Chris@16 24 template <class Graph, class Node, class ChIt, class Derived>
Chris@16 25 class graph_as_tree_base
Chris@16 26 {
Chris@16 27 typedef Derived Tree;
Chris@16 28 public:
Chris@16 29 typedef Node node_descriptor;
Chris@16 30 typedef ChIt children_iterator;
Chris@16 31
Chris@16 32 graph_as_tree_base(Graph& g, Node root) : _g(g), _root(root) { }
Chris@16 33
Chris@16 34 friend Node root(const Tree& t) { return t._root; }
Chris@16 35
Chris@16 36 template <class N>
Chris@16 37 friend std::pair<ChIt,ChIt>
Chris@16 38 children(N n, const Tree& t) { return adjacent_vertices(n, t._g); }
Chris@16 39
Chris@16 40 template<class N>
Chris@16 41 friend Node parent(N n, const Tree& t) {
Chris@16 42 return boost::get(t.parent_pa(), n);
Chris@16 43 }
Chris@16 44
Chris@16 45 Graph& _g;
Chris@16 46 Node _root;
Chris@16 47 };
Chris@16 48
Chris@16 49 struct graph_as_tree_tag { };
Chris@16 50
Chris@16 51 template <class Graph, class ParentMap
Chris@16 52 , class Node
Chris@16 53 #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Chris@16 54 = typename graph_traits<Graph>::vertex_descriptor
Chris@16 55 #endif
Chris@16 56 , class ChIt
Chris@16 57 #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Chris@16 58 = typename graph_traits<Graph>::adjacency_iterator
Chris@16 59 #endif
Chris@16 60 >
Chris@16 61 class graph_as_tree
Chris@16 62 : public graph_as_tree_base<Graph, Node, ChIt,
Chris@16 63 graph_as_tree<Graph,ParentMap,Node,ChIt> >
Chris@16 64 {
Chris@16 65 typedef graph_as_tree self;
Chris@16 66 typedef graph_as_tree_base<Graph, Node, ChIt, self> super;
Chris@16 67 public:
Chris@16 68 graph_as_tree(Graph& g, Node root) : super(g, root) { }
Chris@16 69
Chris@16 70 graph_as_tree(Graph& g, Node root, ParentMap p) : super(g, root), _p(p) {
Chris@16 71 breadth_first_search(g, root,
Chris@16 72 visitor(make_bfs_visitor
Chris@16 73 (record_predecessors(p, boost::on_tree_edge()))));
Chris@16 74 }
Chris@16 75 ParentMap parent_pa() const { return _p; }
Chris@16 76 typedef graph_as_tree_tag graph_tag; // for property_map
Chris@16 77 protected:
Chris@16 78 ParentMap _p;
Chris@16 79 };
Chris@16 80
Chris@16 81
Chris@16 82 namespace detail {
Chris@16 83
Chris@16 84 struct graph_as_tree_vertex_property_selector {
Chris@16 85 template <typename GraphAsTree, typename Property, typename Tag>
Chris@16 86 struct bind_ {
Chris@16 87 typedef typename GraphAsTree::base_type Graph;
Chris@16 88 typedef property_map<Graph, Tag> PMap;
Chris@16 89 typedef typename PMap::type type;
Chris@16 90 typedef typename PMap::const_type const_type;
Chris@16 91 };
Chris@16 92 };
Chris@16 93
Chris@16 94 struct graph_as_tree_edge_property_selector {
Chris@16 95 template <typename GraphAsTree, typename Property, typename Tag>
Chris@16 96 struct bind_ {
Chris@16 97 typedef typename GraphAsTree::base_type Graph;
Chris@16 98 typedef property_map<Graph, Tag> PMap;
Chris@16 99 typedef typename PMap::type type;
Chris@16 100 typedef typename PMap::const_type const_type;
Chris@16 101 };
Chris@16 102 };
Chris@16 103
Chris@16 104 } // namespace detail
Chris@16 105
Chris@16 106 template <>
Chris@16 107 struct vertex_property_selector<graph_as_tree_tag> {
Chris@16 108 typedef detail::graph_as_tree_vertex_property_selector type;
Chris@16 109 };
Chris@16 110
Chris@16 111 template <>
Chris@16 112 struct edge_property_selector<graph_as_tree_tag> {
Chris@16 113 typedef detail::graph_as_tree_edge_property_selector type;
Chris@16 114 };
Chris@16 115
Chris@16 116 template <typename Graph, typename P, typename N, typename C,
Chris@16 117 typename Property>
Chris@16 118 typename property_map<Graph, Property>::type
Chris@16 119 get(Property p, graph_as_tree<Graph,P,N,C>& g)
Chris@16 120 {
Chris@16 121 return get(p, g._g);
Chris@16 122 }
Chris@16 123
Chris@16 124 template <typename Graph, typename P, typename N, typename C,
Chris@16 125 typename Property>
Chris@16 126 typename property_map<Graph, Property>::const_type
Chris@16 127 get(Property p, const graph_as_tree<Graph,P,N,C>& g)
Chris@16 128 {
Chris@16 129 const Graph& gref = g._g; // in case GRef is non-const
Chris@16 130 return get(p, gref);
Chris@16 131 }
Chris@16 132
Chris@16 133 template <typename Graph, typename P, typename N, typename C,
Chris@16 134 typename Property, typename Key>
Chris@16 135 typename property_traits<
Chris@16 136 typename property_map<Graph, Property>::const_type
Chris@16 137 >::value_type
Chris@16 138 get(Property p, const graph_as_tree<Graph,P,N,C>& g, const Key& k)
Chris@16 139 {
Chris@16 140 return get(p, g._g, k);
Chris@16 141 }
Chris@16 142
Chris@16 143 template <typename Graph, typename P, typename N, typename C,
Chris@16 144 typename Property, typename Key, typename Value>
Chris@16 145 void
Chris@16 146 put(Property p, const graph_as_tree<Graph,P,N,C>& g, const Key& k,
Chris@16 147 const Value& val)
Chris@16 148 {
Chris@16 149 put(p, g._g, k, val);
Chris@16 150 }
Chris@16 151
Chris@16 152 } // namespace boost
Chris@16 153
Chris@16 154 #endif // BOOST_GRAPH_GRAPH_AS_TREE_HPP