Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 //=======================================================================
2 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
11 // 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
13 #ifndef BOOST_GRAPH_GRAPH_SEARCH_VISITORS_HPP
14 #define BOOST_GRAPH_GRAPH_SEARCH_VISITORS_HPP
17 #include <boost/config.hpp>
18 #include <boost/property_map.hpp>
19 #include <boost/graph/graph_traits.hpp>
20 #include <boost/limits.hpp>
21 #include <boost/graph/detail/is_same.hpp>
25 // This is a bit more convenient than std::numeric_limits because
26 // you don't have to explicitly provide type T.
28 inline T numeric_limits_max(T) { return (std::numeric_limits<T>::max)(); }
30 //========================================================================
34 // For partial specialization workaround
35 enum event_visitor_enum
37 on_initialize_vertex_num, on_start_vertex_num,
38 on_discover_vertex_num, on_finish_vertex_num, on_examine_vertex_num,
39 on_examine_edge_num, on_tree_edge_num, on_non_tree_edge_num,
40 on_gray_target_num, on_black_target_num,
41 on_forward_or_cross_edge_num, on_back_edge_num,
42 on_edge_relaxed_num, on_edge_not_relaxed_num,
43 on_edge_minimized_num, on_edge_not_minimized_num
46 template<typename Event, typename Visitor>
47 struct functor_to_visitor : Visitor
49 typedef Event event_filter;
50 functor_to_visitor(const Visitor& visitor) : Visitor(visitor) {}
55 struct on_no_event { enum { num = detail::on_no_event_num }; };
57 struct on_initialize_vertex {
58 enum { num = detail::on_initialize_vertex_num }; };
59 struct on_start_vertex { enum { num = detail::on_start_vertex_num }; };
60 struct on_discover_vertex { enum { num = detail::on_discover_vertex_num }; };
61 struct on_examine_vertex { enum { num = detail::on_examine_vertex_num }; };
62 struct on_finish_vertex { enum { num = detail::on_finish_vertex_num }; };
64 struct on_examine_edge { enum { num = detail::on_examine_edge_num }; };
65 struct on_tree_edge { enum { num = detail::on_tree_edge_num }; };
66 struct on_non_tree_edge { enum { num = detail::on_non_tree_edge_num }; };
67 struct on_gray_target { enum { num = detail::on_gray_target_num }; };
68 struct on_black_target { enum { num = detail::on_black_target_num }; };
69 struct on_forward_or_cross_edge {
70 enum { num = detail::on_forward_or_cross_edge_num }; };
71 struct on_back_edge { enum { num = detail::on_back_edge_num }; };
73 struct on_edge_relaxed { enum { num = detail::on_edge_relaxed_num }; };
74 struct on_edge_not_relaxed {
75 enum { num = detail::on_edge_not_relaxed_num }; };
76 struct on_edge_minimized { enum { num = detail::on_edge_minimized_num }; };
77 struct on_edge_not_minimized {
78 enum { num = detail::on_edge_not_minimized_num }; };
80 struct true_tag { enum { num = true }; };
81 struct false_tag { enum { num = false }; };
83 //========================================================================
84 // base_visitor and null_visitor
86 // needed for MSVC workaround
87 template <class Visitor>
89 typedef on_no_event event_filter;
90 template <class T, class Graph>
91 void operator()(T, Graph&) { }
94 struct null_visitor : public base_visitor<null_visitor> {
95 typedef on_no_event event_filter;
96 template <class T, class Graph>
97 void operator()(T, Graph&) { }
100 //========================================================================
101 // The invoke_visitors() function
104 template <class Visitor, class T, class Graph>
106 invoke_dispatch(Visitor& v, T x, Graph& g, true_tag) {
109 template <class Visitor, class T, class Graph>
111 invoke_dispatch(Visitor&, T, Graph&, false_tag) { }
112 } // namespace detail
114 template <class Visitor, class Rest, class T, class Graph, class Tag>
116 invoke_visitors(std::pair<Visitor, Rest>& vlist, T x, Graph& g, Tag tag) {
117 typedef typename Visitor::event_filter Category;
118 typedef typename graph_detail::is_same<Category, Tag>::is_same_tag
120 detail::invoke_dispatch(vlist.first, x, g, IsSameTag());
121 invoke_visitors(vlist.second, x, g, tag);
123 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
124 template <class Visitor, class T, class Graph, class Tag>
126 invoke_visitors(base_visitor<Visitor>& vis, T x, Graph& g, Tag) {
127 typedef typename Visitor::event_filter Category;
128 typedef typename graph_detail::is_same<Category, Tag>::is_same_tag
130 Visitor& v = static_cast<Visitor&>(vis);
131 detail::invoke_dispatch(v, x, g, IsSameTag());
134 template <class Visitor, class T, class Graph, class Tag>
136 invoke_visitors(Visitor& v, T x, Graph& g, Tag) {
137 typedef typename Visitor::event_filter Category;
138 typedef typename graph_detail::is_same<Category, Tag>::is_same_tag
140 detail::invoke_dispatch(v, x, g, IsSameTag());
144 //========================================================================
145 // predecessor_recorder
147 template <class PredecessorMap, class Tag>
148 struct predecessor_recorder
149 : public base_visitor<predecessor_recorder<PredecessorMap, Tag> >
151 typedef Tag event_filter;
152 predecessor_recorder(PredecessorMap pa) : m_predecessor(pa) { }
153 template <class Edge, class Graph>
154 void operator()(Edge e, const Graph& g) {
155 put(m_predecessor, target(e, g), source(e, g));
157 PredecessorMap m_predecessor;
159 template <class PredecessorMap, class Tag>
160 predecessor_recorder<PredecessorMap, Tag>
161 record_predecessors(PredecessorMap pa, Tag) {
162 return predecessor_recorder<PredecessorMap, Tag> (pa);
165 //========================================================================
166 // edge_predecessor_recorder
168 template <class PredEdgeMap, class Tag>
169 struct edge_predecessor_recorder
170 : public base_visitor<edge_predecessor_recorder<PredEdgeMap, Tag> >
172 typedef Tag event_filter;
173 edge_predecessor_recorder(PredEdgeMap pa) : m_predecessor(pa) { }
174 template <class Edge, class Graph>
175 void operator()(Edge e, const Graph& g) {
176 put(m_predecessor, target(e, g), e);
178 PredEdgeMap m_predecessor;
180 template <class PredEdgeMap, class Tag>
181 edge_predecessor_recorder<PredEdgeMap, Tag>
182 record_edge_predecessors(PredEdgeMap pa, Tag) {
183 return edge_predecessor_recorder<PredEdgeMap, Tag> (pa);
186 //========================================================================
189 template <class DistanceMap, class Tag>
190 struct distance_recorder
191 : public base_visitor<distance_recorder<DistanceMap, Tag> >
193 typedef Tag event_filter;
194 distance_recorder(DistanceMap pa) : m_distance(pa) { }
195 template <class Edge, class Graph>
196 void operator()(Edge e, const Graph& g) {
197 typename graph_traits<Graph>::vertex_descriptor
198 u = source(e, g), v = target(e, g);
199 put(m_distance, v, get(m_distance, u) + 1);
201 DistanceMap m_distance;
203 template <class DistanceMap, class Tag>
204 distance_recorder<DistanceMap, Tag>
205 record_distances(DistanceMap pa, Tag) {
206 return distance_recorder<DistanceMap, Tag> (pa);
209 //========================================================================
213 template <class TimeMap, class TimeT, class Tag>
215 : public base_visitor<time_stamper<TimeMap, TimeT, Tag> >
217 typedef Tag event_filter;
218 time_stamper(TimeMap pa, TimeT& t) : m_time_pa(pa), m_time(t) { }
219 template <class Vertex, class Graph>
220 void operator()(Vertex u, const Graph&) {
221 put(m_time_pa, u, ++m_time);
226 template <class TimeMap, class TimeT, class Tag>
227 time_stamper<TimeMap, TimeT, Tag>
228 stamp_times(TimeMap pa, TimeT& time_counter, Tag) {
229 return time_stamper<TimeMap, TimeT, Tag>(pa, time_counter);
232 //========================================================================
235 template <class PA, class OutputIterator, class Tag>
236 struct property_writer
237 : public base_visitor<property_writer<PA, OutputIterator, Tag> >
239 typedef Tag event_filter;
241 property_writer(PA pa, OutputIterator out) : m_pa(pa), m_out(out) { }
243 template <class T, class Graph>
244 void operator()(T x, Graph&) { *m_out++ = get(m_pa, x); }
246 OutputIterator m_out;
248 template <class PA, class OutputIterator, class Tag>
249 property_writer<PA, OutputIterator, Tag>
250 write_property(PA pa, OutputIterator out, Tag) {
251 return property_writer<PA, OutputIterator, Tag>(pa, out);
254 #define BOOST_GRAPH_EVENT_STUB(Event,Kind) \
255 typedef ::boost::Event Event##_type; \
256 template<typename Visitor> \
257 Kind##_visitor<std::pair<detail::functor_to_visitor<Event##_type, \
258 Visitor>, Visitors> > \
259 do_##Event(Visitor visitor) \
261 typedef std::pair<detail::functor_to_visitor<Event##_type, Visitor>, \
262 Visitors> visitor_list; \
263 typedef Kind##_visitor<visitor_list> result_type; \
264 return result_type(visitor_list(visitor, m_vis)); \
267 } /* namespace boost */