Boost logo

Boost :

Subject: Re: [boost] [property tree] boost::filesystem::path
From: Johan Råde (rade_at_[hidden])
Date: 2008-09-23 03:08:10


Johan Råde wrote:
> Currently there is a problem when you put and then get
> a boost::filesystem::path to/from a property tree.
> When you get the path, then the path is first read into a string.
> Then a stringstream is constructed, and the path is extracted from the
> stringstream.
> The problem is that when you extract a path from a stream
> and the path contains spaces, then the path is truncated at the first
> space.

The problem can be solved by adding the following code to
boost/propery_tree/detail/translator_implementation.hpp.
The only drawback I can see is that this introduces a dependency of property tree on basic_path.
Maybe one could forward declare basic_path instead.

--Johan Råde

----------------------------------------------------------------------------------

#include <boost/filesystem/path.hpp>

namespace boost { namespace property_tree { namespace detail {

template<class String, class Traits>
struct extractor<typename String::value_type, boost::filesystem::basic_path<String, Traits> >
{
     inline bool operator()(const std::basic_string<typename String::value_type>& data,
                            boost::filesystem::basic_path<String, Traits>& extracted,
                            const std::locale&) const
     {
         extracted = data;
         return true;
     }
};

template<class String, class Traits>
struct inserter<typename String::value_type, boost::filesystem::basic_path<String, Traits> >
{
     inline bool operator()(std::basic_string<typename String::value_type>& data,
                            const boost::filesystem::basic_path<String, Traits>& inserted,
                            const std::locale) const
     {
         data = inserted.string();
         return true;
     }
};

}}}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk