From 4f5989b7e35050bee7b226b48e21e872d3c22845 Mon Sep 17 00:00:00 2001 From: Hussien Hussien Date: Wed, 7 Jun 2017 23:27:41 -0400 Subject: [PATCH] Patch graphml.hpp Fix serialization of boolean attribute values from '1' or '0' to 'true' or 'false' per this ticket: https://svn.boost.org/trac/boost/ticket/11092 --- include/boost/graph/graphml.hpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/boost/graph/graphml.hpp b/include/boost/graph/graphml.hpp index a7faa647..32953ddb 100644 --- a/include/boost/graph/graphml.hpp +++ b/include/boost/graph/graphml.hpp @@ -289,10 +289,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, { if (i->second->key() == typeid(Graph*)) { + std::string type_name = "string"; + mpl::for_each(get_type_name(i->second->value(), type_names, type_name)); // The const_cast here is just to get typeid correct for property // map key; the graph should not be mutated using it. out << " first] << "\">" - << encode_char_entities(i->second->get_string(const_cast(&g))) << "\n"; + << (type_name == "boolean" ? (i->second->get_string(const_cast(&g)) == "1" ? "true" : "false") + : encode_char_entities(i->second->get_string(const_cast(&g)))) << "\n"; } } @@ -306,8 +309,11 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, { if (i->second->key() == typeid(vertex_descriptor)) { + std::string type_name = "string"; + mpl::for_each(get_type_name(i->second->value(), type_names, type_name)); out << " first] << "\">" - << encode_char_entities(i->second->get_string(*v)) << "\n"; + << (type_name == "boolean" ? (i->second->get_string((*v)) == "1" ? "true" : "false") + : encode_char_entities(i->second->get_string(*v))) << "\n"; } } out << " \n"; @@ -327,8 +333,11 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, { if (i->second->key() == typeid(edge_descriptor)) { + std::string type_name = "string"; + mpl::for_each(get_type_name(i->second->value(), type_names, type_name)); out << " first] << "\">" - << encode_char_entities(i->second->get_string(*e)) << "\n"; + << (type_name == "boolean" ? (i->second->get_string((*e)) == "1" ? "true" : "false") + : encode_char_entities(i->second->get_string(*e))) << "\n"; } } out << " \n";