Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53213 - in trunk: boost/graph libs/graph/test
From: jewillco_at_[hidden]
Date: 2009-05-23 13:16:21


Author: jewillco
Date: 2009-05-23 13:16:20 EDT (Sat, 23 May 2009)
New Revision: 53213
URL: http://svn.boost.org/trac/boost/changeset/53213

Log:
Changed GraphML writer to escape strings; added test of this; fixes #2567
Text files modified:
   trunk/boost/graph/graphml.hpp | 11 +++++++----
   trunk/libs/graph/test/graphml_test.cpp | 6 +++++-
   trunk/libs/graph/test/graphml_test.xml | 7 ++++++-
   3 files changed, 18 insertions(+), 6 deletions(-)

Modified: trunk/boost/graph/graphml.hpp
==============================================================================
--- trunk/boost/graph/graphml.hpp (original)
+++ trunk/boost/graph/graphml.hpp 2009-05-23 13:16:20 EDT (Sat, 23 May 2009)
@@ -22,6 +22,7 @@
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/find.hpp>
 #include <boost/mpl/for_each.hpp>
+#include <boost/property_tree/detail/xml_parser_utils.hpp>
 #include <exception>
 #include <sstream>
 
@@ -226,6 +227,8 @@
     typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
     typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
 
+ using boost::property_tree::xml_parser::encode_char_entities;
+
     BOOST_STATIC_CONSTANT(bool,
                           graph_is_directed =
                           (is_convertible<directed_category*, directed_tag*>::value));
@@ -254,7 +257,7 @@
             continue;
         std::string type_name = "string";
         mpl::for_each<value_types>(get_type_name<value_types>(i->second->value(), type_names, type_name));
- out << " <key id=\"" << key_id << "\" for=\""
+ out << " <key id=\"" << encode_char_entities(key_id) << "\" for=\""
             << (i->second->key() == typeid(Graph) ? "graph" : (i->second->key() == typeid(vertex_descriptor) ? "node" : "edge")) << "\""
             << " attr.name=\"" << i->first << "\""
             << " attr.type=\"" << type_name << "\""
@@ -272,7 +275,7 @@
         if (i->second->key() == typeid(Graph))
         {
             out << " <data key=\"" << graph_key_ids[i->first] << "\">"
- << i->second->get_string(g) << "</data>\n";
+ << encode_char_entities(i->second->get_string(g)) << "</data>\n";
         }
     }
 
@@ -287,7 +290,7 @@
             if (i->second->key() == typeid(vertex_descriptor))
             {
                 out << " <data key=\"" << vertex_key_ids[i->first] << "\">"
- << i->second->get_string(*v) << "</data>\n";
+ << encode_char_entities(i->second->get_string(*v)) << "</data>\n";
             }
         }
         out << " </node>\n";
@@ -308,7 +311,7 @@
             if (i->second->key() == typeid(edge_descriptor))
             {
                 out << " <data key=\"" << edge_key_ids[i->first] << "\">"
- << i->second->get_string(*e) << "</data>\n";
+ << encode_char_entities(i->second->get_string(*e)) << "</data>\n";
             }
         }
         out << " </edge>\n";

Modified: trunk/libs/graph/test/graphml_test.cpp
==============================================================================
--- trunk/libs/graph/test/graphml_test.cpp (original)
+++ trunk/libs/graph/test/graphml_test.cpp 2009-05-23 13:16:20 EDT (Sat, 23 May 2009)
@@ -29,6 +29,7 @@
 #include <boost/graph/adjacency_list.hpp>
 #include <boost/graph/graphml.hpp>
 #include <fstream>
+#include <string>
 
 using namespace std;
 using namespace boost;
@@ -36,12 +37,14 @@
 int main(int argc, char** argv)
 {
     typedef adjacency_list<vecS,vecS,directedS,
- property<vertex_color_t,int>,
+ property<vertex_color_t,int,
+ property<vertex_name_t,string> >,
                            property<edge_weight_t,double> > graph_t;
     graph_t g;
     dynamic_properties dp;
     dp.property("foo",get(vertex_color_t(),g));
     dp.property("weight",get(edge_weight_t(),g));
+ dp.property("name",get(vertex_name_t(),g));
 
     ifstream ifile(argv[1]);
     read_graphml(ifile, g, dp);
@@ -62,6 +65,7 @@
     dynamic_properties dp2;
     dp2.property("foo",get(vertex_color_t(),g2));
     dp2.property("weight",get(edge_weight_t(),g2));
+ dp2.property("name",get(vertex_name_t(),g2));
     ifile.open("graphml_test_out.xml");
     read_graphml(ifile, g2, dp2);
     ifile.close();

Modified: trunk/libs/graph/test/graphml_test.xml
==============================================================================
--- trunk/libs/graph/test/graphml_test.xml (original)
+++ trunk/libs/graph/test/graphml_test.xml 2009-05-23 13:16:20 EDT (Sat, 23 May 2009)
@@ -15,6 +15,9 @@
   <key id="d2" for="edge" attr.name="weight" attr.type="double">
     <default>0.0</default>
   </key>
+ <key id="d3" for="node" attr.name="name" attr.type="string">
+ <default>hello</default>
+ </key>
 
   <graph id="G" edgedefault="directed">
     <node id="n0"/>
@@ -23,7 +26,9 @@
       <data key="d1">100</data>
     </node>
     <node id="n3"/>
- <node id="n4"/>
+ <node id="n4">
+ <data key="d3">foo&lt;</data>
+ </node>
     <node id="n5"/>
     <node id="n6">
         <data key="d1">0</data>


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