Boost C++ Libraries: Ticket #10105: graphml attribute type mapping for types not in specification https://svn.boost.org/trac10/ticket/10105 <p> At the moment, <code>write_graphml</code> tries to convert non-standard attribute value types (that are not in specification) which it got from <code>dynamic_properties</code>, to standard ones. A type is converted to a simple form, say <code>unsigned int</code> to <code>int</code>, etc, by a predefined mapping in <code>write_graphml</code>: <code>value_types</code> and <code>type_names</code>. The conversion only affects graph metainformation (<code>&lt;graphml&gt;</code>'s <code>&lt;key&gt;</code> elements): conversion of an attribute value to a string is done by dynamic properties in <code>dynamic_property-&gt;get_string()</code> (that is, the value is actually never converted by the writing function). </p> <p> On the other hand, <code>read_graphml</code> tries to use type info from <code>&lt;key&gt;</code> elements and converts a string to the specified type and then passes it to dynamic property map as a <code>boost::any</code> instance. If a property map is passed to dynamic_properties that has non-standard value_type (not in <code>boost::mutate_graph_impl::value_types</code> list), but still "supported", like <code>unsigned int</code>, the <code>read_graphml</code> first checks if value types match and then, because they are not, unconditionally <code>any_cast</code>'s to <code>std::string</code>, which fails with <code>bad_any_cast</code> being thrown. </p> <p> This is unfortunate - a user has a promise that some attribute types are supported during writing, but then she can't read it back to the same property map. </p> <p> On the contrary, <code>read_graphvis</code> doesn't try to convert an attribute value before passing it to <code>dynamic_property_map</code>, due to the fact that graphvis files contain no type information :). In its turn, a <code>dynamic_property_map</code> converts passed <code>std::string</code> to its value type successfully. </p> <p> Maybe a better strategy is: </p> <p> 1) in <code>write_graphml</code>, write attribute types as currently done. </p> <p> 2) in <code>read_graphml</code>, disregard attribute type information and convert string representations to values in a <code>dynamic_property_map</code>. A more sophisticated and maybe type-safe alternative is to use a more complicated logic and check <code>dynamic_property_map-&gt;value()</code> for every possible matching value type in <code>write_graphml::value_types</code> for a given type name from <code>write_graphml::type_names</code>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10105 Trac 1.4.3