Boost logo

Boost Users :

Subject: [Boost-users] Problem to substitute the std allocator with boost.asio and boost.filesystem
From: watsonsong (911songfeiyu_at_[hidden])
Date: 2010-08-02 04:28:53


I subsitute the std allocator with my own stl allocator, and defined a new
string type like this:

typedef std::basic_string<char, std::char_traits<char>, MySTLAllocator<char>
> my_string;
typedef std::basic_string<wchar_t, std::char_traits<wchar_t>,
MySTLAllocator<wchar_t> > my_wstring;

And I want to use them in my project, but I met some problem when I use
boost.asio and boost.filesystem.

The boost asio directly use std::string, I can not find a way to deal with
it. I know I can pass a c style string char* to the asio, but it was less
efficiency.

When use the boost.filesystem, I tried this way, but I also met some
problem:
namespace MyNamespace
{
    struct path_traits;
    typedef boost::filesystem::basic_path<my_string, path_traits> path;
    typedef boost::filesystem::basic_path<my_wstring, path_traits> wpath;
    struct path_traits
    {
        typedef my_string internal_string_type;
        typedef my_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, which is also use the std::string
directly:
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.

-- 
View this message in context: http://old.nabble.com/Problem-to-substitute-the-std-allocator-with-boost.asio-and-boost.filesystem-tp29322995p29322995.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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