Boost logo

Boost Users :

Subject: [Boost-users] How to replace the std::string to myown string in boost::filesystem
From: SONGFY (911songfeiyu_at_[hidden])
Date: 2010-07-12 03:44:04


    For the changing of the std::string allocator, I retypedef the std::string to my string, just like this:
namespace MyNamespace
{
   template<typename Elem, typename Traits>
    class basic_string : public std::basic_string<Elem, Traits, STLAllocator<Elem> >
    {
        // reimplement the typedefs and constructors.
    };
 
    typedef basic_string<char, std::char_traits<char> > string;
    typedef basic_string<wchar_t, std::char_traits<wchar_t> > wstring;
}
So I want the boost::filesystem use my own string type, but I met some problem:
The code like this:
namespace MyNamespace
{
    struct path_traits;
    typedef boost::filesystem::basic_path<string, path_traits> path;
    typedef boost::filesystem::basic_path<wstring, path_traits> wpath;
    struct path_traits
    {
        typedef string internal_string_type;
        typedef string external_string_type;
        static external_string_type to_external( const path &,
            const internal_string_type & src ) { return src; }
        static internal_string_type to_internal(
            const external_string_type & src ) { return src; }
    };
    typedef boost::filesystem::basic_recursive_directory_iterator<path> recursive_directory_iterator;
    typedef boost::filesystem::basic_recursive_directory_iterator<wpath> wrecursive_directory_iterator;
}
 
namespace boost
{
namespace filesystem
{
    template<> struct is_basic_path<MyNamespace::path>
      { BOOST_STATIC_CONSTANT( bool, value = true ); };
    template<> struct is_basic_path<MyNamespace::wpath>
      { BOOST_STATIC_CONSTANT( bool, value = true ); };
}
}
 
namespace MyNamespace
{
    inline bool is_directory( const path & ph )
      { return boost::filesystem::is_directory<path>( ph ); }
    inline bool is_directory( const wpath & ph )
      { return boost::filesystem::is_directory<wpath>( ph ); }
}

For replace all the function is a huge work, and in this way I can not replace it for I met this function:
BOOST_FILESYSTEM_DECL file_status
        status_api( const std::string & ph, system::error_code & ec );
 
Maybe this way is too bother, I think there must be an easy way to replace the string.
Is there any way to resolve this? Thank you.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net