mirror of
https://github.com/boostorg/graph.git
synced 2025-05-09 23:14:00 +00:00
Re-enabled Spirit-based parser (but not by default) and cleaned up Graphviz reader implementation
[SVN r60770]
This commit is contained in:
parent
0f4d9c80a1
commit
1ba64f82ec
@ -89,26 +89,18 @@ namespace read_graphviz_detail {
|
||||
|
||||
} // namespace read_graphviz_detail
|
||||
|
||||
// This is also in boost/graph/graphviz.hpp
|
||||
namespace detail {
|
||||
namespace graph {
|
||||
BOOST_GRAPH_DECL bool read_graphviz(const std::string& str, boost::detail::graph::mutate_graph* mg);
|
||||
BOOST_GRAPH_DECL bool read_graphviz_new(const std::string& str, boost::detail::graph::mutate_graph* mg);
|
||||
} // end namespace graph
|
||||
} // end namespace detail
|
||||
|
||||
template <typename MutableGraph>
|
||||
bool read_graphviz(const std::string& str,
|
||||
MutableGraph& graph, boost::dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
bool read_graphviz_new(const std::string& str,
|
||||
MutableGraph& graph, boost::dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
boost::detail::graph::mutate_graph_impl<MutableGraph> mg(graph, dp, node_id);
|
||||
return detail::graph::read_graphviz(str, &mg);
|
||||
}
|
||||
|
||||
template <typename InputIter, typename MutableGraph>
|
||||
bool read_graphviz(InputIter begin, InputIter end,
|
||||
MutableGraph& graph, boost::dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
return read_graphviz(std::string(begin, end), graph, dp, node_id);
|
||||
return detail::graph::read_graphviz_new(str, &mg);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
@ -581,9 +581,9 @@ struct dot_skipper : public boost::spirit::classic::grammar<dot_skipper>
|
||||
} // namespace detail
|
||||
|
||||
template <typename MultiPassIterator, typename MutableGraph>
|
||||
bool read_graphviz(MultiPassIterator begin, MultiPassIterator end,
|
||||
MutableGraph& graph, dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
bool read_graphviz_spirit(MultiPassIterator begin, MultiPassIterator end,
|
||||
MutableGraph& graph, dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
using namespace boost;
|
||||
using namespace boost::spirit::classic;
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <boost/property_map/dynamic_property_map.hpp>
|
||||
#include <boost/graph/overloading.hpp>
|
||||
#include <boost/graph/dll_import_export.hpp>
|
||||
#include <boost/spirit/include/classic_multi_pass.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -771,26 +772,7 @@ class mutate_graph_impl : public mutate_graph
|
||||
std::map<edge_t, bgl_edge_t> bgl_edges;
|
||||
};
|
||||
|
||||
BOOST_GRAPH_DECL
|
||||
bool read_graphviz(std::istream& in, mutate_graph& graph);
|
||||
|
||||
} } // end namespace detail::graph
|
||||
|
||||
// Parse the passed stream as a GraphViz dot file.
|
||||
template <typename MutableGraph>
|
||||
bool read_graphviz(std::istream& in, MutableGraph& graph,
|
||||
dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id")
|
||||
{
|
||||
std::string data;
|
||||
in >> std::noskipws;
|
||||
std::copy(std::istream_iterator<char>(in),
|
||||
std::istream_iterator<char>(),
|
||||
std::back_inserter(data));
|
||||
return read_graphviz(data,graph,dp,node_id);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
} } } // end namespace boost::detail::graph
|
||||
|
||||
#ifdef BOOST_GRAPH_USE_SPIRIT_PARSER
|
||||
# ifndef BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS
|
||||
@ -801,6 +783,54 @@ bool read_graphviz(std::istream& in, MutableGraph& graph,
|
||||
# include <boost/graph/detail/read_graphviz_new.hpp>
|
||||
#endif // BOOST_GRAPH_USE_SPIRIT_PARSER
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Parse the passed string as a GraphViz dot file.
|
||||
template <typename MutableGraph>
|
||||
bool read_graphviz(const std::string& data,
|
||||
MutableGraph& graph,
|
||||
dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
#ifdef BOOST_GRAPH_USE_SPIRIT_PARSER
|
||||
return read_graphviz_spirit(data.begin(), data.end(), graph, dp, node_id);
|
||||
#else // Non-Spirit parser
|
||||
return read_graphviz_new(data,graph,dp,node_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Parse the passed iterator range as a GraphViz dot file.
|
||||
template <typename InputIterator, typename MutableGraph>
|
||||
bool read_graphviz(InputIterator user_first,
|
||||
InputIterator user_last,
|
||||
MutableGraph& graph,
|
||||
dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id") {
|
||||
#ifdef BOOST_GRAPH_USE_SPIRIT_PARSER
|
||||
typedef InputIterator is_t;
|
||||
typedef boost::spirit::classic::multi_pass<is_t> iterator_t;
|
||||
|
||||
iterator_t first(boost::spirit::classic::make_multi_pass(user_first));
|
||||
iterator_t last(boost::spirit::classic::make_multi_pass(user_last));
|
||||
|
||||
return read_graphviz_spirit(first, last, graph, dp, node_id);
|
||||
#else // Non-Spirit parser
|
||||
return read_graphviz_new(std::string(user_first, user_last), graph, dp, node_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Parse the passed stream as a GraphViz dot file.
|
||||
template <typename MutableGraph>
|
||||
bool read_graphviz(std::istream& in, MutableGraph& graph,
|
||||
dynamic_properties& dp,
|
||||
std::string const& node_id = "node_id")
|
||||
{
|
||||
typedef std::istream_iterator<char> is_t;
|
||||
in >> std::noskipws;
|
||||
return read_graphviz(is_t(in), is_t(), graph, dp, node_id);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_GRAPH_USE_MPI
|
||||
# include <boost/graph/distributed/graphviz.hpp>
|
||||
#endif
|
||||
|
@ -793,7 +793,7 @@ namespace read_graphviz_detail {
|
||||
namespace detail {
|
||||
namespace graph {
|
||||
|
||||
BOOST_GRAPH_DECL bool read_graphviz(const std::string& str, boost::detail::graph::mutate_graph* mg) {
|
||||
BOOST_GRAPH_DECL bool read_graphviz_new(const std::string& str, boost::detail::graph::mutate_graph* mg) {
|
||||
read_graphviz_detail::parser_result parsed_file;
|
||||
read_graphviz_detail::parse_graphviz_from_string(str, parsed_file, mg->is_directed());
|
||||
read_graphviz_detail::translate_results_to_graph(parsed_file, mg);
|
||||
|
@ -1,47 +0,0 @@
|
||||
// Copyright 2004-5 Trustees of Indiana University
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
//
|
||||
// read_graphviz_spirit.hpp -
|
||||
// Initialize a model of the BGL's MutableGraph concept and an associated
|
||||
// collection of property maps using a graph expressed in the GraphViz
|
||||
// DOT Language.
|
||||
//
|
||||
// Based on the grammar found at:
|
||||
// http://www.graphviz.org/cvs/doc/info/lang.html
|
||||
//
|
||||
// See documentation for this code at:
|
||||
// http://www.boost.org/libs/graph/doc/read-graphviz.html
|
||||
//
|
||||
|
||||
// Authors: Ronald Garcia and Douglas Gregor
|
||||
//
|
||||
|
||||
#define BOOST_GRAPH_SOURCE
|
||||
|
||||
#ifndef BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS
|
||||
# define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS
|
||||
#endif
|
||||
#include <boost/graph/graphviz.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace boost { namespace detail { namespace graph {
|
||||
|
||||
#if 0
|
||||
BOOST_GRAPH_DECL
|
||||
bool read_graphviz(std::istream& in, mutate_graph& graph)
|
||||
{
|
||||
using namespace boost;
|
||||
|
||||
typedef std::istream_iterator<char> is_t;
|
||||
|
||||
std::string str((is_t(in)), is_t());
|
||||
|
||||
return read_graphviz(str.begin(), str.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
} } } // end namespace boost::detail::graph
|
Loading…
x
Reference in New Issue
Block a user