1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
5 | <meta name="generator" content="Docutils 0.3.3: http://docutils.sourceforge.net/" /> |
---|
6 | <title>Boost read_graphviz</title> |
---|
7 | <link rel="stylesheet" href="default.css" type="text/css" /> |
---|
8 | </head> |
---|
9 | <body> |
---|
10 | <h1 class="title"><a class="reference" href="../../../index.htm"><img align="middle" alt="Boost" src="../../../boost.png" /></a> <tt class="literal"><span class="pre">read_graphviz</span></tt></h1> |
---|
11 | <div class="document" id="logo-read-graphviz"> |
---|
12 | <pre class="literal-block"> |
---|
13 | template <typename MutableGraph> |
---|
14 | bool read_graphviz(std::istream& in, MutableGraph& graph, |
---|
15 | dynamic_properties& dp, |
---|
16 | const std::string& node_id = "node_id"); |
---|
17 | |
---|
18 | // Only available if BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS is defined |
---|
19 | template <typename MultiPassIterator, typename MutableGraph> |
---|
20 | bool read_graphviz(MultiPassIterator begin, MultiPassIterator end, |
---|
21 | MutableGraph& graph, dynamic_properties& dp, |
---|
22 | const std::string& node_id = "node_id"); |
---|
23 | |
---|
24 | // Deprecated GraphViz readers |
---|
25 | void read_graphviz(const std::string& file, GraphvizDigraph& g); |
---|
26 | void read_graphviz(FILE* file, GraphvizDigraph& g); |
---|
27 | void read_graphviz(const std::string& file, GraphvizGraph& g); |
---|
28 | void read_graphviz(FILE* file, GraphvizGraph& g); |
---|
29 | </pre> |
---|
30 | <p>The <tt class="literal"><span class="pre">read_graphviz</span></tt> function interprets a graph described using the |
---|
31 | <a class="reference" href="http://graphviz.org/">GraphViz</a> DOT language and builds a BGL graph that captures that |
---|
32 | description. Using this function, you can initialize a graph using |
---|
33 | data stored as text. To use the iterator version of <tt class="literal"><span class="pre">read_graphviz</span></tt>, |
---|
34 | you will need to define the macro BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS |
---|
35 | before including the header <tt class="literal"><span class="pre"><boost/graph/graphviz.hpp></span></tt>. Doing so |
---|
36 | may greatly increase the amount of time required to compile the |
---|
37 | GraphViz reader.</p> |
---|
38 | <p>The DOT language can specify both directed and undirected graphs, and |
---|
39 | <tt class="literal"><span class="pre">read_graphviz</span></tt> differentiates between the two. One must pass |
---|
40 | <tt class="literal"><span class="pre">read_graphviz</span></tt> an undirected graph when reading an undirected graph; |
---|
41 | the same is true for directed graphs. Furthermore, <tt class="literal"><span class="pre">read_graphviz</span></tt> |
---|
42 | will throw an exception if it encounters parallel edges and cannot add |
---|
43 | them to the graph.</p> |
---|
44 | <p>To handle properties expressed in the DOT language, <tt class="literal"><span class="pre">read_graphviz</span></tt> |
---|
45 | takes a <a class="reference" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object and operates on its collection of |
---|
46 | property maps. The reader passes all the properties encountered to |
---|
47 | this object, using the GraphViz string keys as the property keys. |
---|
48 | Furthermore, <tt class="literal"><span class="pre">read_graphviz</span></tt> stores node identifier names under the |
---|
49 | vertex property map named node_id.</p> |
---|
50 | <dl> |
---|
51 | <dt>Requirements:</dt> |
---|
52 | <dd><ul class="first last simple"> |
---|
53 | <li>The type of the graph must model the <a class="reference" href="MutableGraph.html">Mutable Graph</a> concept.</li> |
---|
54 | <li>The type of the iterator must model the <a class="reference" href="../../iterator/index.html">Multi-Pass Iterator</a> |
---|
55 | concept.</li> |
---|
56 | <li>The property map value types must be default-constructible.</li> |
---|
57 | </ul> |
---|
58 | </dd> |
---|
59 | </dl> |
---|
60 | <div class="contents topic" id="contents"> |
---|
61 | <p class="topic-title first"><a name="contents">Contents</a></p> |
---|
62 | <ul class="simple"> |
---|
63 | <li><a class="reference" href="#where-defined" id="id2" name="id2">Where Defined</a></li> |
---|
64 | <li><a class="reference" href="#exceptions" id="id3" name="id3">Exceptions</a></li> |
---|
65 | <li><a class="reference" href="#building-the-graphviz-readers" id="id4" name="id4">Building the GraphViz Readers</a></li> |
---|
66 | <li><a class="reference" href="#deprecated-readers" id="id5" name="id5">Deprecated Readers</a></li> |
---|
67 | <li><a class="reference" href="#notes" id="id6" name="id6">Notes</a></li> |
---|
68 | <li><a class="reference" href="#see-also" id="id7" name="id7">See Also</a></li> |
---|
69 | <li><a class="reference" href="#future-work" id="id8" name="id8">Future Work</a></li> |
---|
70 | </ul> |
---|
71 | </div> |
---|
72 | <div class="section" id="where-defined"> |
---|
73 | <h1><a class="toc-backref" href="#id2" name="where-defined">Where Defined</a></h1> |
---|
74 | <p><tt class="literal"><span class="pre"><boost/graph/graphviz.hpp></span></tt></p> |
---|
75 | </div> |
---|
76 | <div class="section" id="exceptions"> |
---|
77 | <h1><a class="toc-backref" href="#id3" name="exceptions">Exceptions</a></h1> |
---|
78 | <pre class="literal-block"> |
---|
79 | struct graph_exception : public std::exception { |
---|
80 | virtual ~graph_exception() throw(); |
---|
81 | virtual const char* what() const throw() = 0; |
---|
82 | }; |
---|
83 | |
---|
84 | struct bad_parallel_edge : public graph_exception { |
---|
85 | std::string from; |
---|
86 | std::string to; |
---|
87 | |
---|
88 | bad_parallel_edge(const std::string&, const std::string&); |
---|
89 | virtual ~bad_parallel_edge() throw(); |
---|
90 | const char* what() const throw(); |
---|
91 | }; |
---|
92 | |
---|
93 | struct directed_graph_error : public graph_exception { |
---|
94 | virtual ~directed_graph_error() throw(); |
---|
95 | virtual const char* what() const throw(); |
---|
96 | }; |
---|
97 | |
---|
98 | struct undirected_graph_error : public graph_exception { |
---|
99 | virtual ~undirected_graph_error() throw(); |
---|
100 | virtual const char* what() const throw(); |
---|
101 | }; |
---|
102 | </pre> |
---|
103 | <p>Under certain circumstances, <tt class="literal"><span class="pre">read_graphviz</span></tt> will throw one of the |
---|
104 | above exceptions. The three concrete exceptions can all be caught |
---|
105 | using the general <tt class="literal"><span class="pre">graph_exception</span></tt> moniker when greater precision |
---|
106 | is not needed. In addition, all of the above exceptions derive from |
---|
107 | the standard <tt class="literal"><span class="pre">std::exception</span></tt> for even more generalized error |
---|
108 | handling.</p> |
---|
109 | <p>The <tt class="literal"><span class="pre">bad_parallel_edge</span></tt> exception is thrown when an attempt to add a |
---|
110 | parallel edge to the supplied MutableGraph fails. The DOT language |
---|
111 | supports parallel edges, but some BGL-compatible graph types do not. |
---|
112 | One example of such a graph is <tt class="literal"><span class="pre">boost::adjacency_list<setS,vecS></span></tt>, |
---|
113 | which allows at most one edge between any two vertices.</p> |
---|
114 | <p>The <tt class="literal"><span class="pre">directed_graph_error</span></tt> exception occurs when an undirected graph |
---|
115 | type is passed to <tt class="literal"><span class="pre">read_graph</span></tt> but the textual representation of the |
---|
116 | graph is directed, as indicated by the <tt class="literal"><span class="pre">digraph</span></tt> keyword in the DOT |
---|
117 | language.</p> |
---|
118 | <p>The <tt class="literal"><span class="pre">undirected_graph_error</span></tt> exception occurs when a directed graph |
---|
119 | type is passed to <tt class="literal"><span class="pre">read_graph</span></tt> but the textual representation of the |
---|
120 | graph is undirected, as indicated by the <tt class="literal"><span class="pre">graph</span></tt> keyword in the DOT |
---|
121 | language.</p> |
---|
122 | </div> |
---|
123 | <div class="section" id="building-the-graphviz-readers"> |
---|
124 | <h1><a class="toc-backref" href="#id4" name="building-the-graphviz-readers">Building the GraphViz Readers</a></h1> |
---|
125 | <p>To use the GraphViz readers, you will need to build and link against |
---|
126 | the "bgl-viz" library. The library can be built by following the |
---|
127 | <a class="reference" href="../../../more/getting_started.html#Build_Install">Boost Jam Build Instructions</a> for the subdirectory <tt class="literal"><span class="pre">libs/graph/build</span></tt>.</p> |
---|
128 | </div> |
---|
129 | <div class="section" id="deprecated-readers"> |
---|
130 | <h1><a class="toc-backref" href="#id5" name="deprecated-readers">Deprecated Readers</a></h1> |
---|
131 | <p>The deprecated readers do not provide exceptions on error (they |
---|
132 | abort), they require the use of one of the predefined graph types |
---|
133 | (<tt class="literal"><span class="pre">GraphvizDigraph</span></tt> or <tt class="literal"><span class="pre">GraphvizGraph</span></tt>), and they do not support |
---|
134 | arbitrary properties. They will be removed in a future Boost version.</p> |
---|
135 | </div> |
---|
136 | <div class="section" id="notes"> |
---|
137 | <h1><a class="toc-backref" href="#id6" name="notes">Notes</a></h1> |
---|
138 | <blockquote> |
---|
139 | <ul class="simple"> |
---|
140 | <li>The <tt class="literal"><span class="pre">read_graphviz</span></tt> function does not use any code from the |
---|
141 | GraphViz distribution to interpret the DOT Language. Rather, the |
---|
142 | implementation was based on documentation found on the GraphViz web |
---|
143 | site, as well as experiments run using the dot application. The |
---|
144 | resulting interpretation may be subtly different from dot for some |
---|
145 | corner cases that are not well specified.</li> |
---|
146 | <li><tt class="literal"><span class="pre">read_graphviz</span></tt> treats subgraphs as syntactic sugar. It does not |
---|
147 | reflect subgraphs as actual entities in the BGL. Rather, they are |
---|
148 | used to shorten some edge definitions as well as to give a subset |
---|
149 | of all nodes or edges certain properties. For example, the |
---|
150 | DOT graphs <tt class="literal"><span class="pre">digraph</span> <span class="pre">{</span> <span class="pre">a</span> <span class="pre">-></span> <span class="pre">subgraph</span> <span class="pre">{b</span> <span class="pre">-></span> <span class="pre">c}</span> <span class="pre">-></span> <span class="pre">e</span> <span class="pre">}</span></tt> and |
---|
151 | <tt class="literal"><span class="pre">digraph</span> <span class="pre">{</span> <span class="pre">a</span> <span class="pre">-></span> <span class="pre">b</span> <span class="pre">-></span> <span class="pre">e</span> <span class="pre">;</span> <span class="pre">a</span> <span class="pre">-></span> <span class="pre">c</span> <span class="pre">-></span> <span class="pre">e</span> <span class="pre">;</span> <span class="pre">b</span> <span class="pre">-></span> <span class="pre">c}</span></tt> are equivalent.</li> |
---|
152 | <li>Subgraph IDs refer to subgraphs defined earlier in the graph |
---|
153 | description. Undefined subgraphs behave as empty subgraphs |
---|
154 | (<tt class="literal"><span class="pre">{}</span></tt>).</li> |
---|
155 | <li>On successful reading of a graph, every vertex and edge will have |
---|
156 | an associated value for every respective edge and vertex property |
---|
157 | encountered while interpreting the graph. These values will be set |
---|
158 | using the <tt class="literal"><span class="pre">dynamic_properties</span></tt> object. Some properties may be |
---|
159 | <tt class="literal"><span class="pre">put</span></tt> multiple times during the course of reading in order to |
---|
160 | ensure the same semantics as the GraphViz tools. Those edges and |
---|
161 | vertices that are not explicitly given a value for a property (and that |
---|
162 | property has no default) will be |
---|
163 | given the default constructed value of the value type. <strong>Be sure |
---|
164 | that property map value types are default constructible.</strong></li> |
---|
165 | </ul> |
---|
166 | </blockquote> |
---|
167 | </div> |
---|
168 | <div class="section" id="see-also"> |
---|
169 | <h1><a class="toc-backref" href="#id7" name="see-also">See Also</a></h1> |
---|
170 | <p><a class="reference" href="write-graphviz.html">write_graphviz</a></p> |
---|
171 | </div> |
---|
172 | <div class="section" id="future-work"> |
---|
173 | <h1><a class="toc-backref" href="#id8" name="future-work">Future Work</a></h1> |
---|
174 | <blockquote> |
---|
175 | <ul class="simple"> |
---|
176 | <li>Currently the parser relies upon lowercase language keywords |
---|
177 | (i.e. "graph", "edge", etc.). The DOT Language specifies that they |
---|
178 | are case-insensitive. This change should be easy given the proper |
---|
179 | understanding of Spirit and some free time (hint hint!)</li> |
---|
180 | <li>The parser currently does not handle continuation lines as defined |
---|
181 | in the DOT Language. Some more sophisticated parsing of identifiers |
---|
182 | (so-called "ID" in the source) is required to support this.</li> |
---|
183 | </ul> |
---|
184 | </blockquote> |
---|
185 | </div> |
---|
186 | </div> |
---|
187 | <hr class="footer" /> |
---|
188 | <div class="footer"> |
---|
189 | Generated on: 2005-03-23 18:37 UTC. |
---|
190 | </div> |
---|
191 | </body> |
---|
192 | </html> |
---|