From 1ba64f82ec5c164c68f68cc1a9d7e60eeea57006 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Mon, 22 Mar 2010 19:16:38 +0000 Subject: [PATCH] Re-enabled Spirit-based parser (but not by default) and cleaned up Graphviz reader implementation [SVN r60770] --- .../boost/graph/detail/read_graphviz_new.hpp | 18 ++--- .../graph/detail/read_graphviz_spirit.hpp | 6 +- include/boost/graph/graphviz.hpp | 70 +++++++++++++------ src/read_graphviz_new.cpp | 2 +- src/read_graphviz_spirit.cpp | 47 ------------- 5 files changed, 59 insertions(+), 84 deletions(-) delete mode 100644 src/read_graphviz_spirit.cpp diff --git a/include/boost/graph/detail/read_graphviz_new.hpp b/include/boost/graph/detail/read_graphviz_new.hpp index 215f9ef9..7c7986dc 100644 --- a/include/boost/graph/detail/read_graphviz_new.hpp +++ b/include/boost/graph/detail/read_graphviz_new.hpp @@ -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 -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 mg(graph, dp, node_id); - return detail::graph::read_graphviz(str, &mg); -} - -template -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 diff --git a/include/boost/graph/detail/read_graphviz_spirit.hpp b/include/boost/graph/detail/read_graphviz_spirit.hpp index 815befe9..4e8b22e5 100644 --- a/include/boost/graph/detail/read_graphviz_spirit.hpp +++ b/include/boost/graph/detail/read_graphviz_spirit.hpp @@ -581,9 +581,9 @@ struct dot_skipper : public boost::spirit::classic::grammar } // namespace detail template -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; diff --git a/include/boost/graph/graphviz.hpp b/include/boost/graph/graphviz.hpp index 52f3468a..a41116d0 100644 --- a/include/boost/graph/graphviz.hpp +++ b/include/boost/graph/graphviz.hpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace boost { @@ -771,26 +772,7 @@ class mutate_graph_impl : public mutate_graph std::map 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 -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(in), - std::istream_iterator(), - 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 #endif // BOOST_GRAPH_USE_SPIRIT_PARSER +namespace boost { + +// Parse the passed string as a GraphViz dot file. +template +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 +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 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 +bool read_graphviz(std::istream& in, MutableGraph& graph, + dynamic_properties& dp, + std::string const& node_id = "node_id") +{ + typedef std::istream_iterator 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 #endif diff --git a/src/read_graphviz_new.cpp b/src/read_graphviz_new.cpp index 7da57788..9e87ca23 100644 --- a/src/read_graphviz_new.cpp +++ b/src/read_graphviz_new.cpp @@ -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); diff --git a/src/read_graphviz_spirit.cpp b/src/read_graphviz_spirit.cpp deleted file mode 100644 index 7fcdc280..00000000 --- a/src/read_graphviz_spirit.cpp +++ /dev/null @@ -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 -#include - -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 is_t; - - std::string str((is_t(in)), is_t()); - - return read_graphviz(str.begin(), str.end()); -} -#endif - -} } } // end namespace boost::detail::graph