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