1
// Copyright 2004-9 Trustees of Indiana University
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)
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
13
// Based on the grammar found at:
14
// http://www.graphviz.org/cvs/doc/info/lang.html
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
20
// See documentation for this code at:
21
// http://www.boost.org/libs/graph/doc/read-graphviz.html
24
// Author: Jeremiah Willcock
28
#ifndef BOOST_READ_GRAPHVIZ_NEW_HPP
29
#define BOOST_READ_GRAPHVIZ_NEW_HPP
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>
46
namespace read_graphviz_detail {
47
typedef std::string node_name;
48
typedef std::string subgraph_name;
50
typedef std::map<std::string, std::string> properties;
52
struct node_and_port {
54
std::string angle; // Or empty if no angle
55
std::vector<std::string> location; // Up to two identifiers
57
friend inline bool operator==(const node_and_port& a, const node_and_port& b) {
58
return a.name == b.name &&
60
a.location == b.location;
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;
76
struct parser_result {
77
bool graph_is_directed;
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
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);
87
// Translate from those results to a graph
88
void translate_results_to_graph(const parser_result& r, ::boost::detail::graph::mutate_graph* mg);
90
} // namespace read_graphviz_detail
92
// This is also in boost/graph/graphviz.hpp
95
BOOST_GRAPH_DECL bool read_graphviz(const std::string& str, boost::detail::graph::mutate_graph* mg);
96
} // end namespace graph
97
} // end namespace detail
99
template <typename MutableGraph>
100
bool read_graphviz(const std::string& str,
101
MutableGraph& graph, boost::dynamic_properties& dp,
102
std::string const& node_id = "node_id") {
103
boost::detail::graph::mutate_graph_impl<MutableGraph> mg(graph, dp, node_id);
104
return detail::graph::read_graphviz(str, &mg);
107
template <typename InputIter, typename MutableGraph>
108
bool read_graphviz(InputIter begin, InputIter end,
109
MutableGraph& graph, boost::dynamic_properties& dp,
110
std::string const& node_id = "node_id") {
111
return read_graphviz(std::string(begin, end), graph, dp, node_id);
116
#endif // BOOST_READ_GRAPHVIZ_NEW_HPP