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