[property_tree] handling of filesystem::path

property_tree::ptree does not handle filesystem::path values correctly if the path contains spaces. Here is a proposed fix and a test. The test succeeds, but if you comment out the patch, then the test fails. ---------------------------------------------------------------------------------- #include <boost/property_tree/ptree.hpp> // patch that fixes the problem namespace boost { namespace filesystem { template<class String, class PathTraits> class basic_path; }}; namespace boost { namespace property_tree { template<typename String, typename PathTraits> struct path_translator { typedef boost::filesystem::basic_path<String, PathTraits> Path; typedef String internal_type; typedef Path external_type; boost::optional<Path> get_value(const String& s) { return Path(s); } boost::optional<String> put_value(const Path &p) { return p.string(); } }; template <typename Char, typename StringTraits, typename Alloc, typename PathTraits> struct translator_between< std::basic_string<Char, StringTraits, Alloc>, boost::filesystem::basic_path<std::basic_string<Char, StringTraits, Alloc>, PathTraits> > { typedef std::basic_string<Char, StringTraits, Alloc> String; typedef path_translator<String, PathTraits> type; }; }} // a simple test #include <boost/filesystem/path.hpp> #include <boost/optional.hpp> using boost::filesystem::path; using boost::optional; using boost::property_tree::ptree; int main() { path p1("a b"); ptree t; t.put_value(p1); optional<path> p2 = t.get_value_optional<path>(); assert(p2); assert(p1 == *p2); }

Johan Råde wrote:
property_tree::ptree does not handle filesystem::path values correctly if the path contains spaces. That means that fs::path's streaming operators don't round-trip. That's a Boost.Filesystem bug, not a Boost.PropertyTree bug. Unless you can show that the streaming operators do round-trip, but PTree messes it up.
Sebastian

On Sun, Jun 13, 2010 at 7:23 AM, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Johan Råde wrote:
property_tree::ptree does not handle filesystem::path values correctly if the path contains spaces. That means that fs::path's streaming operators don't round-trip. That's a Boost.Filesystem bug, not a Boost.PropertyTree bug. Unless you can show that the streaming operators do round-trip, but PTree messes it up.
Agreed. See https://svn.boost.org/trac/boost/ticket/3863 I've been working filesystem tickets during the Bug Sprint, and plan to work this one within the next few days. --Beman

On 6/13/2010 5:42 PM, Beman Dawes wrote:
On Sun, Jun 13, 2010 at 7:23 AM, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Johan Råde wrote:
property_tree::ptree does not handle filesystem::path values correctly if the path contains spaces. That means that fs::path's streaming operators don't round-trip. That's a Boost.Filesystem bug, not a Boost.PropertyTree bug. Unless you can show that the streaming operators do round-trip, but PTree messes it up.
Agreed. See https://svn.boost.org/trac/boost/ticket/3863
I've been working filesystem tickets during the Bug Sprint, and plan to work this one within the next few days.
Maybe 1. The stream operators << and >> can not be implemented in a round-trippable way for fs::path 2. They should be removed from the filesystem library 3. property_tree should handle fs::path without relying on stream_translator
participants (3)
-
Beman Dawes
-
Johan Råde
-
Sebastian Redl