1 | // Copyright 2004-5 Trustees of Indiana University |
---|
2 | |
---|
3 | // Use, modification and distribution is subject to the Boost Software |
---|
4 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | // |
---|
8 | // read_graphviz_spirit.hpp - |
---|
9 | // Initialize a model of the BGL's MutableGraph concept and an associated |
---|
10 | // collection of property maps using a graph expressed in the GraphViz |
---|
11 | // DOT Language. |
---|
12 | // |
---|
13 | // Based on the grammar found at: |
---|
14 | // http://www.graphviz.org/cvs/doc/info/lang.html |
---|
15 | // |
---|
16 | // See documentation for this code at: |
---|
17 | // http://www.boost.org/libs/graph/doc/read-graphviz.html |
---|
18 | // |
---|
19 | |
---|
20 | // Authors: Ronald Garcia and Douglas Gregor |
---|
21 | // |
---|
22 | |
---|
23 | #ifndef BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS |
---|
24 | # define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS |
---|
25 | #endif |
---|
26 | #include <boost/graph/graphviz.hpp> |
---|
27 | |
---|
28 | namespace boost { namespace detail { namespace graph { |
---|
29 | |
---|
30 | bool read_graphviz(std::istream& in, mutate_graph& graph) |
---|
31 | { |
---|
32 | using namespace boost; |
---|
33 | using namespace boost::spirit; |
---|
34 | |
---|
35 | typedef std::istream_iterator<char> is_t; |
---|
36 | typedef multi_pass<is_t> iterator_t; |
---|
37 | |
---|
38 | iterator_t first(make_multi_pass(is_t(in))); |
---|
39 | iterator_t last(make_multi_pass(is_t())); |
---|
40 | |
---|
41 | // Turn off white space skipping on the stream |
---|
42 | in.unsetf(std::ios::skipws); |
---|
43 | |
---|
44 | typedef skip_parser_iteration_policy< boost::detail::graph::dot_skipper> |
---|
45 | iter_policy_t; |
---|
46 | typedef scanner_policies<iter_policy_t> scanner_policies_t; |
---|
47 | typedef scanner<iterator_t, scanner_policies_t> scanner_t; |
---|
48 | |
---|
49 | boost::detail::graph::dot_grammar p(graph); |
---|
50 | boost::detail::graph::dot_skipper skip_p; |
---|
51 | |
---|
52 | iter_policy_t iter_policy(skip_p); |
---|
53 | scanner_policies_t policies(iter_policy); |
---|
54 | |
---|
55 | scanner_t scan(first, last, policies); |
---|
56 | |
---|
57 | return p.parse(scan); |
---|
58 | } |
---|
59 | |
---|
60 | } } } // end namespace boost::detail::graph |
---|