• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
7<title>Boost write_graphml</title>
8<link rel="stylesheet" href="../../../rst.css" type="text/css" />
9</head>
10<body>
11<div class="document" id="logo-write-graphml">
12<h1 class="title"><a class="reference external" href="../../../index.htm"><img align="middle" alt="Boost" class="align-middle" src="../../../boost.png" /></a> <tt class="docutils literal"><span class="pre">write_graphml</span></tt></h1>
13
14<!-- Copyright (C) 2006  Tiago de Paula Peixoto <tiago@forked.de>
15
16Distributed under the Boost Software License, Version 1.0. (See
17accompanying file LICENSE_1_0.txt or copy at
18http://www.boost.org/LICENSE_1_0.txt)
19
20Authors: Tiago de Paula Peixoto -->
21<pre class="literal-block">
22template&lt;typename Graph&gt;
23void
24write_graphml(std::ostream&amp; out, const Graph&amp; g, const dynamic_properties&amp; dp,
25              bool ordered_vertices=false);
26
27template&lt;typename Graph, typename VertexIndexMap&gt;
28void
29write_graphml(std::ostream&amp; out, const Graph&amp; g, VertexIndexMap vertex_index,
30              const dynamic_properties&amp; dp, bool ordered_vertices=false);
31</pre>
32<p>This is to write a BGL graph object into an output stream in the
33<a class="reference external" href="http://graphml.graphdrawing.org/">GraphML</a> format.  Both overloads of <tt class="docutils literal"><span class="pre">write_graphml</span></tt> will emit all of
34the properties stored in the <a class="reference external" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object, thereby
35retaining the properties that have been read in through the dual
36function <a class="reference external" href="read_graphml.html">read_graphml</a>. The second overload must be used when the
37graph doesn't have an internal vertex index map, which must then be
38supplied with the appropriate parameter.</p>
39<div class="contents topic" id="contents">
40<p class="topic-title first">Contents</p>
41<ul class="simple">
42<li><a class="reference internal" href="#where-defined" id="id2">Where Defined</a></li>
43<li><a class="reference internal" href="#parameters" id="id3">Parameters</a></li>
44<li><a class="reference internal" href="#example" id="id4">Example</a></li>
45<li><a class="reference internal" href="#see-also" id="id5">See Also</a></li>
46<li><a class="reference internal" href="#notes" id="id6">Notes</a></li>
47</ul>
48</div>
49<div class="section" id="where-defined">
50<h1><a class="toc-backref" href="#id2">Where Defined</a></h1>
51<p><tt class="docutils literal"><span class="pre">&lt;boost/graph/graphml.hpp&gt;</span></tt></p>
52</div>
53<div class="section" id="parameters">
54<h1><a class="toc-backref" href="#id3">Parameters</a></h1>
55<dl class="docutils">
56<dt>OUT: <tt class="docutils literal"><span class="pre">std::ostream&amp;</span> <span class="pre">out</span></tt></dt>
57<dd>A standard <tt class="docutils literal"><span class="pre">std::ostream</span></tt> object.</dd>
58<dt>IN: <tt class="docutils literal"><span class="pre">VertexListGraph&amp;</span> <span class="pre">g</span></tt></dt>
59<dd>A directed or undirected graph.  The
60graph's type must be a model of <a class="reference external" href="VertexListGraph.html">VertexListGraph</a>. If the graph
61doesn't have an internal <tt class="docutils literal"><span class="pre">vertex_index</span></tt> property map, one
62must be supplied with the vertex_index parameter.</dd>
63<dt>IN: <tt class="docutils literal"><span class="pre">VertexIndexMap</span> <span class="pre">vertex_index</span></tt></dt>
64<dd>A vertex property map containing the indexes in the range
65[0,num_vertices(g)].</dd>
66<dt>IN: <tt class="docutils literal"><span class="pre">dynamic_properties&amp;</span> <span class="pre">dp</span></tt></dt>
67<dd>Contains all of the vertex, edge, and graph properties that should be
68emitted by the GraphML writer.</dd>
69<dt>IN: <tt class="docutils literal"><span class="pre">bool</span> <span class="pre">ordered_vertices</span></tt></dt>
70<dd>This tells whether or not the order of the vertices from vertices(g)
71matches the order of the indexes. If <tt class="docutils literal"><span class="pre">true</span></tt>, the <tt class="docutils literal"><span class="pre">parse.nodeids</span></tt>
72graph attribute will be set to <tt class="docutils literal"><span class="pre">canonical</span></tt>. Otherwise it will be
73set to <tt class="docutils literal"><span class="pre">free</span></tt>.</dd>
74</dl>
75</div>
76<div class="section" id="example">
77<h1><a class="toc-backref" href="#id4">Example</a></h1>
78<p>This example demonstrates using BGL-GraphML interface to write
79a BGL graph into a GraphML format file.</p>
80<pre class="literal-block">
81enum files_e { dax_h, yow_h, boz_h, zow_h, foo_cpp,
82               foo_o, bar_cpp, bar_o, libfoobar_a,
83               zig_cpp, zig_o, zag_cpp, zag_o,
84               libzigzag_a, killerapp, N };
85const char* name[] = { &quot;dax.h&quot;, &quot;yow.h&quot;, &quot;boz.h&quot;, &quot;zow.h&quot;, &quot;foo.cpp&quot;,
86                       &quot;foo.o&quot;, &quot;bar.cpp&quot;, &quot;bar.o&quot;, &quot;libfoobar.a&quot;,
87                       &quot;zig.cpp&quot;, &quot;zig.o&quot;, &quot;zag.cpp&quot;, &quot;zag.o&quot;,
88                       &quot;libzigzag.a&quot;, &quot;killerapp&quot; };
89
90int main(int,char*[])
91{
92    typedef pair&lt;int,int&gt; Edge;
93    Edge used_by[] = {
94        Edge(dax_h, foo_cpp), Edge(dax_h, bar_cpp), Edge(dax_h, yow_h),
95        Edge(yow_h, bar_cpp), Edge(yow_h, zag_cpp),
96        Edge(boz_h, bar_cpp), Edge(boz_h, zig_cpp), Edge(boz_h, zag_cpp),
97        Edge(zow_h, foo_cpp),
98        Edge(foo_cpp, foo_o),
99        Edge(foo_o, libfoobar_a),
100        Edge(bar_cpp, bar_o),
101        Edge(bar_o, libfoobar_a),
102        Edge(libfoobar_a, libzigzag_a),
103        Edge(zig_cpp, zig_o),
104        Edge(zig_o, libzigzag_a),
105        Edge(zag_cpp, zag_o),
106        Edge(zag_o, libzigzag_a),
107        Edge(libzigzag_a, killerapp)
108     };
109
110    const int nedges = sizeof(used_by)/sizeof(Edge);
111
112    typedef adjacency_list&lt; vecS, vecS, directedS,
113        property&lt; vertex_color_t, string &gt;,
114        property&lt; edge_weight_t, int &gt;
115        &gt; Graph;
116    Graph g(used_by, used_by + nedges, N);
117
118    graph_traits&lt;Graph&gt;::vertex_iterator v, v_end;
119    for (boost::tie(v,v_end) = vertices(g); v != v_end; ++v)
120        put(vertex_color_t(), g, *v, name[*v]);
121
122    graph_traits&lt;Graph&gt;::edge_iterator e, e_end;
123    for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
124        put(edge_weight_t(), g, *e, 3);
125
126    dynamic_properties dp;
127    dp.property(&quot;name&quot;, get(vertex_color_t(), g));
128    dp.property(&quot;weight&quot;, get(edge_weight_t(), g));
129
130    write_graphml(std::cout, g, dp, true);
131 }
132</pre>
133<p>The output will be:</p>
134<pre class="literal-block">
135&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
136&lt;graphml xmlns=&quot;http://graphml.graphdrawing.org/xmlns/graphml&quot;  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://graphml.graphdrawing.org/xmlns/graphml http://graphml.graphdrawing.org/xmlns/graphml/graphml-attributes-1.0rc.xsd&quot;&gt;
137  &lt;key id=&quot;key0&quot; for=&quot;node&quot; attr.name=&quot;name&quot; attr.type=&quot;string&quot; /&gt;
138  &lt;key id=&quot;key1&quot; for=&quot;edge&quot; attr.name=&quot;weight&quot; attr.type=&quot;int&quot; /&gt;
139  &lt;graph id=&quot;G&quot; edgedefault=&quot;directed&quot; parse.nodeids=&quot;canonical&quot; parse.edgeids=&quot;canonical&quot; parse.order=&quot;nodesfirst&quot;&gt;
140    &lt;node id=&quot;n0&quot;&gt;
141      &lt;data key=&quot;key0&quot;&gt;dax.h&lt;/data&gt;
142    &lt;/node&gt;
143    &lt;node id=&quot;n1&quot;&gt;
144      &lt;data key=&quot;key0&quot;&gt;yow.h&lt;/data&gt;
145    &lt;/node&gt;
146    &lt;node id=&quot;n2&quot;&gt;
147      &lt;data key=&quot;key0&quot;&gt;boz.h&lt;/data&gt;
148    &lt;/node&gt;
149    &lt;node id=&quot;n3&quot;&gt;
150      &lt;data key=&quot;key0&quot;&gt;zow.h&lt;/data&gt;
151    &lt;/node&gt;
152    &lt;node id=&quot;n4&quot;&gt;
153      &lt;data key=&quot;key0&quot;&gt;foo.cpp&lt;/data&gt;
154    &lt;/node&gt;
155    &lt;node id=&quot;n5&quot;&gt;
156      &lt;data key=&quot;key0&quot;&gt;foo.o&lt;/data&gt;
157    &lt;/node&gt;
158    &lt;node id=&quot;n6&quot;&gt;
159      &lt;data key=&quot;key0&quot;&gt;bar.cpp&lt;/data&gt;
160    &lt;/node&gt;
161    &lt;node id=&quot;n7&quot;&gt;
162      &lt;data key=&quot;key0&quot;&gt;bar.o&lt;/data&gt;
163    &lt;/node&gt;
164    &lt;node id=&quot;n8&quot;&gt;
165      &lt;data key=&quot;key0&quot;&gt;libfoobar.a&lt;/data&gt;
166    &lt;/node&gt;
167    &lt;node id=&quot;n9&quot;&gt;
168      &lt;data key=&quot;key0&quot;&gt;zig.cpp&lt;/data&gt;
169    &lt;/node&gt;
170    &lt;node id=&quot;n10&quot;&gt;
171      &lt;data key=&quot;key0&quot;&gt;zig.o&lt;/data&gt;
172    &lt;/node&gt;
173    &lt;node id=&quot;n11&quot;&gt;
174      &lt;data key=&quot;key0&quot;&gt;zag.cpp&lt;/data&gt;
175    &lt;/node&gt;
176    &lt;node id=&quot;n12&quot;&gt;
177      &lt;data key=&quot;key0&quot;&gt;zag.o&lt;/data&gt;
178    &lt;/node&gt;
179    &lt;node id=&quot;n13&quot;&gt;
180      &lt;data key=&quot;key0&quot;&gt;libzigzag.a&lt;/data&gt;
181    &lt;/node&gt;
182    &lt;node id=&quot;n14&quot;&gt;
183      &lt;data key=&quot;key0&quot;&gt;killerapp&lt;/data&gt;
184    &lt;/node&gt;
185    &lt;edge id=&quot;e0&quot; source=&quot;n0&quot; target=&quot;n4&quot;&gt;
186      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
187    &lt;/edge&gt;
188    &lt;edge id=&quot;e1&quot; source=&quot;n0&quot; target=&quot;n6&quot;&gt;
189      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
190    &lt;/edge&gt;
191    &lt;edge id=&quot;e2&quot; source=&quot;n0&quot; target=&quot;n1&quot;&gt;
192      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
193    &lt;/edge&gt;
194    &lt;edge id=&quot;e3&quot; source=&quot;n1&quot; target=&quot;n6&quot;&gt;
195      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
196    &lt;/edge&gt;
197    &lt;edge id=&quot;e4&quot; source=&quot;n1&quot; target=&quot;n11&quot;&gt;
198      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
199    &lt;/edge&gt;
200    &lt;edge id=&quot;e5&quot; source=&quot;n2&quot; target=&quot;n6&quot;&gt;
201      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
202    &lt;/edge&gt;
203    &lt;edge id=&quot;e6&quot; source=&quot;n2&quot; target=&quot;n9&quot;&gt;
204       &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
205    &lt;/edge&gt;
206    &lt;edge id=&quot;e7&quot; source=&quot;n2&quot; target=&quot;n11&quot;&gt;
207      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
208    &lt;/edge&gt;
209    &lt;edge id=&quot;e8&quot; source=&quot;n3&quot; target=&quot;n4&quot;&gt;
210      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
211    &lt;/edge&gt;
212    &lt;edge id=&quot;e9&quot; source=&quot;n4&quot; target=&quot;n5&quot;&gt;
213      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
214    &lt;/edge&gt;
215    &lt;edge id=&quot;e10&quot; source=&quot;n5&quot; target=&quot;n8&quot;&gt;
216      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
217    &lt;/edge&gt;
218    &lt;edge id=&quot;e11&quot; source=&quot;n6&quot; target=&quot;n7&quot;&gt;
219      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
220    &lt;/edge&gt;
221    &lt;edge id=&quot;e12&quot; source=&quot;n7&quot; target=&quot;n8&quot;&gt;
222      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
223    &lt;/edge&gt;
224    &lt;edge id=&quot;e13&quot; source=&quot;n8&quot; target=&quot;n13&quot;&gt;
225      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
226    &lt;/edge&gt;
227    &lt;edge id=&quot;e14&quot; source=&quot;n9&quot; target=&quot;n10&quot;&gt;
228      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
229    &lt;/edge&gt;
230    &lt;edge id=&quot;e15&quot; source=&quot;n10&quot; target=&quot;n13&quot;&gt;
231      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
232    &lt;/edge&gt;
233    &lt;edge id=&quot;e16&quot; source=&quot;n11&quot; target=&quot;n12&quot;&gt;
234      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
235    &lt;/edge&gt;
236    &lt;edge id=&quot;e17&quot; source=&quot;n12&quot; target=&quot;n13&quot;&gt;
237      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
238    &lt;/edge&gt;
239    &lt;edge id=&quot;e18&quot; source=&quot;n13&quot; target=&quot;n14&quot;&gt;
240      &lt;data key=&quot;key1&quot;&gt;3&lt;/data&gt;
241    &lt;/edge&gt;
242  &lt;/graph&gt;
243&lt;/graphml&gt;
244</pre>
245</div>
246<div class="section" id="see-also">
247<h1><a class="toc-backref" href="#id5">See Also</a></h1>
248<p>_read_graphml</p>
249</div>
250<div class="section" id="notes">
251<h1><a class="toc-backref" href="#id6">Notes</a></h1>
252<blockquote>
253<ul class="simple">
254<li>Note that you can use GraphML file write facilities without linking
255against the <tt class="docutils literal"><span class="pre">boost_graph</span></tt> library.</li>
256</ul>
257</blockquote>
258</div>
259</div>
260<div class="footer">
261<hr class="footer" />
262Generated on: 2009-06-12 00:41 UTC.
263Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
264
265</div>
266</body>
267</html>
268