Chris@16
|
1 // Copyright 2004-9 Trustees of Indiana University
|
Chris@16
|
2
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 //
|
Chris@16
|
8 // read_graphviz_new.hpp -
|
Chris@16
|
9 // Initialize a model of the BGL's MutableGraph concept and an associated
|
Chris@16
|
10 // collection of property maps using a graph expressed in the GraphViz
|
Chris@16
|
11 // DOT Language.
|
Chris@16
|
12 //
|
Chris@16
|
13 // Based on the grammar found at:
|
Chris@16
|
14 // http://www.graphviz.org/cvs/doc/info/lang.html
|
Chris@16
|
15 //
|
Chris@16
|
16 // Jeremiah rewrite used grammar found at:
|
Chris@16
|
17 // http://www.graphviz.org/doc/info/lang.html
|
Chris@16
|
18 // and page 34 or http://www.graphviz.org/pdf/dotguide.pdf
|
Chris@16
|
19 //
|
Chris@16
|
20 // See documentation for this code at:
|
Chris@16
|
21 // http://www.boost.org/libs/graph/doc/read-graphviz.html
|
Chris@16
|
22 //
|
Chris@16
|
23
|
Chris@16
|
24 // Author: Jeremiah Willcock
|
Chris@16
|
25 // Ronald Garcia
|
Chris@16
|
26 //
|
Chris@16
|
27
|
Chris@16
|
28 #ifndef BOOST_READ_GRAPHVIZ_NEW_HPP
|
Chris@16
|
29 #define BOOST_READ_GRAPHVIZ_NEW_HPP
|
Chris@16
|
30
|
Chris@16
|
31 #include <boost/ref.hpp>
|
Chris@16
|
32 #include <boost/property_map/dynamic_property_map.hpp>
|
Chris@16
|
33 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
34 #include <boost/detail/workaround.hpp>
|
Chris@16
|
35 #include <algorithm>
|
Chris@16
|
36 #include <string>
|
Chris@16
|
37 #include <vector>
|
Chris@16
|
38 #include <set>
|
Chris@16
|
39 #include <utility>
|
Chris@16
|
40 #include <map>
|
Chris@16
|
41 #include <iostream>
|
Chris@16
|
42 #include <cstdlib>
|
Chris@16
|
43
|
Chris@16
|
44 namespace boost {
|
Chris@16
|
45
|
Chris@16
|
46 namespace read_graphviz_detail {
|
Chris@16
|
47 typedef std::string node_name;
|
Chris@16
|
48 typedef std::string subgraph_name;
|
Chris@16
|
49
|
Chris@16
|
50 typedef std::map<std::string, std::string> properties;
|
Chris@16
|
51
|
Chris@16
|
52 struct node_and_port {
|
Chris@16
|
53 node_name name;
|
Chris@16
|
54 std::string angle; // Or empty if no angle
|
Chris@16
|
55 std::vector<std::string> location; // Up to two identifiers
|
Chris@16
|
56
|
Chris@16
|
57 friend inline bool operator==(const node_and_port& a, const node_and_port& b) {
|
Chris@16
|
58 return a.name == b.name &&
|
Chris@16
|
59 a.angle == b.angle &&
|
Chris@16
|
60 a.location == b.location;
|
Chris@16
|
61 }
|
Chris@16
|
62
|
Chris@16
|
63 friend inline bool operator<(const node_and_port& a, const node_and_port& b) {
|
Chris@16
|
64 if (a.name != b.name) return a.name < b.name;
|
Chris@16
|
65 if (a.angle != b.angle) return a.angle < b.angle;
|
Chris@16
|
66 return a.location < b.location;
|
Chris@16
|
67 }
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 struct edge_info {
|
Chris@16
|
71 node_and_port source;
|
Chris@16
|
72 node_and_port target;
|
Chris@16
|
73 properties props;
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76 struct parser_result {
|
Chris@16
|
77 bool graph_is_directed;
|
Chris@16
|
78 bool graph_is_strict;
|
Chris@16
|
79 std::map<node_name, properties> nodes; // Global set
|
Chris@16
|
80 std::vector<edge_info> edges;
|
Chris@16
|
81 std::map<subgraph_name, properties> graph_props; // Root and subgraphs
|
Chris@16
|
82 };
|
Chris@16
|
83
|
Chris@16
|
84 // The actual parser, from libs/graph/src/read_graphviz_new.cpp
|
Chris@16
|
85 void parse_graphviz_from_string(const std::string& str, parser_result& result, bool want_directed);
|
Chris@16
|
86
|
Chris@16
|
87 // Translate from those results to a graph
|
Chris@16
|
88 void translate_results_to_graph(const parser_result& r, ::boost::detail::graph::mutate_graph* mg);
|
Chris@16
|
89
|
Chris@16
|
90 } // namespace read_graphviz_detail
|
Chris@16
|
91
|
Chris@16
|
92 namespace detail {
|
Chris@16
|
93 namespace graph {
|
Chris@16
|
94 BOOST_GRAPH_DECL bool read_graphviz_new(const std::string& str, boost::detail::graph::mutate_graph* mg);
|
Chris@16
|
95 } // end namespace graph
|
Chris@16
|
96 } // end namespace detail
|
Chris@16
|
97
|
Chris@16
|
98 template <typename MutableGraph>
|
Chris@16
|
99 bool read_graphviz_new(const std::string& str,
|
Chris@16
|
100 MutableGraph& graph, boost::dynamic_properties& dp,
|
Chris@16
|
101 std::string const& node_id = "node_id") {
|
Chris@16
|
102 boost::detail::graph::mutate_graph_impl<MutableGraph> mg(graph, dp, node_id);
|
Chris@16
|
103 return detail::graph::read_graphviz_new(str, &mg);
|
Chris@16
|
104 }
|
Chris@16
|
105
|
Chris@16
|
106 } // namespace boost
|
Chris@16
|
107
|
Chris@16
|
108 #endif // BOOST_READ_GRAPHVIZ_NEW_HPP
|