Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:11

0001 // Copyright 2004-9 Trustees of Indiana University
0002 
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //
0008 // read_graphviz_new.hpp -
0009 //   Initialize a model of the BGL's MutableGraph concept and an associated
0010 //  collection of property maps using a graph expressed in the GraphViz
0011 // DOT Language.
0012 //
0013 //   Based on the grammar found at:
0014 //   https://web.archive.org/web/20041213234742/http://www.graphviz.org/cvs/doc/info/lang.html
0015 //
0016 //   Jeremiah rewrite used grammar found at:
0017 //   http://www.graphviz.org/doc/info/lang.html
0018 //   and page 34 or http://www.graphviz.org/pdf/dotguide.pdf
0019 //
0020 //   See documentation for this code at:
0021 //     http://www.boost.org/libs/graph/doc/read_graphviz.html
0022 //
0023 
0024 // Author: Jeremiah Willcock
0025 //         Ronald Garcia
0026 //
0027 
0028 #ifndef BOOST_READ_GRAPHVIZ_NEW_HPP
0029 #define BOOST_READ_GRAPHVIZ_NEW_HPP
0030 
0031 #include <boost/ref.hpp>
0032 #include <boost/property_map/dynamic_property_map.hpp>
0033 #include <boost/graph/graph_traits.hpp>
0034 #include <boost/detail/workaround.hpp>
0035 #include <algorithm>
0036 #include <string>
0037 #include <vector>
0038 #include <set>
0039 #include <utility>
0040 #include <map>
0041 #include <iostream>
0042 #include <cstdlib>
0043 
0044 namespace boost
0045 {
0046 
0047 namespace read_graphviz_detail
0048 {
0049     typedef std::string node_name;
0050     typedef std::string subgraph_name;
0051 
0052     typedef std::map< std::string, std::string > properties;
0053 
0054     struct node_and_port
0055     {
0056         node_name name;
0057         std::string angle; // Or empty if no angle
0058         std::vector< std::string > location; // Up to two identifiers
0059 
0060         friend inline bool operator==(
0061             const node_and_port& a, const node_and_port& b)
0062         {
0063             return a.name == b.name && a.angle == b.angle
0064                 && a.location == b.location;
0065         }
0066 
0067         friend inline bool operator<(
0068             const node_and_port& a, const node_and_port& b)
0069         {
0070             if (a.name != b.name)
0071                 return a.name < b.name;
0072             if (a.angle != b.angle)
0073                 return a.angle < b.angle;
0074             return a.location < b.location;
0075         }
0076     };
0077 
0078     struct edge_info
0079     {
0080         node_and_port source;
0081         node_and_port target;
0082         properties props;
0083     };
0084 
0085     struct parser_result
0086     {
0087         bool graph_is_directed;
0088         bool graph_is_strict;
0089         std::map< node_name, properties > nodes; // Global set
0090         std::vector< edge_info > edges;
0091         std::map< subgraph_name, properties > graph_props; // Root and subgraphs
0092     };
0093 
0094     // The actual parser, from libs/graph/src/read_graphviz_new.cpp
0095     void parse_graphviz_from_string(
0096         const std::string& str, parser_result& result, bool want_directed);
0097 
0098     // Translate from those results to a graph
0099     void translate_results_to_graph(
0100         const parser_result& r, ::boost::detail::graph::mutate_graph* mg);
0101 
0102 } // namespace read_graphviz_detail
0103 
0104 namespace detail
0105 {
0106     namespace graph
0107     {
0108         BOOST_GRAPH_DECL bool read_graphviz_new(
0109             const std::string& str, boost::detail::graph::mutate_graph* mg);
0110     } // end namespace graph
0111 } // end namespace detail
0112 
0113 template < typename MutableGraph >
0114 bool read_graphviz_new(const std::string& str, MutableGraph& graph,
0115     boost::dynamic_properties& dp, std::string const& node_id = "node_id")
0116 {
0117     boost::detail::graph::mutate_graph_impl< MutableGraph > mg(
0118         graph, dp, node_id);
0119     return detail::graph::read_graphviz_new(str, &mg);
0120 }
0121 
0122 } // namespace boost
0123 
0124 #endif // BOOST_READ_GRAPHVIZ_NEW_HPP