|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81313 - in trunk: boost/graph libs/graph/doc libs/graph/src
From: jewillco_at_[hidden]
Date: 2012-11-12 17:30:19
Author: jewillco
Date: 2012-11-12 17:30:19 EST (Mon, 12 Nov 2012)
New Revision: 81313
URL: http://svn.boost.org/trac/boost/changeset/81313
Log:
Added support for reading reliably from files with more than one GraphML graph
Text files modified:
trunk/boost/graph/graphml.hpp | 6 +++---
trunk/libs/graph/doc/read_graphml.html | 8 ++++++--
trunk/libs/graph/doc/read_graphml.rst | 7 ++++++-
trunk/libs/graph/src/graphml.cpp | 18 ++++++++++++------
4 files changed, 27 insertions(+), 12 deletions(-)
Modified: trunk/boost/graph/graphml.hpp
==============================================================================
--- trunk/boost/graph/graphml.hpp (original)
+++ trunk/boost/graph/graphml.hpp 2012-11-12 17:30:19 EST (Mon, 12 Nov 2012)
@@ -204,14 +204,14 @@
const char* mutate_graph_impl<MutableGraph>::m_type_names[] = {"boolean", "int", "long", "float", "double", "string"};
void BOOST_GRAPH_DECL
-read_graphml(std::istream& in, mutate_graph& g);
+read_graphml(std::istream& in, mutate_graph& g, size_t desired_idx);
template<typename MutableGraph>
void
-read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp)
+read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp, size_t desired_idx = 0)
{
mutate_graph_impl<MutableGraph> mg(g,dp);
- read_graphml(in, mg);
+ read_graphml(in, mg, desired_idx);
}
template <typename Types>
Modified: trunk/libs/graph/doc/read_graphml.html
==============================================================================
--- trunk/libs/graph/doc/read_graphml.html (original)
+++ trunk/libs/graph/doc/read_graphml.html 2012-11-12 17:30:19 EST (Mon, 12 Nov 2012)
@@ -20,7 +20,7 @@
Authors: Tiago de Paula Peixoto -->
<pre class="literal-block">
void read_graphml(std::istream& in, MutableGraph& graph,
- dynamic_properties& dp);
+ dynamic_properties& dp, size_t graph_index = 0);
</pre>
<p>The <tt class="docutils literal"><span class="pre">read_graphml</span></tt> function interprets a graph described using the
<a class="reference external" href="http://graphml.graphdrawing.org/">GraphML</a> format and builds a BGL graph that captures that
@@ -39,6 +39,10 @@
and with the appropriate C++ value type based on the GraphML attribute type
definition. Graph properties are also set with the same
<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>
+<p>If the file contains multiple graphs, the <tt class="docutils literal"><span class="pre">graph_index</span></tt> parameter controls
+which graph will be loaded. It defaults to <tt class="docutils literal"><span class="pre">0</span></tt>, meaning that the first graph
+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
+number of graphs in the file, an empty graph will be returned.</p>
<dl class="docutils">
<dt>Requirements:</dt>
<dd><ul class="first last simple">
@@ -156,7 +160,7 @@
</div>
<div class="footer">
<hr class="footer" />
-Generated on: 2009-06-12 00:41 UTC.
+Generated on: 2012-11-12 22:25 UTC.
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.
</div>
Modified: trunk/libs/graph/doc/read_graphml.rst
==============================================================================
--- trunk/libs/graph/doc/read_graphml.rst (original)
+++ trunk/libs/graph/doc/read_graphml.rst 2012-11-12 17:30:19 EST (Mon, 12 Nov 2012)
@@ -19,7 +19,7 @@
::
void read_graphml(std::istream& in, MutableGraph& graph,
- dynamic_properties& dp);
+ dynamic_properties& dp, size_t graph_index = 0);
The ``read_graphml`` function interprets a graph described using the
@@ -42,6 +42,11 @@
definition. Graph properties are also set with the same
dynamic_properties_ object, where the key type is the type of the graph itself.
+If the file contains multiple graphs, the ``graph_index`` parameter controls
+which graph will be loaded. It defaults to ``0``, meaning that the first graph
+in the file will be loaded. If ``graph_index`` is greater than or equal to the
+number of graphs in the file, an empty graph will be returned.
+
Requirements:
- The type of the graph must model the `Mutable Graph`_ concept.
- The type of the iterator must model the `Multi-Pass Iterator`_
Modified: trunk/libs/graph/src/graphml.cpp
==============================================================================
--- trunk/libs/graph/src/graphml.cpp (original)
+++ trunk/libs/graph/src/graphml.cpp 2012-11-12 17:30:19 EST (Mon, 12 Nov 2012)
@@ -34,17 +34,23 @@
}
static void get_graphs(const boost::property_tree::ptree& top,
+ size_t desired_idx /* or -1 for all */,
std::vector<const boost::property_tree::ptree*>& result) {
using boost::property_tree::ptree;
+ size_t current_idx = 0;
BOOST_FOREACH(const ptree::value_type& n, top) {
if (n.first == "graph") {
- result.push_back(&n.second);
- get_graphs(n.second, result);
+ if (current_idx == desired_idx || desired_idx == (size_t)(-1)) {
+ result.push_back(&n.second);
+ get_graphs(n.second, (size_t)(-1), result);
+ if (desired_idx != (size_t)(-1)) break;
+ }
+ ++current_idx;
}
}
}
- void run(std::istream& in)
+ void run(std::istream& in, size_t desired_idx)
{
using boost::property_tree::ptree;
ptree pt;
@@ -74,7 +80,7 @@
}
// Search for graphs
std::vector<const ptree*> graphs;
- get_graphs(gml, graphs);
+ get_graphs(gml, desired_idx, graphs);
BOOST_FOREACH(const ptree* gr, graphs) {
// Search for nodes
BOOST_FOREACH(const ptree::value_type& node, *gr) {
@@ -209,9 +215,9 @@
namespace boost
{
void BOOST_GRAPH_DECL
-read_graphml(std::istream& in, mutate_graph& g)
+read_graphml(std::istream& in, mutate_graph& g, size_t desired_idx)
{
graphml_reader reader(g);
- reader.run(in);
+ reader.run(in, desired_idx);
}
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk