read_graphml.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 read_graphml</title>
  8. <link rel="stylesheet" href="../../../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="logo-read-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">read_graphml</span></tt></h1>
  13. <!-- Copyright (C) 2006 Tiago de Paula Peixoto <tiago@forked.de>
  14. Distributed under the Boost Software License, Version 1.0. (See
  15. accompanying file LICENSE_1_0.txt or copy at
  16. http://www.boost.org/LICENSE_1_0.txt)
  17. Authors: Tiago de Paula Peixoto -->
  18. <pre class="literal-block">
  19. void read_graphml(std::istream&amp; in, MutableGraph&amp; graph,
  20. dynamic_properties&amp; dp, size_t graph_index = 0);
  21. </pre>
  22. <p>The <tt class="docutils literal"><span class="pre">read_graphml</span></tt> function interprets a graph described using the
  23. <a class="reference external" href="http://graphml.graphdrawing.org/">GraphML</a> format and builds a BGL graph that captures that
  24. description. Using this function, you can initialize a graph using
  25. data stored as text.</p>
  26. <p>The GraphML format can specify both directed and undirected graphs, and
  27. <tt class="docutils literal"><span class="pre">read_graphml</span></tt> differentiates between the two. One must pass
  28. <tt class="docutils literal"><span class="pre">read_graphml</span></tt> an undirected graph when reading an undirected graph;
  29. the same is true for directed graphs. Furthermore, <tt class="docutils literal"><span class="pre">read_graphml</span></tt>
  30. will throw an exception if it encounters parallel edges and cannot add
  31. them to the graph.</p>
  32. <p>To handle attributes expressed in the GraphML format, <tt class="docutils literal"><span class="pre">read_graphml</span></tt>
  33. takes a <a class="reference external" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object and operates on its collection of
  34. property maps. The reader passes all the properties encountered to
  35. this object, using the GraphML attribute names as the property names,
  36. and with the appropriate C++ value type based on the GraphML attribute type
  37. definition. Graph properties are also set with the same
  38. <a class="reference external" href="../../property_map/doc/dynamic_property_map.html">dynamic_properties</a> object, where the key type is the type of the graph itself.</p>
  39. <p>If the file contains multiple graphs, the <tt class="docutils literal"><span class="pre">graph_index</span></tt> parameter controls
  40. which graph will be loaded. It defaults to <tt class="docutils literal"><span class="pre">0</span></tt>, meaning that the first graph
  41. in the file will be loaded. If <tt class="docutils literal"><span class="pre">graph_index</span></tt> is greater than or equal to the
  42. number of graphs in the file, an empty graph will be returned.</p>
  43. <dl class="docutils">
  44. <dt>Requirements:</dt>
  45. <dd><ul class="first last simple">
  46. <li>The type of the graph must model the <a class="reference external" href="MutableGraph.html">Mutable Graph</a> concept.</li>
  47. <li>The type of the iterator must model the <a class="reference external" href="../../iterator/index.html">Multi-Pass Iterator</a>
  48. concept.</li>
  49. <li>The property map value types must be default-constructible.</li>
  50. </ul>
  51. </dd>
  52. </dl>
  53. <div class="contents topic" id="contents">
  54. <p class="topic-title first">Contents</p>
  55. <ul class="simple">
  56. <li><a class="reference internal" href="#where-defined" id="id2">Where Defined</a></li>
  57. <li><a class="reference internal" href="#exceptions" id="id3">Exceptions</a></li>
  58. <li><a class="reference internal" href="#building-the-graphml-reader" id="id4">Building the GraphML reader</a></li>
  59. <li><a class="reference internal" href="#notes" id="id5">Notes</a></li>
  60. <li><a class="reference internal" href="#see-also" id="id6">See Also</a></li>
  61. </ul>
  62. </div>
  63. <div class="section" id="where-defined">
  64. <h1><a class="toc-backref" href="#id2">Where Defined</a></h1>
  65. <p><tt class="docutils literal"><span class="pre">&lt;boost/graph/graphml.hpp&gt;</span></tt></p>
  66. </div>
  67. <div class="section" id="exceptions">
  68. <h1><a class="toc-backref" href="#id3">Exceptions</a></h1>
  69. <pre class="literal-block">
  70. struct graph_exception : public std::exception {
  71. virtual ~graph_exception() throw();
  72. virtual const char* what() const throw() = 0;
  73. };
  74. struct bad_parallel_edge : public graph_exception {
  75. std::string from;
  76. std::string to;
  77. bad_parallel_edge(const std::string&amp;, const std::string&amp;);
  78. virtual ~bad_parallel_edge() throw();
  79. const char* what() const throw();
  80. };
  81. struct directed_graph_error : public graph_exception {
  82. virtual ~directed_graph_error() throw();
  83. virtual const char* what() const throw();
  84. };
  85. struct undirected_graph_error : public graph_exception {
  86. virtual ~undirected_graph_error() throw();
  87. virtual const char* what() const throw();
  88. };
  89. struct parse_error : public graph_exception {
  90. parse_error(const std::string&amp;);
  91. virtual ~parse_error() throw() {}
  92. virtual const char* what() const throw();
  93. std::string statement;
  94. std::string error;
  95. };
  96. </pre>
  97. <p>Under certain circumstances, <tt class="docutils literal"><span class="pre">read_graphml</span></tt> will throw one of the
  98. above exceptions. The three concrete exceptions can all be caught
  99. using the general <tt class="docutils literal"><span class="pre">graph_exception</span></tt> moniker when greater precision
  100. is not needed. In addition, all of the above exceptions derive from
  101. the standard <tt class="docutils literal"><span class="pre">std::exception</span></tt> for even more generalized error
  102. handling.</p>
  103. <p>The <tt class="docutils literal"><span class="pre">bad_parallel_edge</span></tt> exception is thrown when an attempt to add a
  104. parallel edge to the supplied MutableGraph fails. The GraphML format
  105. supports parallel edges, but some BGL-compatible graph types do not.
  106. One example of such a graph is <tt class="docutils literal"><span class="pre">boost::adjacency_list&lt;setS,vecS&gt;</span></tt>,
  107. which allows at most one edge can between any two vertices.</p>
  108. <p>The <tt class="docutils literal"><span class="pre">directed_graph_error</span></tt> exception occurs when an undirected graph
  109. type is passed to <tt class="docutils literal"><span class="pre">read_graph</span></tt>, but the graph defined in the GraphML
  110. file contains at least one directed edge.</p>
  111. <p>The <tt class="docutils literal"><span class="pre">undirected_graph_error</span></tt> exception occurs when a directed graph
  112. type is passed to <tt class="docutils literal"><span class="pre">read_graph</span></tt>, but the graph defined in the GraphML
  113. file contains at least one undirected edge.</p>
  114. <p>The <tt class="docutils literal"><span class="pre">parse_error</span></tt> exception occurs when a syntax error is
  115. encountered in the GraphML file. The error string will contain the
  116. line and column where the error was encountered.</p>
  117. </div>
  118. <div class="section" id="building-the-graphml-reader">
  119. <h1><a class="toc-backref" href="#id4">Building the GraphML reader</a></h1>
  120. <p>To use the GraphML reader, you will need to build and link against
  121. the &quot;boost_graph&quot; library. The library can be built by following the
  122. <a class="reference external" href="../../../more/getting_started.html#Build_Install">Boost Jam Build Instructions</a> for the subdirectory <tt class="docutils literal"><span class="pre">libs/graph/build</span></tt>.</p>
  123. </div>
  124. <div class="section" id="notes">
  125. <h1><a class="toc-backref" href="#id5">Notes</a></h1>
  126. <blockquote>
  127. <ul class="simple">
  128. <li>On successful reading of a graph, every vertex and edge will have
  129. an associated value for every respective edge and vertex property
  130. encountered while interpreting the graph. These values will be set
  131. using the <tt class="docutils literal"><span class="pre">dynamic_properties</span></tt> object. Some properties may be
  132. <tt class="docutils literal"><span class="pre">put</span></tt> multiple times during the course of reading in order to
  133. ensure the GraphML semantics. Those edges and vertices that are
  134. not explicitly given a value for a property (and that property has
  135. no default) will be given the default constructed value of the
  136. value type. <strong>Be sure that property map value types are default
  137. constructible.</strong></li>
  138. <li>Nested graphs are supported as long as they are exactly of the same
  139. type as the root graph, i.e., are also directed or undirected. Note
  140. that since nested graphs are not directly supported by BGL, they
  141. are in fact completely ignored when building the graph, and the
  142. internal vertices or edges are interpreted as belonging to the root
  143. graph.</li>
  144. <li>Hyperedges and Ports are not supported.</li>
  145. </ul>
  146. </blockquote>
  147. </div>
  148. <div class="section" id="see-also">
  149. <h1><a class="toc-backref" href="#id6">See Also</a></h1>
  150. <p><a class="reference external" href="write_graphml.html">write_graphml</a></p>
  151. </div>
  152. </div>
  153. <div class="footer">
  154. <hr class="footer" />
  155. Generated on: 2012-11-12 22:25 UTC.
  156. Generated 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.
  157. </div>
  158. </body>
  159. </html>