read_graphml.rst 6.0 KB

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