mirror of
https://github.com/boostorg/graph.git
synced 2025-05-11 05:14:01 +00:00
Added support for reading reliably from files with more than one GraphML graph
[SVN r81313]
This commit is contained in:
parent
1bb17dab63
commit
4495a409e5
@ -20,7 +20,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
|||||||
Authors: Tiago de Paula Peixoto -->
|
Authors: Tiago de Paula Peixoto -->
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
void read_graphml(std::istream& in, MutableGraph& graph,
|
void read_graphml(std::istream& in, MutableGraph& graph,
|
||||||
dynamic_properties& dp);
|
dynamic_properties& dp, size_t graph_index = 0);
|
||||||
</pre>
|
</pre>
|
||||||
<p>The <tt class="docutils literal"><span class="pre">read_graphml</span></tt> function interprets a graph described using the
|
<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
|
<a class="reference external" href="http://graphml.graphdrawing.org/">GraphML</a> format and builds a BGL graph that captures that
|
||||||
@ -39,6 +39,10 @@ this object, using the GraphML attribute names as the property names,
|
|||||||
and with the appropriate C++ value type based on the GraphML attribute type
|
and with the appropriate C++ value type based on the GraphML attribute type
|
||||||
definition. Graph properties are also set with the same
|
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>
|
<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">
|
<dl class="docutils">
|
||||||
<dt>Requirements:</dt>
|
<dt>Requirements:</dt>
|
||||||
<dd><ul class="first last simple">
|
<dd><ul class="first last simple">
|
||||||
@ -156,7 +160,7 @@ graph.</li>
|
|||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<hr 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.
|
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>
|
</div>
|
||||||
|
@ -19,7 +19,7 @@ __ ../../../index.htm
|
|||||||
::
|
::
|
||||||
|
|
||||||
void read_graphml(std::istream& in, MutableGraph& graph,
|
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
|
The ``read_graphml`` function interprets a graph described using the
|
||||||
@ -42,6 +42,11 @@ and with the appropriate C++ value type based on the GraphML attribute type
|
|||||||
definition. Graph properties are also set with the same
|
definition. Graph properties are also set with the same
|
||||||
dynamic_properties_ object, where the key type is the type of the graph itself.
|
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:
|
Requirements:
|
||||||
- The type of the graph must model the `Mutable Graph`_ concept.
|
- The type of the graph must model the `Mutable Graph`_ concept.
|
||||||
- The type of the iterator must model the `Multi-Pass Iterator`_
|
- The type of the iterator must model the `Multi-Pass Iterator`_
|
||||||
|
@ -204,14 +204,14 @@ template<typename MutableGraph>
|
|||||||
const char* mutate_graph_impl<MutableGraph>::m_type_names[] = {"boolean", "int", "long", "float", "double", "string"};
|
const char* mutate_graph_impl<MutableGraph>::m_type_names[] = {"boolean", "int", "long", "float", "double", "string"};
|
||||||
|
|
||||||
void BOOST_GRAPH_DECL
|
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>
|
template<typename MutableGraph>
|
||||||
void
|
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);
|
mutate_graph_impl<MutableGraph> mg(g,dp);
|
||||||
read_graphml(in, mg);
|
read_graphml(in, mg, desired_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Types>
|
template <typename Types>
|
||||||
|
@ -34,17 +34,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void get_graphs(const boost::property_tree::ptree& top,
|
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) {
|
std::vector<const boost::property_tree::ptree*>& result) {
|
||||||
using boost::property_tree::ptree;
|
using boost::property_tree::ptree;
|
||||||
|
size_t current_idx = 0;
|
||||||
BOOST_FOREACH(const ptree::value_type& n, top) {
|
BOOST_FOREACH(const ptree::value_type& n, top) {
|
||||||
if (n.first == "graph") {
|
if (n.first == "graph") {
|
||||||
result.push_back(&n.second);
|
if (current_idx == desired_idx || desired_idx == (size_t)(-1)) {
|
||||||
get_graphs(n.second, result);
|
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;
|
using boost::property_tree::ptree;
|
||||||
ptree pt;
|
ptree pt;
|
||||||
@ -74,7 +80,7 @@ public:
|
|||||||
}
|
}
|
||||||
// Search for graphs
|
// Search for graphs
|
||||||
std::vector<const ptree*> graphs;
|
std::vector<const ptree*> graphs;
|
||||||
get_graphs(gml, graphs);
|
get_graphs(gml, desired_idx, graphs);
|
||||||
BOOST_FOREACH(const ptree* gr, graphs) {
|
BOOST_FOREACH(const ptree* gr, graphs) {
|
||||||
// Search for nodes
|
// Search for nodes
|
||||||
BOOST_FOREACH(const ptree::value_type& node, *gr) {
|
BOOST_FOREACH(const ptree::value_type& node, *gr) {
|
||||||
@ -209,9 +215,9 @@ private:
|
|||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
void BOOST_GRAPH_DECL
|
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);
|
graphml_reader reader(g);
|
||||||
reader.run(in);
|
reader.run(in, desired_idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user